Sha256: d281f6476a47df15b4b220fb3a2bc946959dac271ff584071fd9eb7fb4742be0

Contents?: true

Size: 1.33 KB

Versions: 2

Compression:

Stored size: 1.33 KB

Contents

import { P2pController } from "p2p"

export default class extends P2pController {
    //
    // p2p callbacks
    //
    p2pNegotiating() {
        // your peer start to negotiate with the host through ActionCable
    }

    p2pConnecting() {
        // your peer is connecting directly with the host peer
    }

    p2pConnected() {
        // your peer's connected to the host peer
        // from now you could start send message to the other through the host peer
    }

    p2pDisconnected() {
        // your peer's disconnected from the host peer
    }

    p2pClosed() {}

    p2pError() {}

    // receiving message from the other through the host peer
    p2pReceivedMessage(message) {
        switch(message["type"]) {
            case "Data":
                // message["data"]: the raw text(or whatever)
                break
            case "Data.Connection.State":
                // message["data"]: the current connection state of other peers
                // for (let [peer, state] of Object.entries(message["data"])) {}
                break
            default:
                break
        }
    }

    //
    // send message to the others through the host peer:
    // this.p2pSendMessage('hi')
    //
    // this.iamHost: your peer is the host or not
    // this.peerId: your peer id
    // this.hostPeerId: the host peer id
    //
}

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
p2p_streams_channel-0.0.3 lib/rails/generators/p2p_streams_channel/templates/controller.js
p2p_streams_channel-0.0.2 lib/rails/generators/p2p_streams_channel/templates/controller.js