@reactoo/watchtogether-sdk-js 2.7.1 → 2.7.2

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.
@@ -175,8 +175,8 @@
175
175
 
176
176
  let Instance = WatchTogetherSDK({debug:true})({instanceType:'reactooDemo'});
177
177
 
178
- Instance.auth.$on('login', () => {
179
- console.log('We are in');
178
+ Instance.auth.$on('login', (r) => {
179
+ console.log('We are in', r);
180
180
  });
181
181
 
182
182
  Instance.iot.$on('connect', () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reactoo/watchtogether-sdk-js",
3
- "version": "2.7.1",
3
+ "version": "2.7.2",
4
4
  "description": "Javascript SDK for Reactoo",
5
5
  "main": "src/index.js",
6
6
  "unpkg": "dist/watchtogether-sdk.min.js",
@@ -223,7 +223,7 @@ class RoomSession {
223
223
  this._maxRetries = 5;
224
224
  this._keepAliveId = null;
225
225
  this._participants = [];
226
- this._subscribeToUserIds = []; // all if empty
226
+ this._restrictSubscribeToUserIds = []; // all if empty
227
227
  this._talkIntercomChannels = ['participants'];
228
228
  this._listenIntercomChannels = ['participants'];
229
229
  this._roomType = 'watchparty';
@@ -264,7 +264,7 @@ class RoomSession {
264
264
  let localUserRole = myUser?.role || 'participant';
265
265
  let remoteUserRole = remoteUser?.role || 'participant';
266
266
  return this.userRoleSubscriptionRules[localUserRole][(this._roomType || 'watchparty')].indexOf(remoteUserRole) > -1
267
- && (this._subscribeToUserIds.length === 0 || this._subscribeToUserIds.indexOf(remoteUser?.userId) > -1);
267
+ && (this._restrictSubscribeToUserIds.length === 0 || this._restrictSubscribeToUserIds.indexOf(remoteUser?.userId) > -1);
268
268
  }
269
269
 
270
270
  _intercomSubscribe = (stream) => {
@@ -602,11 +602,8 @@ class RoomSession {
602
602
  streams[i]["display"] = userId;
603
603
  }
604
604
  this._log('Remote userId: ', userId);
605
-
606
605
  this._pushToRemoteUsersCache(userId, streams, id);
607
-
608
606
  if (this._participantShouldSubscribe(userId)) {
609
-
610
607
  this._log('Creating user: ', userId);
611
608
  this._createParticipant(userId, id)
612
609
  .then(handle => {
@@ -3180,7 +3177,9 @@ class RoomSession {
3180
3177
 
3181
3178
  setRestrictSubscribeToUserIds(userIds = []) {
3182
3179
  this._restrictSubscribeToUserIds = structuredClone(userIds);
3183
-
3180
+ if(!this.isConnected) {
3181
+ return Promise.resolve(this._restrictSubscribeToUserIds);
3182
+ }
3184
3183
  // sanity check by getting listparticipants and comparing it to _remoteUsersCache
3185
3184
  this.sendMessage(this.handleId, {body: {request: 'listparticipants', room: this.roomId}})
3186
3185
  .then(r => {
@@ -3193,25 +3192,49 @@ class RoomSession {
3193
3192
 
3194
3193
  // get rid of participants that are in participants but not in remoteUsersCache
3195
3194
  remoteUsersCache = remoteUsersCache.filter(r => participants.find(p => p.id === r.id));
3196
-
3197
3195
  remoteUsersCache.forEach(r => {
3198
- if(this._participantShouldSubscribe(r.id)) {
3199
- // if(this._getHandle(null, id)) {
3200
- //
3201
- // }
3202
- }
3203
- else {
3196
+ const handle = this._getHandle(null, null, decodeJanusDisplay(r.userId)?.userId);
3204
3197
 
3205
- }
3206
- })
3198
+ if(this._participantShouldSubscribe(r.userId)) {
3199
+ // todo: do a nicer flag to indicate inactive handle than just checking for pc
3200
+ if(!handle || !handle.webrtcStuff?.pc) {
3201
+ this._log('Subscribing to ', r.userId)
3202
+ this._createParticipant(r.userId, r.id)
3203
+ .then(handle => {
3204
+ this._updateParticipantsTrackData(handle.handleId, r.streams);
3205
+ const subscribe = r.streams.filter(s => !s.disabled && this._intercomSubscribe(s)).map(stream => ({feed: stream.id, mid: stream.mid}));
3206
+ handle.webrtcStuff.subscribeMap = structuredClone(subscribe);
3207
+ return this.sendMessage(handle.handleId, {
3208
+ body: {
3209
+ "request": "join",
3210
+ "room": this.roomId,
3211
+ "ptype": "subscriber",
3212
+ "private_id": this.privateId,
3213
+ streams: subscribe,
3214
+ //"feed": id,
3215
+ ...(this.webrtcVersion > 1000 ? {id: this.userId} : {}),
3216
+ pin: this.pin
3217
+ }
3218
+ })
3219
+ })
3220
+ .catch(err => {
3221
+ this.emit('error', err);
3222
+ })
3207
3223
 
3224
+ }
3208
3225
 
3209
- console.log(participants, remoteUsersCache);
3226
+ else {
3227
+ this._log('Already subscribed to ', r.userId);
3228
+ }
3210
3229
 
3230
+ } else if(handle) {
3231
+ this._log('Unsubscribing from ', r.userId)
3232
+ this._removeParticipant(handle.handleId);
3233
+ }
3234
+ })
3211
3235
  });
3212
3236
 
3213
3237
 
3214
- return this._restrictSubscribeToUserIds;
3215
3238
  }
3216
3239
 
3217
3240