senza-sdk 4.2.65-d2761c0.0 → 4.3.1-ca3d96f.0

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 (27) hide show
  1. package/dist/bundle.js +1 -1
  2. package/package.json +17 -8
  3. package/src/api.js +258 -327
  4. package/src/{alarmManager.js → implementation/alarmManager.js} +15 -52
  5. package/src/implementation/api.js +363 -0
  6. package/src/{deviceManager.js → implementation/deviceManager.js} +6 -78
  7. package/src/{lifecycle.js → implementation/lifecycle.js} +37 -225
  8. package/src/implementation/messageManager.js +55 -0
  9. package/src/{platformManager.js → implementation/platformManager.js} +5 -23
  10. package/src/{remotePlayer.js → implementation/remotePlayer.js} +35 -237
  11. package/src/{senzaShakaPlayer.js → implementation/senzaShakaPlayer.js} +92 -125
  12. package/src/{utils.js → implementation/utils.js} +15 -6
  13. package/src/interface/alarmManager.js +76 -0
  14. package/src/interface/api.js +8 -0
  15. package/src/{devSequence.js → interface/devSequence.js} +35 -0
  16. package/src/interface/deviceManager.js +142 -0
  17. package/src/interface/lifecycle.js +283 -0
  18. package/src/interface/messageManager.js +53 -0
  19. package/src/interface/platformManager.js +41 -0
  20. package/src/interface/remotePlayer.js +470 -0
  21. package/src/interface/senzaShakaPlayer.js +168 -0
  22. package/src/interface/utils.js +45 -0
  23. package/src/messageManager.js +0 -88
  24. /package/src/{SessionInfo.js → implementation/SessionInfo.js} +0 -0
  25. /package/src/{devHelper.js → implementation/devHelper.js} +0 -0
  26. /package/src/{eventListenersManager.js → implementation/eventListenersManager.js} +0 -0
  27. /package/src/{subtitlesUtils.js → implementation/subtitlesUtils.js} +0 -0
@@ -0,0 +1,470 @@
1
+ import { noop } from "./utils";
2
+
3
+ // TODO: check that the link below to the error list is working on dashreadme
4
+ /** Error object to be thrown on remotePlayer api failures.
5
+ * [See error list]{@link RemotePlayer#error}
6
+ */
7
+ export class RemotePlayerError extends Error {
8
+ }
9
+
10
+ /**
11
+ * @typedef {Object} Config
12
+ * @property {string} preferredAudioLanguage
13
+ * @property {string} preferredSubtitlesLanguage
14
+ * @property {number} minSuggestedPresentationDelay - minimal delay allowed for live playback in seconds
15
+ * @property {boolean} autoPlay - (Not implemented yet) upon loading start playing automatically
16
+ */
17
+
18
+ /**
19
+ * @event RemotePlayer#canplay
20
+ * @description canplay event will be dispatched when the remote player can start play the event
21
+ * @example
22
+ * remotePlayer.addEventListener("canplay", () => {
23
+ * console.info("remotePlayer canplay");
24
+ * remotePlayer.play();
25
+ * });
26
+ */
27
+ /**
28
+ * @event RemotePlayer#loadedmetadata
29
+ * @description loadedmetadata event will be dispatched when the remote player metadata is loaded
30
+ * and the audio/video tracks are available
31
+ * @example
32
+ * remotePlayer.addEventListener("loadedmetadata", () => {
33
+ * console.info("remotePlayer loadedmetadata", remotePlayer.getAudioTracks(), remotePlayer.getTextTracks());
34
+ * });
35
+ */
36
+
37
+ /**
38
+ * @event RemotePlayer#timeupdate
39
+ * @example
40
+ * remotePlayer.addEventListener("timeupdate", () => {
41
+ * console.info("remotePlayer timeupdate", remotePlayer.currentTime);
42
+ * localPlayer.getMediaElement().currentTime = remotePlayer.currentTime || 0;
43
+ * });
44
+ */
45
+
46
+ /**
47
+ * @event RemotePlayer#tracksupdate
48
+ * @example
49
+ * remotePlayer.addEventListener("tracksupdate", () => {
50
+ * console.info("remotePlayer tracksupdate", remotePlayer.getAudioTracks(), remotePlayer.getTextTracks());
51
+ * });
52
+ */
53
+
54
+ /**
55
+ * @event RemotePlayer#ended
56
+ * @example
57
+ * remotePlayer.addEventListener("ended", () => {
58
+ * console.info("remotePlayer ended");
59
+ * });
60
+ */
61
+
62
+ /**
63
+ * @event RemotePlayer#onloadmodechange
64
+ * @example
65
+ * remotePlayer.addEventListener("onloadmodechange", () => {
66
+ * console.info("remotePlayer load mode changed to", remotePlayer.getLoadMode());
67
+ * });
68
+ */
69
+
70
+ /**
71
+ * @event RemotePlayer#error
72
+ * @type {object}
73
+ * @property {int} detail.errorCode
74
+ * @property {string} detail.message
75
+ *
76
+ * @see Possible error codes:
77
+ *
78
+ * | Code | Domain | Description |
79
+ * | :-------- | :---------------- | :-----------------------------------------------------------------------------------------------|
80
+ * | 23 | Player | load() failed due to remote player initialization error |
81
+ * | 98 | Player | load() failed due to remote player failure to send message to the client |
82
+ * | 99 | Player | load() failed due to remote player reporting invalid message |
83
+ * | 1000 | Encrypted content | Failed to create or initialise the CDM |
84
+ * | 1001 | Encrypted content | Failed to create a CDM session |
85
+ * | 1002 | Encrypted content | CDM failed to generate a license request |
86
+ * | 1003 | Encrypted content | The CDM rejected the license server response |
87
+ * | 1004 | Encrypted content | The CDM rejected the license server certificate |
88
+ * | 1005 | Encrypted content | All keys in the license have expired |
89
+ * | 1006 | Encrypted content | Output device is incompatible with the license requirements (HDCP) |
90
+ * | 1007 | Encrypted content | The device has been revoked |
91
+ * | 1008 | Encrypted content | The device secrets aren't available |
92
+ * | 1009 | Encrypted content | Keys are loaded but the KID requested by playback isn't found. The app has likely issued a license for the wrong content or there is a mismatch between the KIDs in the license and the data plane |
93
+ * | 1010 | Encrypted content | The CDM failed to provision, therefore it is not possible to play encrypted content |
94
+ * | 1100 | Encrypted content | The CDM session has already received a license response. The app has likely issued 2, or more, license responses for the same request. The subsequent licenses will be ignored so this error is informational only |
95
+ * | 1101 | Encrypted content | The license has been rejected since an error was received by the CDM. The app has likely sent a non-200 code to `WriteLicenseResponse` |
96
+ * | 1102 | Encrypted content | A license response wasn't received from the app within a pre-defined timeout |
97
+ * | 1103 | Encrypted content | The CDM session associated with this license response is in an invalid state. This is an internal Senza platform error |
98
+ * | 1104 | Encrypted content | The CDM failed to send a license request to the app. This is an internal Senza platform error |
99
+ * | 1999 | Encrypted content | An unknown encrypted content error |
100
+ * | 2000 | Player | Content makes reference to no or unsupported key system |
101
+ * | 3000 | Player | Unexpected problem with playback, only used if no more specific code in 3xxx range applies |
102
+ * | 3001 | Player | Problem accessing content manifest, only used if no more specific code in 8xxx range applies |
103
+ * | 3002 | Player | Unexpectedly stopped playback |
104
+ * | 3100 | Player | Problem parsing MP4 content |
105
+ * | 3200 | Player | Problem with decoder |
106
+ * | 3300 | Player | DRM keys unavailable, player waited for keys but none arrived |
107
+ * | 3400 | Player | Problem accessing segments, only used if no more specific code in 34xx range applies |
108
+ * | 3401 | Player | Problem accessing segments, connection issue or timeout |
109
+ * | 3402 | Player | Problem accessing segments, server returned HTTP error code |
110
+ * | 3403 | Player | Problem accessing segments, server authentication issue |
111
+ * | 3404 | Player | Problem accessing segments, server returned not found |
112
+ * | 3900-3999 | Player | Internal player error |
113
+ * | 6000 | Player | The remote player api call has reached the configurable timeout with no response from the remote player |
114
+ * | 6001 | Player | play() was called while the remote player is not loaded |
115
+ * | 6002 | Player | load() was called while the application was in state 'background' or 'inTransitionToBackground' |
116
+ * | 6500 | Player | remotePlayer api was called before initializing remotePlayer |
117
+ * | 6501 | Player | load() was called while previous load/unload was still in progress |
118
+ * | 6502 | Player | unload() was called while previous unload/load was still in progress |
119
+ * | 8001 | Player | Error pulling manifest. bad parameters |
120
+ * | 8002 | Player | Error pulling manifest. filters returned no data |
121
+ * | 8003 | Player | Error pulling manifest. fetch error |
122
+ * | 8004 | Player | Error pulling manifest. parse error |
123
+ * | 8005 | Player | Error pulling manifest. stale manifest detected |
124
+ * | 8006 | Player | Error updating manifest. internal cache error |
125
+ * | 8007 | Player | Error updating manifest. internal error during backoff |
126
+ * | 8008 | Player | Error pulling manifest. sidx parsing error |
127
+ * | 8009 | Player | Error pulling manifest. internal error |
128
+ *
129
+ * @example
130
+ * remotePlayer.addEventListener("error", (event) => {
131
+ * console.error("received remotePlayer error:", event.detail.errorCode, event.detail.message);
132
+ * });
133
+ */
134
+ /**
135
+ * @event RemotePlayer#playing
136
+ * @description playing event will be dispatched when the remote player started playback of the first audio frame. This event can be used to synchronize the local player with the remote player.
137
+ * @example
138
+ * remotePlayer.addEventListener("playing", () => {
139
+ * console.info("remotePlayer playing");
140
+ * });
141
+ * */
142
+ /**
143
+ * @event RemotePlayer#license-request
144
+ * @description Fired whenever the platform requires a license to play encrypted content.
145
+ * The Web App is responsible for passing the (opaque) license request blob to the license server and passing the (opaque) license server response to the CDM by calling the `writeLicenseResponse` method on the event.
146
+ * @type {LicenseRequestEvent}
147
+ * @property {object} detail - Object containing ievent data
148
+ * @property {string} detail.licenseRequest - Base64 coded opaque license request. The app is responsible for decoding the request before sending to the license server. Note that after decoding, the request may still be in Base64 form and this form should be sent to the license server without further decoding
149
+ * @property {writeLicenseResponse} writeLicenseResponse - Write the license server response to the platform
150
+ * @example
151
+ * Whilst the payload structure and access controls are specific to each license server implementation, the Widevine UAT license server requires no authentication and minimal payload formatting and therefore serves as a useful case study that may be adapted.
152
+ *
153
+ * remotePlayer.addEventListener("license-request", async (event) => {
154
+ * console.log("Got license-request event");
155
+ * const requestBuffer = event?.detail?.licenseRequest;
156
+ * const requestBufferStr = String.fromCharCode.apply(null, new Uint8Array(requestBuffer));
157
+ * console.log("License Request in base64:", requestBufferStr);
158
+ * const decodedLicenseRequest = window.atob(requestBufferStr); // from base 64
159
+ * const licenseRequestBytes = Uint8Array.from(decodedLicenseRequest, (l) => l.charCodeAt(0));
160
+ * // call Google API
161
+ * const res = await getLicenseFromServer(licenseRequestBytes.buffer);
162
+ * console.log("Writing response to platform ", res.code, res.responseBody);
163
+ * event.writeLicenseResponse(res.code, res.responseBody);
164
+ * });
165
+
166
+ * async function getLicenseFromServer(licenseRequest) {
167
+ * console.log("Requesting License from Widevine server");
168
+ * const response = await fetch("https://proxy.uat.widevine.com/proxy", {
169
+ * "method": "POST",
170
+ * "body": licenseRequest,
171
+ * "headers" : {
172
+ * "Content-Type": "application/octet-stream"
173
+ * }
174
+ * });
175
+ * const code = response.status;
176
+ * if (code !== 200) {
177
+ * console.error("failed to to get response from widevine:", code);
178
+ * const responseBody = await response.text();
179
+ * console.error(responseBody);
180
+ * return {code, responseBody};
181
+ * }
182
+ * const responseBody = await response.arrayBuffer();
183
+ * console.info("Got response: ");
184
+ * return {code, responseBody};
185
+ * }
186
+ */
187
+
188
+
189
+ /**
190
+ * RemotePlayer a singleton class to communicate with remote player
191
+ * @fires timeupdate
192
+ * @fires tracksupdate
193
+ * @fires ended
194
+ * @fires error
195
+ * @fires onloadmodechange
196
+ * @fires seeking (Not implemented yet)
197
+ * @fires seeked (Not implemented yet)
198
+ * @fires loadedmetadata (Not implemented yet)
199
+ * @fires canplay
200
+ * @fires license-request
201
+ */
202
+ export class RemotePlayer extends EventTarget {
203
+
204
+ /**
205
+ * @typedef {Object} LoadMode
206
+ * @property {string} NOT_LOADED
207
+ * @property {string} LOADING
208
+ * @property {string} LOADED
209
+ * @property {string} UNLOADING
210
+ */
211
+ LoadMode = Object.freeze({
212
+ NOT_LOADED: "notLoaded",
213
+ LOADING: "loading",
214
+ LOADED: "loaded",
215
+ UNLOADING: "unloading"
216
+ });
217
+
218
+ /** get the player configuration.
219
+ * @returns {Config}
220
+ * */
221
+ getConfiguration() {
222
+ return { preferredAudioLanguage: "", preferredSubtitlesLanguage: "" };
223
+ }
224
+
225
+ /** setting values for properties in the player configuration using an object.
226
+ * If the config does not support a property this is a no-op.
227
+ * @param {Object} props the object with all the different properties to change
228
+ * @example
229
+ * remotePlayer.configure({ preferredAudioLanguage: 'en-US' })
230
+ *
231
+ * */
232
+ configure(props) {
233
+ noop("RemotePlayer.configure", props);
234
+ }
235
+
236
+ /** In order to support a seamless switch between the video in the UI and ABR, the web application must
237
+ * register the video element being used for the currently played video before calling the load and play apis.
238
+ * @param {object} video The video element currently playing video in the web application
239
+ * @deprecated use attach function instead
240
+ * */
241
+ registerVideoElement(video) {
242
+ this.attach(video);
243
+ }
244
+
245
+ /** In order to support a seamless switch between the video in the UI and ABR, the web application must
246
+ * attach the video element being used for the currently played video before calling the load and play apis.
247
+ * @param {object} video The video element currently playing video in the web application
248
+ * */
249
+ attach(video) {
250
+ noop("RemotePlayer.attach", video);
251
+ }
252
+
253
+ /** Detach the video element from the remote player
254
+ */
255
+ detach() {
256
+ noop("RemotePlayer.detach");
257
+ }
258
+
259
+ /** Tell the remote player to load the given URL.
260
+ * @param {string} url url to load
261
+ * @param {number} [position] start position in seconds (if not provided, start from beginning (VOD) or current time (LTV))
262
+ * @returns {Promise}
263
+ * @throws {RemotePlayerError} error object contains code & msg
264
+ *
265
+ * */
266
+ async load(url, position) {
267
+ return noop("RemotePlayer.load", url, position);
268
+ }
269
+
270
+ /**
271
+ * Play loaded URL. Assuming load was called before.
272
+ * Need to call lifecycle.moveToBackground() in order to move the ui to the background and display the remote player playback in full screen
273
+ * @example
274
+ * remotePlayer.load("https://example.com/video.mp4", 0);
275
+ * remotePlayer.play();
276
+ * lifecycle.moveToBackground();
277
+ *
278
+ * @returns {Promise}
279
+ * @throws {RemotePlayerError} error object contains code & msg
280
+ */
281
+ async play() {
282
+ return noop("RemotePlayer.play");
283
+ }
284
+
285
+ /** Pauses the currently playing audio or video
286
+ * When pausing in background, it will pause all streams (audio, video, subtitles) to support pausing in background.
287
+ * When pausing in foreground, if audio in ui enabled, it will only pause audio stream.
288
+ * When pausing in foreground, if audio is not enabled, remote player is not playing and therefore no call is sent.
289
+ * @returns {Promise}
290
+ * @throws {RemotePlayerError} error object contains code & msg
291
+ *
292
+ * */
293
+ async pause() {
294
+ return noop("RemotePlayer.pause");
295
+ }
296
+
297
+ /** Stop playback
298
+ * @returns {Promise}
299
+ * @throws {RemotePlayerError} error object contains code & msg
300
+ * */
301
+ async stop() {
302
+ return noop("RemotePlayer.stop");
303
+ }
304
+
305
+ /** Get the currently loaded uri, or empty string is player is not loaded.
306
+ * @returns {string} loaded uri
307
+ * @throws {RemotePlayerError} error object contains code & msg
308
+ *
309
+ * */
310
+ getAssetUri() {
311
+ return "";
312
+ }
313
+
314
+ /** Get the current load mode (either NOT_LOADED or LOADING or LOADED).
315
+ * @returns {LoadMode} current load mode
316
+ * @throws {RemotePlayerError} error object contains code & msg
317
+ * @example
318
+ * import { remotePlayer } from "senza-sdk";
319
+ * const loadMode = remotePlayer.getLoadMode();
320
+ * if (loadMode === remotePlayer.LoadMode.LOADED) {
321
+ * console.log("remote player is currently loaded");
322
+ * }
323
+ *
324
+ * */
325
+ getLoadMode() {
326
+ return RemotePlayer.LoadMode.NOT_LOADED;
327
+ }
328
+
329
+ /**
330
+ * @typedef {Object} TextTrack
331
+ * @property {string} id - A unique ID for the track
332
+ * @property {string} lang - The track's language
333
+ * @property {boolean} selected - Whether the track is selected
334
+ * @property {boolean} autoTranslate - (Optional) Whether the track is an auto-translated language
335
+ */
336
+ /** Get all the text (subtitles) tracks.
337
+ * Text tracks are available only after playing content and returning to the UI.
338
+ * When text tracks are updated, the @event tracksupdate if fired.
339
+ * Auto Translation languages are returned only for VOD assets where there is at least one text track in the manifest to be used for translation.
340
+ * The list of tracks is sorted ascending to two parts by the lang key in the following order:
341
+ * 1. The actual text tracks which is available in the asset manifest and the selected track
342
+ * 2. Auto-Translation tracks
343
+ * @returns {TextTrack[]} an array of TextTracks if available, otherwise - empty array
344
+ *
345
+ * */
346
+ getTextTracks() {
347
+ return [];
348
+ }
349
+
350
+ /**
351
+ * @typedef {Object} AudioTrack
352
+ * @property {string} id - A unique ID for the track
353
+ * @property {string} lang - The track's language
354
+ * @property {boolean} selected - Whether the track is selected
355
+ */
356
+ /** Get all the audio tracks.
357
+ * Text tracks are available only after playing content and returning to the UI.
358
+ * When audio tracks are updated, the @event tracksupdate is fired.
359
+ * @returns {AudioTrack[]} an array of objects if available, otherwise - empty array
360
+ *
361
+ * */
362
+ getAudioTracks() {
363
+ return [];
364
+ }
365
+
366
+ /** Select a specific audio track.
367
+ * Track id should come from a call to getAudioTracks.
368
+ * If no tracks exist - this is a no-op.
369
+ * If the id does not match the id of any of the existing tracks - this is a no-op.
370
+ * @param {string} audioTrackId - The ID of the audio track to select.
371
+ * @returns {Promise<void>} A Promise that resolves once the selection process is complete.
372
+ * @throws {RemotePlayerError} If the player is not initialized or not loaded.
373
+ **/
374
+ async selectAudioTrack(audioTrackId) {
375
+ return noop("RemotePlayer.selectAudioTrack", audioTrackId);
376
+ }
377
+
378
+ /** Select a specific text (subtitle) track.
379
+ * Track id should come from a call to getTextTracks.
380
+ * If no tracks exist - this is a no-op.
381
+ * If the id does not match the id of any of the existing tracks - this is a no-op.
382
+ * @param {string} textTrackId - The ID of the text track to select.
383
+ * @returns {Promise<void>} A Promise that resolves once the selection process is complete.
384
+ * @throws {RemotePlayerError} If the player is not initialized or not loaded.
385
+ * */
386
+ async selectTextTrack(textTrackId) {
387
+ return noop("RemotePlayer.selectTextTrack", textTrackId);
388
+ }
389
+
390
+ /**
391
+ * Enable or disable the subtitles.
392
+ * If the player is in an unloaded state, the request will be applied next time content is played.
393
+ * @param {boolean} visible whether the subtitles are visible or not
394
+ * @throws {TypeError} if visible is not a boolean variable
395
+ */
396
+ setTextTrackVisibility(visible) {
397
+ return noop("RemotePlayer.setTextTrackVisibility", visible);
398
+ }
399
+
400
+ /**
401
+ * Getter/Setter for currentTime
402
+ */
403
+ get currentTime() {
404
+ return 0;
405
+ }
406
+
407
+ set currentTime(playbackPosition) {
408
+ noop("RemotePlayer.currentTime", playbackPosition);
409
+ }
410
+
411
+ /**
412
+ * For VOD asset, the duration of the asset
413
+ * @readonly
414
+ */
415
+ get duration() {
416
+ return 0;
417
+ }
418
+
419
+ /**
420
+ * Whether the subtitles are visible or not.
421
+ * @readonly
422
+ */
423
+ get textTrackVisibility() {
424
+ return false;
425
+ }
426
+
427
+ /** Get the presentation start time as a date. This should only be called when the player has loaded a live stream.
428
+ * If the player has not loaded a live stream, this will return null.
429
+ * @returns {Date} presentation start time
430
+ *
431
+ * */
432
+ getPresentationStartTimeAsDate() {
433
+ return null;
434
+ }
435
+
436
+ /** Tell the remote player to unload the loaded URL.
437
+ * @returns {Promise}
438
+ * @throws {RemotePlayerError} error object contains code & msg
439
+ * @alpha API has not yet been released
440
+ *
441
+ * */
442
+ async unload() {
443
+ return noop("RemotePlayer.unload");
444
+ }
445
+
446
+ /**
447
+ * @function writeLicenseResponse
448
+ * @param {number} statusCode - License server HTTP response code, e.g. 200, 401, etc. Must be 200 to indicate a successful license exchange.
449
+ * @param {string} response - License server response as opaque binary data in an ArrayBuffer.
450
+ * @private
451
+ */
452
+ }
453
+
454
+ /**
455
+ * @module
456
+ * @private
457
+ * @type {RemotePlayer}
458
+ * @example
459
+ * import { init, remotePlayer } from "senza-sdk";
460
+ * await init();
461
+ * try {
462
+ * await remotePlayer.load("http://playable.url/file.mp4");
463
+ * remotePlayer.play();
464
+ * } catch(err) {
465
+ * console.log("remotePlayer api failed with error code", err.code, err.msg);
466
+ * }
467
+ *
468
+ * @returns {RemotePlayer} pointer to the RemotePlayer singleton
469
+ */
470
+ "needed for the module doc comment to be recognized";
@@ -0,0 +1,168 @@
1
+ import * as shaka from "shaka-player";
2
+
3
+ // Define custom error category
4
+ shaka.util.Error.Category.SENZA_PLAYER_ERROR = 50;
5
+ shaka.util.Error.Code.SENZA_PLAYER_ERROR = 10500;
6
+
7
+ // Copy the shaka module and replace the Player class with SenzaShakaPlayer
8
+ // if we don't Copy the shaka module, the Player class will be replaced for all the other modules that import shaka
9
+ const senzaShaka = { ...shaka };
10
+
11
+
12
+ /**
13
+ * SenzaShakaPlayer subclass of Shaka that handles both local and remote playback.
14
+ *
15
+ * @class SenzaShakaPlayer
16
+ *
17
+ * @example
18
+ * import { SenzaShakaPlayer } from "./senzaShakaPlayer.js";
19
+ *
20
+ * try {
21
+ * const videoElement = document.getElementById("video");
22
+ * const player = new SenzaShakaPlayer(videoElement);
23
+ * await player.load("http://playable.url/file.mpd");
24
+ * await videoElement.play(); // will start the playback
25
+ *
26
+ * } catch (err) {
27
+ * console.error("SenzaShakaPlayer failed with error", err);
28
+ * }
29
+ */
30
+
31
+ export class SenzaShakaPlayer extends shaka.Player {
32
+ /**
33
+ * Creates an instance of SenzaShakaPlayer, which is a subclass of shaka.Player.
34
+ *
35
+ * @param {HTMLVideoElement} videoElement - The video element to be used for local playback. This parameter is optional. If not provided, the video element can be attached later using the attach method.
36
+ * @param {HTMLElement=} videoContainer - The videoContainer to construct UITextDisplayer
37
+ * @param {function(shaka.Player)=} dependencyInjector Optional callback
38
+ * which is called to inject mocks into the Player. Used for testing.
39
+ */
40
+ constructor(videoElement, videoContainer, dependencyInjector) {
41
+ super(videoElement, videoContainer, dependencyInjector);
42
+ }
43
+
44
+ /**
45
+ * Overrides the attach method of shaka.Player to attach the video element.
46
+ *
47
+ * @param {HTMLVideoElement} videoElement - The video element to be used for local playback.
48
+ * @param {boolean} [initializeMediaSource=true] - Whether to initialize the media source.
49
+ */
50
+ async attach(videoElement, initializeMediaSource = true) {
51
+ await super.attach(videoElement, initializeMediaSource);
52
+ }
53
+
54
+ /**
55
+ * Detach the player from the current media element. Leaves the player in a
56
+ * state where it cannot play media, until it has been attached to something
57
+ * else.
58
+ *
59
+ * @param {boolean=} keepAdManager
60
+ *
61
+ * @return {!Promise}
62
+ * @export
63
+ */
64
+ async detach(keepAdManager = false) {
65
+ return super.detach(keepAdManager);
66
+ }
67
+
68
+ /**
69
+ * Unloads the currently playing stream, if any.
70
+ *
71
+ * @param {boolean=} initializeMediaSource
72
+ * @param {boolean=} keepAdManager
73
+ * @return {!Promise}
74
+ * @export
75
+ */
76
+ async unload(initializeMediaSource = true, keepAdManager = false) {
77
+ return super.unload(initializeMediaSource, keepAdManager);
78
+ }
79
+
80
+ /**
81
+ * Overrides the getTextTracks method to use the remote player's text tracks.
82
+ * @returns {Array} An array of text tracks.
83
+ */
84
+ getTextLanguages() {
85
+ return super.getTextLanguages();
86
+ }
87
+
88
+ /**
89
+ * Overrides the getAudioTracks method to use the remote player's audio tracks.
90
+ * @returns {Array} An array of audio tracks.
91
+ */
92
+ getAudioLanguages() {
93
+ return super.getAudioLanguages();
94
+ }
95
+
96
+ /**
97
+ * Overrides the selectAudioLanguage method to use the remote player's audio track selection.
98
+ * @param {string} language - The language to select.
99
+ * @param {string=} role - The role of the track to select. (e.g. 'main', 'caption', or 'commentary')
100
+ */
101
+ selectAudioLanguage(language, role) {
102
+ super.selectAudioLanguage(language, role);
103
+ }
104
+
105
+ /**
106
+ * Overrides the selectTextLanguage method to use the remote player's text track selection.
107
+ * @param {string} language - The language to select.
108
+ * @param {string=} role - The role of the track to select.
109
+ */
110
+ selectTextLanguage(language, role) {
111
+ super.selectTextLanguage(language, role);
112
+ }
113
+
114
+ /**
115
+ * Overrides the setTextTrackVisibility method to use the remote player's text track visibility settings.
116
+ * @param {boolean} visible - Whether the text tracks should be visible.
117
+ */
118
+ setTextTrackVisibility(visible) {
119
+ super.setTextTrackVisibility(visible);
120
+ }
121
+
122
+ /**
123
+ * Helper function that makes it easier to check if lifecycle.state is
124
+ * either background or inTransitionToBackground.
125
+ */
126
+ get isInRemotePlayback() {
127
+ return false;
128
+ }
129
+
130
+ /**
131
+ * Loads a media URL into both local and remote players.
132
+ *
133
+ * @param {string} url - The URL of the media to load.
134
+ * @returns {Promise<void>}
135
+ */
136
+ async load(url, startTime, mimeType) {
137
+ return super.load(url, startTime, mimeType);
138
+ }
139
+
140
+ /***
141
+ * Destroys the player instance, cleaning up resources and event listeners.
142
+ * @returns {Promise<void>}
143
+ */
144
+ async destroy() {
145
+ return super.destroy();
146
+ }
147
+
148
+ /**
149
+ * Override the configure method to add custom configuration handling
150
+ * Supports the following additional configuration options:
151
+ * - shouldStopRemotePlayerOnError: boolean - If true, remote player will be stopped on error
152
+ *
153
+ * @override
154
+ * @param {Object} config - Configuration object to be merged with existing config
155
+ * @param {boolean} [config.shouldStopRemotePlayerOnError=true] - Whether to stop remote player on error
156
+ * @example
157
+ * player.configure({
158
+ * shouldStopRemotePlayerOnError: false, // Don't stop remote player on error
159
+ * // ... other shaka configurations
160
+ * });
161
+ */
162
+ configure(config) {
163
+ return super.configure(config);
164
+ }
165
+ }
166
+
167
+ senzaShaka.Player = SenzaShakaPlayer;
168
+ export { senzaShaka as shaka };
@@ -0,0 +1,45 @@
1
+ import pack from "../../package.json";
2
+ const { version } = pack;
3
+
4
+ /* eslint-disable no-console */
5
+ class SdkLogger {
6
+
7
+ constructor(logFields) {
8
+ this.logFields = logFields;
9
+ }
10
+ debug(...data) {
11
+ console.debug(this.formatLogString(data));
12
+ }
13
+ log(...data) {
14
+ console.log(this.formatLogString(data));
15
+ }
16
+ info(...data) {
17
+ console.info(this.formatLogString(data));
18
+ }
19
+ warn(...data) {
20
+ console.warn(this.formatLogString(data));
21
+ }
22
+ error(...data) {
23
+ console.error(this.formatLogString(data));
24
+ }
25
+ metrics(metricObj) {
26
+ console.info(`[hs-sdk] [metrics] ${JSON.stringify(metricObj)}`);
27
+ }
28
+ withFields(logFields) {
29
+ return new SdkLogger({ ...this.logFields, ...logFields });
30
+ }
31
+ formatLogString(data) {
32
+ let logString = "[hs-sdk] " + data.join(" ");
33
+ if (this.logFields) {
34
+ logString += " [log-fields] " + JSON.stringify(this.logFields);
35
+ }
36
+ return logString;
37
+ }
38
+ }
39
+
40
+ export const sdkLogger = new SdkLogger({ sdkVersion: version });
41
+
42
+ export function noop(functionname, ...args) {
43
+ console.log(`Called "${functionname}" with args:`, ...args || [], "This feature is only supported E2E.");
44
+ return Promise.resolve();
45
+ }