Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/* 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)
}