Sha256: f8af497e208f37ccee61dab823458e082b4fe0c4b57c1e8e4210882d18785004

Contents?: true

Size: 988 Bytes

Versions: 3

Compression:

Stored size: 988 Bytes

Contents

import { Controller } from "@hotwired/stimulus"

export default class extends Controller {
    connect() {
        this.p2pSetup()
    }

    p2pSetup() {
        this.p2pFrame = this.element.closest("p2p-frame")
        if (this.p2pFrame) {
            this.p2pFrame.setP2pListener(this)
        } else {
            throw new Error("Couldn't find p2p-frame!")
        }
    }

    get peerId() {
        this.p2pFrame.peer?.peerId
    }
    
    get hostPeerId() {
        this.p2pFrame.peer?.hostPeerId
    }

    get iamHost() {
        this.p2pFrame.peer?.iamHost
    }

    // p2p callbacks
    
    p2pNegotiating() {}

    p2pConnecting() {}

    p2pConnected() {}

    p2pDisconnected() {}

    p2pClosed() {}

    p2pError() {}

    // send/received p2p message

    p2pSendMessage(message) {
        if (this.p2pFrame) {
            this.p2pFrame.sendP2pMessage(message)
        }
    }

    p2pReceivedMessage(message) {}
}

Version data entries

3 entries across 2 versions & 1 rubygems

Version Path
p2p_streams_channel-0.0.3 lib/rails/generators/p2p_streams_channel/templates/p2p/p2p_controller.js
p2p_streams_channel-0.0.3 spec/dummy/vendor/javascript/p2p/p2p_controller.js
p2p_streams_channel-0.0.2 app/assets/javascripts/p2p/p2p_controller.js