@reactoo/watchtogether-sdk-js 2.5.85 → 2.5.87

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.5.85",
3
+ "version": "2.5.87",
4
4
  "description": "Javascript SDK for Reactoo",
5
5
  "main": "src/index.js",
6
6
  "unpkg": "dist/watchtogether-sdk.min.js",
@@ -1966,9 +1966,73 @@ class RoomSession {
1966
1966
 
1967
1967
  this._setupTransceivers(this.handleId, [hasAudio, false, hasVideo, false]);
1968
1968
 
1969
+ const emitEvents = () => {
1970
+ this.isPublished = true;
1971
+ if(config.stream) {
1972
+ let tracks = config.stream.getTracks();
1973
+ tracks.forEach(track => {
1974
+ // used as a flag to not emit tracks that been already emitted
1975
+ if(!track.onended) {
1976
+ this.emit('addLocalParticipant', {
1977
+ tid: generateUUID(),
1978
+ id: handle.handleId,
1979
+ userId: decodeJanusDisplay(handle.userId)?.userId,
1980
+ role: decodeJanusDisplay(this.display)?.role,
1981
+ track,
1982
+ stream: config.stream,
1983
+ adding: true,
1984
+ constructId: this.constructId,
1985
+ metaData: this.options.metaData,
1986
+ hasAudioTrack: hasAudio,
1987
+ hasVideoTrack: hasVideo
1988
+ });
1989
+ track.onended = (ev) => {
1990
+ this.emit('addLocalParticipant', {
1991
+ tid:generateUUID(),
1992
+ id: handle.handleId,
1993
+ userId: decodeJanusDisplay(handle.userId)?.userId,
1994
+ role: decodeJanusDisplay(this.display)?.role,
1995
+ track: ev.target,
1996
+ stream: config.stream,
1997
+ adding: false,
1998
+ removing: true,
1999
+ constructId: this.constructId,
2000
+ metaData: this.options.metaData,
2001
+ hasAudioTrack: hasAudio,
2002
+ hasVideoTrack: hasVideo
2003
+ });
2004
+ }
2005
+ }
2006
+ })
2007
+ }
2008
+ else {
2009
+ this.emit('addLocalParticipant', {
2010
+ tid: generateUUID(),
2011
+ id: handle.handleId,
2012
+ userId: decodeJanusDisplay(handle.userId)?.userId,
2013
+ role: decodeJanusDisplay(this.display)?.role,
2014
+ stream: null,
2015
+ adding: false,
2016
+ constructId: this.constructId,
2017
+ metaData: this.options.metaData,
2018
+ hasAudioTrack: hasAudio,
2019
+ hasVideoTrack: hasVideo
2020
+ });
2021
+ }
2022
+ this.emit('published', {status: true, hasStream: !!config.stream});
2023
+ this.emit('publishing', false);
2024
+ this.emit('localHasVideo', hasVideo);
2025
+ this.emit('localHasAudio', hasAudio);
2026
+ this.emit('localMuted', {type: 'video', value: isVideoMuted});
2027
+ this.emit('localMuted', {type: 'audio', value: isAudioMuted});
2028
+ return this;
2029
+ };
2030
+
1969
2031
  // this should be enough
1970
2032
  if(this.isPublished) {
1971
- return Promise.resolve();
2033
+ return Promise
2034
+ .all([audioTrackReplacePromise, videoTrackReplacePromise])
2035
+ .then(() => emitEvents())
1972
2036
  }
1973
2037
 
1974
2038
  return Promise
@@ -2024,67 +2088,7 @@ class RoomSession {
2024
2088
  });
2025
2089
  }
2026
2090
  })
2027
- .then(r => {
2028
- this.isPublished = true;
2029
- if(config.stream) {
2030
- let tracks = config.stream.getTracks();
2031
- tracks.forEach(track => {
2032
- // used as a flag to not emit tracks that been already emitted
2033
- if(!track.onended) {
2034
- this.emit('addLocalParticipant', {
2035
- tid: generateUUID(),
2036
- id: handle.handleId,
2037
- userId: decodeJanusDisplay(handle.userId)?.userId,
2038
- role: decodeJanusDisplay(this.display)?.role,
2039
- track,
2040
- stream: config.stream,
2041
- adding: true,
2042
- constructId: this.constructId,
2043
- metaData: this.options.metaData,
2044
- hasAudioTrack: hasAudio,
2045
- hasVideoTrack: hasVideo
2046
- });
2047
- track.onended = (ev) => {
2048
- this.emit('addLocalParticipant', {
2049
- tid:generateUUID(),
2050
- id: handle.handleId,
2051
- userId: decodeJanusDisplay(handle.userId)?.userId,
2052
- role: decodeJanusDisplay(this.display)?.role,
2053
- track: ev.target,
2054
- stream: config.stream,
2055
- adding: false,
2056
- removing: true,
2057
- constructId: this.constructId,
2058
- metaData: this.options.metaData,
2059
- hasAudioTrack: hasAudio,
2060
- hasVideoTrack: hasVideo
2061
- });
2062
- }
2063
- }
2064
- })
2065
- } else {
2066
- this.emit('addLocalParticipant', {
2067
- tid: generateUUID(),
2068
- id: handle.handleId,
2069
- userId: decodeJanusDisplay(handle.userId)?.userId,
2070
- role: decodeJanusDisplay(this.display)?.role,
2071
- stream: null,
2072
- adding: false,
2073
- constructId: this.constructId,
2074
- metaData: this.options.metaData,
2075
- hasAudioTrack: hasAudio,
2076
- hasVideoTrack: hasVideo
2077
- });
2078
- }
2079
-
2080
- this.emit('published', {status: true, hasStream: !!config.stream});
2081
- this.emit('publishing', false);
2082
- this.emit('localHasVideo', hasVideo);
2083
- this.emit('localHasAudio', hasAudio);
2084
- this.emit('localMuted', {type: 'video', value: isVideoMuted});
2085
- this.emit('localMuted', {type: 'audio', value: isAudioMuted});
2086
- return r;
2087
- })
2091
+ .then(() => emitEvents())
2088
2092
  .catch(e => {
2089
2093
  this.emit('publishing', false);
2090
2094
  return Promise.reject(e);