teleportxr 1.0.39 → 1.0.41

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.
package/client/client.js CHANGED
@@ -131,15 +131,15 @@ class Client {
131
131
  if(this.scene.backgroundTexturePath&&this.scene.backgroundTexturePath!="")
132
132
  {
133
133
  this.setupCommand.BackgroundMode_backgroundMode=BackgroundMode.TEXTURE;
134
- this.setupCommand.uid_backgroundTexture=resources.AddTexture(this.scene.backgroundTexturePath);
134
+ this.setupCommand.uid_backgroundTexture=resources.GetOrAddTexture(this.scene.backgroundTexturePath);
135
135
  }
136
136
  if(this.scene.diffuseCubemapPath&&this.scene.diffuseCubemapPath!="")
137
137
  {
138
- this.clientDynamicLighting.uid_diffuse_cubemap_texture_uid=resources.AddTexture(this.scene.diffuseCubemapPath);
138
+ this.clientDynamicLighting.uid_diffuse_cubemap_texture_uid=resources.GetOrAddTexture(this.scene.diffuseCubemapPath);
139
139
  }
140
140
  if(this.scene.specularCubemapPath&&this.scene.specularCubemapPath!="")
141
141
  {
142
- this.clientDynamicLighting.uid_specular_cubemap_texture_uid=resources.AddTexture(this.scene.specularCubemapPath);
142
+ this.clientDynamicLighting.uid_specular_cubemap_texture_uid=resources.GetOrAddTexture(this.scene.specularCubemapPath);
143
143
  }
144
144
  }
145
145
 
@@ -103,6 +103,21 @@ class WebRtcConnection extends EventEmitter
103
103
  }
104
104
  reconnect()
105
105
  {
106
+ // Close and clean up the previous PeerConnection before creating a new one.
107
+ // Failing to do so leaves the old ICE agent (and its UDP socket) alive, which
108
+ // causes it to keep sending/receiving STUN messages with stale credentials and
109
+ // confuses the peer's new ICE agent (ufrag mismatch).
110
+ if (this.peerConnection)
111
+ {
112
+ this.peerConnection.removeEventListener('iceconnectionstatechange', this._onIceConnectionStateChange);
113
+ this.peerConnection.removeEventListener('icegatheringstatechange', this._onIceGatheringStateChange);
114
+ this.peerConnection.removeEventListener("icecandidateerror", this._onIceCandidateError);
115
+ this.peerConnection.removeEventListener("connectionstatechange", this._onConnectionStateChange);
116
+ if (this.onIceCandidate)
117
+ this.peerConnection.removeEventListener('icecandidate', this.onIceCandidate);
118
+ try { this.peerConnection.close(); } catch (e) {}
119
+ this.peerConnection = null;
120
+ }
106
121
  this.peerConnection =new DefaultRTCPeerConnection({ sdpSemantics: 'unified-plan', iceServers: this.iceServers, iceTransportPolicy: this.iceTransportPolicy});
107
122
  this.beforeOffer();
108
123
  this.connectionTimer = this.options.setTimeout(() =>
@@ -267,8 +282,9 @@ class WebRtcConnection extends EventEmitter
267
282
  } else if (this.peerConnection.iceConnectionState === 'disconnected'
268
283
  || this.peerConnection.iceConnectionState === 'failed')
269
284
  {
270
- this.peerConnection.restartIce();
271
- console.log("restartIce()");
285
+ // Do not call restartIce() here: reconnect() below creates a brand-new
286
+ // PeerConnection, so any ICE restart on the old PC is immediately
287
+ // abandoned and produces a third set of dangling ICE credentials.
272
288
  if (!this.connectionTimer && !this.reconnectionTimer)
273
289
  {
274
290
  const self = this;
@@ -312,21 +328,13 @@ class WebRtcConnection extends EventEmitter
312
328
  this.reconnectionTimer = null;
313
329
  }
314
330
 
315
- // Check the connection state
316
- if(this.peerConnection)
317
- if (this.peerConnection.connectionState == "connected" ||
318
- this.peerConnection.connectionState == "failed")
331
+ // Always close the PeerConnection regardless of connectionState.
332
+ // Previously it was only closed when state was "connected" or "failed",
333
+ // which left the ICE agent alive (and its socket bound) when state was
334
+ // "disconnected", causing stale STUN traffic toward the peer on reconnect.
335
+ if (this.peerConnection)
319
336
  {
320
- // Close each track
321
- /* this.peerConnection.cl.forEach(mediaStream => { {
322
- mediaStream.videoTracks.forEach( it => {it.setEnabled(false); });
323
- mediaStream.audioTracks.forEach( it => {it.setEnabled(false); });
324
-
325
- };
326
- });;6'7*/
327
-
328
- // Close the connection
329
- this.peerConnection.close();
337
+ try { this.peerConnection.close(); } catch (e) {}
330
338
  }
331
339
 
332
340
  // Nullify the reference
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.39",
18
+ "version": "1.0.41",
19
19
  "repository": {
20
20
  "type": "git",
21
21
  "url": "git+https://github.com/simul/teleport-nodejs.git"
package/scene/node.js CHANGED
@@ -247,7 +247,7 @@ class Node {
247
247
  return Node.sizeof();
248
248
  }
249
249
  setMeshComponent(mesh_url) {
250
- resources.AddMesh(mesh_url);
250
+ resources.GetOrAddMesh(mesh_url);
251
251
  this.components.forEach((component) => {
252
252
  if (component.getType() == NodeDataType.Mesh) {
253
253
  component.meshUrl = mesh_url;
@@ -150,7 +150,10 @@ function AddTypedResource(typename, path) {
150
150
  return uid;
151
151
  }
152
152
 
153
- function AddResourceFromUrl(type, url) {
153
+ function GetOrAddResourceFromUrl(type, url) {
154
+ if (Resource.pathToUid.has(url)) {
155
+ return Resource.pathToUid.get(url);
156
+ }
154
157
  var uid = core.generateUid();
155
158
  var res = null;
156
159
  switch (type) {
@@ -159,7 +162,7 @@ function AddResourceFromUrl(type, url) {
159
162
  throw new Error(
160
163
  "Type ",
161
164
  type,
162
- " can't be instantiated with AddResourceFromUrl()."
165
+ " can't be instantiated with GetOrAddResourceFromUrl()."
163
166
  );
164
167
  break;
165
168
  default:
@@ -186,7 +189,7 @@ function GetOrAddResourceUidFromUrl(type, url){
186
189
  return uid;
187
190
  if(!url)
188
191
  return 0;
189
- return AddResourceFromUrl(type, url);
192
+ return GetOrAddResourceFromUrl(type, url);
190
193
  }
191
194
 
192
195
  function GetResourceFromUrl(url) {
@@ -202,14 +205,14 @@ function GetResourceFromUid(uid) {
202
205
  return res;
203
206
  }
204
207
 
205
- //! Add the texture url as a resource.
206
- function AddTexture(url) {
207
- return AddResourceFromUrl(core.GeometryPayloadType.TexturePointer, url);
208
+ //! Get or add the texture url as a resource.
209
+ function GetOrAddTexture(url) {
210
+ return GetOrAddResourceFromUrl(core.GeometryPayloadType.TexturePointer, url);
208
211
  }
209
212
 
210
- //! Add the texture url as a resource.
211
- function AddMesh(url) {
212
- return AddResourceFromUrl(core.GeometryPayloadType.MeshPointer, url);
213
+ //! Get or add the mesh url as a resource.
214
+ function GetOrAddMesh(url) {
215
+ return GetOrAddResourceFromUrl(core.GeometryPayloadType.MeshPointer, url);
213
216
  }
214
217
 
215
218
  function AddFontAtlas(path) {
@@ -233,8 +236,8 @@ module.exports = {
233
236
  GetResourceUidFromUrl,
234
237
  GetOrAddResourceUidFromUrl,
235
238
  GetResourceFromUid,
236
- AddTexture,
237
- AddMesh,
239
+ GetOrAddTexture,
240
+ GetOrAddMesh,
238
241
  AddFontAtlas,
239
242
  AddTextCanvas,
240
243
  AddTypedResource,
package/scene/scene.js CHANGED
@@ -176,17 +176,17 @@ class Scene {
176
176
  if(j.environment.background_texture)
177
177
  {
178
178
  this.backgroundTexturePath=j.environment.background_texture;
179
- resources.AddTexture(this.backgroundTexturePath);
179
+ resources.GetOrAddTexture(this.backgroundTexturePath);
180
180
  }
181
181
  if(j.environment.diffuse_cubemap)
182
182
  {
183
183
  this.diffuseCubemapPath=j.environment.diffuse_cubemap;
184
- resources.AddTexture(this.diffuseCubemapPath);
184
+ resources.GetOrAddTexture(this.diffuseCubemapPath);
185
185
  }
186
186
  if(j.environment.specular_cubemap)
187
187
  {
188
188
  this.specularCubemapPath=j.environment.specular_cubemap;
189
- resources.AddTexture(this.specularCubemapPath);
189
+ resources.GetOrAddTexture(this.specularCubemapPath);
190
190
  }
191
191
  }
192
192
  if(j.font_atlases)