@reactoo/watchtogether-sdk-js 2.5.32 → 2.5.38

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.
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- import {wait} from "../modules/wt-utils";
3
+ import {decodeJanusDisplay, wait} from "../modules/wt-utils";
4
4
  import _emitter_ from "../modules/wt-emitter";
5
5
 
6
6
  // SYNCHRONISATION MODULES
@@ -17,7 +17,7 @@ import syncDisabled from "../modules/sync-modules/sync-disabled";
17
17
  import syncDaznDash from "../modules/sync-modules/sync-dazn-dash";
18
18
  import syncUniversal from "../modules/sync-modules/sync-universal";
19
19
 
20
- let roomSession = function ({roomId, pinHash, isTalkback, isMonitor, isInstructor}, room, wt) {
20
+ let roomSession = function ({roomId, pinHash, isTalkback, isInstructor}, room, wt) {
21
21
 
22
22
  let primaryRoomId = roomId;
23
23
  let publicCustomEvents = ['changePlayerSource', 'chatMessage', 'userUpdate', 'reconnecting', 'connecting', 'remoteMuted', 'scaling'];
@@ -31,6 +31,7 @@ let roomSession = function ({roomId, pinHash, isTalkback, isMonitor, isInstructo
31
31
 
32
32
  const emitter = _emitter_();
33
33
  let alpTimeoutId = null;
34
+ let abortController = null;
34
35
  let ___; // return object
35
36
 
36
37
  room.on('addLocalParticipant', () => {
@@ -86,13 +87,14 @@ let roomSession = function ({roomId, pinHash, isTalkback, isMonitor, isInstructo
86
87
  connect: function ({reactooRoomId = null} = {}) {
87
88
  emitter.emit('connecting', true);
88
89
  clearTimeout(alpTimeoutId);
89
- return Promise.all([wt.room.__joinRoom({
90
- roomId: reactooRoomId || primaryRoomId,
91
- pinHash,
92
- isTalkback,
93
- isMonitor,
94
- isInstructor
95
- }), wt.user.getUserSelf()])
90
+ abortController = new AbortController();
91
+ return Promise.all([
92
+ wt.room.__joinRoom({
93
+ roomId: reactooRoomId || primaryRoomId,
94
+ pinHash,
95
+ isTalkback,
96
+ isInstructor}, abortController?.signal),
97
+ wt.user.getUserSelf()])
96
98
  .then(([roomData, userData]) => {
97
99
  // Happens when we reroute user to a different room
98
100
  if(roomData?.data?.reactooRoomId !== roomId) {
@@ -102,7 +104,21 @@ let roomSession = function ({roomId, pinHash, isTalkback, isMonitor, isInstructo
102
104
  return Promise.all([roomData, userData])
103
105
  })
104
106
  .then(([roomData, userData]) => Promise.all([roomData, userData, this.setRoomVars()]))
105
- .then(([roomData, userData, _]) => Promise.all([roomData, userData, room.connect(roomData.data.roomId, roomData.data.pin, roomData.data.href, roomData.data.iceServers, roomData.data.accessToken, roomData.data.display, roomData.data.userId, roomData.data.webrtcVersion, (roomData.data.bitrate ? parseInt(roomData.data.bitrate) : 0), isMonitor, roomData.data.recordingFilename)]))
107
+ .then(([roomData, userData, _]) => Promise.all([
108
+ roomData,
109
+ userData,
110
+ room.connect(
111
+ roomData.data.roomId,
112
+ roomData.data.pin,
113
+ roomData.data.href,
114
+ roomData.data.iceServers,
115
+ roomData.data.accessToken,
116
+ roomData.data.display,
117
+ roomData.data.userId,
118
+ roomData.data.webrtcVersion,
119
+ (roomData.data.bitrate ? parseInt(roomData.data.bitrate) : 0),
120
+ roomData.data.recordingFilename)
121
+ ]))
106
122
  .finally(() => {
107
123
  emitter.emit('connecting', false);
108
124
  })
@@ -111,6 +127,7 @@ let roomSession = function ({roomId, pinHash, isTalkback, isMonitor, isInstructo
111
127
 
112
128
  disconnect: function (dontWaitForResponses) {
113
129
  clearTimeout(alpTimeoutId);
130
+ abortController?.abort?.();
114
131
  return room.disconnect(dontWaitForResponses);
115
132
  },
116
133
 
@@ -120,7 +137,7 @@ let roomSession = function ({roomId, pinHash, isTalkback, isMonitor, isInstructo
120
137
  emitter.emit('reconnecting', true);
121
138
  room.isRestarting = true;
122
139
 
123
- let wasPublished = room._isPublished;
140
+ let wasPublished = room.isPublished;
124
141
  let handle = room._getHandle(room.handleId);
125
142
  let stream = null;
126
143
  if (handle?.webrtcStuff?.stream && wasPublished) {
@@ -179,7 +196,7 @@ let roomSession = function ({roomId, pinHash, isTalkback, isMonitor, isInstructo
179
196
  emitter.emit('chatMessage', msg);
180
197
  } else if (msg.user_action === 'remote_muted') {
181
198
  if (msg.from !== room.userId) {
182
- emitter.emit('remoteMuted', {userId: msg.from, ...(msg.text && JSON.parse(msg.text))})
199
+ emitter.emit('remoteMuted', {userId: decodeJanusDisplay(msg.from)?.userId, ...(msg.text && JSON.parse(msg.text))})
183
200
  }
184
201
  } else if (msg.user_action === 'remote_muted_request') {
185
202
  if (msg.from !== room.userId) {
@@ -287,12 +304,13 @@ let roomSession = function ({roomId, pinHash, isTalkback, isMonitor, isInstructo
287
304
  },
288
305
 
289
306
  setRoomVars: () => {
290
- return wt.room.getRoomById(roomId, pinHash)
307
+ return wt.room.getRoomById(roomId, pinHash, undefined, false, abortController?.signal)
291
308
  .then(r => {
292
309
  // setting observers userId's so we can ignore them when creating participant
310
+ room.setRoomType(r.data.type);
293
311
  room.setObserverIds(r.data.allowedObservers);
294
312
  room.setTalkbackIds(r.data.allowedTalkbacks);
295
- room.setInstructorId(r.data.classroom?.instructorUserId);
313
+ room.setInstructorId(r.data.classroom?.instructorUserId || r.data.videowall?.hostUserId);
296
314
  });
297
315
  },
298
316
 
@@ -178,10 +178,16 @@ let room = function () {
178
178
  .then(client => client.apis.wt.setUser({messageId, userId, roomId, flag, timestamp, option}));
179
179
  },
180
180
 
181
- getRoomById: (id, pinHash = undefined, showPublic = undefined, demo = false) => {
181
+ getRoomById: (id, pinHash = undefined, showPublic = undefined, demo = false, signal) => {
182
182
  return this.__privates.auth.__client
183
- .then(client => client.apis.wt.getRoom({id, pinHash, "public": showPublic, demo}))
184
-
183
+ .then(client => client.apis.wt.getRoom({id, pinHash, "public": showPublic, demo}, {
184
+ ...(signal ? {
185
+ requestInterceptor: (req) => {
186
+ req.signal = signal;
187
+ return req;
188
+ }
189
+ } : {}),
190
+ }))
185
191
  },
186
192
 
187
193
  getRoomBySlug: (slug, password = undefined, showPublic = undefined, demo = false) => {
@@ -199,26 +205,22 @@ let room = function () {
199
205
  }))
200
206
  },
201
207
 
202
- __joinRoom: ({roomId, pinHash, instanceType = this.__instanceType, isTalkback = undefined, isMonitor = undefined, isInstructor = undefined, customBearer = undefined} = {}) => {
208
+ __joinRoom: ({roomId, pinHash, instanceType = this.__instanceType, isTalkback = undefined, isInstructor = undefined, customBearer = undefined} = {}, signal) => {
203
209
  return this.__privates.auth.__client
204
210
  .then(client => client.apis.wt.join({
205
211
  roomId,
206
212
  pinHash,
207
213
  instanceType,
208
214
  isTalkback,
209
- isMonitor,
210
215
  isInstructor,
211
216
  platform: this.browser === 'firefox' ? 'web-firefox' : 'web'
212
217
  }, {
213
- ...(customBearer ? {
218
+ ...(signal ? {
214
219
  requestInterceptor: (req) => {
215
- if (!req.headers) {
216
- req.headers = {};
217
- }
218
- req.headers['Authorization'] = customBearer;
220
+ req.signal = signal;
219
221
  return req;
220
222
  }
221
- } : {})
223
+ } : {}),
222
224
  }))
223
225
  },
224
226
 
@@ -196,7 +196,7 @@ const syncVodDashJs = function ({room, wt, roomSession, emitter} = {}) {
196
196
  };
197
197
 
198
198
  const isConnected = () => {
199
- return room._isDataChannelOpen && room._hasJoined;
199
+ return room._isDataChannelOpen && room.isConnected;
200
200
  };
201
201
 
202
202
  const buffering = (event) => {
@@ -178,7 +178,7 @@ const syncDashJs = function ({room, wt, roomSession, emitter} = {}) {
178
178
  };
179
179
 
180
180
  const isConnected = () => {
181
- return room._isDataChannelOpen && room._hasJoined;
181
+ return room._isDataChannelOpen && room.isConnected;
182
182
  };
183
183
 
184
184
  const buffering = (event) => {
@@ -178,7 +178,7 @@ const syncDaznDash = function ({room, wt, roomSession, emitter} = {}) {
178
178
  };
179
179
 
180
180
  const isConnected = () => {
181
- return room._isDataChannelOpen && room._hasJoined;
181
+ return room._isDataChannelOpen && room.isConnected;
182
182
  };
183
183
 
184
184
  const parseDataEvents = (msg = {}) => {
@@ -178,7 +178,7 @@ const syncDoris = function ({room, wt, roomSession, emitter} = {}) {
178
178
  };
179
179
 
180
180
  const isConnected = () => {
181
- return room._isDataChannelOpen && room._hasJoined;
181
+ return room._isDataChannelOpen && room.isConnected;
182
182
  };
183
183
 
184
184
  const parseDataEvents = (msg = {}) => {
@@ -198,7 +198,7 @@ const syncVodHlsJs = function ({room, wt, roomSession, emitter} = {}) {
198
198
  };
199
199
 
200
200
  const isConnected = () => {
201
- return room._isDataChannelOpen && room._hasJoined;
201
+ return room._isDataChannelOpen && room.isConnected;
202
202
  };
203
203
 
204
204
  const buffering = (event, data = {}) => {
@@ -197,7 +197,7 @@ const syncHlsJs = function ({room, wt, roomSession, emitter} = {}) {
197
197
  };
198
198
 
199
199
  const isConnected = () => {
200
- return room._isDataChannelOpen && room._hasJoined;
200
+ return room._isDataChannelOpen && room.isConnected;
201
201
  };
202
202
 
203
203
  const buffering = (event, data = {}) => {
@@ -196,7 +196,7 @@ const syncVodHlsJs = function ({room, wt, roomSession, emitter} = {}) {
196
196
  };
197
197
 
198
198
  const isConnected = () => {
199
- return room._isDataChannelOpen && room._hasJoined;
199
+ return room._isDataChannelOpen && room.isConnected;
200
200
  };
201
201
 
202
202
  const executePlayerIotEvents = (data) => {
@@ -178,7 +178,7 @@ const syncNativeHls = function ({room, wt, roomSession, emitter} = {}) {
178
178
  };
179
179
 
180
180
  const isConnected = () => {
181
- return room._isDataChannelOpen && room._hasJoined;
181
+ return room._isDataChannelOpen && room.isConnected;
182
182
  };
183
183
 
184
184
  const parseDataEvents = (msg = {}) => {
@@ -196,7 +196,7 @@ const syncVodShakaDash = function ({room, wt, roomSession, emitter} = {}) {
196
196
  };
197
197
 
198
198
  const isConnected = () => {
199
- return room._isDataChannelOpen && room._hasJoined;
199
+ return room._isDataChannelOpen && room.isConnected;
200
200
  };
201
201
 
202
202
  const buffering = (event) => {
@@ -184,7 +184,7 @@ const syncDaznDash = function ({room, wt, roomSession, emitter} = {}) {
184
184
  };
185
185
 
186
186
  const isConnected = () => {
187
- return room._isDataChannelOpen && room._hasJoined;
187
+ return room._isDataChannelOpen && room.isConnected;
188
188
  };
189
189
 
190
190
  const parseDataEvents = (msg = {}) => {
@@ -181,7 +181,7 @@ const syncUniversal = function ({room, wt, roomSession, emitter} = {}) {
181
181
  };
182
182
 
183
183
  const isConnected = () => {
184
- return room._isDataChannelOpen && room._hasJoined;
184
+ return room._isDataChannelOpen && room.isConnected;
185
185
  };
186
186
 
187
187
  const parseDataEvents = (msg = {}) => {
@@ -1,6 +1,7 @@
1
1
 
2
2
  import {device} from 'aws-iot-device-sdk';
3
3
  import emitter from './wt-emitter';
4
+ import {decodeJanusDisplay} from "./wt-utils";
4
5
 
5
6
  class Iot {
6
7
 
@@ -68,14 +69,14 @@ class Iot {
68
69
  this.startCredentialsExpirationCheck(expiration);
69
70
 
70
71
  let __s = () => {
71
- this.device.off('connect', __s);
72
- this.device.off('error', __e);
72
+ this.device?.off('connect', __s);
73
+ this.device?.off('error', __e);
73
74
  resolve(this.device)
74
75
  };
75
76
 
76
77
  let __e = (e) => {
77
- this.device.off('connect', __s);
78
- this.device.off('error', __e);
78
+ this.device?.off('connect', __s);
79
+ this.device?.off('error', __e);
79
80
  reject(e);
80
81
  };
81
82
 
@@ -156,10 +157,16 @@ class Iot {
156
157
  }
157
158
 
158
159
  __messageCb(t, message, packet) {
159
-
160
160
  const topic = t.split('/');
161
- const payload = JSON.parse(this.decoder.decode(message));
162
-
161
+ let payload = JSON.parse(this.decoder.decode(message));
162
+
163
+ if(payload.display) {
164
+ const decodedDisplay = decodeJanusDisplay(payload.display);
165
+ if(decodedDisplay.userId) {
166
+ payload = {...payload, userId: decodedDisplay.userId}
167
+ }
168
+ }
169
+
163
170
  if(topic[0] === 'user') { // user
164
171
  const userId = topic[1].replace("_", ':');
165
172
  this.emit('message', {userId, ...payload, event: payload.event ? `user:${payload.event}` : 'user'});