-
-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
95 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,47 @@ | ||
# WebRTC Connector for [Yjs](https://github.com/y-js/yjs) | ||
|
||
It propagates document updates directly to all users via WebRTC. While WebRTC is not the most reliable connector, messages are propagated with almost no delay. | ||
It propagates document updates directly to all users via WebRTC. | ||
|
||
* Very fast message propagation (not noticeable) | ||
* Very easy to use | ||
* Very little server load (you still have to set up a [signaling server](http://www.html5rocks.com/en/tutorials/webrtc/infrastructure/)) | ||
* Not suited for a large amount of collaborators | ||
* WebRTC is not supported in all browsers, and some have troubles communicating with each other | ||
* Fast message propagation | ||
* No setup required, a default signalling server is available | ||
* Very little server load | ||
* Not suited for a large amount of collaborators on a single document (each peer is connected to each other) | ||
|
||
We provide you with a free signaling server (it is used by default), but in production you should set up your own signaling server. You could use the [signalmaster](https://github.com/DadaMonad/signalmaster) from &yet, which is very easy to set up. | ||
## Setup | ||
|
||
## Use it! | ||
Retrieve this with bower or npm. | ||
##### Install | ||
|
||
##### NPM | ||
``` | ||
npm install y-webrtc --save | ||
```sh | ||
npm i y-webrtc | ||
``` | ||
|
||
##### Bower | ||
``` | ||
bower install y-webrtc --save | ||
##### Client code | ||
|
||
```js | ||
import * as Y from 'yjs' | ||
import { WebrtcProvider } from '../src/y-webrtc.js' | ||
|
||
const ydoc = new Y.Doc() | ||
const provider = new WebrtcProvider('prosemirror', ydoc) | ||
const yarray = ydoc.get('prosemirror', Y.XmlFragment) | ||
``` | ||
|
||
# Start Hacking | ||
This connector is also a nice starting point to build your own connector. The only 75 SLOCs of code are pretty well documented and understandable. If you have any troubles, don't hesitate to ask me for help! | ||
##### Signalling | ||
|
||
### Example | ||
The peers find each other by connecting to a signalling server. This package implements a small signalling server in `./bin/server.js`. | ||
|
||
``` | ||
Y({ | ||
db: { | ||
name: 'memory' | ||
}, | ||
connector: { | ||
name: 'webrtc', // use the webrtc connector | ||
room: 'Textarea-example-dev' | ||
}, | ||
sourceDir: '/bower_components', // location of the y-* modules | ||
share: { | ||
textarea: 'Text' // y.share.textarea is of type Y.Text | ||
} | ||
}).then(function (y) { | ||
// bind the textarea to a shared text element | ||
y.share.textarea.bind(document.getElementById('textfield')) | ||
} | ||
```sh | ||
# start signalling server | ||
PORT=4444 node ./bin/server.js | ||
``` | ||
|
||
# Set up Signaling server | ||
This webrtc connector is compatible to [this signaling server](https://github.com/DadaMonad/signalmaster) (signalmaster) | ||
Peers using the same signalling server will find each other. You can specify several custom signalling servers like so: | ||
|
||
```js | ||
const provider = new WebrtcProvider('prosemirror', ydoc, { signalling: ['wss://y-webrtc-ckynwnzncc.now.sh', 'ws://localhost:4444'] }) | ||
``` | ||
|
||
## License | ||
Yjs is licensed under the [MIT License](./LICENSE). | ||
|
||
<[email protected]> | ||
|
||
|
||
<[email protected]> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters