@flashphoner/websdk 2.0.223 → 2.0.225

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/src/util.js CHANGED
@@ -92,7 +92,7 @@ const Browser = {
92
92
  return !!window.chrome && /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor) && !/OPR/.test(navigator.userAgent);
93
93
  },
94
94
  isEdge: function () {
95
- return !isIE && !!window.StyleMedia;
95
+ return !this.isIE() && !!window.StyleMedia;
96
96
  },
97
97
  isOpera: function () {
98
98
  return (!!window.opr && !!opr.addons) || !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0;
@@ -118,6 +118,33 @@ const Browser = {
118
118
  },
119
119
  isChromiumEdge: function () {
120
120
  return /Chrome/i.test(navigator.userAgent) && /Edg/i.test(navigator.userAgent);
121
+ },
122
+ version: function () {
123
+ var version = navigator.userAgent.match(/version\/(\d+)/i);
124
+ if (version) {
125
+ return version[1];
126
+ } else {
127
+ if (this.isEdge()) {
128
+ version = /\brv[ :]+(\d+)/g.exec(navigator.userAgent) || [];
129
+ }
130
+ if (this.isOpera()) {
131
+ version = navigator.userAgent.match(/\b(OPR)\/(\d+)/) || [];
132
+ }
133
+ if (this.isChromiumEdge()) {
134
+ version = navigator.userAgent.match(/\b(Edg)\/(\d+)/) || [];
135
+ }
136
+ if (this.isSamsungBrowser()) {
137
+ version = navigator.userAgent.match(/\b(SamsungBrowser)\/(\d+)/) || [];
138
+ }
139
+ if (this.isChrome()) {
140
+ version = navigator.userAgent.match(/\b(Chrome)\/(\d+)/) || [];
141
+ }
142
+ if (this.isFirefox()) {
143
+ version = navigator.userAgent.match(/\b(Firefox)\/(\d+)/) || [];
144
+ }
145
+ return version[2] || 0;
146
+ }
147
+ return 0;
121
148
  }
122
149
  };
123
150
 
@@ -384,6 +411,16 @@ const getCurrentCodecAndSampleRate = function(sdp, mediaType) {
384
411
  return ret;
385
412
  };
386
413
 
414
+ const isPromise = function(object) {
415
+ if (object !== null &&
416
+ typeof object === 'object' &&
417
+ typeof object.then === 'function' &&
418
+ typeof object.catch === 'function') {
419
+ return true;
420
+ }
421
+
422
+ return false;
423
+ };
387
424
 
388
425
  module.exports = {
389
426
  isEmptyObject,
@@ -394,5 +431,6 @@ module.exports = {
394
431
  SDP,
395
432
  logger,
396
433
  stripCodecs,
397
- getCurrentCodecAndSampleRate
434
+ getCurrentCodecAndSampleRate,
435
+ isPromise
398
436
  };
@@ -1,4 +1,4 @@
1
- 'use strict';
1
+ -'use strict';
2
2
 
3
3
  var browserDetails = require('webrtc-adapter').default.browserDetails;
4
4
  const { v1: uuid_v1 } = require('uuid');
@@ -59,6 +59,8 @@ var createConnection = function (options) {
59
59
  var videoContentHint = options.videoContentHint ? options.videoContentHint : 'detail';
60
60
  // Pass the option to unmute automatically (true by default) #WCS-2425
61
61
  var unmutePlayOnStart = options.unmutePlayOnStart !== undefined ? options.unmutePlayOnStart : true;
62
+ // Use a standard HTML5 video controls if needed (to enable fullscreen in Safari 16 for example) #WCS-3606
63
+ var useControls = options.useControls || false;
62
64
 
63
65
  if (bidirectional) {
64
66
  localVideo = getCacheInstance(localDisplay);
@@ -74,7 +76,7 @@ var createConnection = function (options) {
74
76
  }
75
77
  remoteVideo = getCacheInstance(remoteDisplay);
76
78
  if (!remoteVideo) {
77
- remoteVideo = createVideoElement();
79
+ remoteVideo = createVideoElement(useControls);
78
80
  remoteDisplay.appendChild(remoteVideo);
79
81
  }
80
82
  remoteVideo.id = id + "-remote";
@@ -95,7 +97,7 @@ var createConnection = function (options) {
95
97
  if (cachedVideo) {
96
98
  remoteVideo = cachedVideo;
97
99
  } else {
98
- remoteVideo = createVideoElement();
100
+ remoteVideo = createVideoElement(useControls);
99
101
  display.appendChild(remoteVideo);
100
102
  }
101
103
  remoteVideo.id = id;
@@ -113,9 +115,18 @@ var createConnection = function (options) {
113
115
  setContentHint(localVideo.srcObject, videoContentHint);
114
116
  connection.addStream(localVideo.srcObject);
115
117
  }
118
+ } else {
119
+ // There is a custom video element, get its id if set #WCS-3606
120
+ if (remoteVideo.id) {
121
+ id = remoteVideo.id;
122
+ }
116
123
  }
117
124
  }
118
125
  if (localVideo) {
126
+ // Enable local video controls if option requires #WCS-3606
127
+ if (useControls) {
128
+ enableVideoControls(localVideo);
129
+ }
119
130
  var videoTrack = localVideo.srcObject.getVideoTracks()[0];
120
131
  if (videoTrack) {
121
132
  videoCams.forEach((cam, index) => {
@@ -133,6 +144,12 @@ var createConnection = function (options) {
133
144
  });
134
145
  }
135
146
  }
147
+ if (remoteVideo) {
148
+ // Enable remote video controls if option requires #WCS-3606
149
+ if (useControls) {
150
+ enableVideoControls(remoteVideo);
151
+ }
152
+ }
136
153
  function setContentHint(stream, hint) {
137
154
  stream.getVideoTracks().forEach(function(track) {
138
155
  if(track.contentHint === undefined) {
@@ -480,7 +497,13 @@ var createConnection = function (options) {
480
497
  if (!document.fullscreenElement && !document.mozFullScreenElement &&
481
498
  !document.webkitFullscreenElement && !document.msFullscreenElement) {
482
499
  if (video.requestFullscreen) {
483
- video.requestFullscreen();
500
+ var result = video.requestFullscreen();
501
+ // Chromium based browsers return a promise which is rejected although user click is present #WCS-3606
502
+ if (util.isPromise(result)) {
503
+ result.catch(function(e) {
504
+ logger.debug(LOG_PREFIX, e);
505
+ });
506
+ }
484
507
  } else if (video.msRequestFullscreen) {
485
508
  video.msRequestFullscreen();
486
509
  } else if (video.mozRequestFullScreen) {
@@ -489,10 +512,18 @@ var createConnection = function (options) {
489
512
  video.webkitRequestFullscreen();
490
513
  } else if (video.webkitEnterFullscreen) {
491
514
  video.webkitEnterFullscreen();
492
- //hack for iOS safari. Video is getting paused when switching from fullscreen to normal mode.
515
+ // iOS (all versions)/MacOS (since 15) Safari hack: video is paused when leaving fullscreen mode #WCS-3606
516
+ var needRestart = false;
493
517
  video.addEventListener("pause", function () {
494
- video.play();
518
+ if(needRestart) {
519
+ video.play();
520
+ needRestart = false;
521
+ }
495
522
  });
523
+ video.addEventListener("webkitendfullscreen", function () {
524
+ video.play();
525
+ needRestart = true;
526
+ });
496
527
  }
497
528
  } else {
498
529
  if (document.exitFullscreen) {
@@ -868,7 +899,9 @@ var loadOrdinaryVideo = function(display, stream, screenShare, constraints, vide
868
899
  vEl = createVideoElement();
869
900
  display.appendChild(vEl);
870
901
  }
871
- vEl.id = uuid_v1() + LOCAL_CACHED_VIDEO;
902
+ if (!vEl.id) {
903
+ vEl.id = uuid_v1() + LOCAL_CACHED_VIDEO;
904
+ }
872
905
  vEl.srcObject = stream;
873
906
  vEl.onloadedmetadata = function (e) {
874
907
  //WCS-2751 Add screen capture using getDisplayMedia in Safari
@@ -896,7 +929,9 @@ var loadCanvasVideo = function (display, stream, video) {
896
929
  vEl = canvas;
897
930
  }
898
931
  }
899
- vEl.id = uuid_v1() + LOCAL_CACHED_VIDEO;
932
+ if (!vEl.id) {
933
+ vEl.id = uuid_v1() + LOCAL_CACHED_VIDEO;
934
+ }
900
935
 
901
936
  let child = vEl.children[0];
902
937
  child.srcObject = stream;
@@ -1203,13 +1238,16 @@ function getCacheInstance(display) {
1203
1238
  }
1204
1239
  }
1205
1240
 
1206
- function createVideoElement() {
1241
+ function createVideoElement(useControls = false) {
1207
1242
  let video = document.createElement('video');
1208
1243
  // Prepare video tag to auto play and add specific Safari tweaks #WCS-2425
1209
1244
  video.muted = true;
1210
- if(util.Browser.isSafariWebRTC()) {
1211
- video.setAttribute("playsinline", "");
1212
- video.setAttribute("webkit-playsinline", "");
1245
+ if (util.Browser.isSafariWebRTC()) {
1246
+ video.setAttribute("playsinline", "");
1247
+ video.setAttribute("webkit-playsinline", "");
1248
+ }
1249
+ if (useControls) {
1250
+ enableVideoControls(video);
1213
1251
  }
1214
1252
  return(video);
1215
1253
  }
@@ -1235,6 +1273,12 @@ function removeVideoElement(video) {
1235
1273
  }
1236
1274
  }
1237
1275
 
1276
+ function enableVideoControls(video) {
1277
+ if(video && !video.controls) {
1278
+ video.setAttribute("controls", "controls");
1279
+ }
1280
+ }
1281
+
1238
1282
  /**
1239
1283
  * Check WebRTC available
1240
1284
  *
@@ -1405,12 +1449,10 @@ var playFirstSound = function () {
1405
1449
  return false;
1406
1450
  };
1407
1451
 
1408
- var playFirstVideo = function (display, isLocal, src) {
1452
+ var playFirstVideo = function (display, isLocal, src, useControls = false) {
1409
1453
  return new Promise(function (resolve, reject) {
1410
1454
  if (!getCacheInstance(display)) {
1411
- var video = document.createElement('video');
1412
- video.setAttribute("playsinline", "");
1413
- video.setAttribute("webkit-playsinline", "");
1455
+ var video = createVideoElement(useControls);
1414
1456
  //Mute video tag to prevent local audio playback in Safari #WCS-3430
1415
1457
  video.muted = true;
1416
1458
  video.id = uuid_v1() + (isLocal ? LOCAL_CACHED_VIDEO : REMOTE_CACHED_VIDEO);
@@ -1421,6 +1463,7 @@ var playFirstVideo = function (display, isLocal, src) {
1421
1463
  video.src = src;
1422
1464
  video.play().then(function () {
1423
1465
  display.appendChild(video);
1466
+ video.removeAttribute("src");
1424
1467
  resolve();
1425
1468
  }).catch(function () {
1426
1469
  //WCS-2375. fixed autoplay in ios safari
@@ -1428,6 +1471,7 @@ var playFirstVideo = function (display, isLocal, src) {
1428
1471
  video.muted = true;
1429
1472
  video.play().then(function () {
1430
1473
  display.appendChild(video);
1474
+ video.removeAttribute("src");
1431
1475
  resolve();
1432
1476
  });
1433
1477
  //WCS-2375. low power mode suspends video play