@reactoo/watchtogether-sdk-js 2.7.97 → 2.7.98

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.
@@ -10,6 +10,7 @@
10
10
  <div class="content">
11
11
  <video id="thevideo" class="contentVideo" autoplay playsinline controls style="width: 400px" muted="muted" src="https://assetcdn.reactoo.com/watfordFc/Norwich_2010_B_roll_2min16_mute.mp4"></video>
12
12
  <div>
13
+ <button onclick="window.connectRoom()">Connect</button>
13
14
  <button onclick="window.startRoom()">Connect and publish</button>
14
15
  <button onclick="window.startRoom2()">Connect and publish with screen share</button>
15
16
  <button onclick="window.startRoom3()">Connect and publish with blank screen</button>
@@ -31,15 +32,31 @@
31
32
  <script type="module">
32
33
  import WatchTogetherSDK from '../dist/watchtogether-sdk.js';
33
34
 
35
+ function getQueryVar(varName){
36
+ const queryStr = decodeURI(window.location.search) + '&';
37
+ const regex = new RegExp('.*?[&\\?]' + varName + '=(.*?)&.*');
38
+ const val = queryStr.replace(regex, "$1");
39
+ return val === queryStr ? null : val;
40
+ }
41
+
34
42
  //https://studio.reactoo.com/room/edf441b3-7415-49c4-9557-273cb93bc746/LJj4W2Cz-nG3U-lb0R-TAaY-o7Thmb8xHSbE
35
43
 
36
44
  let roomId = "5703bcd6-a11e-4a73-bd14-12ed57227a8c"; // It will create room automatically if not set
37
45
  let pinHash = null;
46
+ let role = getQueryVar("role") || 'participant';
47
+
48
+ console.log('role', role);
38
49
 
39
50
  let participants = document.querySelector('.participants');
40
51
  var video = document.querySelector('.contentVideo');
41
52
  let constructId = 'test';
42
53
 
54
+ let sanitizeId = function (id) {
55
+ // remove ":,"
56
+ return id.replace(/[:]/g, '_').replace(/[,]/g, '_');
57
+ }
58
+
59
+
43
60
  // if(Hls.isSupported()) {
44
61
  // var hls = new Hls();
45
62
  // hls.loadSource('https://assetcdn.reactoo.com/watfordFc/Norwich_2010_B_roll_2min16_mute.mp4');
@@ -49,13 +66,6 @@
49
66
  // });
50
67
  // }
51
68
 
52
- function selectSubStream(handleId, substream, source) {
53
- return Instance.room.getSessionByConstructId(constructId).selectSubStream(handleId, substream, source);
54
- }
55
-
56
- function overrideSimulcastSettings(handleId, mid, source, settings) {
57
- return Instance.room.getSessionByConstructId(constructId).overrideSimulcastSettings(handleId, mid, source, settings);
58
- }
59
69
 
60
70
  function hento() {
61
71
  //Instance.system.getSettings();
@@ -72,17 +82,13 @@
72
82
 
73
83
  removeParticipant({id: data.id})
74
84
 
75
- if(!data.stream) {
76
- console.log('no stream for participant');
77
- return;
78
- }
79
-
85
+ const sid = sanitizeId(data.id)
80
86
  for(let key in data.streamMap) {
81
- let tracks = data.stream.getTracks().filter(t => data['streamMap'][key].includes(t.id));
87
+ let tracks = data.tracks.filter(t => data['streamMap'][key].includes(t.id));
82
88
  if(tracks.length) {
83
89
  let stream = new MediaStream();
84
90
  tracks.forEach(t => stream.addTrack(t));
85
- let id = `_p${data.id} part_${data.id}_${key}`;
91
+ let id = `_p${sid} part_${sid}_${key}`;
86
92
  let el = document.createElement("video");
87
93
  el.autoplay = true;
88
94
  el.playsInline = true;
@@ -100,7 +106,10 @@
100
106
  }
101
107
 
102
108
  function removeParticipant(data) {
103
- let id = `_p${data.id}`;
109
+
110
+ console.log('removing participant - participantData', data);
111
+
112
+ let id = `_p${sanitizeId(data.id)}`;
104
113
  let els = document.querySelectorAll(`.${id}`);
105
114
  console.log(id,els);
106
115
  els.length && els.forEach(el => el.parentNode.removeChild(el));
@@ -110,6 +119,10 @@
110
119
  Instance.room.getSessionByConstructId(constructId).disconnect()
111
120
  }
112
121
 
122
+ function connectRoom() {
123
+ Instance.room.getSessionByConstructId(constructId).connect()
124
+ }
125
+
113
126
  function startRoom() {
114
127
  let sess = Instance.room.getSessionByConstructId(constructId);
115
128
  sess.connect()
@@ -173,17 +186,6 @@
173
186
  Instance.room.getSessionByConstructId(constructId).toggleAudio()
174
187
  }
175
188
 
176
- function setListenIntercomChannels(groups) {
177
- Instance.room.getSessionByConstructId(constructId).setListenIntercomChannels(groups)
178
- }
179
-
180
- function setTalkIntercomChannels(groups) {
181
- Instance.room.getSessionByConstructId(constructId).setTalkIntercomChannels(groups)
182
- }
183
-
184
- function setRestrictSubscribeToUserIds(userIds) {
185
- Instance.room.getSessionByConstructId(constructId).setRestrictSubscribeToUserIds(userIds)
186
- }
187
189
 
188
190
  function iotLogout() {
189
191
  return Instance.iot.iotLogout()
@@ -248,7 +250,7 @@
248
250
  return r.data;
249
251
  })
250
252
  })
251
- .then(r => Instance.room.createSession({constructId, roomId:r.roomId, pinHash: r.pinHash, role:'participant', options: {
253
+ .then(r => Instance.room.createSession({constructId, roomId:r.roomId, pinHash: r.pinHash, role:role, options: {
252
254
  // simulcast: true,
253
255
  // simulcastSettings: {
254
256
  // "default" : {
@@ -361,8 +363,8 @@
361
363
  console.log('joined', status); // joined room
362
364
  });
363
365
 
364
- session.$on('published', ({status, hasStream}) => {
365
- console.log('published', status, hasStream); // published yourself (either with stream or dataChannel only, you're now able to sync the player)
366
+ session.$on('published', (status) => {
367
+ console.log('published', status); // published yourself (either with stream or dataChannel only, you're now able to sync the player)
366
368
  });
367
369
 
368
370
  session.$on('publishing', status => {
@@ -389,6 +391,14 @@
389
391
  removeParticipant(participant, true); // remote participant is gone
390
392
  });
391
393
 
394
+ session.$on('addRemoteObserver', (participant) => {
395
+ createParticipant(participant, true); // remote participant is available or updated
396
+ });
397
+
398
+ session.$on('removeRemoteObserver', (participant) => {
399
+ removeParticipant(participant, true); // remote participant is gone
400
+ });
401
+
392
402
  session.$on('userUpdate', (userId) => {
393
403
  console.log('userUpdate', userId); // User "${userId}" updated it's profile, we might do a get request to see what've changed
394
404
  });
@@ -455,6 +465,9 @@
455
465
 
456
466
  });
457
467
 
468
+ window.connectRoom = function () {
469
+ Instance.room.getSessionByConstructId(constructId).connect()
470
+ }
458
471
  // Make functions globally accessible
459
472
  window.startRoom = function() {
460
473
  let sess = Instance.room.getSessionByConstructId(constructId);
@@ -535,6 +548,30 @@
535
548
  })
536
549
  }
537
550
 
551
+ window.selectSubstream = function (id, substream, source) {
552
+ let sess = Instance.room.getSessionByConstructId(constructId);
553
+ sess.selectSubStream(id, substream, source)
554
+ .then((r) => {
555
+ console.log('substream selected', r);
556
+ })
557
+ .catch(e => {
558
+ console.log('substream select error', e);
559
+ })
560
+ }
561
+
562
+ window.setListenIntercomChannels = function(groups) {
563
+ Instance.room.getSessionByConstructId(constructId).setListenIntercomChannels(groups)
564
+ }
565
+
566
+ window.setTalkIntercomChannels = function(groups) {
567
+ Instance.room.getSessionByConstructId(constructId).setTalkIntercomChannels(groups)
568
+ }
569
+
570
+ window.setRestrictSubscribeToUserIds = function(userIds) {
571
+ Instance.room.getSessionByConstructId(constructId).setRestrictSubscribeToUserIds(userIds)
572
+ }
573
+
574
+
538
575
  </script>
539
576
 
540
577
  </body>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reactoo/watchtogether-sdk-js",
3
- "version": "2.7.97",
3
+ "version": "2.7.98",
4
4
  "description": "Javascript SDK for Reactoo",
5
5
  "main": "dist/watchtogether-sdk.min.js",
6
6
  "module": "dist/watchtogether-sdk.min.js",
@@ -36,6 +36,7 @@
36
36
  "@babel/plugin-proposal-class-properties": "^7.18.6",
37
37
  "@babel/plugin-proposal-optional-chaining": "^7.21.0",
38
38
  "@babel/plugin-proposal-private-property-in-object": "^7.21.11",
39
+ "@babel/plugin-transform-private-methods": "^7.25.9",
39
40
  "@babel/preset-env": "^7.22.10",
40
41
  "babel-loader": "^9.1.3",
41
42
  "buffer": "^6.0.3",
@@ -107,9 +107,9 @@ let asset = function() {
107
107
  .then(client => client.http({url, method: 'GET', ...options}))
108
108
  },
109
109
 
110
- createStreamAsset: (id, streamType, title, regionalPreference, ingestType, source, profile) => {
110
+ createStreamAsset: (id, title, streamType, regionalPreference, ingestType, source, profile) => {
111
111
  return this.__privates.auth.__client
112
- .then(client => client.apis.asset.publishAsset({id}, {requestBody: {assetType: 'stream', streamType, title, regionalPreference, ingestType, source, profile}}));
112
+ .then(client => client.apis.asset.publishAsset({id}, {requestBody: {assetType: 'stream', title, stream: {streamType, regionalPreference, ingestType, source, profile}}}));
113
113
  }
114
114
  }
115
115
  };
@@ -47,6 +47,10 @@ let roomSession = function ({roomId, pinHash, role, options = {}}, room, wt) {
47
47
  }, 2000);
48
48
  });
49
49
 
50
+ room.on('requestMuteStatus', () => {
51
+ ___.__requestMuteStatus();
52
+ });
53
+
50
54
  room.on('localMuted', ({type, value, source, mid}) => {
51
55
  ___.sendSystemMessage('remote_muted', {type, value, source, mid})
52
56
  });
@@ -105,12 +109,18 @@ let roomSession = function ({roomId, pinHash, role, options = {}}, room, wt) {
105
109
  role
106
110
  }, abortController?.signal)
107
111
  .then(roomData => {
112
+
108
113
  // Happens when we reroute user to a different room
109
114
  if(roomData?.data?.reactooRoomId !== roomId) {
110
115
  roomId = roomData.data.reactooRoomId;
111
116
  emitter.emit('changeRoomId', roomId);
112
117
  }
118
+
113
119
  room.setRoomType(roomData.data.roomType);
120
+
121
+ const roomSettingSimulcastEnabled = !!roomData?.data?.simulcast;
122
+ const roomSettingSimulcastConfig = roomData?.data?.simulcast||{};
123
+
114
124
  return room.connect(
115
125
  roomData.data.roomId,
116
126
  roomData.data.pin,
@@ -123,8 +133,8 @@ let roomSession = function ({roomId, pinHash, role, options = {}}, room, wt) {
123
133
  roomData.data.webrtcVersion,
124
134
  (roomData.data.bitrate ? parseInt(roomData.data.bitrate) : 0),
125
135
  roomData.data.recordingFilename,
126
- simulcast !== null ? simulcast : !!roomData?.data?.simulcast,
127
- simulcastSettings !== null ? simulcastSettings : roomData?.data?.simulcast,
136
+ simulcast !== null ? simulcast : roomSettingSimulcastEnabled,
137
+ simulcastSettings !== null ? simulcastSettings : roomSettingSimulcastConfig,
128
138
  enableDtx !== null ? enableDtx : roomData?.data?.enableDtx,
129
139
  )
130
140
  })
@@ -373,8 +383,8 @@ let roomSession = function ({roomId, pinHash, role, options = {}}, room, wt) {
373
383
  return room.requestKeyFrame(handleId, mid);
374
384
  },
375
385
 
376
- selectSubStream: (handleId, substream, source, mid) => {
377
- return room.selectSubStream(handleId, substream, source, mid, true);
386
+ selectSubStream: (id, substream, source, mid) => {
387
+ return room.selectSubStream(id, substream, source, mid, true);
378
388
  },
379
389
 
380
390
  setBitrateCap: (bitrate) => {
@@ -389,9 +399,6 @@ let roomSession = function ({roomId, pinHash, role, options = {}}, room, wt) {
389
399
  }).catch(() => null)
390
400
  },
391
401
 
392
- overrideSimulcastSettings: (handleId, mid, source, settings) => {
393
- return room.overrideSimulcastSettings(handleId, mid, source, settings);
394
- },
395
402
 
396
403
  sendSystemMessage: (action, value = {}, to, set_master) => {
397
404
  return room.sendMessage(room.handleId, {
@@ -1,5 +1,5 @@
1
1
  import emitter from './wt-emitter';
2
- import { decodeJanusDisplay } from "../models/utils";
2
+ import {decodeJanusDisplay, generateUUID} from "../models/utils";
3
3
  import Worker from './wt-iot-worker.worker.js';
4
4
 
5
5
  class Iot {
@@ -55,12 +55,12 @@ class Iot {
55
55
  this.startCredentialsExpirationCheck(expiration);
56
56
  this.lastConnectParams = { apiMqttUrl, apiMqttClientId, region, accessKeyId, secretAccessKey, sessionToken, expiration };
57
57
  return new Promise((resolve, reject) => {
58
- const stamp = new Date().getTime();
58
+ const stamp = new Date().getTime() +'_'+ generateUUID();
59
59
 
60
60
  const handleConnectResult = (event) => {
61
61
 
62
62
  if(event.stamp !== stamp) {
63
- this.log('connect event stamp mismatch', event.stamp, stamp);
63
+ this.log('connect event stamp mismatch, ignoring', event.stamp, stamp);
64
64
  return;
65
65
  }
66
66
 
@@ -101,11 +101,11 @@ class Iot {
101
101
 
102
102
  return new Promise((resolve, reject) => {
103
103
 
104
- const stamp = new Date().getTime();
104
+ const stamp = new Date().getTime()+'_'+ generateUUID();
105
105
 
106
106
  const handleDisconnectResult = (event) => {
107
107
  if(event.stamp !== stamp) {
108
- this.log('disconnect event stamp mismatch', event.stamp, stamp);
108
+ this.log('disconnect event stamp mismatch, ignoring', event.stamp, stamp);
109
109
  return;
110
110
  }
111
111
  clearTimeout(timeoutId);
@@ -164,11 +164,11 @@ class Iot {
164
164
  }
165
165
 
166
166
  return new Promise((resolve, reject) => {
167
- const stamp = new Date().getTime();
167
+ const stamp = new Date().getTime()+'_'+ generateUUID();
168
168
  const handleSubscribeResult = (event) => {
169
169
 
170
170
  if(event.stamp !== stamp) {
171
- this.log('subscribe event stamp mismatch', event.stamp, stamp);
171
+ this.log('subscribe event stamp mismatch, ignoring', event.stamp, stamp);
172
172
  return;
173
173
  }
174
174
 
@@ -200,12 +200,12 @@ class Iot {
200
200
 
201
201
  return new Promise((resolve, reject) => {
202
202
 
203
- const stamp = new Date().getTime();
203
+ const stamp = new Date().getTime()+'_'+ generateUUID();;
204
204
 
205
205
  const handleUnsubscribeResult = (event) => {
206
206
 
207
207
  if(event.stamp !== stamp) {
208
- this.log('unsubscribe event stamp mismatch', event.stamp, stamp);
208
+ this.log('unsubscribe event stamp mismatch, ignoring', event.stamp, stamp);
209
209
  return;
210
210
  }
211
211