@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.
@@ -1,102 +1,77 @@
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;
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;
21
19
 
22
20
  function init_page() {
23
- //video display
24
- remoteVideo = document.getElementById("remoteVideo");
25
- $('#remoteVideo').videoPlayer({
26
- 'playerWidth': 1,
27
- 'videoClass': 'video'
28
- });
29
-
30
- onStopped();
31
-
32
21
  //init api
33
22
  try {
34
- Flashphoner.init({
35
- receiverLocation: '../../dependencies/websocket-player/WSReceiver2.js',
36
- decoderLocation: '../../dependencies/websocket-player/video-worker2.js',
37
- preferredMediaProviders: mediaProviders && mediaProviders !== "" ? mediaProviders.split(','): []
38
- });
39
- } catch (e) {
40
- $("#error_output").text(e.message);
41
- return;
42
- }
43
- if (Flashphoner.getMediaProviders()[0] === "WSPlayer") {
44
- if (Browser.isiOS()) {
45
- $(".fullscreen").hide();
23
+ Flashphoner.init({ preferredMediaProviders: mediaProviders && mediaProviders !== "" ? mediaProviders.split(','): [] });
24
+ if (Flashphoner.getMediaProviders()[0] == "WSPlayer") {
25
+ throw new Error("The WSPlayer mediaProvider is deprecated");
46
26
  }
27
+ } catch(e) {
28
+ document.getElementById("status").innerHTML = e.message;
29
+ hideItem('preloader');
30
+ centralButton.hide();
31
+ return;
47
32
  }
48
- if ((Browser.isSafariWebRTC() && Browser.isiOS() && Flashphoner.getMediaProviders()[0] == "WebRTC")) {
49
- $('.volume').hide();
50
- $('.volume-range-block').hide();
51
- }
52
- if (autoplay ) {
53
- // Autoplay will start for muted video tag only, adjust mute button and slider view
54
- firstUnmuted = false;
55
- $('.volume').addClass('volume-none');
56
- $('.volume').html(HTML_VOLUME_MUTE);
57
- $('#slider').slider( "value", 1 );
58
- $(".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();
59
43
  }
60
44
  }
61
45
 
62
- function onStarted(stream) {
63
- stopped = false;
64
- $('#play').css('display', 'none');
65
- $(".play-pause").prop('disabled', false);
66
- $(".fullscreen").prop('disabled', false);
67
- stream.setVolume(currentVolumeValue);
46
+ function onStarted() {
47
+ isStopped = false;
48
+ centralButton.prepareToStop();
68
49
  }
69
50
 
70
51
  function onStopped() {
71
- stopped = true;
72
- $('#play').css('display', 'block');
73
- $('#play').on('click', function() {
74
- if (!$('.play-pause').prop('disabled')) {
75
- if (stopped) {
76
- start();
77
- $('.play-pause').addClass('pause').removeClass('play').prop('disabled', true);
78
- $('#play').css('display', 'none');
79
- } else {
80
- if (stream) {
81
- stream.stop();
82
- }
83
- $('.play-pause').addClass('play').removeClass('pause').prop('disabled', true);
84
- $("#preloader").hide();
85
- };
86
- };
87
- });
88
- $(".play-pause").addClass('play').removeClass('pause').prop('disabled', false);
89
- $(".fullscreen").prop('disabled', true);
90
- $("#preloader").hide();
52
+ isStopped = true;
53
+ hideItem('preloader');
54
+ centralButton.prepareToStart(playBtnClick);
91
55
  }
92
56
 
93
- function start() {
94
- $("#preloader").show();
57
+ function playBtnClick() {
58
+ if (isStopped) {
59
+ centralButton.hide();
60
+ start();
61
+ } else {
62
+ if (playingStream) {
63
+ playingStream.stop();
64
+ }
65
+ }
66
+ }
95
67
 
96
- if (Flashphoner.getMediaProviders()[0] == "WSPlayer") {
97
- Flashphoner.playFirstSound();
98
- } else if (Browser.isSafariWebRTC() || Flashphoner.getMediaProviders()[0] == "MSE") {
99
- Flashphoner.playFirstVideo(remoteVideo, false, PRELOADER_URL).then(function() {
68
+ function start() {
69
+ if (!Browser.isChrome()) {
70
+ // Display the custom preloader in non-Chromium browser
71
+ showItem('preloader');
72
+ }
73
+ if (Browser.isSafari()) {
74
+ Flashphoner.playFirstVideo(remoteVideo, false, PRELOADER_URL, useVideoControls).then(function() {
100
75
  createSession();
101
76
  }).catch(function() {
102
77
  onStopped();
@@ -109,13 +84,15 @@ function start() {
109
84
  function createSession() {
110
85
  //check if we already have session
111
86
  if (Flashphoner.getSessions().length > 0) {
112
- var session = Flashphoner.getSessions()[0];
87
+ let session = Flashphoner.getSessions()[0];
113
88
  playStream(session);
114
89
  return;
115
90
  }
91
+ // In Chromium browsers we need a custom preloader for a new session only
92
+ showItem('preloader');
116
93
  //create session
117
94
  console.log("Create new session with url " + urlServer);
118
- 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'}]};
119
96
  Flashphoner.createSession({urlServer: urlServer, mediaOptions: mediaOptions}).on(SESSION_STATUS.ESTABLISHED, function (session) {
120
97
  setStatus(session.status());
121
98
  //session connected, start playback
@@ -130,337 +107,218 @@ function createSession() {
130
107
  }
131
108
 
132
109
  function playStream(session) {
133
- var options = {
110
+ let playWidth = 0;
111
+ let platHeight = 0;
112
+ let options = {
134
113
  name: streamName,
135
114
  display: remoteVideo,
136
- flashShowFullScreenButton: true
115
+ useControls: useVideoControls
137
116
  };
138
- if (resolution_for_wsplayer) {
139
- options.playWidth = resolution_for_wsplayer.playWidth;
140
- options.playHeight = resolution_for_wsplayer.playHeight;
141
- } else if (resolution) {
142
- options.playWidth = resolution.split("x")[0];
143
- 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
+ };
144
127
  }
145
128
  if (autoplay) {
146
129
  options.unmutePlayOnStart = false;
147
130
  }
148
- stream = session.createStream(options).on(STREAM_STATUS.PENDING, function(stream) {
149
- 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());
150
137
  if (!video.hasListeners) {
151
138
  video.hasListeners = true;
152
- video.addEventListener('playing', function () {
153
- $("#preloader").hide();
154
- });
155
- video.addEventListener('resize', function (event) {
156
- var streamResolution = stream.videoResolution();
157
- if (Object.keys(streamResolution).length === 0) {
158
- resizeVideo(event.target);
159
- } else {
160
- // Change aspect ratio to prevent video stretching
161
- var ratio = streamResolution.width / streamResolution.height;
162
- var newHeight = Math.floor(options.playWidth / ratio);
163
- resizeVideo(event.target, options.playWidth, newHeight);
164
- }
165
- });
139
+ setResizeHandler(video, stream, playWidth);
140
+ if (Browser.isSafariWebRTC()) {
141
+ setWebkitEventHandlers(video);
142
+ } else {
143
+ setEventHandlers(video);
144
+ }
166
145
  }
167
146
  }).on(STREAM_STATUS.PLAYING, function (stream) {
168
- setStatus(stream.status());
169
- 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();
170
156
  }).on(STREAM_STATUS.STOPPED, function () {
171
157
  setStatus(STREAM_STATUS.STOPPED);
172
158
  onStopped();
173
- }).on(STREAM_STATUS.FAILED, function () {
174
- setStatus(STREAM_STATUS.FAILED);
159
+ }).on(STREAM_STATUS.FAILED, function(stream) {
160
+ setStatus(STREAM_STATUS.FAILED, stream);
175
161
  onStopped();
176
- }).on(STREAM_STATUS.NOT_ENOUGH_BANDWIDTH, function (stream) {
177
- 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
+ }
178
171
  });
179
- stream.play();
172
+ playingStream.play();
180
173
  }
181
174
 
182
175
  //show connection or remote stream status
183
- function setStatus(status) {
184
- var statusField = $(".status");
185
- statusField.removeClass("text-success").removeClass("text-muted").removeClass("text-danger");
176
+ function setStatus(status, stream) {
177
+ let statusField = document.getElementById("status");
186
178
  if (status == "PLAYING" || status == "ESTABLISHED" || status == "STOPPED") {
187
179
  //don't display status word because we have this indication on UI
188
- statusField.text("");
180
+ statusField.innerHTML = "";
189
181
  } else if (status == "DISCONNECTED") {
190
- statusField.text(status);
191
- statusField.addClass("text-muted");
182
+ statusField.innerHTML = status;
192
183
  } else if (status == "FAILED") {
193
- statusField.text(status);
194
- statusField.addClass("text-muted");
184
+ statusField.innerHTML = status;
185
+ if (stream && stream.getInfo() !== "") {
186
+ statusField.innerHTML = status + ": " + stream.getInfo();
187
+ }
195
188
  }
196
189
  }
197
190
 
198
- function validateForm() {
199
- var valid = true;
200
- $('#form :text').each(function () {
201
- if (!$(this).val()) {
202
- highlightInput($(this));
203
- 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);
204
197
  } else {
205
- 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);
206
202
  }
207
203
  });
208
- return valid;
209
-
210
- function highlightInput(input) {
211
- input.closest('.form-group').addClass("has-error");
212
- }
213
-
214
- function removeHighlight(input) {
215
- input.closest('.form-group').removeClass("has-error");
216
- }
217
204
  }
218
205
 
219
- function setVolume(volume, slider) {
220
- if (volume < 0) {
221
- console.error("Bad volume: " + volume);
222
- return(false);
223
- }
224
- if (stream) {
225
- if (volume > 0) {
226
- if (!firstUnmuted && slider && Browser.isAndroid()) {
227
- console.error("User should click volume unmute button to enable audio");
228
- return(false);
229
- } else if (stream.isRemoteAudioMuted()) {
230
- stream.unmuteRemoteAudio();
231
- firstUnmuted = true;
232
- }
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();
233
226
  }
234
- stream.setVolume(volume);
235
- }
236
- // Save current volume in page element to restore it when mute/unmute
237
- $('#volume-range').val(volume);
227
+ });
228
+ video.addEventListener("webkitendfullscreen", function () {
229
+ video.play();
230
+ needRestart = true;
231
+ isFullscreen = false;
232
+ });
233
+ }
238
234
 
239
- //chnage volume control icon
240
- if ( currentVolumeValue > 0) {
241
- //volume in range 0-50
242
- if ( currentVolumeValue <= 50 ) {
243
- $('.volume').html(HTML_VOLUME_LOW);
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();
244
245
  }
246
+ });
247
+ }
245
248
 
246
- //volume greater than 50
247
- if ( currentVolumeValue > 50 ) {
248
- $('.volume').html(HTML_VOLUME_HIGH);
249
+ // Object to manage central Play/Stop button
250
+ const centralButton = {
251
+ timer: null,
252
+ displayed: false,
253
+ display: function(timeout = 0) {
254
+ showItem('play');
255
+ centralButton.displayed = true;
256
+ if (timeout > 0 && !centralButton.timer) {
257
+ centralButton.timer = setTimeout(function() {
258
+ centralButton.hide();
259
+ }, timeout);
249
260
  }
250
-
251
- if ($('.volume').hasClass('volume-none')) {
252
- $('.volume').removeClass('volume-none');
261
+ },
262
+ displayToggle: function(timeout) {
263
+ if(!centralButton.displayed) {
264
+ centralButton.display(timeout);
265
+ } else {
266
+ centralButton.hide();
253
267
  }
254
-
255
- } else if ( currentVolumeValue == 0 ) {
256
- // Zero volume is equal to audio mute
257
- $('.volume').html(HTML_VOLUME_ZERO);
258
- if (!$('.volume').hasClass('volume-none')) {
259
- $('.volume').addClass('volume-none');
268
+ },
269
+ setAction: function(action) {
270
+ document.getElementById('play').onclick = action;
271
+ },
272
+ setView: function(view) {
273
+ let button = document.getElementById('play');
274
+ let image = button.querySelector('img');
275
+ if (view === "play") {
276
+ button.classList.remove('stop');
277
+ button.classList.add('play');
278
+ image.src = 'images/play.png';
279
+ } else if (view === "stop") {
280
+ button.classList.remove('play');
281
+ button.classList.add('stop');
282
+ image.src = 'images/stop.png';
283
+ }
284
+ },
285
+ hide: function() {
286
+ hideItem('play');
287
+ centralButton.displayed = false;
288
+ centralButton.stopTimer();
289
+ },
290
+ stopTimer: function() {
291
+ if (centralButton.timer) {
292
+ clearTimeout(centralButton.timer);
293
+ centralButton.timer = null;
260
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();
261
308
  }
309
+ };
262
310
 
263
- return(true);
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
+ }
264
317
  }
265
318
 
266
- (function ($) {
267
- $.fn.videoPlayer = function (options) {
268
- var settings = {
269
- playerWidth: '0.95', // Default is 95%
270
- videoClass: 'video' // Video Class
271
- };
272
-
273
- if (options) {
274
- $.extend(settings, options);
275
- }
276
-
277
- return this.each(function () {
278
- var $this = $(this);
279
- var $settings = settings;
280
- var $that = $this.parent('.' + $settings.videoClass);
281
- $that.find('.player').css({
282
- 'width': ($settings.playerWidth * 100) + '%',
283
- 'left': ((100 - $settings.playerWidth * 100) / 2) + '%'
284
- });
285
-
286
- var $mclicking = false,
287
- $vclicking = false,
288
- $volhover = false,
289
- $clearTimeout;
290
- y = 0;
291
-
292
- $that.bind('selectstart', function () {
293
- return false;
294
- });
295
-
296
- $that.find('.play-pause').bind('click', function () {
297
- // If playing, etc, change classes to show pause or play button
298
- if (!$(this).prop('disabled')) {
299
- if (stopped) {
300
- start();
301
- $(this).addClass('pause').removeClass('play').prop('disabled', true);
302
- $('#play').css('display', 'none');
303
- } else {
304
- if (stream) {
305
- stream.stop();
306
- }
307
- $(this).addClass('play').removeClass('pause').prop('disabled', true);
308
- $("#preloader").hide();
309
- }
310
- }
311
- });
312
-
313
- $that.bind('click', function () {
314
- if ( !stopped ) {
315
- if ($clearTimeout) {
316
- clearTimeout($clearTimeout);
317
- }
318
- $that.find('.player').stop(true, false).animate({'opacity': '1'}, 0.5);
319
- $clearTimeout = setTimeout(function() {
320
- $that.find('.player').stop(true, false).animate({'opacity': '0'}, 0.5);
321
- }, 5000);
322
- };
323
- });
324
-
325
- $that.find('.volume').hover(function () {
326
- $volhover = true;
327
- }, function () {
328
- $volhover = false;
329
- });
330
-
331
- $('body, html').bind('mousemove', function (e) {
332
- if ( !stopped ) {
333
- $that.hover(function () {
334
- $that.find('.player').stop(true, false).animate({'opacity': '1'}, 0.5);
335
- }, function () {
336
- $that.find('.player').stop(true, false).animate({'opacity': '0'}, 0.5);
337
- });
338
- }
339
- if (!$volhover) {
340
- $that.find('.volume-holder').stop(true, false).fadeOut(100);
341
- $that.find('.volume-icon').removeClass('volume-icon-hover');
342
- }
343
- else {
344
- $that.find('.volume-icon').addClass('volume-icon-hover');
345
- $that.find('.volume-holder').fadeIn(100);
346
- }
347
- });
348
-
349
- // Requests fullscreen based on browser.
350
- $('.fullscreenBtn').click(function () {
351
- if ( stream ) {
352
- stream.fullScreen();
353
- };
354
- });
355
- var init = $( "#slider" ).slider({
356
- value: 50,
357
- orientation: "horizontal",
358
- range: "min",
359
- slide: function( event, ui ) {
360
- valueRange()
361
- },
362
- stop: function( event, ui ) {
363
- valueRange()
364
- }
365
- });
366
- valueRange();
367
-
368
- var prevVol=1;
369
- function valueRange() {
370
- currentVolumeValue = $( "#slider" ).slider( "value" );
371
- if (setVolume(currentVolumeValue, true)) {
372
- // Save previous volume state to set when stream is unmuted by button
373
- prevVol = currentVolumeValue ? currentVolumeValue : 1;
374
-
375
- }
376
- }
377
-
378
- //mute unmute volume on click
379
- $('.volume').on('click', function () {
380
- if ($('.volume').hasClass('volume-none')) {
381
- // Restore previous volume state
382
- $('#slider').slider( "value", prevVol );
383
- currentVolumeValue = prevVol;
384
- setVolume(currentVolumeValue, false);
385
- $('.volume').removeClass('volume-none');
386
- } else {
387
- // Save previous volume state and mute audio
388
- prevVol = $('#volume-range').val();
389
- $('#slider').slider( "value", 0);
390
- currentVolumeValue = 0;
391
- setVolume(currentVolumeValue, false);
392
- $('.volume').addClass('volume-none');
393
- };
394
- });
395
-
396
-
397
- //show slider wile changing volume
398
- $('.volume-range-block').focusin( function () {
399
- $(this).addClass('open-width').addClass('open');
400
- });
401
- $('.volume-range-block').focusout( function () {
402
- $(this).removeClass('open-width').removeClass('open');
403
- });
404
-
405
-
406
- isMobile = {
407
- Android: function() {
408
- return navigator.userAgent.match(/Android/i);
409
- },
410
- BlackBerry: function() {
411
- return navigator.userAgent.match(/BlackBerry/i);
412
- },
413
- iOS: function() {
414
- return navigator.userAgent.match(/iPhone|iPad|iPod/i);
415
- },
416
- Opera: function() {
417
- return navigator.userAgent.match(/Opera Mini/i);
418
- },
419
- Windows: function() {
420
- return navigator.userAgent.match(/IEMobile/i);
421
- },
422
- any: function() {
423
- return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
424
- }
425
- };
426
- if (isMobile.any()) {
427
- $('.volume-range-block').addClass('open-width-full')
428
- }
429
- var prevFull;
430
-
431
- $(document).on('webkitfullscreenchange mozfullscreenchange fullscreenchange', function(e) {
432
- if (stream) {
433
-
434
- $('.player').toggleClass('fullscreenon'); //Add class for all controls in full screen mode
435
- $('.volume-range-block').toggleClass('fullscreen-vol'); //Add class to volume control for full screen mode
436
-
437
- if ( $('.player').hasClass('fullscreenon') ) {
438
- prevFull = $('.fullscreenBtn').html();
439
-
440
- //change full screen button to full screen exit button
441
- $('.fullscreenBtn').html(HTML_FULLSCREEN_EXIT);
442
-
443
- //activate controls on mouse moving
444
- $that.bind('mousemove touchmove', function () {
445
- if ($clearTimeout) {
446
- clearTimeout($clearTimeout);
447
- }
448
- $that.find('.player').stop(true, false).animate({'opacity': '1'}, 0.1);
449
- $clearTimeout = setTimeout(function() {
450
- $that.find('.player').stop(true, false).animate({'opacity': '0'}, 0.5);
451
- }, 15000);
452
- });
453
- } else {
454
-
455
- $('.fullscreenBtn').html(prevFull);
456
- $('.fullscreenBtn').click(function () {
457
- if ( stream ) {
458
- stream.fullScreen();
459
- };
460
- });
461
- };
462
- };
463
- });
464
- });
319
+ function hideItem(id) {
320
+ let item = document.getElementById(id);
321
+ if (item) {
322
+ item.style.display = "none";
323
+ }
465
324
  }
466
- })(jQuery);