teleportxr 1.0.22 → 1.0.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -18,15 +18,12 @@ class WebRtcConnection extends EventEmitter
|
|
|
18
18
|
constructor(id, options = {})
|
|
19
19
|
{
|
|
20
20
|
super();
|
|
21
|
-
const
|
|
22
|
-
"stun:stun.l.google.com:19302"
|
|
23
|
-
|
|
24
|
-
this.iceServers =
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
this.iceServers.push({ 'urls': iceServers[s] });
|
|
28
|
-
}
|
|
29
|
-
//this.iceServers=[{'urls': 'stun:stun.l.google.com:19302'}];
|
|
21
|
+
const defaultIceServers = [
|
|
22
|
+
{ urls: "stun:stun.l.google.com:19302" }
|
|
23
|
+
];
|
|
24
|
+
this.iceServers = (options && Array.isArray(options.iceServers) && options.iceServers.length)
|
|
25
|
+
? options.iceServers
|
|
26
|
+
: defaultIceServers;
|
|
30
27
|
this.id = id;
|
|
31
28
|
this.state = 'open';
|
|
32
29
|
|
|
@@ -40,17 +37,19 @@ class WebRtcConnection extends EventEmitter
|
|
|
40
37
|
...options
|
|
41
38
|
};
|
|
42
39
|
|
|
43
|
-
const {
|
|
44
|
-
RTCPeerConnection,
|
|
45
|
-
timeToConnected,
|
|
46
|
-
timeToReconnected
|
|
47
|
-
} = options;
|
|
48
|
-
|
|
49
40
|
this.messageReceivedReliableCb =options.messageReceivedReliable;
|
|
50
41
|
this.messageReceivedUnreliableCb =options.messageReceivedUnreliable;
|
|
51
42
|
this.connectionStateChangedCb=options.connectionStateChanged;
|
|
52
43
|
this.sendConfigMessage =options.sendConfigMessage;
|
|
53
44
|
|
|
45
|
+
this._onIceConnectionStateChange = this.onIceConnectionStateChange.bind(this);
|
|
46
|
+
this._onIceGatheringStateChange = this.onIceGatheringStateChange.bind(this);
|
|
47
|
+
this._onConnectionStateChange = this.connectionStateChanged.bind(this);
|
|
48
|
+
this._onIceCandidateError = (event) =>
|
|
49
|
+
{
|
|
50
|
+
console.log("ICE candidate error: "+event.errorCode+" "+event.errorText+" "+event.port+" "+event.url);
|
|
51
|
+
};
|
|
52
|
+
|
|
54
53
|
|
|
55
54
|
Object.defineProperties(this, {
|
|
56
55
|
iceConnectionState: {
|
|
@@ -102,14 +101,10 @@ class WebRtcConnection extends EventEmitter
|
|
|
102
101
|
|
|
103
102
|
this.reconnectionTimer = null;
|
|
104
103
|
|
|
105
|
-
this.peerConnection.addEventListener('iceconnectionstatechange', this.
|
|
106
|
-
this.peerConnection.addEventListener('icegatheringstatechange', this.
|
|
107
|
-
this.peerConnection.addEventListener("icecandidateerror",
|
|
108
|
-
|
|
109
|
-
console.log("ICE candidate error: "+event.errorCode+" "+event.errorText+" "+event.port+" "+event.url);
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
this.peerConnection.addEventListener("connectionstatechange", this.connectionStateChanged.bind(this));
|
|
104
|
+
this.peerConnection.addEventListener('iceconnectionstatechange', this._onIceConnectionStateChange);
|
|
105
|
+
this.peerConnection.addEventListener('icegatheringstatechange', this._onIceGatheringStateChange);
|
|
106
|
+
this.peerConnection.addEventListener("icecandidateerror", this._onIceCandidateError);
|
|
107
|
+
this.peerConnection.addEventListener("connectionstatechange", this._onConnectionStateChange);
|
|
113
108
|
|
|
114
109
|
this.onIceCandidate= ({ candidate })=>
|
|
115
110
|
{
|
|
@@ -144,11 +139,11 @@ class WebRtcConnection extends EventEmitter
|
|
|
144
139
|
|
|
145
140
|
this.timeout = options.setTimeout(() =>
|
|
146
141
|
{
|
|
147
|
-
peerConnection.removeEventListener('icecandidate', this.onIceCandidate
|
|
142
|
+
peerConnection.removeEventListener('icecandidate', this.onIceCandidate);
|
|
148
143
|
this.deferred.reject(new Error('Timed out waiting for host candidates'));
|
|
149
144
|
}, timeToHostCandidates);
|
|
150
|
-
|
|
151
|
-
peerConnection.addEventListener('icecandidate', this.onIceCandidate
|
|
145
|
+
|
|
146
|
+
peerConnection.addEventListener('icecandidate', this.onIceCandidate);
|
|
152
147
|
|
|
153
148
|
await this.deferred.promise;
|
|
154
149
|
}
|
|
@@ -256,13 +251,14 @@ class WebRtcConnection extends EventEmitter
|
|
|
256
251
|
console.log("WebRtcConnection.close()");
|
|
257
252
|
if(this.peerConnection)
|
|
258
253
|
{
|
|
259
|
-
this.peerConnection.removeEventListener('iceconnectionstatechange', this.
|
|
260
|
-
|
|
261
|
-
this.peerConnection.
|
|
262
|
-
this.peerConnection.removeEventListener(
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
254
|
+
this.peerConnection.removeEventListener('iceconnectionstatechange', this._onIceConnectionStateChange);
|
|
255
|
+
this.peerConnection.removeEventListener('icegatheringstatechange', this._onIceGatheringStateChange);
|
|
256
|
+
this.peerConnection.removeEventListener("icecandidateerror", this._onIceCandidateError);
|
|
257
|
+
this.peerConnection.removeEventListener("connectionstatechange", this._onConnectionStateChange);
|
|
258
|
+
if (this.onIceCandidate)
|
|
259
|
+
{
|
|
260
|
+
this.peerConnection.removeEventListener('icecandidate', this.onIceCandidate);
|
|
261
|
+
}
|
|
266
262
|
}
|
|
267
263
|
if (this.connectionTimer)
|
|
268
264
|
{
|
|
@@ -39,9 +39,16 @@ class WebRtcConnectionManager
|
|
|
39
39
|
|
|
40
40
|
createConnection(clientID,connectionStateChangedCb,messageReceivedReliableCb,messageReceivedUnreliableCb)
|
|
41
41
|
{
|
|
42
|
+
const existing = this.connections.get(clientID);
|
|
43
|
+
if (existing)
|
|
44
|
+
{
|
|
45
|
+
console.log("createConnection: replacing existing connection for "+clientID);
|
|
46
|
+
existing.close();
|
|
47
|
+
this.connections.delete(clientID);
|
|
48
|
+
}
|
|
42
49
|
var options=this.options;
|
|
43
50
|
options.sendConfigMessage =this.sendConfigMessage;
|
|
44
|
-
|
|
51
|
+
|
|
45
52
|
options.messageReceivedReliable =messageReceivedReliableCb;
|
|
46
53
|
options.messageReceivedUnreliable =messageReceivedUnreliableCb;
|
|
47
54
|
options.connectionStateChanged =connectionStateChangedCb;
|
|
@@ -73,6 +80,11 @@ class WebRtcConnectionManager
|
|
|
73
80
|
{
|
|
74
81
|
this.sendConfigMessage=cfm;
|
|
75
82
|
}
|
|
83
|
+
SetIceServers(iceServers)
|
|
84
|
+
{
|
|
85
|
+
if (Array.isArray(iceServers))
|
|
86
|
+
this.options.iceServers=iceServers;
|
|
87
|
+
}
|
|
76
88
|
}
|
|
77
89
|
|
|
78
90
|
WebRtcConnectionManager.create = function create (options)
|
package/index.js
CHANGED
|
@@ -21,10 +21,12 @@ function generateRandomBigInt() {
|
|
|
21
21
|
|
|
22
22
|
const serverID = generateRandomBigInt();
|
|
23
23
|
|
|
24
|
-
function initServer(signaling_port) {
|
|
24
|
+
function initServer(signaling_port, options) {
|
|
25
25
|
var cm=client_manager.getInstance();
|
|
26
26
|
const webRtcConnectionManager = WebRtcConnectionManager.getInstance();
|
|
27
27
|
webRtcConnectionManager.SetSendConfigMessage(signaling.sendConfigMessage);
|
|
28
|
+
if (options && Array.isArray(options.iceServers))
|
|
29
|
+
webRtcConnectionManager.SetIceServers(options.iceServers);
|
|
28
30
|
return signaling.init(serverID, webRtcConnectionManager,cm.newClient.bind(cm),cm.disconnectClient.bind(cm),signaling_port);
|
|
29
31
|
}
|
|
30
32
|
|
package/package.json
CHANGED