项目作者: abhishekgahlot

项目描述 :
P2P WebRTC based encrypted data transfer between peers.
高级语言: JavaScript
项目地址: git://github.com/abhishekgahlot/gutenberg-rtc.git
创建时间: 2017-06-28T12:27:59Z
项目社区:https://github.com/abhishekgahlot/gutenberg-rtc

开源协议:

下载


Gutenberg Collaborative Editing Plugin

Based on WebRTC


Installation

  1. npm install

Building

  1. npm run build

Local Server

  1. npm start

Testing

  1. npm test

Starting App

Peer starting collaboration has to generate a uuid using

  1. var grtcID = GRTC.uuid(); // static function

After that pass that to GRTC module

  1. window.history.pushState('', '', '#' + grtcID); // optional to add to url so can share with others.
  2. var grtc = new GRTC(grtcID, window.location.origin, true); // 3rd param is transport layer for encrypted session.

Peer not starting collaboration has to join and get that grtcID somehow possibly by sharing url


API

Events

  • ‘peerFound’
  • Checked via long polling to /get/grtcID route to server

    1. grtc.on('peerFound', function(peer){
    2. // peer => peer signal used for connection establishment
    3. });
  • ‘peerSignal’

  • Received from other peer as offer.

    1. grtc.on('peerSignal', function(signal){
    2. // signal => signal that is received from another peer.
    3. });
  • ‘peerConnected’

  • Emitted after peerSignal and connection is established.

    1. grtc.on('peerConnected', function(){
    2. // peer is connected.
    3. });
  • ‘peerData’

  • when data is received.
    1. grtc.on('peerData', function(data){
    2. //data is always json stringified
    3. });

Miscellaneous Events

  • ‘publicKey’
  • when other peer publicKey is fetched.

    1. grtc.on('publicKey', function(pubKey){
    2. //pubKey => encrypt shared token using this and send that to peer.
    3. });
  • ‘peerSecret’

  • when you received secret encrypted using your public key

    1. grtc.on('peerSecret', function(secret){
    2. //secret => its decrypted using your private key.
    3. });
  • ‘secretAck’

  • this is ack when peer reply to initiator that secret is received.
    ```
    grtc.on(‘secretAck’, function(){

});

  1. * 'transport'
  2. * this is emitted on both initiator and peers that transport layer is ready to use.

grtc.on(‘transport’, function(){
// you can call grtc.secureSend(‘something’) function
});
```

Data Format

Payload should always be JSON object which can be sent directly using grtc.send without stringify