teleportxr 1.0.22 → 1.0.24

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,15 @@ class WebRtcConnection extends EventEmitter
18
18
  constructor(id, options = {})
19
19
  {
20
20
  super();
21
- const iceServers=[
22
- "stun:stun.l.google.com:19302"
23
- ];
24
- this.iceServers = [] ;
25
- for(const s in iceServers)
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;
27
+ this.iceTransportPolicy = (options && (options.iceTransportPolicy === 'all' || options.iceTransportPolicy === 'relay'))
28
+ ? options.iceTransportPolicy
29
+ : 'all';
30
30
  this.id = id;
31
31
  this.state = 'open';
32
32
 
@@ -40,17 +40,19 @@ class WebRtcConnection extends EventEmitter
40
40
  ...options
41
41
  };
42
42
 
43
- const {
44
- RTCPeerConnection,
45
- timeToConnected,
46
- timeToReconnected
47
- } = options;
48
-
49
43
  this.messageReceivedReliableCb =options.messageReceivedReliable;
50
44
  this.messageReceivedUnreliableCb =options.messageReceivedUnreliable;
51
45
  this.connectionStateChangedCb=options.connectionStateChanged;
52
46
  this.sendConfigMessage =options.sendConfigMessage;
53
47
 
48
+ this._onIceConnectionStateChange = this.onIceConnectionStateChange.bind(this);
49
+ this._onIceGatheringStateChange = this.onIceGatheringStateChange.bind(this);
50
+ this._onConnectionStateChange = this.connectionStateChanged.bind(this);
51
+ this._onIceCandidateError = (event) =>
52
+ {
53
+ console.log("ICE candidate error: "+event.errorCode+" "+event.errorText+" "+event.port+" "+event.url);
54
+ };
55
+
54
56
 
55
57
  Object.defineProperties(this, {
56
58
  iceConnectionState: {
@@ -88,7 +90,7 @@ class WebRtcConnection extends EventEmitter
88
90
  }
89
91
  reconnect()
90
92
  {
91
- this.peerConnection =new DefaultRTCPeerConnection({ sdpSemantics: 'unified-plan', 'iceServers': this.iceServers});
93
+ this.peerConnection =new DefaultRTCPeerConnection({ sdpSemantics: 'unified-plan', iceServers: this.iceServers, iceTransportPolicy: this.iceTransportPolicy});
92
94
  this.beforeOffer();
93
95
  this.connectionTimer = this.options.setTimeout(() =>
94
96
  {
@@ -102,14 +104,10 @@ class WebRtcConnection extends EventEmitter
102
104
 
103
105
  this.reconnectionTimer = null;
104
106
 
105
- this.peerConnection.addEventListener('iceconnectionstatechange', this.onIceConnectionStateChange.bind(this));
106
- this.peerConnection.addEventListener('icegatheringstatechange', this.onIceGatheringStateChange.bind(this));
107
- this.peerConnection.addEventListener("icecandidateerror", (event) => {
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));
107
+ this.peerConnection.addEventListener('iceconnectionstatechange', this._onIceConnectionStateChange);
108
+ this.peerConnection.addEventListener('icegatheringstatechange', this._onIceGatheringStateChange);
109
+ this.peerConnection.addEventListener("icecandidateerror", this._onIceCandidateError);
110
+ this.peerConnection.addEventListener("connectionstatechange", this._onConnectionStateChange);
113
111
 
114
112
  this.onIceCandidate= ({ candidate })=>
115
113
  {
@@ -144,11 +142,11 @@ class WebRtcConnection extends EventEmitter
144
142
 
145
143
  this.timeout = options.setTimeout(() =>
146
144
  {
147
- peerConnection.removeEventListener('icecandidate', this.onIceCandidate.bind(this));
145
+ peerConnection.removeEventListener('icecandidate', this.onIceCandidate);
148
146
  this.deferred.reject(new Error('Timed out waiting for host candidates'));
149
147
  }, timeToHostCandidates);
150
-
151
- peerConnection.addEventListener('icecandidate', this.onIceCandidate.bind(this));
148
+
149
+ peerConnection.addEventListener('icecandidate', this.onIceCandidate);
152
150
 
153
151
  await this.deferred.promise;
154
152
  }
@@ -256,13 +254,14 @@ class WebRtcConnection extends EventEmitter
256
254
  console.log("WebRtcConnection.close()");
257
255
  if(this.peerConnection)
258
256
  {
259
- this.peerConnection.removeEventListener('iceconnectionstatechange', this.onIceConnectionStateChange.bind(this));
260
-
261
- this.peerConnection.eve
262
- this.peerConnection.removeEventListener('iceconnectionstatechange', this.onIceConnectionStateChange.bind(this));
263
- this.peerConnection.removeEventListener('icegatheringstatechange', this.onIceGatheringStateChange.bind(this));
264
- //this.peerConnection.removeEventListener("icecandidateerror", (event) => {
265
- this.peerConnection.removeEventListener("connectionstatechange", this.connectionStateChanged.bind(this));
257
+ this.peerConnection.removeEventListener('iceconnectionstatechange', this._onIceConnectionStateChange);
258
+ this.peerConnection.removeEventListener('icegatheringstatechange', this._onIceGatheringStateChange);
259
+ this.peerConnection.removeEventListener("icecandidateerror", this._onIceCandidateError);
260
+ this.peerConnection.removeEventListener("connectionstatechange", this._onConnectionStateChange);
261
+ if (this.onIceCandidate)
262
+ {
263
+ this.peerConnection.removeEventListener('icecandidate', this.onIceCandidate);
264
+ }
266
265
  }
267
266
  if (this.connectionTimer)
268
267
  {
@@ -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,16 @@ 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
+ }
88
+ SetIceTransportPolicy(policy)
89
+ {
90
+ if (policy === 'all' || policy === 'relay')
91
+ this.options.iceTransportPolicy=policy;
92
+ }
76
93
  }
77
94
 
78
95
  WebRtcConnectionManager.create = function create (options)
package/index.js CHANGED
@@ -21,10 +21,14 @@ 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);
30
+ if (options && options.iceTransportPolicy)
31
+ webRtcConnectionManager.SetIceTransportPolicy(options.iceTransportPolicy);
28
32
  return signaling.init(serverID, webRtcConnectionManager,cm.newClient.bind(cm),cm.disconnectClient.bind(cm),signaling_port);
29
33
  }
30
34
 
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  },
16
16
  "name": "teleportxr",
17
17
  "description": "Teleport Spatial Server on node.js",
18
- "version": "1.0.22",
18
+ "version": "1.0.24",
19
19
  "repository": {
20
20
  "type": "git",
21
21
  "url": "git+https://github.com/simul/teleport-nodejs.git"