@flashphoner/websdk 2.0.224 → 2.0.226

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.
@@ -60,10 +60,6 @@
60
60
  <label class="check-label" for="MSE"><input id="MSE" type="checkbox" checked/>
61
61
  MSE</label>
62
62
  </li>
63
- <li class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s"></span>
64
- <label class="check-label" for="WSPlayer"><input id="WSPlayer" type="checkbox" checked/>
65
- WSPlayer</label>
66
- </li>
67
63
  </ul>
68
64
  </div>
69
65
  </div>
@@ -0,0 +1,80 @@
1
+ //Set WCS URL
2
+ function setURL() {
3
+ let proto;
4
+ let url;
5
+ let port;
6
+ if (window.location.protocol == "http:") {
7
+ proto = "ws://";
8
+ port = "8080";
9
+ } else {
10
+ proto = "wss://";
11
+ port = "8443";
12
+ }
13
+
14
+ url = proto + window.location.hostname + ":" + port;
15
+ return url;
16
+ }
17
+
18
+ function getUrlParam(name) {
19
+ let url = window.location.href;
20
+ name = name.replace(/[\[\]]/g, "\\$&");
21
+ let regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
22
+ results = regex.exec(url);
23
+ if (!results) return null;
24
+ if (!results[2]) return '';
25
+ return decodeURIComponent(results[2].replace(/\+/g, " "));
26
+ }
27
+
28
+ /**
29
+ * Resize video object to fit parent div.
30
+ * Div structure: div WxH -> div wrapper (display) -> video
31
+ * @param video HTML element from resize event target
32
+ */
33
+ function resizeVideo(video, width, height) {
34
+ if (!video.parentNode) {
35
+ return;
36
+ }
37
+ if (video instanceof HTMLCanvasElement) {
38
+ video.videoWidth = video.width;
39
+ video.videoHeight = video.height;
40
+ }
41
+ let display = video.parentNode;
42
+ let parentSize = {
43
+ w: display.parentNode.clientWidth,
44
+ h: display.parentNode.clientHeight
45
+ };
46
+ let newSize;
47
+ if (width && height) {
48
+ newSize = downScaleToFitSize(width, height, parentSize.w, parentSize.h);
49
+ } else {
50
+ newSize = downScaleToFitSize(video.videoWidth, video.videoHeight, parentSize.w, parentSize.h);
51
+ }
52
+ display.style.width = newSize.w + "px";
53
+ display.style.height = newSize.h + "px";
54
+
55
+ //vertical align
56
+ let margin = 0;
57
+ if (parentSize.h - newSize.h > 1) {
58
+ margin = Math.floor((parentSize.h - newSize.h) / 2);
59
+ }
60
+ display.style.margin = margin + "px auto";
61
+ console.log("Resize from " + video.videoWidth + "x" + video.videoHeight + " to " + display.offsetWidth + "x" + display.offsetHeight);
62
+ }
63
+
64
+
65
+ function downScaleToFitSize(videoWidth, videoHeight, dstWidth, dstHeight) {
66
+ let newWidth, newHeight;
67
+ let videoRatio = videoWidth / videoHeight;
68
+ let dstRatio = dstWidth / dstHeight;
69
+ if (dstRatio > videoRatio) {
70
+ newHeight = dstHeight;
71
+ newWidth = Math.floor(videoRatio * dstHeight);
72
+ } else {
73
+ newWidth = dstWidth;
74
+ newHeight = Math.floor(dstWidth / videoRatio);
75
+ }
76
+ return {
77
+ w: newWidth,
78
+ h: newHeight
79
+ };
80
+ }
@@ -53,16 +53,19 @@ function init_page() {
53
53
  }
54
54
  }).slider("disable");
55
55
  onStopped();
56
+ if (Browser.isSafari()) {
57
+ // Enable video controls for fullscreen mode to work in Safari 16
58
+ useVideoControls = true;
59
+ $("#fullScreen").hide();
60
+ if (Browser.isiOS()) {
61
+ $("#volume").hide();
62
+ }
63
+ }
56
64
  if (autoplay) {
57
65
  // We can start autoplay with muted audio only, so set volume slider to 0 #WCS-2425
58
66
  $("#volumeControl").slider('value', 0);
59
67
  $("#playBtn").click();
60
68
  }
61
- // Enable video controls for fullscreen mode to work in Safari 16
62
- if (Browser.isSafariWebRTC() && Browser.version() > 13) {
63
- useVideoControls = true;
64
- $("#fullScreen").hide();
65
- }
66
69
  }
67
70
 
68
71
  function onStarted(stream) {
@@ -93,7 +96,7 @@ function playBtnClick() {
93
96
  $("#streamName").prop('disabled', true);
94
97
  if (Flashphoner.getMediaProviders()[0] === "WSPlayer") {
95
98
  Flashphoner.playFirstSound();
96
- } else if (Browser.isSafariWebRTC() || Flashphoner.getMediaProviders()[0] === "MSE") {
99
+ } else if (Browser.isSafari()) {
97
100
  Flashphoner.playFirstVideo(remoteVideo, false, PRELOADER_URL, useVideoControls).then(function() {
98
101
  start();
99
102
  }).catch(function () {
@@ -108,6 +111,7 @@ function playBtnClick() {
108
111
  function start() {
109
112
  var url = $('#url').val();
110
113
  //check if we already have session
114
+ $("#preloader").show();
111
115
  if (Flashphoner.getSessions().length > 0) {
112
116
  var session = Flashphoner.getSessions()[0];
113
117
  if (session.getServerUrl() == url) {
@@ -141,7 +145,6 @@ function playStream(session) {
141
145
  var options = {
142
146
  name: streamName,
143
147
  display: remoteVideo,
144
- flashShowFullScreenButton: true,
145
148
  useControls: useVideoControls
146
149
  };
147
150
  if (Flashphoner.getMediaProviders()[0] === "MSE" && mseCutByIFrameOnly) {
@@ -160,7 +163,6 @@ function playStream(session) {
160
163
  options.unmutePlayOnStart = false;
161
164
  }
162
165
  stream = session.createStream(options).on(STREAM_STATUS.PENDING, function (stream) {
163
- $("#preloader").show();
164
166
  var video = document.getElementById(stream.id());
165
167
  if (!video.hasListeners) {
166
168
  video.hasListeners = true;
@@ -194,17 +196,25 @@ function playStream(session) {
194
196
  needRestart = true;
195
197
  });
196
198
  }
199
+ // Hide preloader when playing video
200
+ video.addEventListener("playing", function () {
201
+ $("#preloader").hide();
202
+ });
197
203
  }
198
204
  }).on(STREAM_STATUS.PLAYING, function (stream) {
199
- $("#preloader").hide();
205
+ // Android Firefox may pause stream playback via MSE even if video element is muted
206
+ if (Flashphoner.getMediaProviders()[0] == "MSE" && autoplay && Browser.isAndroidFirefox()) {
207
+ let video = document.getElementById(stream.id());
208
+ if (video && video.paused) {
209
+ video.play();
210
+ }
211
+ }
200
212
  setStatus(stream.status());
201
213
  onStarted(stream);
202
214
  }).on(STREAM_STATUS.STOPPED, function () {
203
- $("#preloader").hide();
204
215
  setStatus(STREAM_STATUS.STOPPED);
205
216
  onStopped();
206
217
  }).on(STREAM_STATUS.FAILED, function(stream) {
207
- $("#preloader").hide();
208
218
  setStatus(STREAM_STATUS.FAILED, stream);
209
219
  onStopped();
210
220
  }).on(STREAM_EVENT, function(streamEvent){
@@ -6,6 +6,8 @@ var remoteVideo;
6
6
  var extensionId = "nlbaajplpmleofphigmgaifhoikjmbkg";
7
7
  var extensionNotInstalled;
8
8
 
9
+ var askExtension = getUrlParam("askExtension") || false;
10
+
9
11
  function init_page() {
10
12
  //init api
11
13
  try {
@@ -29,20 +31,22 @@ function init_page() {
29
31
 
30
32
  } else if (Browser.isChrome() && !Browser.isAndroid() && !Browser.isiOS()) {
31
33
  interval = setInterval(function() {
32
- chrome.runtime.sendMessage(extensionId, {type: "isInstalled"}, function (response) {
33
- if (chrome.runtime.lastError) { //WCS-2369 - cacth runtime.lastError
34
- (inIframe()) ? $("#installFromMarket").show() : $("#installExtensionButton").show();
35
- clearInterval(interval);
36
- onExtensionAvailable();
37
- $('#woChromeExtension').prop('checked', true);
38
- $('#woChromeExtension').prop('disabled', true);
39
- extensionNotInstalled = true;
40
- } else {
41
- $("#extension").hide();
34
+ try {
35
+ chrome.runtime.sendMessage(extensionId, {type: "isInstalled"}, function (response) {
36
+ if (chrome.runtime.lastError) { //WCS-2369 - catch runtime.lastError
37
+ onExtensionNotFound();
38
+ } else {
39
+ $("#extension").hide();
40
+ onExtensionAvailable();
41
+ }
42
42
  clearInterval(interval);
43
- onExtensionAvailable();
44
- }
45
- });
43
+ });
44
+ } catch (e) {
45
+ // Catch chrome.runtime.sendMessage undefined exception #WCS-3638
46
+ console.log("Can't detect screen sharing extension: "+e);
47
+ onExtensionNotFound();
48
+ clearInterval(interval);
49
+ }
46
50
  }, 500);
47
51
  } else if(isSafariMacOS()) {
48
52
  $("#extension").hide();
@@ -84,6 +88,22 @@ function isSafariMacOS() {
84
88
  return Browser.isSafari() && !Browser.isAndroid() && !Browser.isiOS();
85
89
  }
86
90
 
91
+ function onExtensionNotFound() {
92
+ if (askExtension === true) {
93
+ if (inIframe()) {
94
+ $("#installFromMarket").show();
95
+ } else {
96
+ $("#installExtensionButton").show();
97
+ }
98
+ } else {
99
+ $("#extension").hide();
100
+ }
101
+ onExtensionAvailable();
102
+ $('#woChromeExtension').prop('checked', true);
103
+ $('#woChromeExtension').prop('disabled', true);
104
+ extensionNotInstalled = true;
105
+ }
106
+
87
107
  function onExtensionAvailable() {
88
108
  localVideo = document.getElementById("localVideo");
89
109
  remoteVideo = document.getElementById("remoteVideo");