Skip to content
Snippets Groups Projects
index.js 976 B
Newer Older
/* global Y */
"use strict"

var {
  peerjs: { Peer }
} = require("peerjs")

function extend(Y) {
  class WebRTC extends Y.AbstractConnector {
    constructor(y, options) {
      if (options === undefined) {
        throw new Error("Options must not be undefined!")
      }

      options.role = "slave"
      super(y, options)
      this.webrtcOptions = options

      this.connect()
    }

    connect() {
      var peer = new Peer({
        host: this.webrtcOptions.host,
        port: this.webrtcOptions.port,
        path: this.webrtcOptions.path
      })

      peer.on("open", function(id) {
        console.log("My peer ID is: " + id)
      })
    }

    disconnect() {
      super.disconnect()
    }

    reconnect() {
      super.reconnect()
    }

    send(/*uid, message*/) {}

    broadcast(/*message*/) {}

    isDisconnected() {
      return false
    }
  }

  Y.extend("webrtc", WebRTC)
}

module.exports = extend
if (typeof Y !== "undefined") {
  extend(Y)
}