@brandbrigade/ott-bb-player 1.0.43 → 1.0.45

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.
@@ -0,0 +1,254 @@
1
+ import Augmentor from "./Augmentor";
2
+ import { RenderingMode } from "./enums/RenderingMode";
3
+ import { SyncMethod } from "./enums/SyncMethod";
4
+ import merge from "lodash/merge";
5
+ import { datadogLogs } from '@datadog/browser-logs';
6
+ import { version } from '/package.json';
7
+
8
+ datadogLogs.init({
9
+ clientToken: 'pub4844895ac30067ac2c4aaa025dbc39d7',
10
+ site: 'us3.datadoghq.com',
11
+ forwardErrorsToLogs: true,
12
+ sessionSampleRate: 100
13
+ });
14
+
15
+ export default class OTTPlayer {
16
+ constructor(video, srcFrameRate, optionsFromMK) {
17
+ console.log(`OTTPlayer: version: ${version}`);
18
+ this.video = video;
19
+ this.srcFrameRate = srcFrameRate;
20
+ console.log("optionsFromMK: ", optionsFromMK);
21
+ this.options = merge(
22
+ {
23
+ enabled: true,
24
+ stopAugment: false, //setted to true when there is exception or smt went wrong
25
+ stopAugmentFor: -1, // disable augmentation for several secs (should be used for temporaty issues that occures while working)
26
+ gameId: "Unknown",
27
+ medialook: false,
28
+ allGamesURL: "https://www.virtualott.com/games/",
29
+ cloudFrontURL: "https://db8igqxlbvayn.cloudfront.net/prod",
30
+ mediaIdJsonURL: "https://games-prod.virtualott.com/map",
31
+ offsetJsonURL: "https://games-prod.virtualott.com/offset",
32
+ renderingMode: RenderingMode.Augment, //MUST, other will not work in this test
33
+ SynchMethod: SyncMethod.None,
34
+ debug: false,
35
+ hls_fps: 60000 / 1001,
36
+ augmentation: {
37
+ renderTimecode: true,
38
+ offset: 0,
39
+ },
40
+ syncPoint: {
41
+ frame: 0,
42
+ playerTime: 0,
43
+ mediaTimeMS: 0,
44
+ },
45
+ },
46
+ optionsFromMK || {},
47
+ );
48
+
49
+ console.log("options after merge with MK's options: ", JSON.parse(JSON.stringify(this.options)));
50
+
51
+ console.BBlog = function (message) {
52
+ console.log("OTTPlayer: " + message);
53
+ datadogLogs.logger.info('Web Unsorted msg: ' + message, {name: 'test'});
54
+ };
55
+ console.BBerror = function (...args) {
56
+ console.log("OTTPlayer: ", ...args);
57
+ datadogLogs.logger.error('Web Unsorted error: ' + args.join(', '), {name: 'test'});
58
+ };
59
+
60
+ this.getGlobalConfig();
61
+ }
62
+
63
+ //after we merged the options with the url-param global config
64
+ init() {
65
+ //override with global options:
66
+ if (typeof window.globalConfig === "undefined")
67
+ this.options = Object.assign(this.options, {});
68
+ else this.options = Object.assign(this.options, JSON.parse(JSON.stringify(window.globalConfig)))
69
+ //normalize hls_fps
70
+ var tmp_mes = {};
71
+ tmp_mes.value1 = this.options.hls_fps;
72
+ this.setFps(tmp_mes);
73
+ console.log("options after merge with the global options: ", JSON.parse(JSON.stringify(this.options)));
74
+ //if the debug option is off - make the debug-div disappear
75
+ if (!this.options.debug) {
76
+ let elementsToHide = [
77
+ "debugText",
78
+ "forplus",
79
+ "forDoNotRender",
80
+ "debugText2",
81
+ "toggleBtn",
82
+ "numberInput",
83
+ "plus05CorrectionCheckbox",
84
+ "doNotRenderAugmentationCheckbox",
85
+ "plus05CorrectionLabel",
86
+ "doNotRenderAugmentationLabel",
87
+ "br1",
88
+ "br2",
89
+ "qualityButton",
90
+ "qualitySelect",
91
+ ];
92
+ for (let i = 0; i < elementsToHide.length; i++) {
93
+ const elemToHide = document.getElementById(elementsToHide[i]);
94
+ if (elemToHide) {
95
+ elemToHide.style.display = "none";
96
+ }
97
+ }
98
+ }
99
+
100
+ this.fetchAndFindGameIdAndOffsetFromMediaId(this.options.gameId);
101
+ }
102
+
103
+ weHaveTheGameID() {
104
+ this.frameDrawer = new Augmentor(this.video, this.options);
105
+ if (this.options.renderingMode == RenderingMode.Augment) {
106
+ this.frameDrawer.initializeComponents();
107
+ }
108
+ }
109
+
110
+ async getGlobalConfig() {
111
+ //make sure we have global config
112
+ const URLParams = new URL(document.location);
113
+ const CONFIG_NAME = URLParams.searchParams.get("config") || "";
114
+ if (CONFIG_NAME !== "") {
115
+ try {
116
+ const response = await fetch(CONFIG_NAME);
117
+ if (!response.ok) {
118
+ throw new Error("Network response was not ok");
119
+ }
120
+ const configJson = await response.json();
121
+ if (typeof window.globalConfig == "undefined") window.globalConfig = {};
122
+ globalConfig = Object.assign({}, configJson, window.globalConfig);
123
+ console.log('final global config:', window.globalConfig)
124
+ } catch (error) {
125
+ console.BBerror("Error fetching JSON:", error);
126
+ }
127
+ }
128
+ this.init();
129
+ }
130
+
131
+ mediaID = null;
132
+
133
+ // Function to fetch the JSON and find the value for mediaID
134
+ async fetchAndFindGameIdAndOffsetFromMediaId(mediaID) {
135
+ mediaID = 'bbtest45'
136
+ if (this.options.mediaIdJsonURL == "test") {
137
+ this.weHaveTheGameID();
138
+ return;
139
+ }
140
+
141
+ try {
142
+ const response = await fetch(this.options.mediaIdJsonURL + "/" + mediaID);
143
+ if (!response.ok) {
144
+ throw new Error(`HTTP error! Status: ${response.status}`);
145
+ }
146
+
147
+ const jsonData = await response.json();
148
+
149
+ if (jsonData.hasOwnProperty("GAME_ID")) {
150
+ console.log({jsonData})
151
+ const value = jsonData["GAME_ID"];
152
+ console.log(`GameId for mediaid= ${mediaID}: ${value}`);
153
+ this.options.gameId = value;
154
+ this.weHaveTheGameID();
155
+ this.fetchOffsetForGameIdMediaID(this.options.gameId, mediaID);
156
+ } else {
157
+ console.BBerror(`MediaID ${mediaID} not found in JSON.`);
158
+ this.options.stopAugment = true;
159
+ }
160
+ } catch (error) {
161
+ console.BBerror("Error fetching and processing GameId JSON:" + error);
162
+ }
163
+ }
164
+
165
+ // Function to fetch the JSON and find the value for mediaID
166
+ async fetchOffsetForGameIdMediaID(gameId, mediaId) {
167
+ if (this.options.offsetJsonURL == "test") return 0;
168
+ try {
169
+ const response = await fetch(
170
+ this.options.offsetJsonURL + "/" + gameId,
171
+ );
172
+
173
+ if (!response.ok) {
174
+ console.log(`HTTP error! Status: ${response.status}`);
175
+ setTimeout(() => {
176
+ this.fetchOffsetForGameIdMediaID(gameId, mediaId);
177
+ }, 5000);
178
+ }
179
+
180
+ const jsonData = await response.json();
181
+
182
+ if (
183
+ jsonData.hasOwnProperty("offset") &&
184
+ jsonData.hasOwnProperty("found")
185
+ ) {
186
+ const value = jsonData["offset"];
187
+ const found = jsonData["found"];
188
+
189
+ if (found == true) {
190
+ console.log(`Offset for gameid= ${gameId}: ${value}`);
191
+ this.options.augmentation.offset = value;
192
+ //call get-offset again later on
193
+ setTimeout(() => {
194
+ this.fetchOffsetForGameIdMediaID(gameId, mediaId);
195
+ }, 60000);
196
+ }
197
+ } else {
198
+ console.log(`offset for ${gameId} not found in JSON.`);
199
+ setTimeout(() => {
200
+ this.fetchOffsetForGameIdMediaID(gameId, mediaId);
201
+ }, 5000);
202
+ }
203
+ } catch (error) {
204
+ console.BBerror("Error fetching and processing offset:", error);
205
+ setTimeout(() => {
206
+ this.fetchOffsetForGameIdMediaID(gameId, mediaId);
207
+ }, 5000);
208
+ }
209
+ }
210
+
211
+ toggle(flag) {
212
+ this.options.enabled = flag;
213
+ }
214
+
215
+ getCanvas() {
216
+ return this.frameDrawer.getCanvas();
217
+ }
218
+
219
+ setFps(message) {
220
+ var fps = message.value1;
221
+ switch (fps) {
222
+ case 59.94:
223
+ case 60000 / 1001:
224
+ this.options.hls_fps = 60000 / 1001;
225
+ break;
226
+ case 29.97:
227
+ case 30000 / 1001:
228
+ this.options.hls_fps = 30000 / 1001;
229
+ break;
230
+ default:
231
+ console.error("Unsupported hls-src frame-rate: " + fps + "fps");
232
+ this.options.hls_fps = fps;
233
+ break;
234
+ }
235
+ }
236
+
237
+ setSyncPoint(syncPoint) {
238
+ this.options.syncPoint = syncPoint;
239
+ }
240
+
241
+ onNewSegment(eventObj) {
242
+ this.frameDrawer.onNewSegmentForMetadata(eventObj);
243
+ }
244
+
245
+ onNewMetadata(eventObj) {
246
+ this.frameDrawer.onNewMetadata(eventObj);
247
+ }
248
+ }
249
+
250
+ window.BB = {
251
+ MAX_LOGOS: 4,
252
+ RENDER_IN_WORKER: true,
253
+ OTTPlayer,
254
+ };
package/src/Socket.js ADDED
@@ -0,0 +1,44 @@
1
+ import io from "socket.io-client";
2
+ import { Platform } from "./utils";
3
+
4
+
5
+ export default class Socket {
6
+ constructor(callback) {
7
+ this.isConnected = false;
8
+ this.folderName = "";
9
+ this.callback = callback;
10
+ this.name = "";
11
+ }
12
+
13
+ connect(channel) {
14
+ if (this.isConnected) return;
15
+ this.isConnected = true;
16
+
17
+ const socket = io("https://www.virtualott.com", { reconnect: true });
18
+ socket.on("connect", () => {
19
+ console.log("socket connected");
20
+
21
+ socket.emit("setinfo", { device: Platform.getDeviceName() }, (info) => {
22
+ this.name = info.name;
23
+ socket.emit("join", channel, (data) => {
24
+ console.log(`join ${channel} room`);
25
+ this.callback("join", data);
26
+ });
27
+ });
28
+ });
29
+ socket.on("error", (err) => {
30
+ console.error(`error::${err}`);
31
+ });
32
+ socket.on("disconnect", (reason) => {
33
+ console.error(`disconnect from signaling::${reason}`);
34
+ });
35
+ socket.on("messageroom", (message) => {
36
+ this.callback("messageroom", message);
37
+ console.log("messageroom: ", message);
38
+ });
39
+ socket.on("ads", (message) => {
40
+ this.callback("ads", message);
41
+ console.log("ads:", message);
42
+ });
43
+ }
44
+ }
@@ -0,0 +1,30 @@
1
+ import Composer3DForWorker from "./Composer3DForWorker.js";
2
+
3
+ let composer = null;
4
+ onmessage = (evt) => {
5
+ switch (evt.data.method) {
6
+ case "onUserClickOnCanvas":
7
+ if (composer) composer.onUserClickOnCanvas(evt.data.data);
8
+ break;
9
+ case "cleanGL":
10
+ if (composer) composer.cleanGL();
11
+ break;
12
+ case "addAdvertisement":
13
+ if (composer) composer.addAdvertisement(evt.data.data);
14
+ break;
15
+ case "selectAd":
16
+ if (composer) composer.selectAd(evt.data.data);
17
+ break;
18
+ case "onMetaData":
19
+ if (composer) composer.onMetaData(evt.data.data);
20
+ break;
21
+ case "renderAugmentation":
22
+ if (composer) composer.renderAugmentation(evt.data.data);
23
+ break;
24
+ case "constructor":
25
+ composer = new Composer3DForWorker(evt.data.options, evt.data.canvas);
26
+ break;
27
+ default:
28
+ console.error("Wrong Thread Message");
29
+ }
30
+ };
@@ -0,0 +1,8 @@
1
+ {
2
+ "url": "https://nbablpng.akamaized.net/live/hls-itc/bbtestexternal/v1-121.m3u8?stSecret=rj12sw543terw32422334swees",
3
+ "cloudFrontURL": "https://db8igqxlbvayn.cloudfront.net",
4
+ "mediaIdJsonURL": "https://games-dev.virtualott.com/map",
5
+ "offsetJsonURL": "https://games-dev.virtualott.com/offset",
6
+ "debug": true,
7
+ "augmentation": { "channelName": "nba2" }
8
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "url": "https://nbablpng.akamaized.net/live/hls-itc/bbtestexternal/v7-121.m3u8?stSecret=rj12sw543terw32422334swees",
3
+ "cloudFrontURL": "https://db8igqxlbvayn.cloudfront.net",
4
+ "mediaIdJsonURL": "https://games-dev.virtualott.com/map",
5
+ "offsetJsonURL": "https://games-dev.virtualott.com/offset",
6
+ "debug": true,
7
+ "augmentation": { "channelName": "nba2" }
8
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "url": "https://nbablpng.akamaized.net/live/hls-itc/bbtestexternal/v2-121.m3u8?stSecret=rj12sw543terw32422334swees",
3
+ "cloudFrontURL": "https://db8igqxlbvayn.cloudfront.net",
4
+ "mediaIdJsonURL": "https://games-dev.virtualott.com/map",
5
+ "offsetJsonURL": "https://games-dev.virtualott.com/offset",
6
+ "debug": true,
7
+ "hls_fps": 29.97
8
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "url": "https://nbablpng.akamaized.net/live/hls-itc/bbtestexternal/index.m3u8?ISO3166=US&sessionId=2249876534844428711287488243568748000000457785884432&stSecret=rj12sw543terw32422334swees",
3
+ "cloudFrontURL": "https://db8igqxlbvayn.cloudfront.net",
4
+ "mediaIdJsonURL": "https://games-dev.virtualott.com/map",
5
+ "offsetJsonURL": "https://games-dev.virtualott.com/offset",
6
+ "debug": true
7
+ }
@@ -0,0 +1,5 @@
1
+ export const RenderingMode = {
2
+ RenderDigits: Symbol("RenderDigits"),
3
+ RenderTimecode: Symbol("RenderTimecode"),
4
+ Augment: Symbol("Augment"),
5
+ };
@@ -0,0 +1,5 @@
1
+ export const SyncMethod = {
2
+ OnNewSegment: Symbol("OnNewSegment"),
3
+ OnMetadata: Symbol("OnMetadata"),
4
+ None: Symbol("None"),
5
+ };
package/src/index.js ADDED
@@ -0,0 +1,241 @@
1
+ import OTTPlayer from "./OTTPlayer";
2
+
3
+ window.globalConfig
4
+ // = {
5
+ // debug: true,
6
+ // augmentation: {
7
+ // channelName: "nba2",
8
+ // renderTimecode: true
9
+ // },
10
+ // // gameId: "12-11-2024-Test9-National",
11
+ // gameId: "06-11-2024-Test9-Home",
12
+ // maskMP4: true
13
+ // }
14
+
15
+ function doAllStuff() {
16
+ const video = document.getElementById("video_element");
17
+ const wmcEvents = amc.AmcEvents;
18
+ const wmcConstants = amc.AmcConstants;
19
+
20
+ // MK STUF
21
+ let config = {
22
+ server_url: "https://ottapp-appgw-amp-a.prodb.nba.tv3cloud.com",
23
+ owner_Uid: "azuki",
24
+ playback_mode: wmcConstants.IMC_MODE_LIVE,
25
+ start: "LIVE",
26
+ media_id: "bbtestexternal", //"bbtest45"
27
+ app_id: "100419", //"99569"
28
+ authorization_token:
29
+ "AuthToken1jVDLbtswEPwa6yaBb5EHHQQ3TtLCbYrWRXvkY2ULlkSFpJI4X186jxYo2iIAsRzMzswC0y6uh8lCc0hpjivarsgmvwDDqZ_2sw7pVM3BO1NNRlfpjtrBL66yfsyq4jrGBcIf3pjifyxn7W-pPcCoY_UwDtHrufJhn9n7mAdBiOfvafQOptSnU4Z20P143k96hGaJJbEYgOGuVIzqkhmjSmkoKxmzrmOIEFC4-AqTntK1axx0ehlS0Q6Dvwf3ysdfi12EkHVvDW6t9ctTsjWaZ64rNWaQRdKWCrquRMZ1WBqCwLni3fOVlyNvsvy1r7G3wUffpZdWXxuT58bEPxoLfoAmLiba0BsIRbukgw_9o069n7Y6HhvMFWaUUS44xhTXhDOpakIoVgwJJYkQUlKCGVdCEs4xx0QoLpGSgiOCCVWEMoRpxrwmjEiORQayuHiY-wDx09Tk1JoKlO3FOoBO4J5JUXOBMvkBTpdL7xphGEiU6wfG6pIBpaVxFkoNOVIbgykxxdW2XX-5agkXzeXxbv7B9uPuuL-5uWjXcs-3O_RtRbr3k9l8vv3IH4neHG6-m1vkV9T9BA",
30
+ };
31
+ //let bbPlayer = null;
32
+
33
+ function processEventPlay(eventObj) {
34
+ switch (eventObj.eventType) {
35
+ case wmcEvents.AMC_EVENT_STATE_CHANGED:
36
+ // start the VOD/LIVE playback
37
+ //wmcMgr.createPlayer(config.playback_mode, config.media_id, config.app_id);
38
+ //if (eventObj.value1==2)
39
+ // playing=true;
40
+ console.log("!!!!!!!!!!!!!!!!!!!!!!!! AMC_EVENT_STATE_CHANGED");
41
+ break;
42
+ default:
43
+ }
44
+ }
45
+
46
+ function processEvent(eventObj) {
47
+ switch (eventObj.eventType) {
48
+ case wmcEvents.AMC_EVENT_METRICS_UPDATE:
49
+ console.log("AMC_EVENT_METRICS_UPDATE");
50
+ break;
51
+ case wmcEvents.AMC_EVENT_PLAYER_SEGMENT_PLAYBACK:
52
+ let syncPoint = { frame: 0, playerTime: 0 };
53
+ //bbPlayer.SetSyncPoint(syncPoint);
54
+
55
+ // if (typeof eventObj.mediaInfo.frameRate != "undefined"){
56
+ // console.log("FPS=", eventObj.mediaInfo.frameRate );
57
+ // if(bbPlayer)
58
+ // {
59
+ // bbPlayer.SetFps(eventObj.mediaInfo.frameRate);
60
+ // }
61
+ // }
62
+ break;
63
+
64
+ case wmcEvents.AMC_EVENT_PLAY_READY:
65
+ var logTextBox = document.getElementById("editable-element");
66
+
67
+ wmcMgr.setContainer(video);
68
+ wmcMgr.start();
69
+ break;
70
+ case wmcEvents.AMC_EVENT_PLAYER_METADATA:
71
+ break;
72
+ case wmcEvents.AMC_EVENT_PLAYER_METADATA_PARSED:
73
+ //console.info("AMC_EVENT_PLAYER_METADATA_PARSED",eventObj);
74
+ break;
75
+ case wmcEvents.AMC_EVENT_DEVICE_REGISTERED:
76
+ break;
77
+ case wmcEvents.AMC_EVENT_INIT_COMPLETE:
78
+ // start the VOD/LIVE playback
79
+ wmcMgr.createPlayer(
80
+ config.playback_mode,
81
+ config.media_id,
82
+ config.app_id,
83
+ );
84
+
85
+ break;
86
+
87
+ case wmcEvents.AMC_EVENT_ERROR:
88
+ console.error(
89
+ eventObj.code +
90
+ ":" +
91
+ (eventObj.message ? eventObj.message : eventObj.message.error),
92
+ );
93
+ break;
94
+ default:
95
+ }
96
+ }
97
+
98
+ const wmcMgr = new amc.AmcManager(config.server_url, config.owner_Uid);
99
+ //<!-- enable brandBrigade -->
100
+ // when this flag is enabled sdk will initialise the brandBrigade player with the required information and will make the necessary calls on the appropriate player callbacks
101
+ wmcMgr.enableBrandBrigade(true);
102
+
103
+ wmcMgr.setSTSToken(config.authorization_token);
104
+ wmcMgr.setCDNToken({ start: "LIVE" });
105
+ wmcMgr.setKssUrl(
106
+ "https://ottapp-appgw-client.prodb.nba.tv3cloud.com/S1/kss/signkey",
107
+ );
108
+ wmcMgr.setLogLevel(wmcConstants.IMC_LOG_DEBUG);
109
+
110
+ function onPlaybackControlBlock(eventObj) {
111
+ playBackControlRestrictions =
112
+ eventObj && eventObj.hasOwnProperty("controlRestrictions")
113
+ ? eventObj.controlRestrictions
114
+ : [];
115
+ if (!playBackControlRestrictions.length) {
116
+ return;
117
+ }
118
+ //blockControls();
119
+ }
120
+
121
+ wmcMgr.setNativeHlsParsing(true);
122
+ wmcMgr.addEventListener(
123
+ wmcEvents.AMC_EVENT_PROGRAM_RESTRICTIONS,
124
+ onPlaybackControlBlock,
125
+ );
126
+
127
+ wmcMgr.addEventListener(wmcEvents.AMC_EVENT_PROGRAM_CHANGED, processEvent);
128
+ wmcMgr.addEventListener(wmcEvents.AMC_EVENT_BIT_RATE_CHANGED, processEvent);
129
+ wmcMgr.addEventListener(wmcEvents.AMC_EVENT_AD_STARTED, processEvent);
130
+ wmcMgr.addEventListener(wmcEvents.AMC_EVENT_AD_QUARTILE, processEvent);
131
+ wmcMgr.addEventListener(wmcEvents.AMC_EVENT_AD_FINISHED, processEvent);
132
+ wmcMgr.addEventListener(wmcEvents.AMC_EVENT_AD_BREAK_START, processEvent);
133
+ wmcMgr.addEventListener(wmcEvents.AMC_EVENT_AD_BREAK_END, processEvent);
134
+ wmcMgr.addEventListener(
135
+ wmcEvents.AMC_EVENT_TEXT_TRACKS_CHANGED,
136
+ processEvent,
137
+ );
138
+ wmcMgr.addEventListener(wmcEvents.AMC_EVENT_TEXT_TRACKS_ADDED, processEvent);
139
+ wmcMgr.addEventListener(
140
+ wmcEvents.AMC_EVENT_AUDIO_TRACKS_CHANGED,
141
+ processEvent,
142
+ );
143
+ wmcMgr.addEventListener(wmcEvents.AMC_EVENT_PERIOD_SWITCH, processEvent);
144
+ wmcMgr.addEventListener(wmcEvents.AMC_EVENT_PERIOD_SWITCHED, processEvent);
145
+ wmcMgr.addEventListener(wmcEvents.AMC_EVENT_AD_MARKER_DATA, processEvent);
146
+ wmcMgr.addEventListener(
147
+ wmcEvents.AMC_EVENT_PLAYOUT_METRIC_UPDATE,
148
+ processEvent,
149
+ );
150
+ wmcMgr.addEventListener(wmcEvents.BEACON_FAIL_OPEN_STATUS, processEvent);
151
+ wmcMgr.addEventListener(
152
+ wmcEvents.AMC_EVENT_PROGRAM_QUERY_STATUS,
153
+ processEvent,
154
+ );
155
+ wmcMgr.addEventListener(
156
+ wmcEvents.AMC_EVENT_VIDEO_QUALITY_CHANGED,
157
+ processEvent,
158
+ );
159
+ wmcMgr.addEventListener(wmcEvents.AMC_EVENT_PROFILING, processEvent);
160
+ wmcMgr.addEventListener(
161
+ wmcEvents.AMC_EVENT_PLAYER_SEGMENT_PLAYBACK,
162
+ processEvent,
163
+ );
164
+ wmcMgr.addEventListener(wmcEvents.AMC_EVENT_ERROR, processEvent);
165
+ wmcMgr.addEventListener(wmcEvents.AMC_EVENT_STATE_CHANGED, processEventPlay);
166
+ wmcMgr.addEventListener(
167
+ wmcEvents.AMC_EVENT_VIDEO_POSITION_CHANGED,
168
+ processEvent,
169
+ );
170
+ wmcMgr.addEventListener(wmcEvents.AMC_EVENT_SEEK_COMPLETE, processEvent);
171
+ wmcMgr.addEventListener(wmcEvents.AMC_EVENT_DEVICE_REGISTERED, processEvent);
172
+ wmcMgr.addEventListener(wmcEvents.AMC_EVENT_INIT_COMPLETE, processEvent);
173
+ wmcMgr.addEventListener(wmcEvents.AMC_EVENT_PLAY_READY, processEvent);
174
+ wmcMgr.addEventListener(wmcEvents.AMC_EVENT_PRELOAD_COMPLETE, processEvent);
175
+ wmcMgr.addEventListener(wmcEvents.AMC_EVENT_PLAYER_METADATA, processEvent);
176
+ wmcMgr.addEventListener(
177
+ wmcEvents.AMC_EVENT_PLAYER_METADATA_PARSED,
178
+ processEvent,
179
+ );
180
+ wmcMgr.addEventListener(wmcEvents.AMC_EVENT_METRICS_UPDATE, processEvent);
181
+ wmcMgr.setPlayerKey("60a31c68-c920-42be-a74a-506d51df7233");
182
+ //wmcMgr.setExternalSourceParams({ sourceUrl: "https://nbablpng.akamaized.net/live/hls-itc/bbtest45/v1-121.m3u8?stSecret=rj12sw543terw32422334swees", licenseUrl: "" });
183
+ wmcMgr.setExternalSourceParams({
184
+ sourceUrl: globalConfig.url,
185
+ licenseUrl: "",
186
+ });
187
+ wmcMgr.init();
188
+ const toggleBtn = document.getElementById("toggleBtn");
189
+ function toggleBBPlayer() {
190
+ // if(bbPlayer)
191
+ // {
192
+ // bbPlayer.Toggle(!bbPlayer.options.enabled);
193
+ // toggleBtn.innerText = "Toggle ott player " + (bbPlayer.options.enabled ? "OFF" : "ON");
194
+ // }
195
+ }
196
+ // Add event listener to the quality button
197
+ document.getElementById("qualityButton").addEventListener("click", () => {
198
+ const qualities = wmcMgr.getAvailableVideoQualities();
199
+ const qualitySelect = document.getElementById("qualitySelect");
200
+ qualitySelect.innerHTML = '<option value="">Select Quality</option>'; // Clear previous options
201
+ qualities.forEach((quality) => {
202
+ const option = document.createElement("option");
203
+ option.value = quality.id;
204
+ option.text = quality.label;
205
+ qualitySelect.appendChild(option);
206
+ });
207
+ });
208
+
209
+ // Add event listener to the quality select dropdown
210
+ document
211
+ .getElementById("qualitySelect")
212
+ .addEventListener("change", function () {
213
+ const selectedQuality = this.value;
214
+ if (selectedQuality) {
215
+ wmcMgr.setVideoQuality(selectedQuality);
216
+ }
217
+ });
218
+ }
219
+
220
+ const URLParams = new URL(document.location);
221
+ const CONFIG_NAME = URLParams.searchParams.get("config") || "";
222
+
223
+ //@TODO: config merge happens incorrectly if debug config is in `globalConfig` but correctly for fetched one
224
+ async function fetchConfig() {
225
+ if (CONFIG_NAME) {
226
+ try {
227
+ const response = await fetch(CONFIG_NAME);
228
+ const configJson = await response.json();
229
+ console.log("Got the following config: ", configJson);
230
+ if (!window.globalConfig) window.globalConfig = {};
231
+ window.globalConfig = Object.assign({}, window.globalConfig, configJson);
232
+ doAllStuff();
233
+ } catch (error) {
234
+ console.error("Error fetching JSON:", error);
235
+ }
236
+ } else {
237
+ if (!window.globalConfig) window.globalConfig = {};
238
+ doAllStuff();
239
+ }
240
+ }
241
+ fetchConfig();