ovenplayer 0.10.2 → 0.10.3-3.alpha-2

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.
Files changed (49) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +39 -46
  3. package/dist/ovenplayer.js +1 -1
  4. package/dist/ovenplayer.js.map +1 -1
  5. package/package.json +1 -1
  6. package/src/assets/fonts/seek-icons.svg +13 -13
  7. package/src/js/api/Api.js +231 -140
  8. package/src/js/api/Configurator.js +6 -3
  9. package/src/js/api/SupportChecker.js +9 -3
  10. package/src/js/api/constants.js +203 -15
  11. package/src/js/api/media/Manager.js +15 -106
  12. package/src/js/api/provider/Controller.js +5 -6
  13. package/src/js/api/provider/html5/Provider.js +107 -86
  14. package/src/js/api/provider/html5/providers/Dash.js +39 -110
  15. package/src/js/api/provider/html5/providers/Hls.js +139 -99
  16. package/src/js/api/provider/html5/providers/Html5.js +3 -1
  17. package/src/js/api/provider/html5/providers/WebRTC.js +207 -37
  18. package/src/js/api/provider/html5/providers/WebRTCLoader.js +247 -116
  19. package/src/js/ovenplayer.js +5 -9
  20. package/src/js/ovenplayer.sdk.js +5 -6
  21. package/src/js/utils/browser.js +6 -1
  22. package/src/js/utils/getTouchSection.js +23 -0
  23. package/src/js/utils/likeA$.js +4 -3
  24. package/src/js/utils/resize-sensor.js +168 -1
  25. package/src/js/utils/underscore.js +5 -5
  26. package/src/js/view/components/controls/fullScreenButton.js +22 -15
  27. package/src/js/view/components/controls/main.js +33 -20
  28. package/src/js/view/components/controls/playlistPanel.js +1 -1
  29. package/src/js/view/components/controls/progressBar.js +151 -76
  30. package/src/js/view/components/controls/settingButton.js +65 -48
  31. package/src/js/view/components/controls/settingPanel/audioTrackPanel.js +57 -0
  32. package/src/js/view/components/controls/settingPanel/captionPanel.js +1 -1
  33. package/src/js/view/components/controls/settingPanel/main.js +110 -80
  34. package/src/js/view/components/controls/settingPanel/qualityPanel.js +2 -2
  35. package/src/js/view/components/controls/settingPanel/sourcePanel.js +1 -1
  36. package/src/js/view/components/controls/settingPanel/speedPanel.js +1 -1
  37. package/src/js/view/components/controls/settingPanel/timeDisplayPanel.js +1 -1
  38. package/src/js/view/components/controls/timeDisplay.js +95 -23
  39. package/src/js/view/components/controls/timeDisplayTemplate.js +1 -1
  40. package/src/js/view/components/controls/volumeButton.js +2 -3
  41. package/src/js/view/components/helpers/captionViewer.js +1 -1
  42. package/src/js/view/components/helpers/contextPanel.js +1 -1
  43. package/src/js/view/components/helpers/contextPanelTemplate.js +1 -1
  44. package/src/js/view/components/helpers/main.js +21 -0
  45. package/src/js/view/components/helpers/thumbnailTemplate.js +0 -1
  46. package/src/js/view/engine/Templates.js +2 -0
  47. package/src/js/view/view.js +53 -14
  48. package/src/js/view/viewTemplate.js +8 -8
  49. package/src/stylesheet/ovenplayer.less +565 -308
@@ -5,7 +5,8 @@ import Provider from "api/provider/html5/Provider";
5
5
  import WebRTCLoader from "api/provider/html5/providers/WebRTCLoader";
6
6
  import {isWebRTC} from "utils/validator";
7
7
  import {errorTrigger} from "api/provider/utils";
8
- import {PROVIDER_WEBRTC, STATE_IDLE, CONTENT_META, STATE_PLAYING} from "api/constants";
8
+ import {PROVIDER_WEBRTC, ERROR, PLAYER_STATE, STATE_IDLE, STATE_LOADING} from "api/constants";
9
+ import {ERRORS, PLAYER_WEBRTC_TIMEOUT} from "../../../constants";
9
10
 
10
11
  /**
11
12
  * @brief webrtc provider extended core.
@@ -13,74 +14,243 @@ import {PROVIDER_WEBRTC, STATE_IDLE, CONTENT_META, STATE_PLAYING} from "api/cons
13
14
  * @param playerConfig config.
14
15
  * */
15
16
 
16
- const WebRTC = function(element, playerConfig, adTagUrl){
17
+ const WebRTC = function (element, playerConfig, adTagUrl) {
17
18
  let that = {};
18
19
  let webrtcLoader = null;
19
- let superDestroy_func = null;
20
+ let superDestroy_func = null;
21
+ let superPlay_func = null;
22
+
23
+ let sourceFile = null;
24
+
25
+ let audioCtx = null;
20
26
 
21
27
  let spec = {
22
- name : PROVIDER_WEBRTC,
23
- element : element,
24
- mse : null,
25
- listener : null,
26
- isLoaded : false,
27
- canSeek : false,
28
- isLive : false,
29
- seeking : false,
30
- state : STATE_IDLE,
31
- buffer : 0,
32
- framerate : 0,
33
- currentQuality : -1,
34
- currentSource : -1,
35
- qualityLevels : [],
36
- sources : [],
37
- adTagUrl : adTagUrl
28
+ name: PROVIDER_WEBRTC,
29
+ element: element,
30
+ mse: null,
31
+ listener: null,
32
+ isLoaded: false,
33
+ canSeek: false,
34
+ isLive: false,
35
+ seeking: false,
36
+ state: STATE_IDLE,
37
+ buffer: 0,
38
+ framerate: 0,
39
+ currentQuality: -1,
40
+ currentSource: -1,
41
+ qualityLevels: [],
42
+ sources: [],
43
+ adTagUrl: adTagUrl
44
+ };
45
+
46
+ let connectionTimeout = 10000;
47
+ let timeoutMaxRetry = 0;
48
+ let connectionCheckTimer = null;
49
+ let connected = false;
50
+ let connectionStartTime = null;
51
+ let connectedTime = null;
52
+
53
+ const device = () => {
54
+ return {
55
+ isMobile: /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent),
56
+ iOS: /iPhone|iPad|iPod/i.test(navigator.userAgent)
57
+ }
38
58
  };
39
59
 
40
- that = Provider(spec, playerConfig, function(source){
41
- if(isWebRTC(source.file, source.type)){
42
- OvenPlayerConsole.log("WEBRTC : onBeforeLoad : ", source);
43
- if(webrtcLoader){
60
+ const unlockAudio = (audioCtx) => {
61
+ let currentDevice = device();
62
+ let called = false;
63
+ if (currentDevice.isMobile && audioCtx.state === 'suspended') {
64
+
65
+ document.addEventListener('touchend', () => {
66
+ if (!called && audioCtx.state !== 'running') {
67
+ audioCtx.resume();
68
+ called = true
69
+ }
70
+ })
71
+ }
72
+ };
73
+
74
+ function loadWebRTCLoader() {
75
+
76
+ if (isWebRTC(sourceFile.file, sourceFile.type)) {
77
+
78
+ clearTimeout(connectionCheckTimer);
79
+
80
+ OvenPlayerConsole.log("WEBRTC : onBeforeLoad : ", sourceFile);
81
+
82
+ if (webrtcLoader) {
44
83
  webrtcLoader.destroy();
45
84
  webrtcLoader = null;
46
85
  }
47
86
 
48
- let loadCallback = function(stream){
87
+ const loadCallback = function (stream) {
49
88
 
50
89
  if (element.srcObject) {
51
90
  element.srcObject = null;
52
91
  }
53
92
 
93
+ if (audioCtx) {
94
+ audioCtx.close();
95
+ audioCtx = null;
96
+ }
97
+
54
98
  element.srcObject = stream;
99
+
100
+ if (stream.getAudioTracks().length > 0) {
101
+
102
+ // Add some weird code to avoid the audio delay bug in Safari.
103
+ // We don't even know why this code solves the audio delay.
104
+ const AudioContext = window.AudioContext || window.webkitAudioContext;
105
+
106
+ // This code resolves audio delay in MacOS not IOS.
107
+ audioCtx = new AudioContext();
108
+ unlockAudio(audioCtx);
109
+
110
+
111
+ // This code resolves audio delay in IOS.
112
+ audioCtx.createMediaStreamSource(stream);
113
+ }
114
+
55
115
  };
56
116
 
57
- webrtcLoader = WebRTCLoader(that, source.file, loadCallback, errorTrigger, playerConfig);
117
+ let internalErrorCallback = null;
118
+ let connectedCallback = null;
119
+
120
+ // add callback to check time out
121
+ if (timeoutMaxRetry > 0) {
122
+
123
+ internalErrorCallback = function () {
124
+
125
+ clearTimeout(connectionCheckTimer);
126
+ };
127
+
128
+ connectedCallback = function () {
129
+
130
+ clearTimeout(connectionCheckTimer);
131
+ connectedTime = performance.now();
132
+ connected = true;
133
+ };
134
+ }
135
+
136
+ webrtcLoader = WebRTCLoader(
137
+ that,
138
+ sourceFile.file,
139
+ loadCallback,
140
+ connectedCallback,
141
+ internalErrorCallback,
142
+ errorTrigger,
143
+ playerConfig,
144
+ spec
145
+ );
146
+
147
+ connectionStartTime = performance.now();
148
+ webrtcLoader.connect();
149
+
150
+ // add connection time out checker
151
+ if (timeoutMaxRetry > 0) {
152
+
153
+ that.once(PLAYER_STATE, function (e) {
154
+
155
+ if (!connected) {
156
+ if (e.newstate === STATE_IDLE) {
157
+
158
+ clearTimeout(connectionCheckTimer);
159
+ destroyWebRtcLoader();
160
+ }
161
+ }
162
+ });
163
+
164
+ that.once(ERROR, function () {
165
+
166
+ connected = false;
167
+ });
58
168
 
59
- webrtcLoader.connect(function(){
60
- //ToDo : resolve not workring
61
- }).catch(function(error){
62
- //that.destroy();
63
- //Do nothing
64
- });
169
+ connectionCheckTimer = setTimeout(function () {
170
+
171
+ if (timeoutMaxRetry > 0) {
172
+ if (!connected) {
173
+
174
+ destroyWebRtcLoader();
175
+ loadWebRTCLoader();
176
+ }
177
+ } else {
178
+ destroyWebRtcLoader();
179
+ let error = ERRORS.codes[PLAYER_WEBRTC_TIMEOUT];
180
+ errorTrigger(error, that);
181
+ }
182
+
183
+ timeoutMaxRetry--;
184
+
185
+ }, connectionTimeout);
186
+ }
187
+ }
188
+ }
189
+
190
+ function destroyWebRtcLoader() {
191
+
192
+ if (webrtcLoader) {
193
+ webrtcLoader.destroy();
194
+ webrtcLoader = null;
195
+ element.srcObject = null;
196
+ }
197
+ }
198
+
199
+ that = Provider(spec, playerConfig, function (source) {
200
+
201
+ const config = playerConfig.getConfig();
202
+
203
+ if (config.webrtcConfig) {
204
+
205
+ if (typeof config.webrtcConfig.connectionTimeout === 'number'
206
+ && config.webrtcConfig.connectionTimeout > 0) {
207
+
208
+ connectionTimeout = config.webrtcConfig.connectionTimeout;
209
+ }
210
+
211
+ if (typeof config.webrtcConfig.timeoutMaxRetry === 'number'
212
+ && config.webrtcConfig.timeoutMaxRetry > 0) {
213
+
214
+ timeoutMaxRetry = config.webrtcConfig.timeoutMaxRetry;
215
+ }
65
216
  }
217
+
218
+ sourceFile = source;
219
+ loadWebRTCLoader();
66
220
  });
221
+
67
222
  superDestroy_func = that.super('destroy');
223
+ superPlay_func = that.super('play');
68
224
 
69
225
  OvenPlayerConsole.log("WEBRTC PROVIDER LOADED.");
70
226
 
227
+ that.removeStream = () => {
228
+ element.srcObject = null;
229
+ };
230
+
71
231
 
72
- that.destroy = () =>{
73
- if(webrtcLoader){
74
- webrtcLoader.destroy();
75
- element.srcObject = null;
76
- webrtcLoader = null;
77
- }
232
+ that.destroy = () => {
233
+
234
+ clearTimeout(connectionCheckTimer);
235
+
236
+ destroyWebRtcLoader();
78
237
 
79
238
  OvenPlayerConsole.log("WEBRTC : PROVIDER DESTROYED.");
80
239
 
81
240
  superDestroy_func();
82
241
 
83
242
  };
243
+
244
+ that.play = () => {
245
+
246
+ if (timeoutMaxRetry > 0 && !connected) {
247
+
248
+ loadWebRTCLoader();
249
+ }
250
+
251
+ superPlay_func();
252
+ };
253
+
84
254
  return that;
85
255
  };
86
256