Skip to content

Commit 0088e95

Browse files
committed
demo collaborative text editor with yjs
0 parents  commit 0088e95

File tree

6 files changed

+352
-0
lines changed

6 files changed

+352
-0
lines changed

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 Piyush Chauhan
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Public/index.html

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Text-Editor</title>
6+
</head>
7+
<body>
8+
<textarea style="width: 100%; height: 500px;" id="textfield"></textarea>
9+
<script src="js/app.js"></script>
10+
</body>
11+
</html>

README.md

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Shared editing demo using IPFS and CRDT
2+
3+
> This codebase was developed to demostrate how to use IPFS in conjuction with [Y.js, a CRDT library](http://y-js.org/).
4+
5+
## Set up
6+
7+
### Pre-requisites
8+
9+
- Have Node.js version 6 or greater installed
10+
11+
### Install
12+
13+
```
14+
> git clone https://github.com/ipfs-labs/shared-editing-demo.git
15+
> cd shared-editing-demo
16+
> npm install
17+
```
18+
19+
### Build
20+
21+
```
22+
> npm run build
23+
```
24+
25+
### Run
26+
## Reference
27+
28+
Followed this video by IPFS[https://www.youtube.com/watch?v=-kdx8rJd8rQ](Youtube IPFS).
29+
30+
### Open in browser
31+
32+
Using a modern browser that supports WebRTC, like a recent version of Chrome or Firefox, open several windows of [http://localhost:12345](http://localhost:12345).
33+
34+
## Known issues
35+
36+
This Demo uses WebRTC to establish the connections between nodes. WebRTC is a CPU intensive protocol and not all Browsers will behave correctly, depending on their implementation of WebRTC or the resources available on the machine that they are running. This is a known issue and something the [js-ipfs team is looking at alternatives to solve](https://github.com/ipfs/js-ipfs/issues/962).
37+
38+
39+
## License
40+
41+
MIT

package-lock.json

+218
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "ipfs-text-editor",
3+
"version": "0.0.1",
4+
"description": "Yjs with IPFS",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1",
8+
"start": "http-server -c-1 -p 78945 public"
9+
},
10+
"author": "Piyush Chauhan <[email protected]>",
11+
"license": "MIT",
12+
"dependencies": {
13+
"browserify": "^14.4.0",
14+
"http-server": "^0.10.0",
15+
"ipfs": "^0.25.2",
16+
"y-array": "^10.1.4",
17+
"y-ipfs-connector": "^1.2.1",
18+
"y-memory": "^8.0.9",
19+
"y-text": "^9.5.1",
20+
"yjs": "^12.3.3"
21+
}
22+
}

src/app.js

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
const IPFS = require('ipfs')
2+
const Y = require('yjs')
3+
require('y-memory')(Y)
4+
require('y-array')(Y)
5+
require('y-text')(Y)
6+
require('y-ipfs-connector')(Y)
7+
8+
function repo () {
9+
return 'ipfs/yjs-demo/' + Math.random()
10+
}
11+
12+
const ipfs = new IPFS({
13+
repo: repo(),
14+
EXPERIMENTAL: {
15+
pubsub: true
16+
}
17+
})
18+
19+
ipfs.once('ready', () => ipfs.id((err, info) => {
20+
if (err) { throw err }
21+
22+
console.log('IPFS node ready with address ' + info.id)
23+
24+
Y({
25+
db: {
26+
name: 'memory'
27+
},
28+
connector: {
29+
name: 'ipfs',
30+
room: 'ipfs-yjs-demo',
31+
ipfs: ipfs
32+
},
33+
share: {
34+
textfield: 'Text'
35+
}
36+
}).then((y) => {
37+
y.share.textfield.bind(document.getElementById('textfield'))
38+
})
39+
}))

0 commit comments

Comments
 (0)