@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.
@@ -1,109 +1,76 @@
1
- var SESSION_STATUS = Flashphoner.constants.SESSION_STATUS;
2
- var STREAM_STATUS = Flashphoner.constants.STREAM_STATUS;
3
- var PRELOADER_URL = "../../dependencies/media/preloader.mp4";
4
- var Browser = Flashphoner.Browser;
5
- var remoteVideo;
6
- var resolution_for_wsplayer;
7
- var stream;
8
- var currentVolumeValue = 50, storedVolume;
9
- var stopped = true;
10
- var autoplay = eval(getUrlParam("autoplay")) || false;
11
- var resolution = getUrlParam("resolution");
12
- var mediaProviders = getUrlParam("mediaProviders") || "";
13
- var streamName = getUrlParam("streamName") || "streamName";
14
- var urlServer = getUrlParam("urlServer") || setURL();
15
- const HTML_VOLUME_MUTE='<svg height="100%" version="1.1" viewBox="0 0 36 36" width="100%"><defs><clipPath><path d="m 14.35,-0.14 -5.86,5.86 20.73,20.78 5.86,-5.91 z"></path><path d="M 7.07,6.87 -1.11,15.33 19.61,36.11 27.80,27.60 z"></path><path d="M 9.09,5.20 6.47,7.88 26.82,28.77 29.66,25.99 z" transform="translate(0, 0)"></path></clipPath><clipPath><path d="m -11.45,-15.55 -4.44,4.51 20.45,20.94 4.55,-4.66 z" transform="translate(0, 0)"></path></clipPath></defs><path style="fill: #fff;" clip-path="url(#ytp-svg-volume-animation-mask)" d="M8,21 L12,21 L17,26 L17,10 L12,15 L8,15 L8,21 Z M19,14 L19,22 C20.48,21.32 21.5,19.77 21.5,18 C21.5,16.26 20.48,14.74 19,14 ZM19,11.29 C21.89,12.15 24,14.83 24,18 C24,21.17 21.89,23.85 19,24.71 L19,26.77 C23.01,25.86 26,22.28 26,18 C26,13.72 23.01,10.14 19,9.23 L19,11.29 Z" fill="#fff" id="ytp-svg-12"></path><path clip-path="url(#ytp-svg-volume-animation-slash-mask)" d="M 9.25,9 7.98,10.27 24.71,27 l 1.27,-1.27 Z" fill="#fff" style="fill:#fff;"></path></svg>';
16
- const HTML_VOLUME_ZERO='<svg height="100%" version="1.1" viewBox="0 0 36 36" width="100%"><defs><clipPath><path d="m 14.35,-0.14 -5.86,5.86 20.73,20.78 5.86,-5.91 z"></path><path d="M 7.07,6.87 -1.11,15.33 19.61,36.11 27.80,27.60 z"></path><path d="M 9.09,5.20 6.47,7.88 26.82,28.77 29.66,25.99 z" transform="translate(0, 0)"></path></clipPath><clipPath><path d="m -11.45,-15.55 -4.44,4.51 20.45,20.94 4.55,-4.66 z" transform="translate(0, 0)"></path></clipPath></defs><path style="fill: #fff;" clip-path="url(#ytp-svg-volume-animation-mask)" d="M8,21 L12,21 L17,26 L17,10 L12,15 L8,15 L8,21 Z M19,14 L19,22 C20.48,21.32 21.5,19.77 21.5,18 C21.5,16.26 20.48,14.74 19,14 ZM19,11.29 C21.89,12.15 24,14.83 24,18 C24,21.17 21.89,23.85 19,24.71 L19,26.77 C23.01,25.86 26,22.28 26,18 C26,13.72 23.01,10.14 19,9.23 L19,11.29 Z" fill="#fff" id="ytp-svg-12"></path><path clip-path="url(#ytp-svg-volume-animation-slash-mask)" d="M 9.25,9 7.98,10.27 24.71,27 l 1.27,-1.27 Z" fill="#fff" style="fill:#fff;"></path></svg>';
17
- const HTML_VOLUME_LOW='<svg height="100%" version="1.1" viewBox="0 0 36 36" width="100%"><defs><clipPath><path d="m 14.35,-0.14 -5.86,5.86 20.73,20.78 5.86,-5.91 z"></path><path d="M 7.07,6.87 -1.11,15.33 19.61,36.11 27.80,27.60 z"></path><path d="M 9.09,5.20 6.47,7.88 26.82,28.77 29.66,25.99 z" transform="translate(0, 0)"></path></clipPath><clipPath><path d="m -11.45,-15.55 -4.44,4.51 20.45,20.94 4.55,-4.66 z" transform="translate(0, 0)"></path></clipPath></defs><path style="fill: #fff;" clip-path="url(#ytp-svg-volume-animation-mask)" d="M8,21 L12,21 L17,26 L17,10 L12,15 L8,15 L8,21 Z M19,14 L19,22 C20.48,21.32 21.5,19.77 21.5,18 C21.5,16.26 20.48,14.74 19,14 Z" fill="#fff" id="ytp-svg-12"></path></svg>';
18
- const HTML_VOLUME_HIGH='<svg height="100%" version="1.1" viewBox="0 0 36 36" width="100%"<defs><clipPath><path d="m 14.35,-0.14 -5.86,5.86 20.73,20.78 5.86,-5.91 z"></path><path d="M 7.07,6.87 -1.11,15.33 19.61,36.11 27.80,27.60 z"></path><path d="M 9.09,5.20 6.47,7.88 26.82,28.77 29.66,25.99 z" transform="translate(0, 0)"></path></clipPath><clipPath><path d="m -11.45,-15.55 -4.44,4.51 20.45,20.94 4.55,-4.66 z" transform="translate(0, 0)"></path></clipPath></defs><path style="fill: #fff;" clip-path="url(#ytp-svg-volume-animation-mask)" d="M8,21 L12,21 L17,26 L17,10 L12,15 L8,15 L8,21 Z M19,14 L19,22 C20.48,21.32 21.5,19.77 21.5,18 C21.5,16.26 20.48,14.74 19,14 ZM19,11.29 C21.89,12.15 24,14.83 24,18 C24,21.17 21.89,23.85 19,24.71 L19,26.77 C23.01,25.86 26,22.28 26,18 C26,13.72 23.01,10.14 19,9.23 L19,11.29 Z" fill="#fff" id="ytp-svg-12"></path></svg>';
19
- const HTML_FULLSCREEN_EXIT='<svg height="100%" version="1.1" viewBox="0 0 36 36" width="100%"><g class="ytp-fullscreen-button-corner-2"><path style="fill: #fff;" d="m 14,14 -4,0 0,2 6,0 0,-6 -2,0 0,4 0,0 z"></path></g><g><path style="fill: #fff;" d="m 22,14 0,-4 -2,0 0,6 6,0 0,-2 -4,0 0,0 z"></path></g><g><path style="fill: #fff;" d="m 20,26 2,0 0,-4 4,0 0,-2 -6,0 0,6 0,0 z"></path></g><g><path style="fill: #fff;" d="m 10,22 4,0 0,4 2,0 0,-6 -6,0 0,2 0,0 z"></path></g></svg>';
20
- let firstUnmuted = true;
21
- let useVideoControls = false;
1
+ const SESSION_STATUS = Flashphoner.constants.SESSION_STATUS;
2
+ const STREAM_STATUS = Flashphoner.constants.STREAM_STATUS;
3
+ const STREAM_EVENT = Flashphoner.constants.STREAM_EVENT;
4
+ const STREAM_EVENT_TYPE = Flashphoner.constants.STREAM_EVENT_TYPE;
5
+ const PRELOADER_URL = "../../dependencies/media/preloader.mp4";
6
+ const Browser = Flashphoner.Browser;
7
+ let remoteVideo;
8
+ let playingStream;
9
+ let isStopped = true;
10
+
11
+ let autoplay = eval(getUrlParam("autoplay")) || false;
12
+ let resolution = getUrlParam("resolution");
13
+ let mediaProviders = getUrlParam("mediaProviders") || "";
14
+ let streamName = getUrlParam("streamName") || "streamName";
15
+ let urlServer = getUrlParam("urlServer") || setURL();
16
+
17
+ // Will always use a standard video controls
18
+ let useVideoControls = true;
22
19
 
23
20
  function init_page() {
24
- //video display
25
- remoteVideo = document.getElementById("remoteVideo");
26
- $('#remoteVideo').videoPlayer({
27
- 'playerWidth': 1,
28
- 'videoClass': 'video'
29
- });
30
-
31
- onStopped();
32
-
33
21
  //init api
34
22
  try {
35
- Flashphoner.init({
36
- receiverLocation: '../../dependencies/websocket-player/WSReceiver2.js',
37
- decoderLocation: '../../dependencies/websocket-player/video-worker2.js',
38
- preferredMediaProviders: mediaProviders && mediaProviders !== "" ? mediaProviders.split(','): []
39
- });
40
- } catch (e) {
41
- $("#error_output").text(e.message);
42
- return;
43
- }
44
- if (Flashphoner.getMediaProviders()[0] === "WSPlayer") {
45
- if (Browser.isiOS()) {
46
- $(".fullscreen").hide();
47
- }
48
- }
49
- if ((Browser.isSafariWebRTC() && Flashphoner.getMediaProviders()[0] == "WebRTC")) {
50
- if (Browser.version() > 13) {
51
- // Enable video controls for fullscreen mode to work in Safari
52
- useVideoControls = true;
53
- // Hide custom controls
54
- $('.player').hide();
23
+ Flashphoner.init({ preferredMediaProviders: mediaProviders && mediaProviders !== "" ? mediaProviders.split(','): [] });
24
+ if (Flashphoner.getMediaProviders()[0] == "WSPlayer") {
25
+ throw new Error("The WSPlayer mediaProvider is deprecated");
55
26
  }
27
+ } catch(e) {
28
+ document.getElementById("status").innerHTML = e.message;
29
+ hideItem('preloader');
30
+ centralButton.hide();
31
+ return;
56
32
  }
57
- if (autoplay ) {
58
- // Autoplay will start for muted video tag only, adjust mute button and slider view
59
- firstUnmuted = false;
60
- $('.volume').addClass('volume-none');
61
- $('.volume').html(HTML_VOLUME_MUTE);
62
- $('#slider').slider( "value", 1 );
63
- $(".play-pause").click();
33
+
34
+ // Save video display element
35
+ remoteVideo = document.getElementById("remoteVideo");
36
+
37
+ // Init page elements
38
+ onStopped();
39
+
40
+ // Start playback if autoplay required
41
+ if (autoplay) {
42
+ centralButton.click();
64
43
  }
65
44
  }
66
45
 
67
- function onStarted(stream) {
68
- stopped = false;
69
- centralButton.setView("stop");
70
- centralButton.hide();
71
- $(".play-pause").prop('disabled', false);
72
- $(".fullscreen").prop('disabled', false);
73
- stream.setVolume(currentVolumeValue);
46
+ function onStarted() {
47
+ isStopped = false;
48
+ centralButton.prepareToStop();
74
49
  }
75
50
 
76
51
  function onStopped() {
77
- stopped = true;
78
- centralButton.stopTimer();
79
- centralButton.setView("play");
80
- centralButton.display();
81
- centralButton.setAction(function() {
82
- if (!$('.play-pause').prop('disabled')) {
83
- if (stopped) {
84
- start();
85
- $('.play-pause').addClass('pause').removeClass('play').prop('disabled', true);
86
- centralButton.hide();
87
- } else {
88
- if (stream) {
89
- stream.stop();
90
- }
91
- $('.play-pause').addClass('play').removeClass('pause').prop('disabled', true);
92
- $("#preloader").hide();
93
- };
94
- };
95
- });
96
- $(".play-pause").addClass('play').removeClass('pause').prop('disabled', false);
97
- $(".fullscreen").prop('disabled', true);
98
- $("#preloader").hide();
52
+ isStopped = true;
53
+ hideItem('preloader');
54
+ centralButton.prepareToStart(playBtnClick);
99
55
  }
100
56
 
101
- function start() {
102
- $("#preloader").show();
57
+ function playBtnClick() {
58
+ if (isStopped) {
59
+ centralButton.hide();
60
+ start();
61
+ } else {
62
+ if (playingStream) {
63
+ playingStream.stop();
64
+ }
65
+ }
66
+ }
103
67
 
104
- if (Flashphoner.getMediaProviders()[0] == "WSPlayer") {
105
- Flashphoner.playFirstSound();
106
- } else if (Browser.isSafariWebRTC() || Flashphoner.getMediaProviders()[0] == "MSE") {
68
+ function start() {
69
+ if (!Browser.isChrome()) {
70
+ // Display the custom preloader in non-Chromium browser
71
+ showItem('preloader');
72
+ }
73
+ if (Browser.isSafari()) {
107
74
  Flashphoner.playFirstVideo(remoteVideo, false, PRELOADER_URL, useVideoControls).then(function() {
108
75
  createSession();
109
76
  }).catch(function() {
@@ -117,13 +84,15 @@ function start() {
117
84
  function createSession() {
118
85
  //check if we already have session
119
86
  if (Flashphoner.getSessions().length > 0) {
120
- var session = Flashphoner.getSessions()[0];
87
+ let session = Flashphoner.getSessions()[0];
121
88
  playStream(session);
122
89
  return;
123
90
  }
91
+ // In Chromium browsers we need a custom preloader for a new session only
92
+ showItem('preloader');
124
93
  //create session
125
94
  console.log("Create new session with url " + urlServer);
126
- var mediaOptions = {"iceServers": [{'url': 'turn:turn.flashphoner.com:443?transport=tcp', 'username': 'flashphoner', 'credential': 'coM77EMrV7Cwhyan'}]};
95
+ let mediaOptions = {"iceServers": [{'url': 'turn:turn.flashphoner.com:443?transport=tcp', 'username': 'flashphoner', 'credential': 'coM77EMrV7Cwhyan'}]};
127
96
  Flashphoner.createSession({urlServer: urlServer, mediaOptions: mediaOptions}).on(SESSION_STATUS.ESTABLISHED, function (session) {
128
97
  setStatus(session.status());
129
98
  //session connected, start playback
@@ -138,161 +107,151 @@ function createSession() {
138
107
  }
139
108
 
140
109
  function playStream(session) {
141
- var options = {
110
+ let playWidth = 0;
111
+ let platHeight = 0;
112
+ let options = {
142
113
  name: streamName,
143
114
  display: remoteVideo,
144
- flashShowFullScreenButton: true,
145
115
  useControls: useVideoControls
146
116
  };
147
- if (resolution_for_wsplayer) {
148
- options.playWidth = resolution_for_wsplayer.playWidth;
149
- options.playHeight = resolution_for_wsplayer.playHeight;
150
- } else if (resolution) {
151
- options.playWidth = resolution.split("x")[0];
152
- options.playHeight = resolution.split("x")[1];
117
+ if (resolution) {
118
+ playWidth = resolution.split("x")[0];
119
+ playHeight = resolution.split("x")[1];
120
+ options.constraints = {
121
+ video: {
122
+ width: playWidth,
123
+ height: playHeight
124
+ },
125
+ audio: true
126
+ };
153
127
  }
154
128
  if (autoplay) {
155
129
  options.unmutePlayOnStart = false;
156
130
  }
157
- stream = session.createStream(options).on(STREAM_STATUS.PENDING, function(stream) {
158
- var video = document.getElementById(stream.id());
131
+ playingStream = session.createStream(options).on(STREAM_STATUS.PENDING, function (stream) {
132
+ if (Browser.isChrome()) {
133
+ // Hide a custom preloader in Chrome because there is a standard one with standard controls
134
+ hideItem('preloader');
135
+ }
136
+ let video = document.getElementById(stream.id());
159
137
  if (!video.hasListeners) {
160
138
  video.hasListeners = true;
161
- video.addEventListener('playing', function () {
162
- $("#preloader").hide();
163
- });
164
- video.addEventListener('resize', function (event) {
165
- var streamResolution = stream.videoResolution();
166
- if (Object.keys(streamResolution).length === 0) {
167
- resizeVideo(event.target);
168
- } else {
169
- // Change aspect ratio to prevent video stretching
170
- var ratio = streamResolution.width / streamResolution.height;
171
- var newHeight = Math.floor(options.playWidth / ratio);
172
- resizeVideo(event.target, options.playWidth, newHeight);
173
- }
174
- });
175
- if (useVideoControls && Browser.isSafariWebRTC()) {
176
- // iOS/MacOS hack when using standard controls to leave fullscreen mode
177
- var needRestart = false;
178
- video.addEventListener("pause", function () {
179
- if(needRestart) {
180
- console.log("Video paused after fullscreen, continue...");
181
- video.play();
182
- needRestart = false;
183
- }
184
- });
185
- video.addEventListener("webkitendfullscreen", function () {
186
- video.play();
187
- needRestart = true;
188
- });
139
+ setResizeHandler(video, stream, playWidth);
140
+ if (Browser.isSafariWebRTC()) {
141
+ setWebkitEventHandlers(video);
142
+ } else {
143
+ setEventHandlers(video);
189
144
  }
190
145
  }
191
146
  }).on(STREAM_STATUS.PLAYING, function (stream) {
192
- setStatus(stream.status());
193
- onStarted(stream);
147
+ // Android Firefox may pause stream playback via MSE even if video element is muted
148
+ if (Flashphoner.getMediaProviders()[0] == "MSE" && autoplay && Browser.isAndroidFirefox()) {
149
+ let video = document.getElementById(stream.id());
150
+ if (video && video.paused) {
151
+ video.play();
152
+ }
153
+ }
154
+ setStatus(STREAM_STATUS.PLAYING);
155
+ onStarted();
194
156
  }).on(STREAM_STATUS.STOPPED, function () {
195
157
  setStatus(STREAM_STATUS.STOPPED);
196
158
  onStopped();
197
- }).on(STREAM_STATUS.FAILED, function () {
198
- setStatus(STREAM_STATUS.FAILED);
159
+ }).on(STREAM_STATUS.FAILED, function(stream) {
160
+ setStatus(STREAM_STATUS.FAILED, stream);
199
161
  onStopped();
200
- }).on(STREAM_STATUS.NOT_ENOUGH_BANDWIDTH, function (stream) {
201
- console.log("Not enough bandwidth, consider using lower video resolution or bitrate. Bandwidth " + (Math.round(stream.getNetworkBandwidth() / 1000)) + " bitrate " + (Math.round(stream.getRemoteBitrate() / 1000)));
162
+ }).on(STREAM_EVENT, function(streamEvent){
163
+ if (STREAM_EVENT_TYPE.NOT_ENOUGH_BANDWIDTH === streamEvent.type) {
164
+ let info = streamEvent.payload.info.split("/");
165
+ let remoteBitrate = info[0];
166
+ let networkBandwidth = info[1];
167
+ console.log("Not enough bandwidth, consider using lower video resolution or bitrate. Bandwidth " + (Math.round(networkBandwidth / 1000)) + " bitrate " + (Math.round(remoteBitrate / 1000)));
168
+ } else if (STREAM_EVENT_TYPE.RESIZE === streamEvent.type) {
169
+ console.log("New video size: " + streamEvent.payload.streamerVideoWidth + "x" + streamEvent.payload.streamerVideoHeight);
170
+ }
202
171
  });
203
- stream.play();
172
+ playingStream.play();
204
173
  }
205
174
 
206
175
  //show connection or remote stream status
207
- function setStatus(status) {
208
- var statusField = $(".status");
209
- statusField.removeClass("text-success").removeClass("text-muted").removeClass("text-danger");
176
+ function setStatus(status, stream) {
177
+ let statusField = document.getElementById("status");
210
178
  if (status == "PLAYING" || status == "ESTABLISHED" || status == "STOPPED") {
211
179
  //don't display status word because we have this indication on UI
212
- statusField.text("");
180
+ statusField.innerHTML = "";
213
181
  } else if (status == "DISCONNECTED") {
214
- statusField.text(status);
215
- statusField.addClass("text-muted");
182
+ statusField.innerHTML = status;
216
183
  } else if (status == "FAILED") {
217
- statusField.text(status);
218
- statusField.addClass("text-muted");
184
+ statusField.innerHTML = status;
185
+ if (stream && stream.getInfo() !== "") {
186
+ statusField.innerHTML = status + ": " + stream.getInfo();
187
+ }
219
188
  }
220
189
  }
221
190
 
222
- function validateForm() {
223
- var valid = true;
224
- $('#form :text').each(function () {
225
- if (!$(this).val()) {
226
- highlightInput($(this));
227
- valid = false;
191
+ // Resize event handler
192
+ function setResizeHandler(video, stream, playWidth) {
193
+ video.addEventListener('resize', function (event) {
194
+ let streamResolution = stream.videoResolution();
195
+ if (Object.keys(streamResolution).length === 0) {
196
+ resizeVideo(event.target);
228
197
  } else {
229
- removeHighlight($(this));
198
+ // Change aspect ratio to prevent video stretching
199
+ let ratio = streamResolution.width / streamResolution.height;
200
+ let newHeight = Math.floor(playWidth / ratio);
201
+ resizeVideo(event.target, playWidth, newHeight);
230
202
  }
231
203
  });
232
- return valid;
233
-
234
- function highlightInput(input) {
235
- input.closest('.form-group').addClass("has-error");
236
- }
237
-
238
- function removeHighlight(input) {
239
- input.closest('.form-group').removeClass("has-error");
240
- }
241
204
  }
242
205
 
243
- function setVolume(volume, slider) {
244
- if (volume < 0) {
245
- console.error("Bad volume: " + volume);
246
- return(false);
247
- }
248
- if (stream) {
249
- if (volume > 0) {
250
- if (!firstUnmuted && slider && Browser.isAndroid()) {
251
- console.error("User should click volume unmute button to enable audio");
252
- return(false);
253
- } else if (stream.isRemoteAudioMuted()) {
254
- stream.unmuteRemoteAudio();
255
- firstUnmuted = true;
256
- }
257
- }
258
- stream.setVolume(volume);
259
- }
260
- // Save current volume in page element to restore it when mute/unmute
261
- $('#volume-range').val(volume);
262
-
263
- //chnage volume control icon
264
- if ( currentVolumeValue > 0) {
265
- //volume in range 0-50
266
- if ( currentVolumeValue <= 50 ) {
267
- $('.volume').html(HTML_VOLUME_LOW);
268
- }
269
-
270
- //volume greater than 50
271
- if ( currentVolumeValue > 50 ) {
272
- $('.volume').html(HTML_VOLUME_HIGH);
273
- }
274
-
275
- if ($('.volume').hasClass('volume-none')) {
276
- $('.volume').removeClass('volume-none');
206
+ // iOS/MacOS handlers for fullscreen issues
207
+ function setWebkitEventHandlers(video) {
208
+ let needRestart = false;
209
+ let isFullscreen = false;
210
+ // Hide custom preloader
211
+ video.addEventListener('playing', function () {
212
+ hideItem('preloader');
213
+ });
214
+ // Use webkitbeginfullscreen event to detect full screen mode in iOS Safari
215
+ video.addEventListener("webkitbeginfullscreen", function () {
216
+ isFullscreen = true;
217
+ });
218
+ video.addEventListener("pause", function () {
219
+ if (needRestart) {
220
+ console.log("Video paused after fullscreen, continue...");
221
+ video.play();
222
+ needRestart = false;
223
+ } else if (!(isFullscreen || document.webkitFullscreenElement)) {
224
+ // Stop stream by standard play/pause control
225
+ playingStream.stop();
277
226
  }
227
+ });
228
+ video.addEventListener("webkitendfullscreen", function () {
229
+ video.play();
230
+ needRestart = true;
231
+ isFullscreen = false;
232
+ });
233
+ }
278
234
 
279
- } else if ( currentVolumeValue == 0 ) {
280
- // Zero volume is equal to audio mute
281
- $('.volume').html(HTML_VOLUME_ZERO);
282
- if (!$('.volume').hasClass('volume-none')) {
283
- $('.volume').addClass('volume-none');
235
+ function setEventHandlers(video) {
236
+ // Hide custom preloader
237
+ video.addEventListener('playing', function () {
238
+ hideItem('preloader');
239
+ });
240
+ // Use standard pause control to stop playback
241
+ video.addEventListener("pause", function () {
242
+ if (!(document.fullscreenElement || document.mozFullscreenElement)) {
243
+ // Stop stream by standard play/pause control if we're not in fullscreen
244
+ playingStream.stop();
284
245
  }
285
- }
286
-
287
- return(true);
246
+ });
288
247
  }
289
248
 
290
249
  // Object to manage central Play/Stop button
291
- centralButton = {
250
+ const centralButton = {
292
251
  timer: null,
293
252
  displayed: false,
294
253
  display: function(timeout = 0) {
295
- $('#play').show();
254
+ showItem('play');
296
255
  centralButton.displayed = true;
297
256
  if (timeout > 0 && !centralButton.timer) {
298
257
  centralButton.timer = setTimeout(function() {
@@ -308,19 +267,23 @@ centralButton = {
308
267
  }
309
268
  },
310
269
  setAction: function(action) {
311
- $('#play').on('click', action);
270
+ document.getElementById('play').onclick = action;
312
271
  },
313
272
  setView: function(view) {
273
+ let button = document.getElementById('play');
274
+ let image = button.querySelector('img');
314
275
  if (view === "play") {
315
- $('#play').addClass('play').removeClass('stop');
316
- $('#play img').prop('src', 'images/play.png');
276
+ button.classList.remove('stop');
277
+ button.classList.add('play');
278
+ image.src = 'images/play.png';
317
279
  } else if (view === "stop") {
318
- $('#play').addClass('stop').removeClass('play');
319
- $('#play img').prop('src', 'images/stop.png');
280
+ button.classList.remove('play');
281
+ button.classList.add('stop');
282
+ image.src = 'images/stop.png';
320
283
  }
321
284
  },
322
285
  hide: function() {
323
- $('#play').hide();
286
+ hideItem('play');
324
287
  centralButton.displayed = false;
325
288
  centralButton.stopTimer();
326
289
  },
@@ -329,219 +292,33 @@ centralButton = {
329
292
  clearTimeout(centralButton.timer);
330
293
  centralButton.timer = null;
331
294
  }
295
+ },
296
+ click: function() {
297
+ document.getElementById('play').click();
298
+ },
299
+ prepareToStart: function(action) {
300
+ centralButton.stopTimer();
301
+ centralButton.setView("play");
302
+ centralButton.display();
303
+ centralButton.setAction(action);
304
+ },
305
+ prepareToStop: function() {
306
+ centralButton.setView("stop");
307
+ centralButton.hide();
332
308
  }
333
309
  };
334
310
 
335
- (function ($) {
336
- $.fn.videoPlayer = function (options) {
337
- var settings = {
338
- playerWidth: '0.95', // Default is 95%
339
- videoClass: 'video' // Video Class
340
- };
341
-
342
- if (options) {
343
- $.extend(settings, options);
344
- }
345
-
346
- return this.each(function () {
347
- var $this = $(this);
348
- var $settings = settings;
349
- var $that = $this.parent('.' + $settings.videoClass);
350
- $that.find('.player').css({
351
- 'width': ($settings.playerWidth * 100) + '%',
352
- 'left': ((100 - $settings.playerWidth * 100) / 2) + '%'
353
- });
354
-
355
- var $mclicking = false,
356
- $vclicking = false,
357
- $volhover = false,
358
- $clearTimeout;
359
- y = 0;
360
-
361
- $that.bind('selectstart', function () {
362
- return false;
363
- });
364
-
365
- $that.find('.play-pause').bind('click', function () {
366
- // If playing, etc, change classes to show pause or play button
367
- if (!$(this).prop('disabled')) {
368
- if (stopped) {
369
- start();
370
- $(this).addClass('pause').removeClass('play').prop('disabled', true);
371
- centralButton.hide();
372
- } else {
373
- if (stream) {
374
- stream.stop();
375
- }
376
- $(this).addClass('play').removeClass('pause').prop('disabled', true);
377
- $("#preloader").hide();
378
- }
379
- }
380
- });
381
-
382
-
383
- $that.bind('click', function () {
384
- if ( !stopped ) {
385
- if ($clearTimeout) {
386
- clearTimeout($clearTimeout);
387
- }
388
- centralButton.displayToggle(5000);
389
- $that.find('.player').stop(true, false).animate({'opacity': '1'}, 0.5);
390
- $clearTimeout = setTimeout(function() {
391
- $that.find('.player').stop(true, false).animate({'opacity': '0'}, 0.5);
392
- }, 5000);
393
- };
394
- });
395
-
396
- $that.find('.volume').hover(function () {
397
- $volhover = true;
398
- }, function () {
399
- $volhover = false;
400
- });
401
-
402
- $('body, html').bind('mousemove', function (e) {
403
- if ( !stopped ) {
404
- // Prevent central button displaying by mousemove in mobile browsers
405
- if (!(Browser.isAndroid() || Browser.isiOS())) {
406
- centralButton.display(5000);
407
- }
408
- $that.hover(function () {
409
- $that.find('.player').stop(true, false).animate({'opacity': '1'}, 0.5);
410
- }, function () {
411
- $that.find('.player').stop(true, false).animate({'opacity': '0'}, 0.5);
412
- if (!stopped) {
413
- centralButton.hide();
414
- }
415
- });
416
- }
417
- if (!$volhover) {
418
- $that.find('.volume-holder').stop(true, false).fadeOut(100);
419
- $that.find('.volume-icon').removeClass('volume-icon-hover');
420
- }
421
- else {
422
- $that.find('.volume-icon').addClass('volume-icon-hover');
423
- $that.find('.volume-holder').fadeIn(100);
424
- }
425
- });
426
-
427
- // Requests fullscreen based on browser.
428
- $('.fullscreenBtn').click(function () {
429
- if ( stream ) {
430
- stream.fullScreen();
431
- };
432
- });
433
- var init = $( "#slider" ).slider({
434
- value: 50,
435
- orientation: "horizontal",
436
- range: "min",
437
- slide: function( event, ui ) {
438
- valueRange()
439
- },
440
- stop: function( event, ui ) {
441
- valueRange()
442
- }
443
- });
444
- valueRange();
445
-
446
- var prevVol=1;
447
- function valueRange() {
448
- currentVolumeValue = $( "#slider" ).slider( "value" );
449
- if (setVolume(currentVolumeValue, true)) {
450
- // Save previous volume state to set when stream is unmuted by button
451
- prevVol = currentVolumeValue ? currentVolumeValue : 1;
452
-
453
- }
454
- }
455
-
456
- //mute unmute volume on click
457
- $('.volume').on('click', function () {
458
- if ($('.volume').hasClass('volume-none')) {
459
- // Restore previous volume state
460
- $('#slider').slider( "value", prevVol );
461
- currentVolumeValue = prevVol;
462
- setVolume(currentVolumeValue, false);
463
- $('.volume').removeClass('volume-none');
464
- } else {
465
- // Save previous volume state and mute audio
466
- prevVol = $('#volume-range').val();
467
- $('#slider').slider( "value", 0);
468
- currentVolumeValue = 0;
469
- setVolume(currentVolumeValue, false);
470
- $('.volume').addClass('volume-none');
471
- };
472
- });
473
-
474
-
475
- //show slider wile changing volume
476
- $('.volume-range-block').focusin( function () {
477
- $(this).addClass('open-width').addClass('open');
478
- });
479
- $('.volume-range-block').focusout( function () {
480
- $(this).removeClass('open-width').removeClass('open');
481
- });
482
-
483
-
484
- isMobile = {
485
- Android: function() {
486
- return navigator.userAgent.match(/Android/i);
487
- },
488
- BlackBerry: function() {
489
- return navigator.userAgent.match(/BlackBerry/i);
490
- },
491
- iOS: function() {
492
- return navigator.userAgent.match(/iPhone|iPad|iPod/i);
493
- },
494
- Opera: function() {
495
- return navigator.userAgent.match(/Opera Mini/i);
496
- },
497
- Windows: function() {
498
- return navigator.userAgent.match(/IEMobile/i);
499
- },
500
- any: function() {
501
- return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
502
- }
503
- };
504
- if (isMobile.any()) {
505
- $('.volume-range-block').addClass('open-width-full')
506
- }
507
- var prevFull;
508
-
509
- $(document).on('webkitfullscreenchange mozfullscreenchange fullscreenchange', function(e) {
510
- if (stream) {
511
-
512
- $('.player').toggleClass('fullscreenon'); //Add class for all controls in full screen mode
513
- $('.volume-range-block').toggleClass('fullscreen-vol'); //Add class to volume control for full screen mode
514
-
515
- if ( e.target === document.fullscreenElement ) {
516
- prevFull = $('.fullscreenBtn').html();
517
-
518
- //change full screen button to full screen exit button
519
- $('.fullscreenBtn').html(HTML_FULLSCREEN_EXIT);
520
-
521
- //activate controls on mouse moving
522
- $that.bind('mousemove touchmove', function () {
523
- if ($clearTimeout) {
524
- clearTimeout($clearTimeout);
525
- }
526
- $that.find('.player').stop(true, false).animate({'opacity': '1'}, 0.1);
527
- $clearTimeout = setTimeout(function() {
528
- $that.find('.player').stop(true, false).animate({'opacity': '0'}, 0.5);
529
- }, 15000);
530
- });
531
-
532
- } else {
311
+ // Helper functions to display/hide an element
312
+ function showItem(id) {
313
+ let item = document.getElementById(id);
314
+ if (item) {
315
+ item.style.display = "block";
316
+ }
317
+ }
533
318
 
534
- $('.fullscreenBtn').html(prevFull);
535
- $('.fullscreenBtn').click(function () {
536
- if ( stream ) {
537
- stream.fullScreen();
538
- };
539
- });
540
- };
541
- // Resize video to a parent tag when toggling fullscreen (we may not receive `resize` event in Safari 16) #WCS-3606
542
- resizeVideo(e.target);
543
- };
544
- });
545
- });
319
+ function hideItem(id) {
320
+ let item = document.getElementById(id);
321
+ if (item) {
322
+ item.style.display = "none";
323
+ }
546
324
  }
547
- })(jQuery);