@reactoo/watchtogether-sdk-js 2.6.67 → 2.6.69

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.
Files changed (44) hide show
  1. package/dist/watchtogether-sdk.js +6 -6
  2. package/dist/watchtogether-sdk.min.js +2 -2
  3. package/example/bulk_join_room/bulk_join_room.html +30 -30
  4. package/example/bulk_join_room/bulk_join_room_2.css +6 -1
  5. package/example/bulk_join_room/bulk_join_room_2.html +304 -137
  6. package/example/bulk_join_room/sound_empty.mp3 +0 -0
  7. package/example/index.html +26 -14
  8. package/package.json +1 -1
  9. package/src/models/room-session.js +12 -5
  10. package/src/models/room.js +1 -0
  11. package/src/modules/wt-room.js +504 -51
  12. package/src/modules/wt-utils.js +29 -1
  13. /package/example/bulk_join_room/{persons_gifs → persons_gifs_lq}/1.gif +0 -0
  14. /package/example/bulk_join_room/{persons_gifs → persons_gifs_lq}/10.gif +0 -0
  15. /package/example/bulk_join_room/{persons_gifs → persons_gifs_lq}/11.gif +0 -0
  16. /package/example/bulk_join_room/{persons_gifs → persons_gifs_lq}/12.gif +0 -0
  17. /package/example/bulk_join_room/{persons_gifs → persons_gifs_lq}/13.gif +0 -0
  18. /package/example/bulk_join_room/{persons_gifs → persons_gifs_lq}/14.gif +0 -0
  19. /package/example/bulk_join_room/{persons_gifs → persons_gifs_lq}/15.gif +0 -0
  20. /package/example/bulk_join_room/{persons_gifs → persons_gifs_lq}/16.gif +0 -0
  21. /package/example/bulk_join_room/{persons_gifs → persons_gifs_lq}/17.gif +0 -0
  22. /package/example/bulk_join_room/{persons_gifs → persons_gifs_lq}/18.gif +0 -0
  23. /package/example/bulk_join_room/{persons_gifs → persons_gifs_lq}/19.gif +0 -0
  24. /package/example/bulk_join_room/{persons_gifs → persons_gifs_lq}/2.gif +0 -0
  25. /package/example/bulk_join_room/{persons_gifs → persons_gifs_lq}/20.gif +0 -0
  26. /package/example/bulk_join_room/{persons_gifs → persons_gifs_lq}/21.gif +0 -0
  27. /package/example/bulk_join_room/{persons_gifs → persons_gifs_lq}/22.gif +0 -0
  28. /package/example/bulk_join_room/{persons_gifs → persons_gifs_lq}/23.gif +0 -0
  29. /package/example/bulk_join_room/{persons_gifs → persons_gifs_lq}/24.gif +0 -0
  30. /package/example/bulk_join_room/{persons_gifs → persons_gifs_lq}/25.gif +0 -0
  31. /package/example/bulk_join_room/{persons_gifs → persons_gifs_lq}/26.gif +0 -0
  32. /package/example/bulk_join_room/{persons_gifs → persons_gifs_lq}/27.gif +0 -0
  33. /package/example/bulk_join_room/{persons_gifs → persons_gifs_lq}/28.gif +0 -0
  34. /package/example/bulk_join_room/{persons_gifs → persons_gifs_lq}/29.gif +0 -0
  35. /package/example/bulk_join_room/{persons_gifs → persons_gifs_lq}/3.gif +0 -0
  36. /package/example/bulk_join_room/{persons_gifs → persons_gifs_lq}/30.gif +0 -0
  37. /package/example/bulk_join_room/{persons_gifs → persons_gifs_lq}/31.gif +0 -0
  38. /package/example/bulk_join_room/{persons_gifs → persons_gifs_lq}/32.gif +0 -0
  39. /package/example/bulk_join_room/{persons_gifs → persons_gifs_lq}/4.gif +0 -0
  40. /package/example/bulk_join_room/{persons_gifs → persons_gifs_lq}/5.gif +0 -0
  41. /package/example/bulk_join_room/{persons_gifs → persons_gifs_lq}/6.gif +0 -0
  42. /package/example/bulk_join_room/{persons_gifs → persons_gifs_lq}/7.gif +0 -0
  43. /package/example/bulk_join_room/{persons_gifs → persons_gifs_lq}/8.gif +0 -0
  44. /package/example/bulk_join_room/{persons_gifs → persons_gifs_lq}/9.gif +0 -0
@@ -6,6 +6,8 @@
6
6
  <title>The Bulk Join 2</title>
7
7
  <script src="../../dist/watchtogether-sdk.js"></script>
8
8
  <link rel="stylesheet" href="./bulk_join_room_2.css">
9
+
10
+ <style>.--high-quality{display:none}</style>
9
11
  </head>
10
12
 
11
13
  <body>
@@ -18,49 +20,57 @@
18
20
  <input type="number" id="participants-count" onchange="applySettingsFromForm()">
19
21
  </div>
20
22
 
21
- <div class="form-group">
23
+ <div class="form-group --advanced --high-quality">
24
+ <label for="participants-high-quality">High quality</label>
25
+ <input type="checkbox" id="participants-high-quality" onchange="applySettingsFromForm()">
26
+ </div>
27
+
28
+ <div class="form-group --advanced">
22
29
  <label for="participants-order-randomization">Participants order randomization</label>
23
30
  <input type="checkbox" id="participants-order-randomization" onchange="applySettingsFromForm()">
24
31
  </div>
25
32
 
33
+
26
34
  <div class="form-group">
27
35
  <label for="room-id">Room ID</label>
28
36
  <input type="text" id="room-id" onchange="applySettingsFromForm()">
29
37
  </div>
30
38
 
31
- <div class="form-group">
39
+ <div class="form-group --advanced">
32
40
  <label for="pin-hash">Pin hash</label>
33
41
  <input type="text" id="pin-hash" placeholder="Not required" onchange="applySettingsFromForm()">
34
42
  </div>
35
43
 
36
- <div class="form-group">
44
+ <div class="form-group --advanced">
37
45
  <label for="room-id">Connection delay (seconds)</label>
38
46
  <input type="number" id="connection-delay" min="0" step="0.25" onchange="applySettingsFromForm()">
39
47
  </div>
40
48
 
41
- <div class="form-group">
49
+ <div class="form-group --advanced">
42
50
  <label for="parallel-queues">Parallel connection queues</label>
43
51
  <input type="number" id="parallel-queues" min="1" step="4" onchange="applySettingsFromForm()">
44
52
  </div>
45
53
 
46
- <div class="form-group">
54
+ <div class="form-group --advanced">
47
55
  <label for="instance-type">Instance type</label>
48
56
  <input type="text" id="instance-type" onchange="applySettingsFromForm()">
49
57
  </div>
50
58
 
51
- <div class="form-group">
59
+ <div class="form-group --advanced">
52
60
  <label for="swagger-url">Swagger URL</label>
53
61
  <input type="text" id="swagger-url" onchange="applySettingsFromForm()">
54
62
  </div>
55
63
 
56
- <div class="form-group">
64
+ <div class="form-group --advanced">
57
65
  <label for="fetch-names">Fetch participants names</label>
58
66
  <input type="checkbox" id="fetch-names" onchange="applySettingsFromForm()">
59
67
  </div>
60
68
 
61
69
  <div class="form-group">
62
- <button type="button" onclick="resetSettings()">Reset settings</button>
70
+ <button type="button" class="--advanced" onclick="resetSettings()">Reset settings</button>
71
+ <button type="button" class="--high-quality" onclick="toggleAdvancedSettings()">Toggle advanced settings</button>
63
72
  </div>
73
+
64
74
  </div>
65
75
 
66
76
  <div class="participants-constrols">
@@ -68,17 +78,22 @@
68
78
  <div class="form-group">
69
79
  <button type="button" onclick="createParticipants()">Create participants (without connect)</button>
70
80
  <button type="button" onclick="destroyParticipants()">Destroy participants</button>
71
- <br>
72
- <button type="button" onclick="createSingleParticipant()">Create single participant (without connect)</button>
81
+ <br class="--advanced">
82
+ <button type="button" class="--advanced" onclick="createSingleParticipant()">Create single participant (without connect)</button>
73
83
  <br>
74
84
  <button type="button" onclick="joinParticipantsToRoom()">Join all participants to room</button>
75
85
  <button type="button" onclick="disconnectParticipantsFromRoom()">Disconnect all participants from room</button>
76
- <br>
77
- <div class="form-group">
86
+ <br class="--advanced">
87
+ <div class="form-group --advanced">
78
88
  <label for="participants-names">Participants names (one name per line)</label>
79
89
  <textarea id="participants-names" rows="5" onchange="applySettingsFromForm()"></textarea>
80
90
  </div>
81
- <button type="button" onclick="setParticipantsNames()">Set Participants Names</button>
91
+ <button type="button" class="--advanced" onclick="setParticipantsNames()">Set Participants Names</button>
92
+ </div>
93
+
94
+ <div class="heading --advanced">Room controls</div>
95
+ <div class="form-group --advanced">
96
+ <button type="button" onclick="initiazeFakeChat()">Initiate fake chat</button>
82
97
  </div>
83
98
  </div>
84
99
 
@@ -96,10 +111,12 @@
96
111
  const settingsUrlParameterName = 'settings';
97
112
 
98
113
  const defaultSettings = {
114
+ advancedSettings: true,
99
115
  participantsCount: 5,
116
+ participantsHighQuality: false,
100
117
  participantsOrderRandomization: false,
101
118
  minParticipantsCount: 1,
102
- maxParticipantsCount: 32,
119
+ maxParticipantsCount: 41,
103
120
  roomId: "",
104
121
  pinHash: "",
105
122
  connectionDelay: 1,
@@ -110,7 +127,9 @@
110
127
  participantsNames: [],
111
128
  };
112
129
 
113
- const gifsCount = 32; // Number of gifs in ./persons_gifs folder
130
+ const gifsCount_lq = 32; // Number of gifs in ./persons_gifs_lq folder
131
+ const gifsCount_hq = 17; // Number of gifs in ./persons_gifs_hq folder
132
+ let gifsCount = gifsCount_hq + gifsCount_lq;
114
133
 
115
134
  // ====================== General Variables ===============================
116
135
 
@@ -119,6 +138,7 @@
119
138
  const elements = {
120
139
  form: {
121
140
  participantsCount: document.getElementById("participants-count"),
141
+ participantsHighQuality: document.getElementById("participants-high-quality"),
122
142
  participantsOrderRandomization: document.getElementById("participants-order-randomization"),
123
143
  roomId: document.getElementById("room-id"),
124
144
  pinHash: document.getElementById("pin-hash"),
@@ -134,7 +154,9 @@
134
154
 
135
155
  const participants = new Array(gifsCount).fill(undefined);
136
156
 
137
- const usedGifsIds = [];
157
+ let usedGifsIds = [];
158
+
159
+ let usedGifsTimes = 0;
138
160
 
139
161
  const audioContext = new (window.AudioContext || window.webkitAudioContext)();
140
162
 
@@ -151,7 +173,9 @@
151
173
 
152
174
  function applySettingsFromForm() {
153
175
  settings = {
176
+ advancedSettings: !!settings.advancedSettings,
154
177
  participantsCount: parseInt(elements.form.participantsCount.value) || defaultSettings.participantsCount,
178
+ participantsHighQuality: elements.form.participantsHighQuality.checked,
155
179
  participantsOrderRandomization: elements.form.participantsOrderRandomization.checked,
156
180
  minParticipantsCount: parseInt(settings.minParticipantsCount) || defaultSettings.minParticipantsCount,
157
181
  maxParticipantsCount: parseInt(settings.maxParticipantsCount) || defaultSettings.maxParticipantsCount,
@@ -201,8 +225,24 @@
201
225
  fillSettingsForm();
202
226
  }
203
227
 
228
+ function toggleAdvancedSettings() {
229
+ const advancedSettings = settings.advancedSettings;
230
+ const participantsCount = settings.participantsCount;
231
+ const roomId = settings.roomId;
232
+
233
+ resetSettings();
234
+
235
+ settings.advancedSettings = !advancedSettings;
236
+ settings.participantsCount = participantsCount;
237
+ settings.roomId = roomId;
238
+
239
+ setSettingsToUrl(false);
240
+ location.reload();
241
+ }
242
+
204
243
  function fillSettingsForm() {
205
244
  elements.form.participantsCount.value = settings.participantsCount;
245
+ elements.form.participantsHighQuality.checked = settings.participantsHighQuality;
206
246
  elements.form.participantsOrderRandomization.checked = settings.participantsOrderRandomization;
207
247
  elements.form.roomId.value = settings.roomId;
208
248
  elements.form.pinHash.value = settings.pinHash;
@@ -217,15 +257,31 @@
217
257
  // ====================== Main Logic ==================================
218
258
 
219
259
  function getRandomNotUsedGifId() {
260
+
261
+ if (settings.participantsHighQuality){
262
+ gifsCount = gifsCount_hq;
263
+ } else {
264
+ gifsCount = gifsCount_lq;
265
+ }
266
+
267
+ if (usedGifsIds.length >= gifsCount) {
268
+ usedGifsIds = [];
269
+ usedGifsTimes++;
270
+
271
+ }
272
+
220
273
  const availableGifsIds = new Array(gifsCount).fill().map((_, index) => index+1).filter(e => !usedGifsIds.includes(e));
221
274
  let randomNotUsedGifId;
222
275
 
276
+
223
277
  if (settings.participantsOrderRandomization) {
224
278
  randomNotUsedGifId = availableGifsIds[Math.floor(Math.random() * availableGifsIds.length)];
225
279
  } else {
226
280
  randomNotUsedGifId = Math.min(...availableGifsIds);
227
281
  }
228
282
 
283
+ // console.log(randomNotUsedGifId);
284
+
229
285
  if (randomNotUsedGifId) {
230
286
  usedGifsIds.push(randomNotUsedGifId);
231
287
  return randomNotUsedGifId;
@@ -235,13 +291,24 @@
235
291
  }
236
292
 
237
293
  function createParticipant(participantOrder) {
238
- const gifId = getRandomNotUsedGifId();
294
+
295
+ // const gifId = getRandomNotUsedGifId();
296
+ const gifId = getRandomNotUsedGifId() + usedGifsTimes * gifsCount;
239
297
 
240
298
  if (gifId === null) {
241
299
  return Promise.reject();
242
300
  }
243
301
 
244
- const gifUrl = `./persons_gifs/${gifId}.gif`;
302
+ let gifUrl;
303
+
304
+ if (settings.participantsHighQuality){
305
+ // console.log("hq");
306
+ gifUrl = `./persons_gifs_hq/${gifId - usedGifsTimes * gifsCount}.mp4`;
307
+ } else {
308
+ // console.log("lq");
309
+ gifUrl = `./persons_gifs_lq/${gifId - usedGifsTimes * gifsCount}.gif`;
310
+ }
311
+
245
312
  const frameIndex = 0;
246
313
  const sdkInstance = WatchTogetherSDK({debug: true, storagePrefix: `participant_${gifId}`, apiUrl: settings.swaggerUrl})({instanceType: settings.instanceType});
247
314
 
@@ -250,49 +317,75 @@
250
317
  containerElement.setAttribute('data-participant-id', gifId);
251
318
  containerElement.style.order = participantOrder;
252
319
 
253
- const canvasElement = document.createElement('canvas');
254
- canvasElement.setAttribute('title', `Gif ID - ` + gifId);
255
- const canvasContext = canvasElement.getContext('2d');
256
- containerElement.appendChild(canvasElement);
320
+ let canvasElement;
321
+ let canvasContext;
322
+
323
+ if (settings.participantsHighQuality){
324
+ canvasElement = document.createElement('video')
325
+ canvasElement.setAttribute('title', `Video ID - ` + gifId);
326
+ canvasElement.src = gifUrl;
327
+ canvasElement.muted = false;
328
+ canvasElement.height = 270;
329
+ canvasElement.width = 480;
330
+ canvasElement.autoplay = true;
331
+ canvasElement.loop = true;
332
+ containerElement.appendChild(canvasElement);
333
+ // console.log(canvasElement);
334
+ } else {
335
+ canvasElement = document.createElement('canvas');
336
+ canvasElement.setAttribute('title', `Gif ID - ` + gifId);
337
+ canvasContext = canvasElement.getContext('2d');
338
+ containerElement.appendChild(canvasElement);
339
+ }
340
+
341
+ // const canvasElement = document.createElement('canvas');
342
+ // canvasElement.setAttribute('title', `Gif ID - ` + gifId);
343
+ // const canvasContext = canvasElement.getContext('2d');
344
+ // containerElement.appendChild(canvasElement);
257
345
 
258
346
  let spaceElement = document.createElement('div');
259
- spaceElement.className = 'space';
347
+ spaceElement.classList.add('space');
260
348
  containerElement.appendChild(spaceElement);
261
349
 
262
350
  let participantNameElement;
263
351
  participantNameElement = document.createElement('input');
264
352
  participantNameElement.setAttribute('type', 'text');
265
353
  participantNameElement.setAttribute('placeholder', 'Name');
354
+ participantNameElement.classList.add('--advanced');
266
355
  containerElement.appendChild(participantNameElement);
267
356
 
268
357
  const getNameButtonElement = document.createElement('button');
269
358
  getNameButtonElement.innerText = 'Get name';
270
359
  getNameButtonElement.addEventListener('click', () => {
271
360
  sdkInstance.user.getUserSelf()
272
- .then(response => {
273
- participants[gifId].displayname = response.data.displayname;
274
- participantNameElement.value = response.data.displayname;
275
- });
361
+ .then(response => {
362
+ participants[gifId].displayname = response.data.displayname;
363
+ participantNameElement.value = response.data.displayname;
364
+ });
276
365
  });
366
+ getNameButtonElement.classList.add('--advanced');
277
367
  containerElement.appendChild(getNameButtonElement);
278
368
 
279
369
  const setNameButtonElement = document.createElement('button');
280
370
  setNameButtonElement.innerText = 'Save name';
281
371
  setNameButtonElement.addEventListener('click', () => sdkInstance.user.updateUserSelf({lastRoomId: settings.roomId, displayname: participantNameElement.value}));
372
+ setNameButtonElement.classList.add('--advanced');
282
373
  containerElement.appendChild(setNameButtonElement);
283
374
 
284
375
  spaceElement = document.createElement('div');
285
- spaceElement.className = 'space';
376
+ spaceElement.classList.add('space', '--advanced');
286
377
  containerElement.appendChild(spaceElement);
287
378
 
288
379
  const destroyButtonElement = document.createElement('button');
289
380
  destroyButtonElement.innerText = 'Destroy';
290
381
  destroyButtonElement.addEventListener('click', () => destroyParticipant(participants[gifId]));
382
+ destroyButtonElement.classList.add('--advanced');
291
383
  containerElement.appendChild(destroyButtonElement);
292
384
 
293
385
  const joinButtonElement = document.createElement('button');
294
386
  joinButtonElement.innerText = 'Join';
295
387
  joinButtonElement.addEventListener('click', () => joinParticipantToRoom(participants[gifId]));
388
+ joinButtonElement.classList.add('--advanced');
296
389
  containerElement.appendChild(joinButtonElement);
297
390
 
298
391
  const leaveButtonElement = document.createElement('button');
@@ -301,17 +394,19 @@
301
394
  containerElement.appendChild(leaveButtonElement);
302
395
 
303
396
  spaceElement = document.createElement('div');
304
- spaceElement.className = 'space';
397
+ spaceElement.classList.add('space', '--advanced');
305
398
  containerElement.appendChild(spaceElement);
306
399
 
307
400
  const toggleCameraButtonElement = document.createElement('button');
308
401
  toggleCameraButtonElement.innerText = 'Toggle camera';
309
402
  toggleCameraButtonElement.addEventListener('click', () => participants[gifId].session.toggleVideo());
403
+ toggleCameraButtonElement.classList.add('--advanced');
310
404
  containerElement.appendChild(toggleCameraButtonElement);
311
405
 
312
406
  const toggleAudioButtonElement = document.createElement('button');
313
407
  toggleAudioButtonElement.innerText = 'Toggle audio';
314
408
  toggleAudioButtonElement.addEventListener('click', () => participants[gifId].session.toggleAudio());
409
+ toggleAudioButtonElement.classList.add('--advanced');
315
410
  containerElement.appendChild(toggleAudioButtonElement);
316
411
 
317
412
  const toggleRaiseHandButtonElement = document.createElement('button');
@@ -320,64 +415,120 @@
320
415
  sdkInstance.room.setUser({roomId: settings.roomId, userId: participants[gifId].sdkInstance.userId, flag: participants[gifId].handRaised ? 'handLower' : 'handRaise'});
321
416
  participants[gifId].handRaised = !participants[gifId].handRaised;
322
417
  });
418
+ toggleRaiseHandButtonElement.classList.add('--advanced');
323
419
  containerElement.appendChild(toggleRaiseHandButtonElement);
324
420
 
325
- return fetch(gifUrl)
326
- .then(response => {
327
- const imageDecoder = new ImageDecoder({data: response.body, type: 'image/gif'});
328
-
329
- const participant = {
330
- gifId,
331
- gifUrl,
332
- imageDecoder,
333
- frameIndex,
334
- reverseOrder: false, // boomerang animation
335
- width: null, // Will be set after first frame is decoded
336
- height: null, // Will be set after first frame is decoded
337
- canvas: canvasElement,
338
- canvasContext,
339
- sdkInstance,
340
- loginPromise: sdkInstance.auth.deviceLogin(gifId),
341
- session: null, // Will be set after room join
342
- handRaised: false,
343
- };
344
-
345
- if (settings.fetchNames) {
346
- participant.loginPromise.then(() => sdkInstance.user.getUserSelf())
421
+ let participant;
422
+
423
+ if (settings.participantsHighQuality){
424
+ participant = {
425
+ gifId,
426
+ gifUrl,
427
+ frameIndex,
428
+ reverseOrder: false, // boomerang animation
429
+ width: canvasElement.width, // Will be set after first frame is decoded
430
+ height: canvasElement.height, // Will be set after first frame is decoded
431
+ canvas: canvasElement,
432
+ sdkInstance,
433
+ loginPromise: sdkInstance.auth.deviceLogin(false, gifId),
434
+ session: null, // Will be set after room join
435
+ handRaised: false,
436
+ };
437
+
438
+ if (settings.fetchNames) {
439
+ participant.loginPromise.then(() => sdkInstance.user.getUserSelf())
347
440
  .then(response => {
348
441
  participant.displayname = response.data.displayname;
349
442
  participantNameElement.value = response.data.displayname;
350
443
  });
351
- }
352
-
353
- return imageDecoder
354
- .decode({frameIndex})
355
- .then(decodeResult => {
356
- participant.width = decodeResult.image.displayWidth;
357
- participant.canvas.width = decodeResult.image.displayWidth;
358
-
359
- participant.height = decodeResult.image.displayHeight;
360
- participant.canvas.height = decodeResult.image.displayHeight;
361
444
 
362
- participant.canvas.id = `canvas-${participant.gifId}`;
445
+ }
363
446
 
364
- // Start render loop
365
- renderGif(decodeResult, participant);
447
+ elements.participantsList.appendChild(containerElement);
448
+ return Promise.resolve(participant);
366
449
 
367
- elements.participantsList.appendChild(containerElement);
368
450
 
369
- return participant;
451
+ } else {
452
+ return fetch(gifUrl)
453
+ .then(response => {
454
+ const imageDecoder = new ImageDecoder({data: response.body, type: 'image/gif'});
455
+
456
+ // if(typeof canvasElement !== "object") {
457
+ // console.log(settings.participantsHighQuality, typeof settings.participantsHighQuality, typeof canvasElement);
458
+ // }
459
+
460
+ participant = {
461
+ gifId,
462
+ gifUrl,
463
+ imageDecoder,
464
+ frameIndex,
465
+ reverseOrder: false, // boomerang animation
466
+ width: null, // Will be set after first frame is decoded
467
+ height: null, // Will be set after first frame is decoded
468
+ canvas: canvasElement,
469
+ canvasContext,
470
+ sdkInstance,
471
+ loginPromise: sdkInstance.auth.deviceLogin(false, gifId),
472
+ session: null, // Will be set after room join
473
+ handRaised: false,
474
+ };
475
+
476
+ if (settings.fetchNames) {
477
+ participant.loginPromise.then(() => sdkInstance.user.getUserSelf())
478
+ .then(response => {
479
+ participant.displayname = response.data.displayname;
480
+ participantNameElement.value = response.data.displayname;
481
+ });
482
+ }
483
+
484
+ return imageDecoder
485
+ .decode({frameIndex})
486
+ .then(decodeResult => {
487
+ participant.width = decodeResult.image.displayWidth;
488
+ participant.canvas.width = decodeResult.image.displayWidth;
489
+
490
+ participant.height = decodeResult.image.displayHeight;
491
+ participant.canvas.height = decodeResult.image.displayHeight;
492
+
493
+ participant.canvas.id = `canvas-${participant.gifId}`;
494
+
495
+ // Start render loop
496
+ renderGif(decodeResult, participant);
497
+
498
+ elements.participantsList.appendChild(containerElement);
499
+ return participant;
500
+ });
370
501
  });
371
- });
502
+ }
503
+
372
504
  }
373
505
 
374
506
  function createParticipants(participantsCount = settings.participantsCount) {
507
+
375
508
  destroyParticipants()
376
- .then(() => {
377
- for (let i = 0; i < participantsCount; i++) {
378
- createParticipant(i).then(participant => participants[participant.gifId] = participant);
379
- }
380
- })
509
+ .then(() => {
510
+ for (let i = 0; i < participantsCount; i++) {
511
+ createParticipant(i).then(participant => {
512
+ participants[participant.gifId] = participant;
513
+ });
514
+ }
515
+ })
516
+ }
517
+
518
+ function initiazeFakeChat() {
519
+ req = "https://api.reactoo.com/v3/wt/room?demo=true&id=" + elements.form.roomId.value;
520
+
521
+ const sdkInstance = WatchTogetherSDK({debug: true, storagePrefix: `participant_fakeChat`, apiUrl: settings.swaggerUrl})({instanceType: settings.instanceType});
522
+
523
+ sdkInstance.auth.deviceLogin(false, "participant_fakeChat").then(() => {
524
+ sdkInstance.room.getRoomById(elements.form.roomId.value, elements.form.pinHash.value, undefined, true)
525
+ .then(response => {
526
+ console.log(response);
527
+ })
528
+ .catch(error => {
529
+ console.log(error);
530
+ });
531
+ });
381
532
  }
382
533
 
383
534
  function createSingleParticipant() {
@@ -385,55 +536,65 @@
385
536
 
386
537
  console.log(participantOrder);
387
538
 
539
+
388
540
  createParticipant(participantOrder)
389
- .then(participant => participants[participant.gifId] = participant);
541
+ .then(participant => participants[participant.gifId] = participant);
390
542
  }
391
543
 
392
544
  function destroyParticipant(participant) {
393
545
  disconnectParticipantFromRoom(participant)
394
- .then(() => {
395
- participant.imageDecoder.close();
396
- participant.sdkInstance.auth.logout();
397
- usedGifsIds.splice(usedGifsIds.indexOf(participant.gifId), 1);
398
- document.querySelector('.participant-container[data-participant-id="' + participant.gifId + '"]').remove();
399
-
400
- participants[participant.gifId] = undefined;
401
- });
402
- }
546
+ .then(() => {
547
+ if (participant.imageDecoder) {
548
+ participant.imageDecoder.close();
549
+ }
403
550
 
404
- function destroyParticipants() {
405
- return disconnectParticipantsFromRoom()
406
- .then(() => {
407
- participants.filter(p => p).forEach(participant => {
408
- participant.imageDecoder.close();
409
551
  participant.sdkInstance.auth.logout();
410
552
  usedGifsIds.splice(usedGifsIds.indexOf(participant.gifId), 1);
411
553
  document.querySelector('.participant-container[data-participant-id="' + participant.gifId + '"]').remove();
554
+
555
+ participants[participant.gifId] = undefined;
412
556
  });
557
+ }
558
+
559
+ function destroyParticipants() {
560
+ return disconnectParticipantsFromRoom()
561
+ .then(() => {
562
+ participants.filter(p => p).forEach(participant => {
563
+ if (participant.imageDecoder) {
564
+ participant.imageDecoder.close();
565
+ }
566
+ participant.sdkInstance.auth.logout();
567
+ usedGifsIds.splice(usedGifsIds.indexOf(participant.gifId), 1);
568
+ document.querySelector('.participant-container[data-participant-id="' + participant.gifId + '"]').remove();
569
+ });
413
570
 
414
- for (let i = 0 ; i < participants.length ; i++) {
415
- if (participants[i]) {
416
- participants[i] = undefined;
571
+ for (let i = 0 ; i < participants.length ; i++) {
572
+ if (participants[i]) {
573
+ participants[i] = undefined;
574
+ }
417
575
  }
418
- }
419
- });
576
+ usedGifsTimes = 0;
577
+ });
420
578
  }
421
579
 
422
580
  function joinParticipantToRoom(participant) {
423
581
  return participant.loginPromise.then(() => {
424
582
  participant.sdkInstance.room.createSession({roomId: settings.roomId, pinHash: settings.pinHash})
425
- .then(session => {
426
- participant.session = session;
427
- return Promise.all([session, session.connect()])
428
- })
429
- .then(([session, _]) => {
430
- return getAudioStream()
431
- .then(audioStream => {
432
- participant.stream = participant.canvas.captureStream();
433
- participant.stream.addTrack(audioStream.getAudioTracks()[0]);
434
- return session.publishLocal(participant.stream, 'camera0');
435
- });
436
- });
583
+ .then(session => {
584
+ participant.session = session;
585
+ return Promise.all([session, session.connect()])
586
+ })
587
+ .then(([session, _]) => {
588
+ return getAudioStream()
589
+ .then(audioStream => {
590
+ participant.stream = participant.canvas.captureStream();
591
+ if (participant.stream.getAudioTracks().length === 0) {
592
+ participant.stream.addTrack(audioStream.getAudioTracks()[0]);
593
+ }
594
+ return session.publishLocal(participant.stream, 'camera0')
595
+ // .then(() => participant.session.toggleAudio(false));
596
+ });
597
+ });
437
598
  });
438
599
  }
439
600
 
@@ -446,15 +607,15 @@
446
607
  for (let i = 0 ; i < participants.filter(p => p).length ; i++) {
447
608
  const parallelQueueIndex = i % settings.parallelQueues;
448
609
  parallelQueues[parallelQueueIndex] = parallelQueues[parallelQueueIndex]
449
- .then(() => joinParticipantToRoom(participants.filter(p => p)[i]))
450
- .then(() => new Promise(resolve => setTimeout(resolve, settings.connectionDelay * 1000)));
610
+ .then(() => joinParticipantToRoom(participants.filter(p => p)[i]))
611
+ .then(() => new Promise(resolve => setTimeout(resolve, settings.connectionDelay * 1000)));
451
612
  }
452
613
  } else {
453
614
  // Serial join
454
615
 
455
616
  return participants.filter(p => p).reduce((promiseChain, participant) => {
456
617
  return promiseChain.then(() => joinParticipantToRoom(participant))
457
- .then(() => new Promise(resolve => setTimeout(resolve, settings.connectionDelay * 1000)));
618
+ .then(() => new Promise(resolve => setTimeout(resolve, settings.connectionDelay * 1000)));
458
619
  }, Promise.resolve());
459
620
  }
460
621
  }
@@ -462,12 +623,12 @@
462
623
  function disconnectParticipantFromRoom(participant) {
463
624
  if (participant && participant.loginPromise) {
464
625
  return participant.loginPromise
465
- .then(() => {
466
- if (participant.session && participant.session.disconnect) {
467
- return participant.session.disconnect();
468
- }
469
- })
470
- .then(() => participant.session = null);
626
+ .then(() => {
627
+ if (participant.session && participant.session.disconnect) {
628
+ return participant.session.disconnect();
629
+ }
630
+ })
631
+ .then(() => participant.session = null);
471
632
  }
472
633
  }
473
634
 
@@ -505,19 +666,19 @@
505
666
 
506
667
  // Decode the next frame ahead of display so it's ready in time.
507
668
  participant.imageDecoder.decode({frameIndex: participant.frameIndex})
508
- .then( nextDecodeResult => setTimeout(_ => {
509
- renderGif(nextDecodeResult, participant);
510
- }, decodeResult.image.duration / 1000.0))
511
- .catch(e => {
512
- // We can end up requesting an imageIndex past the end since we're using
513
- // a ReadableStrem from fetch(), when this happens just wrap around.
514
- if (e instanceof RangeError) {
515
- participant.frameIndex = 0;
516
- participant.imageDecoder.decode({frameIndex: imageIndex}).then(decodeResult => renderGif(decodeResult, participant));
517
- } else {
518
- throw e;
519
- }
520
- });
669
+ .then( nextDecodeResult => setTimeout(_ => {
670
+ renderGif(nextDecodeResult, participant);
671
+ }, decodeResult.image.duration / 1000.0))
672
+ .catch(e => {
673
+ // We can end up requesting an imageIndex past the end since we're using
674
+ // a ReadableStrem from fetch(), when this happens just wrap around.
675
+ if (e instanceof RangeError) {
676
+ participant.frameIndex = 0;
677
+ participant.imageDecoder.decode({frameIndex: imageIndex}).then(decodeResult => renderGif(decodeResult, participant));
678
+ } else {
679
+ throw e;
680
+ }
681
+ });
521
682
  }
522
683
 
523
684
  function setParticipantsNames() {
@@ -534,22 +695,22 @@
534
695
  return new Promise(resolve => {
535
696
  const request = new XMLHttpRequest();
536
697
  // https://ttsmp3.com/
537
- request.open('GET', './sound_2.mp3', true);
698
+ request.open('GET', './sound_empty.mp3', true);
538
699
  request.responseType = 'arraybuffer';
539
700
  request.onload = function() {
540
701
  audioContext.decodeAudioData(request.response)
541
- .then(buffer => {
542
- const streamDestination = audioContext.createMediaStreamDestination();
543
- const source = audioContext.createBufferSource();
544
- source.buffer = buffer;
545
- source.connect(streamDestination);
546
- source.loop = true;
547
- source.start();
702
+ .then(buffer => {
703
+ const streamDestination = audioContext.createMediaStreamDestination();
704
+ const source = audioContext.createBufferSource();
705
+ source.buffer = buffer;
706
+ source.connect(streamDestination);
707
+ source.loop = true;
708
+ source.start();
548
709
 
549
- new Audio().srcObject = streamDestination.stream;
710
+ new Audio().srcObject = streamDestination.stream;
550
711
 
551
- resolve(streamDestination.stream);
552
- });
712
+ resolve(streamDestination.stream);
713
+ });
553
714
  }
554
715
  request.send();
555
716
  });
@@ -560,6 +721,12 @@
560
721
  document.addEventListener("DOMContentLoaded", function() {
561
722
  initializeSettings();
562
723
  getSettingsFromUrl();
724
+
725
+ if (!settings.advancedSettings) {
726
+ settings.participantsHighQuality = true;
727
+ document.head.insertAdjacentHTML("beforeend", `<style>.--advanced{display:none}</style>`)
728
+ }
729
+
563
730
  fillSettingsForm();
564
731
  });
565
732