senza-sdk 4.2.9 → 4.2.10
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.
- package/dist/bundle.js +1 -1
- package/package.json +1 -1
- package/src/senzaShakaPlayer.js +69 -17
package/package.json
CHANGED
package/src/senzaShakaPlayer.js
CHANGED
|
@@ -23,46 +23,83 @@ export class SenzaShakaPlayer extends shaka.Player {
|
|
|
23
23
|
/**
|
|
24
24
|
* Creates an instance of SenzaShakaPlayer, which is a subclass of shaka.Player.
|
|
25
25
|
*
|
|
26
|
-
* @param {HTMLVideoElement} videoElement - The video element to be used for local playback.
|
|
26
|
+
* @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.
|
|
27
|
+
* @param {HTMLElement=} videoContainer - The videoContainer to construct UITextDisplayer
|
|
28
|
+
* @param {function(shaka.Player)=} dependencyInjector Optional callback
|
|
29
|
+
* which is called to inject mocks into the Player. Used for testing.
|
|
27
30
|
*/
|
|
28
31
|
constructor(videoElement, videoContainer, dependencyInjector) {
|
|
29
32
|
super(videoElement, videoContainer, dependencyInjector);
|
|
30
|
-
this.videoElement = videoElement;
|
|
31
33
|
this.remotePlayer = remotePlayer;
|
|
34
|
+
this.addEventListeners();
|
|
35
|
+
// if video element is provided, add the listeres here. In this case ,there is no need to call attach.
|
|
36
|
+
if (videoElement) {
|
|
37
|
+
this.videoElement = videoElement;
|
|
38
|
+
this.addVideoElementEventListeners();
|
|
39
|
+
sdkLogger.warn("SenzaShakaPlayer constructor Adding videoElement in the constructor is going to be deprecated in the future. Please use attach method instead.");
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Overrides the attach method of shaka.Player to attach the video element.
|
|
45
|
+
*
|
|
46
|
+
* @param {HTMLVideoElement} videoElement - The video element to be used for local playback.
|
|
47
|
+
* @param {boolean} [initializeMediaSource=true] - Whether to initialize the media source.
|
|
48
|
+
*/
|
|
49
|
+
async attach(videoElement, initializeMediaSource = true) {
|
|
50
|
+
await super.attach(videoElement, initializeMediaSource);
|
|
51
|
+
|
|
52
|
+
if (this.videoElement) {
|
|
53
|
+
sdkLogger.error("SenzaShakaPlayer attach Player is already attached to a video element.");
|
|
54
|
+
this.removeVideoElementEventListeners();
|
|
55
|
+
this.remotePlayer.attach(null);
|
|
56
|
+
}
|
|
32
57
|
|
|
58
|
+
this.videoElement = videoElement;
|
|
33
59
|
this.remotePlayer.attach(this.videoElement);
|
|
60
|
+
this.addVideoElementEventListeners();
|
|
34
61
|
|
|
35
|
-
|
|
62
|
+
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Detach the player from the current media element. Leaves the player in a
|
|
67
|
+
* state where it cannot play media, until it has been attached to something
|
|
68
|
+
* else.
|
|
69
|
+
*
|
|
70
|
+
* @param {boolean=} keepAdManager
|
|
71
|
+
*
|
|
72
|
+
* @return {!Promise}
|
|
73
|
+
* @export
|
|
74
|
+
*/
|
|
75
|
+
async detach(keepAdManager = false) {
|
|
76
|
+
await super.detach(keepAdManager);
|
|
77
|
+
// remote player does not suppot detach yet, this should be implemented.
|
|
78
|
+
this.remotePlayer.attach(null);
|
|
79
|
+
this.videoElement = null;
|
|
80
|
+
sdkLogger.warn("SenzaShakaPlayer detach detach is not fully supported yet");
|
|
36
81
|
}
|
|
37
82
|
|
|
38
83
|
addEventListeners() {
|
|
39
84
|
this.remotePlayer.addEventListener("ended", () => {
|
|
40
85
|
sdkLogger.log("remotePlayer ended");
|
|
41
86
|
lifecycle.moveToForeground();
|
|
42
|
-
this.videoElement
|
|
87
|
+
if (this.videoElement) {
|
|
88
|
+
this.videoElement.dispatchEvent(new Event("ended"));
|
|
89
|
+
}
|
|
43
90
|
});
|
|
44
91
|
|
|
45
92
|
this.remotePlayer.addEventListener("error", (event) => {
|
|
46
93
|
sdkLogger.log("remotePlayer error:", event.detail.errorCode, event.detail.message);
|
|
47
|
-
this.videoElement
|
|
94
|
+
if (this.videoElement) {
|
|
95
|
+
this.videoElement.dispatchEvent(new CustomEvent("error", event));
|
|
96
|
+
}
|
|
48
97
|
});
|
|
49
98
|
|
|
50
99
|
this.addEventListener("error", (event) => {
|
|
51
100
|
sdkLogger.log("localPlayer error:", event.detail.errorCode, event.detail.message);
|
|
52
101
|
});
|
|
53
102
|
|
|
54
|
-
this.videoElement.addEventListener("play", () => {
|
|
55
|
-
this.remotePlayer.play();
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
this.videoElement.addEventListener("pause", () => {
|
|
59
|
-
this.remotePlayer.pause();
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
this.videoElement.addEventListener("seeked", () => {
|
|
63
|
-
this.remotePlayer.currentTime = this.videoElement.currentTime;
|
|
64
|
-
});
|
|
65
|
-
|
|
66
103
|
|
|
67
104
|
this.remotePlayer.addEventListener("license-request", async (event) => {
|
|
68
105
|
sdkLogger.log("remotePlayer", "license-request", "Got license-request event from remote player");
|
|
@@ -93,6 +130,21 @@ export class SenzaShakaPlayer extends shaka.Player {
|
|
|
93
130
|
});
|
|
94
131
|
}
|
|
95
132
|
|
|
133
|
+
addVideoElementEventListeners() {
|
|
134
|
+
this.videoElement.addEventListener("play", () => {
|
|
135
|
+
this.remotePlayer.play();
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
this.videoElement.addEventListener("pause", () => {
|
|
139
|
+
this.remotePlayer.pause();
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
this.videoElement.addEventListener("seeked", () => {
|
|
143
|
+
this.remotePlayer.currentTime = this.videoElement.currentTime;
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
|
|
96
148
|
/**
|
|
97
149
|
* Helper function that makes it easier to check if lifecycle.state is
|
|
98
150
|
* either background or inTransitionToBackground.
|