@flashphoner/websdk 2.0.230 → 2.0.232

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,4 +1,4 @@
1
- Web SDK - 2.0.230
1
+ Web SDK - 2.0.232
2
2
 
3
3
  [Download builds](https://docs.flashphoner.com/display/WEBSDK2EN/Web+SDK+release+notes)
4
4
 
@@ -2,6 +2,32 @@
2
2
  ///////////// Utils ////////////
3
3
  ///////////////////////////////////
4
4
 
5
+ /**
6
+ * Default server ports description
7
+ *
8
+ * @type {{legacy: {http: number, https: number}, wss: number, http: number, https: number, ws: number, hls: {http: number, https: number}}}
9
+ */
10
+ const DEFAULT_PORTS = {
11
+ http: 8081,
12
+ https: 8444,
13
+ legacy: {
14
+ http: 9091,
15
+ https: 8888
16
+ },
17
+ ws: 8080,
18
+ wss: 8443,
19
+ hls: {
20
+ http: 8082,
21
+ https: 8445
22
+ }
23
+ }
24
+
25
+ /**
26
+ * Check if object is not empty
27
+ *
28
+ * @param obj object to check
29
+ * @returns {boolean} true if object is not empty
30
+ */
5
31
  function notEmpty(obj) {
6
32
  if (obj != null && obj != 'undefined' && obj != '') {
7
33
  return true;
@@ -9,34 +35,165 @@ function notEmpty(obj) {
9
35
  return false;
10
36
  }
11
37
 
12
- //Trace
38
+ /**
39
+ * Print trace string to
40
+ *
41
+ * @param str string to print
42
+ */
13
43
  function trace(str) {
14
44
  console.log(str);
15
45
  }
16
46
 
17
- //Get field
47
+ /**
48
+ * Get HTML page field
49
+ *
50
+ * @param name field name
51
+ * @returns {*} field
52
+ */
18
53
  function field(name) {
19
54
  var field = document.getElementById(name).value;
20
55
  return field;
21
56
  }
22
57
 
23
- //Set WCS URL
24
- function setURL() {
25
- var proto;
26
- var url;
27
- var port;
58
+ /**
59
+ * Set default value to port if it is not defined
60
+ *
61
+ * @param port
62
+ * @param value
63
+ * @returns {*}
64
+ */
65
+ function setDefaultPort(port, value) {
66
+ if (port === undefined) {
67
+ return value;
68
+ }
69
+ return port;
70
+ }
71
+
72
+ /**
73
+ * Get server ports configuration
74
+ *
75
+ * @returns {{legacy: {http: number, https: number}, wss: number, http: number, https: number, ws: number, hls: {http: number, https: number}}}
76
+ */
77
+ function getPortsConfig() {
78
+ let portsConfig = DEFAULT_PORTS;
79
+ try {
80
+ // Try to get ports from a separate config declaring the SERVER_PORTS constant
81
+ portsConfig = SERVER_PORTS;
82
+ // Fill the ports absent in config by default values
83
+ portsConfig.http = setDefaultPort(portsConfig.http, DEFAULT_PORTS.http);
84
+ portsConfig.https = setDefaultPort(portsConfig.https, DEFAULT_PORTS.https);
85
+ portsConfig.legacy = setDefaultPort(portsConfig.legacy, DEFAULT_PORTS.legacy);
86
+ portsConfig.legacy.http = setDefaultPort(portsConfig.legacy.http, DEFAULT_PORTS.legacy.http);
87
+ portsConfig.legacy.https = setDefaultPort(portsConfig.legacy.https, DEFAULT_PORTS.legacy.https);
88
+ portsConfig.ws = setDefaultPort(portsConfig.ws, DEFAULT_PORTS.ws);
89
+ portsConfig.wss = setDefaultPort(portsConfig.wss, DEFAULT_PORTS.wss);
90
+ portsConfig.hls = setDefaultPort(portsConfig.hls, DEFAULT_PORTS.hls);
91
+ portsConfig.hls.http = setDefaultPort(portsConfig.hls.http, DEFAULT_PORTS.hls.http);
92
+ portsConfig.hls.https = setDefaultPort(portsConfig.hls.https, DEFAULT_PORTS.hls.https);
93
+ console.log("Use custom server ports");
94
+ } catch(e) {
95
+ console.log("Use default server ports");
96
+ console.log(e.stack);
97
+ }
98
+ return portsConfig;
99
+ }
100
+
101
+ /**
102
+ * Get web interface standard port depending on connection type
103
+ *
104
+ * @returns {string}
105
+ */
106
+ function getWebPort() {
107
+ let portsConfig = getPortsConfig();
108
+ let port;
109
+ if (window.location.protocol == "http:") {
110
+ port = portsConfig.http;
111
+ } else {
112
+ port = portsConfig.https;
113
+ }
114
+ return port;
115
+ }
116
+
117
+ /**
118
+ * Get HTML protocol used depending on connection type
119
+ *
120
+ * @returns {string}
121
+ */
122
+ function getWebProtocol() {
123
+ let proto;
124
+ if (window.location.protocol == "http:") {
125
+ proto = "http://";
126
+ } else {
127
+ proto = "https://";
128
+ }
129
+ return proto;
130
+ }
131
+
132
+ /**
133
+ * Get websocket standard port depending on connection type
134
+ *
135
+ * @returns {string}
136
+ */
137
+ function getWsPort() {
138
+ let portsConfig = getPortsConfig();
139
+ let port;
140
+ if (window.location.protocol == "http:") {
141
+ port = portsConfig.ws;
142
+ } else {
143
+ port = portsConfig.wss;
144
+ }
145
+ return port;
146
+ }
147
+
148
+ /**
149
+ * Get websocket protocol type depending on connection type
150
+ *
151
+ * @returns {string}
152
+ */
153
+ function getWsProtocol() {
154
+ let proto;
28
155
  if (window.location.protocol == "http:") {
29
156
  proto = "ws://";
30
- port = "8080";
31
157
  } else {
32
158
  proto = "wss://";
33
- port = "8443";
34
159
  }
160
+ return proto;
161
+ }
162
+
163
+ /**
164
+ * Get standard HLS port depending on connection type
165
+ *
166
+ * @returns {string}
167
+ */
168
+ function getHlsPort() {
169
+ let portsConfig = getPortsConfig();
170
+ let port;
171
+ if (window.location.protocol == "http:") {
172
+ port = portsConfig.hls.http;
173
+ } else {
174
+ port = portsConfig.hls.https;
175
+ }
176
+ return port;
177
+ }
35
178
 
36
- url = proto + window.location.hostname + ":" + port;
179
+ /**
180
+ * Set default WCS websocket URL (used in most examples)
181
+ *
182
+ * @returns {string}
183
+ */
184
+ function setURL() {
185
+ var proto = getWsProtocol();
186
+ var port = getWsPort();
187
+ var url = proto + window.location.hostname + ":" + port;
37
188
  return url;
38
189
  }
39
190
 
191
+ /**
192
+ * Get URL parameter
193
+ *
194
+ * @param name
195
+ * @returns {string|null}
196
+ */
40
197
  function getUrlParam(name) {
41
198
  var url = window.location.href;
42
199
  name = name.replace(/[\[\]]/g, "\\$&");
@@ -47,40 +204,83 @@ function getUrlParam(name) {
47
204
  return decodeURIComponent(results[2].replace(/\+/g, " "));
48
205
  }
49
206
 
207
+ /**
208
+ * Get default HLS url
209
+ *
210
+ * @returns {string}
211
+ */
50
212
  function getHLSUrl() {
213
+ var proto = getWebProtocol();
214
+ var port = getHlsPort();
215
+ var url = proto + window.location.hostname + ":" + port;
216
+ return url;
217
+ }
51
218
 
52
- var proto;
219
+ /**
220
+ * Get default admin URL (used in Embed Player)
221
+ *
222
+ * @returns {string}
223
+ */
224
+ function getAdminUrl() {
225
+ var portsConfig = getPortsConfig();
226
+ var proto = getWebProtocol();
53
227
  var port;
54
-
55
228
  if (window.location.protocol == "http:") {
56
- proto = "http://";
57
- port = "8082";
229
+ port = portsConfig.legacy.http;
58
230
  } else {
59
- proto = "https://";
60
- port = "8445";
231
+ port = portsConfig.legacy.https;
61
232
  }
62
-
63
233
  var url = proto + window.location.hostname + ":" + port;
64
234
  return url;
65
235
  }
66
236
 
67
- function getAdminUrl() {
237
+ /**
238
+ * Get REST API URL
239
+ *
240
+ * @param hostName host name to override the default one
241
+ * @param hostPort host port to override the default one
242
+ * @returns {string}
243
+ */
244
+ function getRestUrl(hostName, hostPort) {
245
+ let proto = getWebProtocol();
246
+ let port = getWebPort();
247
+ if (!hostName) {
248
+ hostName = window.location.hostname;
249
+ }
250
+ if (hostPort) {
251
+ port = hostPort;
252
+ }
68
253
 
69
- var proto;
70
- var port;
71
- if (window.location.protocol == "http:") {
72
- proto = "http://";
73
- port = "9091";
74
- } else {
75
- proto = "https://";
76
- port = "8888";
254
+ let url = proto + hostName + ":" + port;
255
+ return url;
256
+ }
257
+
258
+ /**
259
+ * Get Websocket URL
260
+ *
261
+ * @param hostName host name to override the default one
262
+ * @param hostPort host port to override the default one
263
+ * @returns {string}
264
+ */
265
+ function getWebsocketUrl(hostName, hostPort) {
266
+ let proto = getWsProtocol();
267
+ let port = getWsPort();
268
+ if (!hostName) {
269
+ hostName = window.location.hostname;
270
+ }
271
+ if (hostPort) {
272
+ port = hostPort;
77
273
  }
78
274
 
79
- var url = proto + window.location.hostname + ":" + port;
275
+ let url = proto + hostName + ":" + port;
80
276
  return url;
81
277
  }
82
278
 
83
- // Detect IE
279
+ /**
280
+ * Detect IE (for compatibility only)
281
+ *
282
+ * @returns {boolean}
283
+ */
84
284
  function detectIE() {
85
285
  var ua = window.navigator.userAgent;
86
286
  var msie = ua.indexOf('MSIE ');
@@ -94,7 +294,10 @@ function detectIE() {
94
294
  return false;
95
295
  }
96
296
 
97
- // Detect Flash
297
+ /**
298
+ * Detect Flash (for compatibility only)
299
+ *
300
+ */
98
301
  function detectFlash() {
99
302
  var hasFlash = false;
100
303
  try {
@@ -133,7 +336,12 @@ $(function () {
133
336
  });
134
337
  });
135
338
 
136
- // Generate simple uuid
339
+ /**
340
+ * Generate simple uuid
341
+ *
342
+ * @param length UUID length
343
+ * @returns {string}
344
+ */
137
345
  function createUUID(length) {
138
346
  var s = [];
139
347
  var hexDigits = "0123456789abcdef";
@@ -185,7 +393,15 @@ function resizeVideo(video, width, height) {
185
393
  console.log("Resize from " + video.videoWidth + "x" + video.videoHeight + " to " + display.offsetWidth + "x" + display.offsetHeight);
186
394
  }
187
395
 
188
-
396
+ /**
397
+ * Helper function to resize video tag
398
+ *
399
+ * @param videoWidth
400
+ * @param videoHeight
401
+ * @param dstWidth
402
+ * @param dstHeight
403
+ * @returns {{w: number, h: number}}
404
+ */
189
405
  function downScaleToFitSize(videoWidth, videoHeight, dstWidth, dstHeight) {
190
406
  var newWidth, newHeight;
191
407
  var videoRatio = videoWidth / videoHeight;
@@ -203,41 +419,57 @@ function downScaleToFitSize(videoWidth, videoHeight, dstWidth, dstHeight) {
203
419
  };
204
420
  }
205
421
 
422
+ /**
423
+ * Set Webkit fullscreen handler functions to video tag
424
+ *
425
+ * @param video
426
+ */
206
427
  function setWebkitFullscreenHandlers(video) {
207
428
  if (video) {
208
429
  let needRestart = false;
430
+ let wasFullscreen = false;
209
431
  // iOS hack when using standard controls to leave fullscreen mode
210
432
  video.addEventListener("pause", function () {
211
433
  if (needRestart) {
212
434
  console.log("Video paused after fullscreen, continue...");
435
+ wasFullscreen = true;
213
436
  video.play();
214
437
  needRestart = false;
215
438
  }
216
439
  });
217
440
  video.addEventListener("webkitendfullscreen", function () {
441
+ wasFullscreen = true;
218
442
  video.play();
219
443
  needRestart = true;
220
444
  });
221
445
  // Start playback in fullscreen if webkit-playsinline is set
222
446
  video.addEventListener("playing", function () {
223
- if (canWebkitFullScreen(video)) {
224
- // After pausing and resuming the video tag may be in invalid state
447
+ // Do not enter fullscreen again if we just left it #WCS-3860
448
+ if (canWebkitFullScreen(video) && !wasFullscreen) {
449
+ // We should catch if fullscreen mode is not available
225
450
  try {
226
451
  video.webkitEnterFullscreen();
227
452
  } catch (e) {
228
453
  console.log("Fullscreen is not allowed: " + e);
229
454
  }
230
455
  }
456
+ wasFullscreen = false;
231
457
  });
232
458
  } else {
233
459
  console.log("No video tag is passed, skip webkit fullscreen handlers setup");
234
460
  }
235
461
  }
236
462
 
463
+ /**
464
+ * Check if fullscreen mode is available in Webkit
465
+ *
466
+ * @param video
467
+ * @returns {boolean}
468
+ */
237
469
  function canWebkitFullScreen(video) {
238
470
  let canFullscreen = false;
239
471
  if (video) {
240
- canFullscreen = video.webkitSupportsFullscreen && !video.webkitDisplayingFullscreen && !document.webkitFullscreenElement;
472
+ canFullscreen = video.webkitSupportsFullscreen && !video.webkitDisplayingFullscreen;
241
473
  }
242
474
  return canFullscreen;
243
475
  }
@@ -8,6 +8,7 @@
8
8
  <link rel="stylesheet" href="console.css">
9
9
  <link rel="stylesheet" type="text/css" href="jquery.dataTables.css">
10
10
  <title>Console</title>
11
+ <script type="text/javascript" src="ports.js"></script>
11
12
  <script type="text/javascript" src="../../dependencies/jquery/jquery-1.12.0.js"></script>
12
13
  <script type="text/javascript" src="../../dependencies/jquery/jquery-ui.js"></script>
13
14
  <script type="text/javascript" src="../../dependencies/bootstrap/js/bootstrap.min.js"></script>
@@ -146,18 +146,19 @@ $(function() {
146
146
 
147
147
  function createNode(id, ip) {
148
148
  let nodeIp = ip;
149
- let port = 8081;
149
+ let port = getWebPort();
150
150
  if (ip.indexOf(':') !== -1) {
151
151
  port = ip.substring(ip.indexOf(":") + 1);
152
152
  nodeIp = ip.substring(0, ip.indexOf(":"));
153
153
  }
154
- var api = FlashphonerRestApi.instance("http://"+nodeIp+":"+port, "http://"+nodeIp+":"+port);
154
+ let restUrl = getRestUrl(nodeIp, port);
155
+ let api = FlashphonerRestApi.instance(restUrl, restUrl);
155
156
  api.id = id;
156
157
  api.ip = nodeIp;
157
158
  api.port = port;
158
159
  api.tests = [];
159
- var state = NODE_STATE.NEW;
160
- var pollState = function(){
160
+ let state = NODE_STATE.NEW;
161
+ let pollState = function(){
161
162
  api.stat.poll().then(function(stat){
162
163
  api.setState(NODE_STATE.ALIVE, stat);
163
164
  setTimeout(pollState, REFRESH_NODE_STATE_INTERVAL);
@@ -269,7 +270,7 @@ function createNode(id, ip) {
269
270
  }
270
271
  };
271
272
  api.getTranscodingGroupStat = async function() {
272
- const result = await fetch("http://" + nodeIp + ":" + port + "/?action=stat&format=json&groups=transcoding_stats")
273
+ const result = await fetch(restUrl + "/?action=stat&format=json&groups=transcoding_stats")
273
274
  const json = await result.json();
274
275
  return json;
275
276
  }
@@ -277,10 +278,7 @@ function createNode(id, ip) {
277
278
  }
278
279
 
279
280
  function addNode(ip) {
280
- var id = ip.replace(/\./g, "");
281
- if (ip.indexOf(':') !== -1) {
282
- id = ip.substring(ip.indexOf(":") + 1).replace(/\./g, "");
283
- }
281
+ var id = ip.replace(/[.:]/g, "");
284
282
  if (nodes[id]) {
285
283
  return;
286
284
  }
@@ -471,7 +469,7 @@ function pullStreamBatch() {
471
469
  var remoteName = $("#pullBatchRemoteName").val();
472
470
  var remote;
473
471
  if (proto == "ws") {
474
- remote = "ws://" + $("#pullStreamBatchNodes").val() + ":8080/";
472
+ remote = getWebsocketUrl($("#pullStreamBatchNodes").val()) + "/";
475
473
  } else {
476
474
  remote = "rtmp://" + $("#pullStreamBatchNodes").val() + ":1935/live/" + remoteName;
477
475
  }
@@ -674,7 +672,7 @@ function doRego(node, testedNode, login, domain, password) {
674
672
  sipPassword: password,
675
673
  sipPort: "5060",
676
674
  sipRegisterRequired: true,
677
- urlServer: "ws://"+testedNode+":8080/"
675
+ urlServer: getWebsocketUrl(testedNode) + "/"
678
676
  };
679
677
  return node.api.createSession(connection);
680
678
  }
@@ -954,7 +952,7 @@ function streamPlayStressTest() {
954
952
  return;
955
953
  }
956
954
 
957
- var remote = "ws://" + $("#streamStressBatchNodes").val() + ":8080";
955
+ var remote = getWebsocketUrl($("#streamStressBatchNodes").val());
958
956
  var name = $("#streamStressBatchName").val();
959
957
  var start = parseInt($("#streamStressBatchStart").val());
960
958
  var end = parseInt($("#streamStressBatchEnd").val());
@@ -1323,7 +1321,7 @@ function streamPublishStressTest() {
1323
1321
  return false;
1324
1322
  }
1325
1323
  var node = getActiveNode();
1326
- var remote = "ws://" + $("#streamPublishStressBatchNodes").val() + ":8080";
1324
+ var remote = getWebsocketUrl($("#streamPublishStressBatchNodes").val());
1327
1325
  var name = $("#streamPublishStressBatchName").val();
1328
1326
  var start = parseInt($("#streamPublishStressBatchStart").val());
1329
1327
  var end = parseInt($("#streamPublishStressBatchEnd").val());
@@ -1443,7 +1441,7 @@ function streamPlayStressTestRandom() {
1443
1441
  var node = getActiveNode();
1444
1442
  var streams = {};
1445
1443
  var remoteNode = getNode($("#streamStressBatchNodes").val());
1446
- var remote = "ws://" + $("#streamStressBatchNodes").val() + ":8080";
1444
+ var remote = getWebsocketUrl($("#streamStressBatchNodes").val());
1447
1445
  var start = 0;
1448
1446
  var end = parseInt($("#streamStressMaxStreams").val());
1449
1447
  var rate = parseInt($("#streamStressBatchRate").val());
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Server ports configuration for load testing
3
+ *
4
+ */
5
+ const SERVER_PORTS = {
6
+ http: 8081,
7
+ https: 8444,
8
+ legacy: {
9
+ http: 9091,
10
+ https: 8888
11
+ },
12
+ ws: 8080,
13
+ wss: 8443,
14
+ hls: {
15
+ http: 8082,
16
+ https: 8445
17
+ }
18
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flashphoner/websdk",
3
- "version": "2.0.230",
3
+ "version": "2.0.232",
4
4
  "description": "Official Flashphoner WebCallServer WebSDK package",
5
5
  "main": "./src/flashphoner-core.js",
6
6
  "types": "./src/flashphoner-core.d.ts",