stormcloud-video-player 0.6.2 → 0.6.3
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/stormcloud-vp.min.js +1 -1
- package/lib/index.cjs +205 -138
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +205 -138
- package/lib/index.js.map +1 -1
- package/lib/player/StormcloudVideoPlayer.cjs +205 -138
- package/lib/player/StormcloudVideoPlayer.cjs.map +1 -1
- package/lib/players/HlsPlayer.cjs +205 -138
- package/lib/players/HlsPlayer.cjs.map +1 -1
- package/lib/players/index.cjs +205 -138
- package/lib/players/index.cjs.map +1 -1
- package/lib/sdk/vastAdLayer.cjs +204 -136
- package/lib/sdk/vastAdLayer.cjs.map +1 -1
- package/lib/ui/StormcloudVideoPlayer.cjs +205 -138
- package/lib/ui/StormcloudVideoPlayer.cjs.map +1 -1
- package/package.json +1 -1
package/lib/sdk/vastAdLayer.cjs
CHANGED
|
@@ -934,7 +934,7 @@ function createVastAdLayer(contentVideo, options) {
|
|
|
934
934
|
}
|
|
935
935
|
function playAd(bids) {
|
|
936
936
|
return _async_to_generator(function() {
|
|
937
|
-
var winner, ad, contentVolume, _contentVideo_parentElement, container, adVolume, mediaFile;
|
|
937
|
+
var winner, ad, contentVolume, adVolume2, mediaFile2, _contentVideo_parentElement, container, adVolume, mediaFile;
|
|
938
938
|
return _ts_generator(this, function(_state) {
|
|
939
939
|
switch(_state.label){
|
|
940
940
|
case 0:
|
|
@@ -978,37 +978,71 @@ function createVastAdLayer(contentVideo, options) {
|
|
|
978
978
|
trackingFired.impression = true;
|
|
979
979
|
contentVolume = contentVideo.volume;
|
|
980
980
|
originalVolume = Math.max(0, Math.min(1, contentVolume || originalVolume));
|
|
981
|
-
if (singleElementMode)
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
981
|
+
if (!singleElementMode) return [
|
|
982
|
+
3,
|
|
983
|
+
3
|
|
984
|
+
];
|
|
985
|
+
mainHlsInstance === null || mainHlsInstance === void 0 ? void 0 : mainHlsInstance.detachMedia();
|
|
986
|
+
teardownCurrentPlayback();
|
|
987
|
+
adVideoElement = contentVideo;
|
|
988
|
+
adHls = void 0;
|
|
989
|
+
adPlaying = true;
|
|
990
|
+
setAdPlayingFlag(true);
|
|
991
|
+
contentVideo.removeAttribute("src");
|
|
992
|
+
contentVideo.load();
|
|
993
|
+
if (!continueLiveStreamDuringAds) {
|
|
994
|
+
contentVideo.pause();
|
|
995
|
+
}
|
|
996
|
+
contentVideo.muted = true;
|
|
997
|
+
contentVideo.volume = 0;
|
|
998
|
+
return [
|
|
999
|
+
4,
|
|
1000
|
+
new Promise(function(resolve) {
|
|
1001
|
+
return setTimeout(resolve, 200);
|
|
1002
|
+
})
|
|
1003
|
+
];
|
|
1004
|
+
case 2:
|
|
1005
|
+
_state.sent();
|
|
1006
|
+
if (destroyed || tornDown) return [
|
|
1007
|
+
2
|
|
1008
|
+
];
|
|
1009
|
+
contentVideo.style.visibility = "visible";
|
|
1010
|
+
contentVideo.style.opacity = "1";
|
|
1011
|
+
emit("content_pause");
|
|
1012
|
+
setupAdEventListeners();
|
|
1013
|
+
adVolume2 = originalMutedState ? 1 : originalVolume;
|
|
1014
|
+
adVideoElement.volume = Math.max(0, Math.min(1, adVolume2));
|
|
1015
|
+
adVideoElement.muted = false;
|
|
1016
|
+
mediaFile2 = selectBestMediaFile(ad.mediaFiles);
|
|
1017
|
+
if (debug) console.log("".concat(LOG, " Loading ad from: ").concat(mediaFile2.url));
|
|
1018
|
+
startPlayback(mediaFile2);
|
|
1019
|
+
return [
|
|
1020
|
+
2
|
|
1021
|
+
];
|
|
1022
|
+
case 3:
|
|
1023
|
+
if (!adContainerEl) {
|
|
1024
|
+
;
|
|
1025
|
+
container = document.createElement("div");
|
|
1026
|
+
container.style.position = "absolute";
|
|
1027
|
+
container.style.left = "0";
|
|
1028
|
+
container.style.top = "0";
|
|
1029
|
+
container.style.right = "0";
|
|
1030
|
+
container.style.bottom = "0";
|
|
1031
|
+
container.style.display = "none";
|
|
1032
|
+
container.style.alignItems = "center";
|
|
1033
|
+
container.style.justifyContent = "center";
|
|
1034
|
+
container.style.pointerEvents = "none";
|
|
1035
|
+
container.style.zIndex = "10";
|
|
1036
|
+
container.style.backgroundColor = "#000";
|
|
1037
|
+
(_contentVideo_parentElement = contentVideo.parentElement) === null || _contentVideo_parentElement === void 0 ? void 0 : _contentVideo_parentElement.appendChild(container);
|
|
1038
|
+
adContainerEl = container;
|
|
1039
|
+
}
|
|
1040
|
+
if (!adVideoElement) {
|
|
1041
|
+
adVideoElement = createAdVideoElement();
|
|
1042
|
+
adContainerEl.appendChild(adVideoElement);
|
|
986
1043
|
setupAdEventListeners();
|
|
987
1044
|
} else {
|
|
988
|
-
|
|
989
|
-
;
|
|
990
|
-
container = document.createElement("div");
|
|
991
|
-
container.style.position = "absolute";
|
|
992
|
-
container.style.left = "0";
|
|
993
|
-
container.style.top = "0";
|
|
994
|
-
container.style.right = "0";
|
|
995
|
-
container.style.bottom = "0";
|
|
996
|
-
container.style.display = "none";
|
|
997
|
-
container.style.alignItems = "center";
|
|
998
|
-
container.style.justifyContent = "center";
|
|
999
|
-
container.style.pointerEvents = "none";
|
|
1000
|
-
container.style.zIndex = "10";
|
|
1001
|
-
container.style.backgroundColor = "#000";
|
|
1002
|
-
(_contentVideo_parentElement = contentVideo.parentElement) === null || _contentVideo_parentElement === void 0 ? void 0 : _contentVideo_parentElement.appendChild(container);
|
|
1003
|
-
adContainerEl = container;
|
|
1004
|
-
}
|
|
1005
|
-
if (!adVideoElement) {
|
|
1006
|
-
adVideoElement = createAdVideoElement();
|
|
1007
|
-
adContainerEl.appendChild(adVideoElement);
|
|
1008
|
-
setupAdEventListeners();
|
|
1009
|
-
} else {
|
|
1010
|
-
teardownCurrentPlayback();
|
|
1011
|
-
}
|
|
1045
|
+
teardownCurrentPlayback();
|
|
1012
1046
|
}
|
|
1013
1047
|
if (!continueLiveStreamDuringAds) {
|
|
1014
1048
|
contentVideo.pause();
|
|
@@ -1020,7 +1054,7 @@ function createVastAdLayer(contentVideo, options) {
|
|
|
1020
1054
|
adVolume = originalMutedState ? 1 : originalVolume;
|
|
1021
1055
|
adVideoElement.volume = Math.max(0, Math.min(1, adVolume));
|
|
1022
1056
|
adVideoElement.muted = false;
|
|
1023
|
-
if (
|
|
1057
|
+
if (adContainerEl) {
|
|
1024
1058
|
adContainerEl.style.display = "flex";
|
|
1025
1059
|
adContainerEl.style.pointerEvents = "auto";
|
|
1026
1060
|
}
|
|
@@ -1124,6 +1158,7 @@ function createVastAdLayer(contentVideo, options) {
|
|
|
1124
1158
|
if (debug) console.log("".concat(LOG, " [preload] HLS manifest parsed, token=").concat(token));
|
|
1125
1159
|
});
|
|
1126
1160
|
hls.on(import_hls.default.Events.ERROR, function(_evt, data) {
|
|
1161
|
+
if (!preloadSlots.has(token)) return;
|
|
1127
1162
|
if (data.fatal) {
|
|
1128
1163
|
if (debug) console.warn("".concat(LOG, " [preload] HLS error for token=").concat(token));
|
|
1129
1164
|
preloadSlots.delete(token);
|
|
@@ -1160,113 +1195,146 @@ function createVastAdLayer(contentVideo, options) {
|
|
|
1160
1195
|
}
|
|
1161
1196
|
function playPreloaded(token) {
|
|
1162
1197
|
return _async_to_generator(function() {
|
|
1163
|
-
var slot, contentVolume, adVolume2, videoEl, container2, adVolume21, adVolume, container;
|
|
1198
|
+
var slot, contentVolume, adVolume2, videoEl, container2, adVolume21, nonFatalNetworkErrors, adVolume, container;
|
|
1164
1199
|
return _ts_generator(this, function(_state) {
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1200
|
+
switch(_state.label){
|
|
1201
|
+
case 0:
|
|
1202
|
+
if (destroyed) return [
|
|
1203
|
+
2,
|
|
1204
|
+
Promise.reject(new Error("Layer has been destroyed"))
|
|
1205
|
+
];
|
|
1206
|
+
slot = preloadSlots.get(token);
|
|
1207
|
+
if (!slot) {
|
|
1208
|
+
if (debug) console.warn("".concat(LOG, " [preload] No slot found for token=").concat(token, ", nothing to play"));
|
|
1209
|
+
return [
|
|
1210
|
+
2
|
|
1211
|
+
];
|
|
1212
|
+
}
|
|
1213
|
+
preloadSlots.delete(token);
|
|
1214
|
+
if (debug) console.log("".concat(LOG, " [preload] Playing preloaded ad, token=").concat(token, ", ready=").concat(slot.ready));
|
|
1215
|
+
contentVolume = contentVideo.volume;
|
|
1216
|
+
originalVolume = Math.max(0, Math.min(1, contentVolume || originalVolume));
|
|
1217
|
+
sessionId = generateSessionId();
|
|
1218
|
+
currentAd = slot.ad;
|
|
1219
|
+
trackingFired = _object_spread({}, createEmptyTrackingState());
|
|
1220
|
+
fireTrackingPixels2(slot.ad.trackingUrls.impression);
|
|
1221
|
+
trackingFired.impression = true;
|
|
1222
|
+
if (!singleElementMode) return [
|
|
1223
|
+
3,
|
|
1224
|
+
2
|
|
1225
|
+
];
|
|
1226
|
+
mainHlsInstance === null || mainHlsInstance === void 0 ? void 0 : mainHlsInstance.detachMedia();
|
|
1227
|
+
teardownCurrentPlayback();
|
|
1228
|
+
adVideoElement = contentVideo;
|
|
1229
|
+
adHls = void 0;
|
|
1230
|
+
adPlaying = true;
|
|
1231
|
+
setAdPlayingFlag(true);
|
|
1232
|
+
contentVideo.removeAttribute("src");
|
|
1233
|
+
contentVideo.load();
|
|
1234
|
+
contentVideo.muted = true;
|
|
1235
|
+
contentVideo.volume = 0;
|
|
1236
|
+
return [
|
|
1237
|
+
4,
|
|
1238
|
+
new Promise(function(resolve) {
|
|
1239
|
+
return setTimeout(resolve, 200);
|
|
1240
|
+
})
|
|
1241
|
+
];
|
|
1242
|
+
case 1:
|
|
1243
|
+
_state.sent();
|
|
1244
|
+
if (destroyed || tornDown) return [
|
|
1245
|
+
2
|
|
1246
|
+
];
|
|
1247
|
+
contentVideo.style.visibility = "visible";
|
|
1248
|
+
contentVideo.style.opacity = "1";
|
|
1249
|
+
emit("content_pause");
|
|
1250
|
+
setupAdEventListeners();
|
|
1251
|
+
adVolume2 = originalMutedState ? 1 : originalVolume;
|
|
1252
|
+
contentVideo.volume = Math.max(0, Math.min(1, adVolume2));
|
|
1253
|
+
contentVideo.muted = false;
|
|
1254
|
+
if (debug) console.log("".concat(LOG, " [preload] singleElementMode: attaching ad to contentVideo, url=").concat(slot.mediaFile.url));
|
|
1255
|
+
startPlayback(slot.mediaFile);
|
|
1256
|
+
return [
|
|
1257
|
+
2
|
|
1258
|
+
];
|
|
1259
|
+
case 2:
|
|
1260
|
+
if (smartTVMode && !slot.videoEl) {
|
|
1261
|
+
teardownCurrentPlayback();
|
|
1262
|
+
if (adVideoElement) {
|
|
1263
|
+
adVideoElement.remove();
|
|
1264
|
+
adVideoElement = void 0;
|
|
1265
|
+
}
|
|
1266
|
+
videoEl = createAdVideoElement();
|
|
1267
|
+
videoEl.style.visibility = "visible";
|
|
1268
|
+
videoEl.style.pointerEvents = "none";
|
|
1269
|
+
container2 = ensureAdContainer();
|
|
1270
|
+
container2.appendChild(videoEl);
|
|
1271
|
+
adVideoElement = videoEl;
|
|
1272
|
+
setupAdEventListeners();
|
|
1273
|
+
if (!continueLiveStreamDuringAds) {
|
|
1274
|
+
contentVideo.pause();
|
|
1275
|
+
}
|
|
1276
|
+
contentVideo.muted = true;
|
|
1277
|
+
contentVideo.volume = 0;
|
|
1278
|
+
adPlaying = true;
|
|
1279
|
+
setAdPlayingFlag(true);
|
|
1280
|
+
adVolume21 = originalMutedState ? 1 : originalVolume;
|
|
1281
|
+
adVideoElement.volume = Math.max(0, Math.min(1, adVolume21));
|
|
1282
|
+
adVideoElement.muted = false;
|
|
1283
|
+
container2.style.display = "flex";
|
|
1284
|
+
container2.style.pointerEvents = "auto";
|
|
1285
|
+
emit("content_pause");
|
|
1286
|
+
if (debug) console.log("".concat(LOG, " [preload] smartTVMode deferred: creating video element and loading, url=").concat(slot.mediaFile.url));
|
|
1287
|
+
startPlayback(slot.mediaFile);
|
|
1288
|
+
return [
|
|
1289
|
+
2
|
|
1290
|
+
];
|
|
1291
|
+
}
|
|
1292
|
+
teardownCurrentPlayback();
|
|
1293
|
+
if (adVideoElement && adVideoElement !== slot.videoEl) {
|
|
1294
|
+
adVideoElement.remove();
|
|
1295
|
+
}
|
|
1296
|
+
slot.videoEl.style.visibility = "visible";
|
|
1297
|
+
slot.videoEl.style.pointerEvents = "none";
|
|
1298
|
+
adVideoElement = slot.videoEl;
|
|
1299
|
+
adHls = slot.hlsInstance;
|
|
1300
|
+
if (adHls) {
|
|
1301
|
+
nonFatalNetworkErrors = 0;
|
|
1302
|
+
adHls.on(import_hls.default.Events.ERROR, function(_event, data) {
|
|
1303
|
+
if (!adPlaying) return;
|
|
1304
|
+
if (data.fatal) {
|
|
1305
|
+
handleAdError();
|
|
1306
|
+
} else if (data.type === import_hls.default.ErrorTypes.NETWORK_ERROR) {
|
|
1307
|
+
nonFatalNetworkErrors++;
|
|
1308
|
+
if (nonFatalNetworkErrors >= 3) {
|
|
1309
|
+
if (debug) console.warn("".concat(LOG, " [preload] Too many non-fatal HLS network errors during playback, treating as fatal"));
|
|
1310
|
+
handleAdError();
|
|
1311
|
+
}
|
|
1312
|
+
}
|
|
1313
|
+
});
|
|
1314
|
+
}
|
|
1315
|
+
setupAdEventListeners();
|
|
1316
|
+
if (!continueLiveStreamDuringAds) {
|
|
1317
|
+
contentVideo.pause();
|
|
1318
|
+
}
|
|
1319
|
+
contentVideo.muted = true;
|
|
1320
|
+
contentVideo.volume = 0;
|
|
1321
|
+
adPlaying = true;
|
|
1322
|
+
setAdPlayingFlag(true);
|
|
1323
|
+
adVolume = originalMutedState ? 1 : originalVolume;
|
|
1324
|
+
adVideoElement.volume = Math.max(0, Math.min(1, adVolume));
|
|
1325
|
+
adVideoElement.muted = false;
|
|
1326
|
+
container = ensureAdContainer();
|
|
1327
|
+
container.style.display = "flex";
|
|
1328
|
+
container.style.pointerEvents = "auto";
|
|
1329
|
+
emit("content_pause");
|
|
1330
|
+
adVideoElement.play().catch(function(error) {
|
|
1331
|
+
console.error("".concat(LOG, " [preload] Error playing preloaded ad:"), error);
|
|
1332
|
+
handleAdError();
|
|
1333
|
+
});
|
|
1334
|
+
return [
|
|
1335
|
+
2
|
|
1336
|
+
];
|
|
1251
1337
|
}
|
|
1252
|
-
contentVideo.muted = true;
|
|
1253
|
-
contentVideo.volume = 0;
|
|
1254
|
-
adPlaying = true;
|
|
1255
|
-
setAdPlayingFlag(true);
|
|
1256
|
-
adVolume = originalMutedState ? 1 : originalVolume;
|
|
1257
|
-
adVideoElement.volume = Math.max(0, Math.min(1, adVolume));
|
|
1258
|
-
adVideoElement.muted = false;
|
|
1259
|
-
container = ensureAdContainer();
|
|
1260
|
-
container.style.display = "flex";
|
|
1261
|
-
container.style.pointerEvents = "auto";
|
|
1262
|
-
emit("content_pause");
|
|
1263
|
-
adVideoElement.play().catch(function(error) {
|
|
1264
|
-
console.error("".concat(LOG, " [preload] Error playing preloaded ad:"), error);
|
|
1265
|
-
handleAdError();
|
|
1266
|
-
});
|
|
1267
|
-
return [
|
|
1268
|
-
2
|
|
1269
|
-
];
|
|
1270
1338
|
});
|
|
1271
1339
|
})();
|
|
1272
1340
|
}
|