@reactoo/watchtogether-sdk-js 2.8.53 → 2.8.55

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reactoo/watchtogether-sdk-js",
3
- "version": "2.8.53",
3
+ "version": "2.8.55",
4
4
  "description": "Javascript SDK for Reactoo",
5
5
  "main": "dist/watchtogether-sdk.min.js",
6
6
  "module": "dist/watchtogether-sdk.min.js",
@@ -1220,7 +1220,9 @@ class RoomSession {
1220
1220
  this.disconnect().catch(()=>{});
1221
1221
  }
1222
1222
  }
1223
- this.emit('error', e)
1223
+ else {
1224
+ this.emit('error', e)
1225
+ }
1224
1226
  });
1225
1227
  }
1226
1228
 
@@ -1921,13 +1923,17 @@ class RoomSession {
1921
1923
  });
1922
1924
  }
1923
1925
  else {
1926
+
1927
+ this.emit('reclaimingConnection', {state: true, status: null});
1924
1928
  this.#send({"janus": "claim"})
1925
1929
  .then(json => {
1926
1930
  this.sessionId = json["session_id"] ? json["session_id"] : json.data["id"];
1927
1931
  this.#startKeepAlive();
1932
+ this.emit('reclaimingConnection', {state: false, status: 'success'});
1928
1933
  resolve(json);
1929
1934
  })
1930
1935
  .catch(error => {
1936
+ this.emit('reclaimingConnection', {state: false, status: 'failed', error});
1931
1937
  reject({type: 'error', id: 17, message: 'reconnection error', data: error})
1932
1938
  })
1933
1939
  .finally(() => {
@@ -1939,6 +1945,7 @@ class RoomSession {
1939
1945
  this.ws.onerror = (e) => {
1940
1946
  this.isEstablishingConnection = false
1941
1947
  this._abortController.signal.removeEventListener('abort', abortConnect);
1948
+ this.emit('reclaimingConnection', {state: false, status: 'failed', error: e});
1942
1949
  reject({type: 'error', id: 18, message: 'ws connection error', data: e});
1943
1950
  }
1944
1951
 
@@ -1982,14 +1989,17 @@ class RoomSession {
1982
1989
  });
1983
1990
  }
1984
1991
  else {
1992
+ this.emit('reclaimingConnection', {state: true, status: null});
1985
1993
  return this.#send({"janus": "claim"})
1986
1994
  .then(json => {
1987
1995
  this.sessionId = json["session_id"] ? json["session_id"] : json.data["id"];
1988
1996
  this.#startKeepAlive();
1989
1997
  this.#longPoll();
1998
+ this.emit('reclaimingConnection', {state: false, status: 'success'});
1990
1999
  return this;
1991
2000
  })
1992
2001
  .catch(error => {
2002
+ this.emit('reclaimingConnection', {state: false, status: 'failed', error});
1993
2003
  return Promise.reject({type: 'error', id: 21, message: 'reconnection error', data: error})
1994
2004
  })
1995
2005
  .finally(() => {
@@ -2029,27 +2039,15 @@ class RoomSession {
2029
2039
 
2030
2040
  async #reconnect() {
2031
2041
 
2032
- if (this.isConnecting) {
2042
+ if (this.isEstablishingConnection) {
2033
2043
  return Promise.reject({type: 'warning', id: 22, message: 'connection already in progress'});
2034
2044
  }
2035
2045
 
2036
- this.isConnecting = true;
2037
-
2038
2046
  if(this.useWebsockets) {
2039
- try {
2040
- await this.#webSocketConnection(true)
2041
- }
2042
- finally {
2043
- this.isConnecting = false;
2044
- }
2047
+ await this.#webSocketConnection(true)
2045
2048
  }
2046
2049
  else {
2047
- try {
2048
- await this.#httpConnection(true)
2049
- }
2050
- finally {
2051
- this.isConnecting = false;
2052
- }
2050
+ await this.#httpConnection(true)
2053
2051
  }
2054
2052
  }
2055
2053
 
@@ -2655,6 +2653,7 @@ class RoomSession {
2655
2653
 
2656
2654
  if (this.handleId === handleId) {
2657
2655
  this._log('Performing local ICE restart');
2656
+ this.emit('iceRestart', {state: true, origin: 'local', status: null});
2658
2657
  const hasAudio = !!(config.stream && config.stream.getAudioTracks().length > 0);
2659
2658
  const hasVideo = !!(config.stream && config.stream.getVideoTracks().length > 0);
2660
2659
  this.#createAO('offer', handleId, true )
@@ -2669,11 +2668,13 @@ class RoomSession {
2669
2668
  })
2670
2669
  .then(r => {
2671
2670
  config.isIceRestarting = false;
2672
- this._log('ICE restart success');
2671
+ this._log('Local ICE restart success');
2672
+ this.emit('iceRestart', {state: false, origin: 'local', status: 'success'});
2673
2673
  })
2674
2674
  .catch((e) => {
2675
2675
  config.isIceRestarting = false;
2676
-
2676
+ this._log('Local ICE restart failed', e);
2677
+ this.emit('iceRestart', {state: false, origin: 'local', status: 'failed', error: e});
2677
2678
  if(this.isSupposeToBeConnected) {
2678
2679
  this.emit('restartConnection');
2679
2680
  wait(10000).then(() => {
@@ -2686,19 +2687,21 @@ class RoomSession {
2686
2687
  else if(!this.isDisconnecting) {
2687
2688
  this.disconnect().catch(()=>{});
2688
2689
  }
2689
-
2690
-
2691
2690
  });
2692
2691
  } else {
2693
2692
  this._log('Performing remote ICE restart', handleId);
2693
+ this.emit('iceRestart', {state: true, origin: 'remote', status: null});
2694
2694
  return this.sendMessage(handleId, {
2695
2695
  body: {"request": "configure", "restart": true}
2696
2696
  }, false, false, 5).then(() => {
2697
2697
  }).then(() => {
2698
2698
  config.isIceRestarting = false;
2699
- this._log('ICE restart success');
2700
- }).catch(() => {
2699
+ this.emit('iceRestart', {state: false, origin: 'remote', status: 'success'});
2700
+ this._log('Remote ICE restart success');
2701
+ }).catch((e) => {
2701
2702
  config.isIceRestarting = false;
2703
+ this.emit('iceRestart', {state: false, origin: 'remote', status: 'failed', error: e});
2704
+ this._log('Remote ICE restart failed');
2702
2705
  });
2703
2706
  }
2704
2707
  }