react-native-theoplayer 11.6.0 → 11.8.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.
- package/CHANGELOG.md +38 -0
- package/README.md +69 -0
- package/android/build.gradle +3 -2
- package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/android/gradle/wrapper/gradle-wrapper.properties +1 -1
- package/android/gradlew +176 -110
- package/android/gradlew.bat +23 -18
- package/android/src/main/java/com/theoplayer/PlayerConfigAdapter.kt +6 -0
- package/android/src/main/java/com/theoplayer/PlayerEventEmitter.kt +2 -2
- package/android/src/main/java/com/theoplayer/ReactTHEOplayerContext.kt +37 -8
- package/android/src/main/java/com/theoplayer/ReactTHEOplayerPackage.kt +3 -0
- package/android/src/main/java/com/theoplayer/ReactTHEOplayerView.kt +51 -3
- package/android/src/main/java/com/theoplayer/ads/AdEventAdapter.kt +4 -0
- package/android/src/main/java/com/theoplayer/ads/AdsModule.kt +6 -6
- package/android/src/main/java/com/theoplayer/drm/ContentProtectionAdapter.kt +17 -5
- package/android/src/main/java/com/theoplayer/drm/ContentProtectionModule.kt +61 -7
- package/android/src/main/java/com/theoplayer/drm/ProxyContentProtectionIntegration.kt +12 -5
- package/android/src/main/java/com/theoplayer/drm/ProxyContentProtectionIntegrationFactory.kt +3 -1
- package/android/src/main/java/com/theoplayer/integration/Integration.kt +72 -0
- package/android/src/main/java/com/theoplayer/integration/IntegrationRegistration.kt +68 -0
- package/android/src/main/java/com/theoplayer/integration/PlayerFacade.kt +187 -0
- package/android/src/main/java/com/theoplayer/integration/PlayerFacadeAdState.kt +19 -0
- package/android/src/main/java/com/theoplayer/integration/PlayerFacadeAds.kt +73 -0
- package/android/src/main/java/com/theoplayer/integration/PlayerFacadeAdsBridge.kt +112 -0
- package/android/src/main/java/com/theoplayer/integration/PlayerFacadeEventSubscription.kt +11 -0
- package/android/src/main/java/com/theoplayer/integration/PlayerFacadeEvents.kt +139 -0
- package/android/src/main/java/com/theoplayer/metrics/MetricsModule.kt +37 -0
- package/android/src/main/java/com/theoplayer/theoads/THEOadsModule.kt +1 -1
- package/android/src/main/java/com/theoplayer/theolive/EndpointAdapter.kt +33 -0
- package/android/src/test/java/com/theoplayer/integration/PlayerFacadeAdsBridgeTest.kt +250 -0
- package/android/src/test/java/com/theoplayer/integration/PlayerFacadeConfigurationTest.kt +30 -0
- package/android/src/test/java/com/theoplayer/integration/PlayerFacadeTest.kt +507 -0
- package/android/src/test/java/com/theoplayer/integration/PlayerFacadeTestHost.kt +104 -0
- package/ios/THEOplayerRCTBridge.m +19 -0
- package/ios/THEOplayerRCTPlayerAPI.swift +31 -0
- package/ios/Theoplayer-Bridging-Header.h +0 -1
- package/ios/contentprotection/THEOplayerRCTContentProtectionAPI.swift +39 -9
- package/ios/contentprotection/THEOplayerRCTContentProtectionAggregator.swift +15 -11
- package/ios/contentprotection/THEOplayerRCTProxyContentProtectionIntegration.swift +12 -7
- package/ios/metrics/THEOplayerRCTMetricsAPI.swift +31 -0
- package/ios/theolive/THEOplayerRCTTHEOliveEventAdapter.swift +21 -0
- package/lib/commonjs/api/barrel.js +31 -20
- package/lib/commonjs/api/barrel.js.map +1 -1
- package/lib/commonjs/api/metrics/MetricsAPI.js +2 -0
- package/lib/commonjs/api/metrics/MetricsAPI.js.map +1 -0
- package/lib/commonjs/api/metrics/barrel.js +17 -0
- package/lib/commonjs/api/metrics/barrel.js.map +1 -0
- package/lib/commonjs/api/player/Integration.js +2 -0
- package/lib/commonjs/api/player/Integration.js.map +1 -0
- package/lib/commonjs/api/player/PlayerEventMap.js +1 -1
- package/lib/commonjs/api/player/THEOplayer.js.map +1 -1
- package/lib/commonjs/api/player/barrel.js +11 -0
- package/lib/commonjs/api/player/barrel.js.map +1 -1
- package/lib/commonjs/api/track/MediaTrack.js +16 -0
- package/lib/commonjs/api/track/MediaTrack.js.map +1 -1
- package/lib/commonjs/internal/THEOplayerView.js +2 -0
- package/lib/commonjs/internal/THEOplayerView.js.map +1 -1
- package/lib/commonjs/internal/THEOplayerView.web.js +3 -1
- package/lib/commonjs/internal/THEOplayerView.web.js.map +1 -1
- package/lib/commonjs/internal/adapter/DefaultNativePlayerState.js +1 -0
- package/lib/commonjs/internal/adapter/DefaultNativePlayerState.js.map +1 -1
- package/lib/commonjs/internal/adapter/THEOplayerAdapter.js +18 -0
- package/lib/commonjs/internal/adapter/THEOplayerAdapter.js.map +1 -1
- package/lib/commonjs/internal/adapter/THEOplayerWebAdapter.js +21 -4
- package/lib/commonjs/internal/adapter/THEOplayerWebAdapter.js.map +1 -1
- package/lib/commonjs/internal/adapter/WebEventForwarder.js +62 -11
- package/lib/commonjs/internal/adapter/WebEventForwarder.js.map +1 -1
- package/lib/commonjs/internal/adapter/metrics/MetricsNativeAdapter.js +18 -0
- package/lib/commonjs/internal/adapter/metrics/MetricsNativeAdapter.js.map +1 -0
- package/lib/commonjs/internal/adapter/metrics/MetricsWebAdapter.js +16 -0
- package/lib/commonjs/internal/adapter/metrics/MetricsWebAdapter.js.map +1 -0
- package/lib/commonjs/internal/adapter/web/IntegrationRegistration.js +6 -0
- package/lib/commonjs/internal/adapter/web/IntegrationRegistration.js.map +1 -0
- package/lib/commonjs/internal/adapter/web/PlayerFacade.js +258 -0
- package/lib/commonjs/internal/adapter/web/PlayerFacade.js.map +1 -0
- package/lib/commonjs/internal/adapter/web/PlayerFacadeAPI.js +6 -0
- package/lib/commonjs/internal/adapter/web/PlayerFacadeAPI.js.map +1 -0
- package/lib/commonjs/internal/adapter/web/PlayerFacadeAdsEvents.js +114 -0
- package/lib/commonjs/internal/adapter/web/PlayerFacadeAdsEvents.js.map +1 -0
- package/lib/commonjs/internal/adapter/web/PlayerFacadeIntegration.js +6 -0
- package/lib/commonjs/internal/adapter/web/PlayerFacadeIntegration.js.map +1 -0
- package/lib/commonjs/internal/adapter/web/PlayerFacadeTypes.js +6 -0
- package/lib/commonjs/internal/adapter/web/PlayerFacadeTypes.js.map +1 -0
- package/lib/commonjs/internal/drm/ContentProtectionRegistry.js +38 -12
- package/lib/commonjs/internal/drm/ContentProtectionRegistry.js.map +1 -1
- package/lib/commonjs/manifest.json +1 -1
- package/lib/commonjs/plugins/typedoc-platform-icons/package-lock.json +200 -58
- package/lib/commonjs/plugins/typedoc-platform-icons/package.json +1 -1
- package/lib/commonjs/plugins/typedoc-platform-icons/tsconfig.json +2 -1
- package/lib/module/api/barrel.js +1 -0
- package/lib/module/api/barrel.js.map +1 -1
- package/lib/module/api/metrics/MetricsAPI.js +2 -0
- package/lib/module/api/metrics/MetricsAPI.js.map +1 -0
- package/lib/module/api/metrics/barrel.js +4 -0
- package/lib/module/api/metrics/barrel.js.map +1 -0
- package/lib/module/api/player/Integration.js +2 -0
- package/lib/module/api/player/Integration.js.map +1 -0
- package/lib/module/api/player/PlayerEventMap.js +1 -1
- package/lib/module/api/player/THEOplayer.js.map +1 -1
- package/lib/module/api/player/barrel.js +1 -0
- package/lib/module/api/player/barrel.js.map +1 -1
- package/lib/module/api/track/MediaTrack.js +16 -0
- package/lib/module/api/track/MediaTrack.js.map +1 -1
- package/lib/module/internal/THEOplayerView.js +2 -0
- package/lib/module/internal/THEOplayerView.js.map +1 -1
- package/lib/module/internal/THEOplayerView.web.js +3 -1
- package/lib/module/internal/THEOplayerView.web.js.map +1 -1
- package/lib/module/internal/adapter/DefaultNativePlayerState.js +1 -0
- package/lib/module/internal/adapter/DefaultNativePlayerState.js.map +1 -1
- package/lib/module/internal/adapter/THEOplayerAdapter.js +18 -0
- package/lib/module/internal/adapter/THEOplayerAdapter.js.map +1 -1
- package/lib/module/internal/adapter/THEOplayerWebAdapter.js +21 -4
- package/lib/module/internal/adapter/THEOplayerWebAdapter.js.map +1 -1
- package/lib/module/internal/adapter/WebEventForwarder.js +62 -11
- package/lib/module/internal/adapter/WebEventForwarder.js.map +1 -1
- package/lib/module/internal/adapter/metrics/MetricsNativeAdapter.js +13 -0
- package/lib/module/internal/adapter/metrics/MetricsNativeAdapter.js.map +1 -0
- package/lib/module/internal/adapter/metrics/MetricsWebAdapter.js +11 -0
- package/lib/module/internal/adapter/metrics/MetricsWebAdapter.js.map +1 -0
- package/lib/module/internal/adapter/web/IntegrationRegistration.js +4 -0
- package/lib/module/internal/adapter/web/IntegrationRegistration.js.map +1 -0
- package/lib/module/internal/adapter/web/PlayerFacade.js +253 -0
- package/lib/module/internal/adapter/web/PlayerFacade.js.map +1 -0
- package/lib/module/internal/adapter/web/PlayerFacadeAPI.js +4 -0
- package/lib/module/internal/adapter/web/PlayerFacadeAPI.js.map +1 -0
- package/lib/module/internal/adapter/web/PlayerFacadeAdsEvents.js +109 -0
- package/lib/module/internal/adapter/web/PlayerFacadeAdsEvents.js.map +1 -0
- package/lib/module/internal/adapter/web/PlayerFacadeIntegration.js +4 -0
- package/lib/module/internal/adapter/web/PlayerFacadeIntegration.js.map +1 -0
- package/lib/module/internal/adapter/web/PlayerFacadeTypes.js +4 -0
- package/lib/module/internal/adapter/web/PlayerFacadeTypes.js.map +1 -0
- package/lib/module/internal/drm/ContentProtectionRegistry.js +38 -12
- package/lib/module/internal/drm/ContentProtectionRegistry.js.map +1 -1
- package/lib/module/manifest.json +1 -1
- package/lib/module/plugins/typedoc-platform-icons/package-lock.json +200 -58
- package/lib/module/plugins/typedoc-platform-icons/package.json +1 -1
- package/lib/module/plugins/typedoc-platform-icons/tsconfig.json +2 -1
- package/lib/typescript/__tests__/ContentProtectionRegistry.test.d.ts +2 -0
- package/lib/typescript/__tests__/ContentProtectionRegistry.test.d.ts.map +1 -0
- package/lib/typescript/__tests__/PlayerFacade.test.d.ts +2 -0
- package/lib/typescript/__tests__/PlayerFacade.test.d.ts.map +1 -0
- package/lib/typescript/__tests__/PlayerFacadeWebAdapter.test.d.ts +2 -0
- package/lib/typescript/__tests__/PlayerFacadeWebAdapter.test.d.ts.map +1 -0
- package/lib/typescript/__tests__/index.test.d.ts +13 -0
- package/lib/typescript/__tests__/index.test.d.ts.map +1 -1
- package/lib/typescript/api/THEOplayerView.d.ts +4 -0
- package/lib/typescript/api/THEOplayerView.d.ts.map +1 -1
- package/lib/typescript/api/barrel.d.ts +1 -0
- package/lib/typescript/api/barrel.d.ts.map +1 -1
- package/lib/typescript/api/config/PlayerConfiguration.d.ts +15 -0
- package/lib/typescript/api/config/PlayerConfiguration.d.ts.map +1 -1
- package/lib/typescript/api/error/ChromecastError.d.ts +2 -2
- package/lib/typescript/api/event/AdEvent.d.ts +1 -1
- package/lib/typescript/api/metrics/MetricsAPI.d.ts +21 -0
- package/lib/typescript/api/metrics/MetricsAPI.d.ts.map +1 -0
- package/lib/typescript/api/metrics/barrel.d.ts +2 -0
- package/lib/typescript/api/metrics/barrel.d.ts.map +1 -0
- package/lib/typescript/api/player/Integration.d.ts +88 -0
- package/lib/typescript/api/player/Integration.d.ts.map +1 -0
- package/lib/typescript/api/player/PlayerEventMap.d.ts +1 -1
- package/lib/typescript/api/player/THEOplayer.d.ts +19 -0
- package/lib/typescript/api/player/THEOplayer.d.ts.map +1 -1
- package/lib/typescript/api/player/barrel.d.ts +1 -0
- package/lib/typescript/api/player/barrel.d.ts.map +1 -1
- package/lib/typescript/api/theoads/interstitial/Interstitial.d.ts +1 -1
- package/lib/typescript/api/theolive/TheoLiveEndpoint.d.ts +23 -5
- package/lib/typescript/api/theolive/TheoLiveEndpoint.d.ts.map +1 -1
- package/lib/typescript/api/theolive/WebrtcOptions.d.ts +1 -1
- package/lib/typescript/api/track/MediaTrack.d.ts +21 -4
- package/lib/typescript/api/track/MediaTrack.d.ts.map +1 -1
- package/lib/typescript/internal/adapter/DefaultNativePlayerState.d.ts +1 -0
- package/lib/typescript/internal/adapter/DefaultNativePlayerState.d.ts.map +1 -1
- package/lib/typescript/internal/adapter/NativePlayerState.d.ts +1 -0
- package/lib/typescript/internal/adapter/NativePlayerState.d.ts.map +1 -1
- package/lib/typescript/internal/adapter/THEOplayerAdapter.d.ts +6 -1
- package/lib/typescript/internal/adapter/THEOplayerAdapter.d.ts.map +1 -1
- package/lib/typescript/internal/adapter/THEOplayerWebAdapter.d.ts +6 -1
- package/lib/typescript/internal/adapter/THEOplayerWebAdapter.d.ts.map +1 -1
- package/lib/typescript/internal/adapter/WebEventForwarder.d.ts +3 -0
- package/lib/typescript/internal/adapter/WebEventForwarder.d.ts.map +1 -1
- package/lib/typescript/internal/adapter/metrics/MetricsNativeAdapter.d.ts +7 -0
- package/lib/typescript/internal/adapter/metrics/MetricsNativeAdapter.d.ts.map +1 -0
- package/lib/typescript/internal/adapter/metrics/MetricsWebAdapter.d.ts +8 -0
- package/lib/typescript/internal/adapter/metrics/MetricsWebAdapter.d.ts.map +1 -0
- package/lib/typescript/internal/adapter/web/IntegrationRegistration.d.ts +53 -0
- package/lib/typescript/internal/adapter/web/IntegrationRegistration.d.ts.map +1 -0
- package/lib/typescript/internal/adapter/web/PlayerFacade.d.ts +26 -0
- package/lib/typescript/internal/adapter/web/PlayerFacade.d.ts.map +1 -0
- package/lib/typescript/internal/adapter/web/PlayerFacadeAPI.d.ts +33 -0
- package/lib/typescript/internal/adapter/web/PlayerFacadeAPI.d.ts.map +1 -0
- package/lib/typescript/internal/adapter/web/PlayerFacadeAdsEvents.d.ts +21 -0
- package/lib/typescript/internal/adapter/web/PlayerFacadeAdsEvents.d.ts.map +1 -0
- package/lib/typescript/internal/adapter/web/PlayerFacadeIntegration.d.ts +43 -0
- package/lib/typescript/internal/adapter/web/PlayerFacadeIntegration.d.ts.map +1 -0
- package/lib/typescript/internal/adapter/web/PlayerFacadeTypes.d.ts +13 -0
- package/lib/typescript/internal/adapter/web/PlayerFacadeTypes.d.ts.map +1 -0
- package/lib/typescript/internal/drm/ContentProtectionRegistry.d.ts +3 -1
- package/lib/typescript/internal/drm/ContentProtectionRegistry.d.ts.map +1 -1
- package/lib/typescript/internal/drm/NativeContentProtectionEvent.d.ts +5 -0
- package/lib/typescript/internal/drm/NativeContentProtectionEvent.d.ts.map +1 -1
- package/package.json +5 -6
- package/react-native-theoplayer.podspec +7 -7
- package/src/__tests__/ContentProtectionRegistry.test.ts +239 -0
- package/src/__tests__/PlayerFacade.test.ts +579 -0
- package/src/__tests__/PlayerFacadeWebAdapter.test.ts +193 -0
- package/src/__tests__/index.test.tsx +15 -1
- package/src/api/THEOplayerView.ts +5 -0
- package/src/api/barrel.ts +1 -0
- package/src/api/config/PlayerConfiguration.ts +16 -0
- package/src/api/error/ChromecastError.ts +2 -2
- package/src/api/event/AdEvent.ts +1 -1
- package/src/api/metrics/MetricsAPI.ts +20 -0
- package/src/api/metrics/barrel.ts +1 -0
- package/src/api/player/Integration.ts +97 -0
- package/src/api/player/PlayerEventMap.ts +1 -1
- package/src/api/player/THEOplayer.ts +21 -0
- package/src/api/player/barrel.ts +1 -0
- package/src/api/theoads/interstitial/Interstitial.ts +1 -1
- package/src/api/theolive/TheoLiveEndpoint.ts +24 -5
- package/src/api/theolive/WebrtcOptions.ts +1 -1
- package/src/api/track/MediaTrack.ts +21 -4
- package/src/internal/THEOplayerView.tsx +2 -2
- package/src/internal/THEOplayerView.web.tsx +2 -2
- package/src/internal/adapter/DefaultNativePlayerState.ts +1 -0
- package/src/internal/adapter/NativePlayerState.ts +1 -0
- package/src/internal/adapter/THEOplayerAdapter.ts +24 -0
- package/src/internal/adapter/THEOplayerWebAdapter.ts +27 -4
- package/src/internal/adapter/WebEventForwarder.ts +74 -13
- package/src/internal/adapter/metrics/MetricsNativeAdapter.ts +12 -0
- package/src/internal/adapter/metrics/MetricsWebAdapter.ts +14 -0
- package/src/internal/adapter/web/IntegrationRegistration.ts +57 -0
- package/src/internal/adapter/web/PlayerFacade.ts +281 -0
- package/src/internal/adapter/web/PlayerFacadeAPI.ts +35 -0
- package/src/internal/adapter/web/PlayerFacadeAdsEvents.ts +119 -0
- package/src/internal/adapter/web/PlayerFacadeIntegration.ts +45 -0
- package/src/internal/adapter/web/PlayerFacadeTypes.ts +14 -0
- package/src/internal/drm/ContentProtectionRegistry.ts +35 -17
- package/src/internal/drm/NativeContentProtectionEvent.ts +5 -0
- package/src/manifest.json +1 -1
- package/src/plugins/typedoc-platform-icons/package-lock.json +200 -58
- package/src/plugins/typedoc-platform-icons/package.json +1 -1
- package/src/plugins/typedoc-platform-icons/tsconfig.json +2 -1
- package/lib/typescript/plugins/expo/Common.d.ts +0 -13
- package/lib/typescript/plugins/expo/Common.d.ts.map +0 -1
- package/lib/typescript/plugins/expo/withCustomPod.d.ts +0 -2
- package/lib/typescript/plugins/expo/withCustomPod.d.ts.map +0 -1
- package/lib/typescript/plugins/expo/withTHEOplayer.d.ts +0 -4
- package/lib/typescript/plugins/expo/withTHEOplayer.d.ts.map +0 -1
- package/lib/typescript/plugins/expo/withTHEOplayerAndroid.d.ts +0 -4
- package/lib/typescript/plugins/expo/withTHEOplayerAndroid.d.ts.map +0 -1
- package/lib/typescript/plugins/expo/withTHEOplayerIOS.d.ts +0 -4
- package/lib/typescript/plugins/expo/withTHEOplayerIOS.d.ts.map +0 -1
- package/lib/typescript/plugins/typedoc-platform-icons/src/index.d.ts +0 -3
- package/lib/typescript/plugins/typedoc-platform-icons/src/index.d.ts.map +0 -1
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
import type { ChromelessPlayer, EventListener, PlayerEventMap } from 'theoplayer';
|
|
2
|
+
import { PlayerFacadeAdsEvents } from './PlayerFacadeAdsEvents';
|
|
3
|
+
import type { IntegrationRegistration, PlayerFacade as PlayerFacadeAPI, PlayerFacadeEvent, PlayerFacadeIntegration } from './PlayerFacadeTypes';
|
|
4
|
+
|
|
5
|
+
type Registration = IntegrationRegistration & { integration?: PlayerFacadeIntegration };
|
|
6
|
+
type PlayerEvent = PlayerEventMap[keyof PlayerEventMap];
|
|
7
|
+
type PlayerEventSubscription = {
|
|
8
|
+
listeners: Set<EventListener<PlayerEvent>>;
|
|
9
|
+
interceptors: Set<(event: PlayerEvent) => boolean>;
|
|
10
|
+
forward: EventListener<PlayerEvent>;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
// Resolve the current backing object on every access while preserving its method receiver and identity.
|
|
14
|
+
function delegate<T extends object, TOverrides extends object>(backing: () => T, overrides: TOverrides): T & TOverrides {
|
|
15
|
+
const methods = new Map<PropertyKey, { original: unknown; receiver: object; bound: unknown }>();
|
|
16
|
+
return new Proxy(Object.create(Object.getPrototypeOf(backing())) as T & TOverrides, {
|
|
17
|
+
get: (_target, property) => {
|
|
18
|
+
const receiver = Object.prototype.hasOwnProperty.call(overrides, property) ? overrides : backing();
|
|
19
|
+
const value: unknown = Reflect.get(receiver, property, receiver);
|
|
20
|
+
if (typeof value !== 'function' || property === 'constructor') return value;
|
|
21
|
+
const cached = methods.get(property);
|
|
22
|
+
if (cached?.original !== value || cached.receiver !== receiver)
|
|
23
|
+
methods.set(property, { original: value, receiver, bound: value.bind(receiver) });
|
|
24
|
+
return methods.get(property)!.bound;
|
|
25
|
+
},
|
|
26
|
+
set: (_target, property, value) => {
|
|
27
|
+
const receiver = Reflect.getOwnPropertyDescriptor(overrides, property)?.set ? overrides : backing();
|
|
28
|
+
return Reflect.set(receiver, property, value, receiver);
|
|
29
|
+
},
|
|
30
|
+
has: (_target, property) => property in overrides || property in backing(),
|
|
31
|
+
ownKeys: () => [...new Set([...Reflect.ownKeys(backing()), ...Reflect.ownKeys(overrides)])],
|
|
32
|
+
getOwnPropertyDescriptor: (_target, property) => {
|
|
33
|
+
const descriptor = Reflect.getOwnPropertyDescriptor(overrides, property) ?? Reflect.getOwnPropertyDescriptor(backing(), property);
|
|
34
|
+
return descriptor && { ...descriptor, configurable: true };
|
|
35
|
+
},
|
|
36
|
+
preventExtensions: () => false,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Stable player surface with generic integration hooks; no playback or ad-lifecycle policy lives here.
|
|
42
|
+
*
|
|
43
|
+
* @internal
|
|
44
|
+
*/
|
|
45
|
+
export class PlayerFacade {
|
|
46
|
+
readonly player: PlayerFacadeAPI;
|
|
47
|
+
private readonly nativeAds: PlayerFacadeAPI['ads'] | undefined;
|
|
48
|
+
private readonly adsEvents: PlayerFacadeAdsEvents;
|
|
49
|
+
private readonly playerSubscriptions = new Map<keyof PlayerEventMap, PlayerEventSubscription>();
|
|
50
|
+
private readonly playerInterceptors = new Set<(event: PlayerEvent) => boolean>();
|
|
51
|
+
private registration?: Registration;
|
|
52
|
+
private closed = false;
|
|
53
|
+
|
|
54
|
+
constructor(readonly contentPlayer: ChromelessPlayer) {
|
|
55
|
+
this.nativeAds = contentPlayer.ads as PlayerFacadeAPI['ads'];
|
|
56
|
+
this.adsEvents = new PlayerFacadeAdsEvents(this.nativeAds, () => this.registration?.integration);
|
|
57
|
+
const readAdState = () => this.registration?.integration?.ads ?? this.registration?.integration?.getAdState?.();
|
|
58
|
+
const readPlaying = () => readAdState()?.playing ?? this.nativeAds?.playing ?? false;
|
|
59
|
+
const readAds = () => readAdState()?.currentAds ?? this.nativeAds?.currentAds ?? [];
|
|
60
|
+
const readBreak = () => {
|
|
61
|
+
const state = readAdState();
|
|
62
|
+
return state ? state.currentAdBreak : this.nativeAds?.currentAdBreak;
|
|
63
|
+
};
|
|
64
|
+
const readTime = () => {
|
|
65
|
+
const value = this.registration?.integration?.getCurrentTime?.();
|
|
66
|
+
return typeof value === 'number' && Number.isFinite(value) && value >= 0 ? value : contentPlayer.currentTime;
|
|
67
|
+
};
|
|
68
|
+
const writeTime = (value: number) => {
|
|
69
|
+
if (this.registration?.integration?.setCurrentTime?.(value) !== true) contentPlayer.currentTime = value;
|
|
70
|
+
};
|
|
71
|
+
const readPaused = () => this.registration?.integration?.isPaused?.() ?? contentPlayer.paused;
|
|
72
|
+
const readSeeking = () => this.registration?.integration?.isSeeking?.() ?? contentPlayer.seeking;
|
|
73
|
+
const readDuration = () => this.registration?.integration?.getDuration?.() ?? contentPlayer.duration;
|
|
74
|
+
const emptyAds = {} as PlayerFacadeAPI['ads'];
|
|
75
|
+
// Consumers may retain player.ads before registration; only its backing source should change.
|
|
76
|
+
const ads = delegate(() => this.registration?.integration?.ads ?? this.nativeAds ?? emptyAds, {
|
|
77
|
+
get playing() {
|
|
78
|
+
return readPlaying();
|
|
79
|
+
},
|
|
80
|
+
get currentAds() {
|
|
81
|
+
return readAds();
|
|
82
|
+
},
|
|
83
|
+
get currentAdBreak() {
|
|
84
|
+
return readBreak();
|
|
85
|
+
},
|
|
86
|
+
addEventListener: this.adsEvents.addEventListener,
|
|
87
|
+
removeEventListener: this.adsEvents.removeEventListener,
|
|
88
|
+
});
|
|
89
|
+
const readMuted = () => this.registration?.integration?.getMuted?.() ?? contentPlayer.muted;
|
|
90
|
+
const writeMuted = (value: boolean) => {
|
|
91
|
+
if (this.registration?.integration?.setMuted?.(value) !== true) contentPlayer.muted = value;
|
|
92
|
+
};
|
|
93
|
+
const readVolume = () => this.registration?.integration?.getVolume?.() ?? contentPlayer.volume;
|
|
94
|
+
const writeVolume = (value: number) => {
|
|
95
|
+
if (this.registration?.integration?.setVolume?.(value) !== true) contentPlayer.volume = value;
|
|
96
|
+
};
|
|
97
|
+
this.player = delegate(() => contentPlayer, {
|
|
98
|
+
get muted() {
|
|
99
|
+
return readMuted();
|
|
100
|
+
},
|
|
101
|
+
set muted(value: boolean) {
|
|
102
|
+
writeMuted(value);
|
|
103
|
+
},
|
|
104
|
+
get volume() {
|
|
105
|
+
return readVolume();
|
|
106
|
+
},
|
|
107
|
+
set volume(value: number) {
|
|
108
|
+
writeVolume(value);
|
|
109
|
+
},
|
|
110
|
+
ads,
|
|
111
|
+
contentPlayer,
|
|
112
|
+
registerIntegration: this.registerIntegration.bind(this),
|
|
113
|
+
addEventListener: this.addPlayerEventListener,
|
|
114
|
+
removeEventListener: this.removePlayerEventListener,
|
|
115
|
+
get currentTime() {
|
|
116
|
+
return readTime();
|
|
117
|
+
},
|
|
118
|
+
set currentTime(value: number) {
|
|
119
|
+
writeTime(value);
|
|
120
|
+
},
|
|
121
|
+
get paused() {
|
|
122
|
+
return readPaused();
|
|
123
|
+
},
|
|
124
|
+
get seeking() {
|
|
125
|
+
return readSeeking();
|
|
126
|
+
},
|
|
127
|
+
get duration() {
|
|
128
|
+
return readDuration();
|
|
129
|
+
},
|
|
130
|
+
play: () => {
|
|
131
|
+
if (this.registration?.integration?.play?.() !== true) contentPlayer.play();
|
|
132
|
+
},
|
|
133
|
+
pause: () => {
|
|
134
|
+
if (this.registration?.integration?.pause?.() !== true) contentPlayer.pause();
|
|
135
|
+
},
|
|
136
|
+
});
|
|
137
|
+
this.getPlayerSubscription('destroy');
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
registerIntegration(integration: PlayerFacadeIntegration): IntegrationRegistration {
|
|
141
|
+
if (this.closed) throw new Error('The player facade has been closed.');
|
|
142
|
+
if (this.registration) throw new Error('Unregister the previous integration first.');
|
|
143
|
+
if (!integration || typeof integration !== 'object') throw new Error('An integration must be an object implementing Integration.');
|
|
144
|
+
for (const method of [
|
|
145
|
+
'getCurrentTime',
|
|
146
|
+
'setCurrentTime',
|
|
147
|
+
'play',
|
|
148
|
+
'pause',
|
|
149
|
+
'isPaused',
|
|
150
|
+
'isSeeking',
|
|
151
|
+
'getDuration',
|
|
152
|
+
'getMuted',
|
|
153
|
+
'setMuted',
|
|
154
|
+
'getVolume',
|
|
155
|
+
'setVolume',
|
|
156
|
+
'getAdState',
|
|
157
|
+
'shouldConsumeAdEvent',
|
|
158
|
+
] as const) {
|
|
159
|
+
if (integration[method] !== undefined && typeof integration[method] !== 'function') {
|
|
160
|
+
throw new Error(`Integration.${method} must be a function.`);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
const registration: Registration = {
|
|
164
|
+
integration,
|
|
165
|
+
dispatchPlayerEvent: (event) => this.dispatchEvent(registration, event),
|
|
166
|
+
dispatchEvent: (event) => this.dispatchEvent(registration, event),
|
|
167
|
+
interceptPlayerEvent: (type, callback) => {
|
|
168
|
+
if (this.closed || this.registration !== registration) return () => undefined;
|
|
169
|
+
const subscription = this.getPlayerSubscription(type);
|
|
170
|
+
const interceptor = callback as (event: PlayerEvent) => boolean;
|
|
171
|
+
subscription.interceptors.add(interceptor);
|
|
172
|
+
return () => {
|
|
173
|
+
subscription.interceptors.delete(interceptor);
|
|
174
|
+
this.releasePlayerSubscription(type, subscription);
|
|
175
|
+
};
|
|
176
|
+
},
|
|
177
|
+
interceptPlayerEvents: (interceptor) => {
|
|
178
|
+
if (this.closed || this.registration !== registration) return () => undefined;
|
|
179
|
+
this.playerInterceptors.add(interceptor);
|
|
180
|
+
return () => {
|
|
181
|
+
this.playerInterceptors.delete(interceptor);
|
|
182
|
+
};
|
|
183
|
+
},
|
|
184
|
+
close: () => {
|
|
185
|
+
registration.integration = undefined;
|
|
186
|
+
if (this.registration !== registration) return;
|
|
187
|
+
this.registration = undefined;
|
|
188
|
+
// Interceptors have explicit disposers so queued backing events can drain after unregistering.
|
|
189
|
+
if (!this.closed) this.adsEvents.rebind();
|
|
190
|
+
},
|
|
191
|
+
};
|
|
192
|
+
this.registration = registration;
|
|
193
|
+
try {
|
|
194
|
+
this.adsEvents.rebind();
|
|
195
|
+
} catch (error) {
|
|
196
|
+
registration.close();
|
|
197
|
+
throw error;
|
|
198
|
+
}
|
|
199
|
+
return registration;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
private getPlayerSubscription(type: keyof PlayerEventMap): PlayerEventSubscription {
|
|
203
|
+
const existing = this.playerSubscriptions.get(type);
|
|
204
|
+
if (existing) return existing;
|
|
205
|
+
// One backing listener per type lets interceptors decide once for all facade consumers.
|
|
206
|
+
const subscription: PlayerEventSubscription = {
|
|
207
|
+
listeners: new Set(),
|
|
208
|
+
interceptors: new Set(),
|
|
209
|
+
forward: (event) => {
|
|
210
|
+
try {
|
|
211
|
+
for (const interceptor of [...subscription.interceptors]) {
|
|
212
|
+
if (subscription.interceptors.has(interceptor) && interceptor(event)) return;
|
|
213
|
+
}
|
|
214
|
+
for (const interceptor of [...this.playerInterceptors]) {
|
|
215
|
+
if (this.playerInterceptors.has(interceptor) && interceptor(event)) return;
|
|
216
|
+
}
|
|
217
|
+
for (const listener of [...subscription.listeners]) {
|
|
218
|
+
if (subscription.listeners.has(listener)) listener(event);
|
|
219
|
+
}
|
|
220
|
+
} finally {
|
|
221
|
+
if (type === 'destroy') this.close();
|
|
222
|
+
}
|
|
223
|
+
},
|
|
224
|
+
};
|
|
225
|
+
this.playerSubscriptions.set(type, subscription);
|
|
226
|
+
this.contentPlayer.addEventListener(type, subscription.forward);
|
|
227
|
+
return subscription;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
private releasePlayerSubscription(type: keyof PlayerEventMap, subscription: PlayerEventSubscription): void {
|
|
231
|
+
if (type === 'destroy' || subscription.listeners.size || subscription.interceptors.size || this.playerSubscriptions.get(type) !== subscription)
|
|
232
|
+
return;
|
|
233
|
+
this.contentPlayer.removeEventListener(type, subscription.forward);
|
|
234
|
+
this.playerSubscriptions.delete(type);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
private readonly addPlayerEventListener: ChromelessPlayer['addEventListener'] = (types, listener) => {
|
|
238
|
+
if (this.closed) throw new Error('The player facade has been closed.');
|
|
239
|
+
for (const type of typeof types === 'string' ? [types] : types) {
|
|
240
|
+
this.getPlayerSubscription(type).listeners.add(listener as EventListener<PlayerEvent>);
|
|
241
|
+
}
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
private readonly removePlayerEventListener: ChromelessPlayer['removeEventListener'] = (types, listener) => {
|
|
245
|
+
for (const type of typeof types === 'string' ? [types] : types) {
|
|
246
|
+
const subscription = this.playerSubscriptions.get(type);
|
|
247
|
+
if (!subscription) continue;
|
|
248
|
+
subscription.listeners.delete(listener as EventListener<PlayerEvent>);
|
|
249
|
+
this.releasePlayerSubscription(type, subscription);
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
private dispatchEvent(registration: Registration, event: PlayerFacadeEvent): void {
|
|
254
|
+
const isCurrentRegistration = () => !this.closed && this.registration === registration;
|
|
255
|
+
if (!isCurrentRegistration()) return;
|
|
256
|
+
if (!event || typeof event.type !== 'string') throw new Error('A THEOplayer event with a type is required.');
|
|
257
|
+
if (PlayerFacadeAdsEvents.isAdEvent(event)) {
|
|
258
|
+
this.adsEvents.dispatch(event, isCurrentRegistration);
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
// Integration events already represent public playback state; backing-player filters must not consume them.
|
|
262
|
+
const listeners = this.playerSubscriptions.get(event.type)?.listeners;
|
|
263
|
+
for (const listener of [...(listeners ?? [])]) {
|
|
264
|
+
if (isCurrentRegistration() && listeners?.has(listener)) listener(event);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
close = (): void => {
|
|
269
|
+
if (this.closed) return;
|
|
270
|
+
this.closed = true;
|
|
271
|
+
this.registration?.close();
|
|
272
|
+
this.playerInterceptors.clear();
|
|
273
|
+
for (const [type, subscription] of this.playerSubscriptions) {
|
|
274
|
+
subscription.listeners.clear();
|
|
275
|
+
subscription.interceptors.clear();
|
|
276
|
+
this.contentPlayer.removeEventListener(type, subscription.forward);
|
|
277
|
+
}
|
|
278
|
+
this.playerSubscriptions.clear();
|
|
279
|
+
this.adsEvents.close();
|
|
280
|
+
};
|
|
281
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { Ads, ChromelessPlayer, EventDispatcher } from 'theoplayer';
|
|
2
|
+
import type { IntegrationRegistration } from './IntegrationRegistration';
|
|
3
|
+
import type { PlayerFacadeIntegration } from './PlayerFacadeIntegration';
|
|
4
|
+
import type { PlayerFacadeAdsEventMap } from './PlayerFacadeTypes';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Describes the stable native Web player handle when the player facade is enabled.
|
|
8
|
+
*
|
|
9
|
+
* @category Player
|
|
10
|
+
* @platform web
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
export interface PlayerFacadeAPI extends ChromelessPlayer {
|
|
14
|
+
/**
|
|
15
|
+
* The stable advertising API, including integration-generated `adclicked` events.
|
|
16
|
+
* Delegates to the registered integration's Ads API or the content player's Ads API.
|
|
17
|
+
*/
|
|
18
|
+
readonly ads: Ads & EventDispatcher<PlayerFacadeAdsEventMap>;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Raw playback engine, unaffected by integration overrides or event interception.
|
|
22
|
+
* Use this player for playback engines and ad schedulers that require the content timeline.
|
|
23
|
+
*/
|
|
24
|
+
readonly contentPlayer: ChromelessPlayer;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Registers an integration that optionally overrides playback and advertising behavior.
|
|
28
|
+
* Only one integration may be registered at a time.
|
|
29
|
+
*
|
|
30
|
+
* @param integration - The hooks and optional Ads API to use until the registration closes.
|
|
31
|
+
* @returns The registration used to dispatch events, install interceptors, and unregister.
|
|
32
|
+
* @throws If the facade is closed, an integration is already registered, or a hook is not a function.
|
|
33
|
+
*/
|
|
34
|
+
registerIntegration(integration: PlayerFacadeIntegration): IntegrationRegistration;
|
|
35
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import type { EventListener } from 'theoplayer';
|
|
2
|
+
import type { PlayerFacadeAds, PlayerFacadeAdsEventMap as AdsEventMap, PlayerFacadeEvent, PlayerFacadeIntegration } from './PlayerFacadeTypes';
|
|
3
|
+
|
|
4
|
+
type AdEventType = keyof AdsEventMap;
|
|
5
|
+
type AdEvent = AdsEventMap[AdEventType];
|
|
6
|
+
type Listener = EventListener<AdEvent>;
|
|
7
|
+
type Subscription = { listeners: Set<Listener>; remove: () => void };
|
|
8
|
+
|
|
9
|
+
// This table selects the Ads event surface; it does not restrict player event dispatch.
|
|
10
|
+
const AD_EVENTS: Record<AdEventType, true> = {
|
|
11
|
+
addadbreak: true,
|
|
12
|
+
removeadbreak: true,
|
|
13
|
+
adbreakbegin: true,
|
|
14
|
+
adbreakend: true,
|
|
15
|
+
adbreakchange: true,
|
|
16
|
+
addad: true,
|
|
17
|
+
updatead: true,
|
|
18
|
+
updateadbreak: true,
|
|
19
|
+
adloaded: true,
|
|
20
|
+
adbegin: true,
|
|
21
|
+
adend: true,
|
|
22
|
+
adskip: true,
|
|
23
|
+
aderror: true,
|
|
24
|
+
adimpression: true,
|
|
25
|
+
adclicked: true,
|
|
26
|
+
adfirstquartile: true,
|
|
27
|
+
admidpoint: true,
|
|
28
|
+
adthirdquartile: true,
|
|
29
|
+
adbuffering: true,
|
|
30
|
+
admetadata: true,
|
|
31
|
+
adsmanagerloaded: true,
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/** Keeps public Ads listeners stable while their backing event source changes. */
|
|
35
|
+
export class PlayerFacadeAdsEvents {
|
|
36
|
+
private readonly subscriptions = new Map<AdEventType, Subscription>();
|
|
37
|
+
private closed = false;
|
|
38
|
+
|
|
39
|
+
constructor(
|
|
40
|
+
private readonly nativeAds: PlayerFacadeAds | undefined,
|
|
41
|
+
private readonly getIntegration: () => PlayerFacadeIntegration | undefined,
|
|
42
|
+
) {}
|
|
43
|
+
|
|
44
|
+
static isAdEvent(event: PlayerFacadeEvent): event is AdEvent {
|
|
45
|
+
return Object.prototype.hasOwnProperty.call(AD_EVENTS, event.type);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
readonly addEventListener = <TType extends AdEventType>(types: TType | readonly TType[], listener: EventListener<AdsEventMap[TType]>): void => {
|
|
49
|
+
if (this.closed) throw new Error('The player facade has been closed.');
|
|
50
|
+
for (const type of typeof types === 'string' ? [types] : types) {
|
|
51
|
+
let subscription = this.subscriptions.get(type);
|
|
52
|
+
if (!subscription) {
|
|
53
|
+
subscription = { listeners: new Set(), remove: () => undefined };
|
|
54
|
+
subscription.remove = this.bindListener(type, subscription);
|
|
55
|
+
this.subscriptions.set(type, subscription);
|
|
56
|
+
}
|
|
57
|
+
subscription.listeners.add(listener as Listener);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
readonly removeEventListener = <TType extends AdEventType>(types: TType | readonly TType[], listener: EventListener<AdsEventMap[TType]>): void => {
|
|
62
|
+
for (const type of typeof types === 'string' ? [types] : types) {
|
|
63
|
+
const subscription = this.subscriptions.get(type);
|
|
64
|
+
if (!subscription) continue;
|
|
65
|
+
subscription.listeners.delete(listener as Listener);
|
|
66
|
+
if (!subscription.listeners.size) {
|
|
67
|
+
subscription.remove();
|
|
68
|
+
this.subscriptions.delete(type);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
private bindListener(type: AdEventType, subscription: Subscription): () => void {
|
|
74
|
+
const integration = this.getIntegration();
|
|
75
|
+
const ads = integration?.ads ?? this.nativeAds;
|
|
76
|
+
let attached = true;
|
|
77
|
+
const isCurrentSource = () => attached && this.getIntegration() === integration && this.subscriptions.get(type) === subscription;
|
|
78
|
+
const forward: Listener = (event) => {
|
|
79
|
+
// A detached source may still deliver an event queued before the integration changed.
|
|
80
|
+
if (!isCurrentSource() || this.closed) return;
|
|
81
|
+
if (ads === this.nativeAds && integration?.shouldConsumeAdEvent?.(event) === true) return;
|
|
82
|
+
this.dispatch(event, isCurrentSource);
|
|
83
|
+
};
|
|
84
|
+
try {
|
|
85
|
+
ads?.addEventListener(type, forward);
|
|
86
|
+
} catch (error) {
|
|
87
|
+
attached = false;
|
|
88
|
+
ads?.removeEventListener(type, forward);
|
|
89
|
+
throw error;
|
|
90
|
+
}
|
|
91
|
+
return () => {
|
|
92
|
+
attached = false;
|
|
93
|
+
ads?.removeEventListener(type, forward);
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
rebind(): void {
|
|
98
|
+
for (const [type, subscription] of this.subscriptions) {
|
|
99
|
+
subscription.remove();
|
|
100
|
+
subscription.remove = this.bindListener(type, subscription);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
dispatch(event: AdEvent, isCurrentRegistration: () => boolean): void {
|
|
105
|
+
const listeners = this.subscriptions.get(event.type)?.listeners;
|
|
106
|
+
for (const listener of [...(listeners ?? [])]) {
|
|
107
|
+
// Listeners can remove each other or unregister the integration during delivery.
|
|
108
|
+
if (!this.closed && isCurrentRegistration() && listeners?.has(listener)) listener(event);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
close(): void {
|
|
113
|
+
if (this.closed) return;
|
|
114
|
+
this.closed = true;
|
|
115
|
+
const subscriptions = [...this.subscriptions.values()];
|
|
116
|
+
this.subscriptions.clear();
|
|
117
|
+
for (const subscription of subscriptions) subscription.remove();
|
|
118
|
+
}
|
|
119
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { Ads } from 'theoplayer';
|
|
2
|
+
import type { Integration } from '../../../api/player/Integration';
|
|
3
|
+
import type { PlayerFacadeAds, PlayerFacadeAdsEventMap } from './PlayerFacadeTypes';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Describes Web-specific advertising overrides for a player facade integration.
|
|
7
|
+
* Optional overrides leave playback ownership and synchronization policy with the integration.
|
|
8
|
+
*
|
|
9
|
+
* @category Player
|
|
10
|
+
* @platform web
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
export interface PlayerFacadeIntegration extends Integration {
|
|
14
|
+
/**
|
|
15
|
+
* Supplies the Ads API and event source behind the stable public `player.ads` object.
|
|
16
|
+
*
|
|
17
|
+
* @remarks
|
|
18
|
+
* Keep this object stable until the registration closes. Existing listeners migrate on registration and close.
|
|
19
|
+
* Omit it to retain the content player's Ads API and optionally override only its state through {@link getAdState}.
|
|
20
|
+
*/
|
|
21
|
+
readonly ads?: PlayerFacadeAds;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Returns the advertising state for integrations that do not supply an Ads object.
|
|
25
|
+
*
|
|
26
|
+
* @remarks
|
|
27
|
+
* Legacy state override for integrations that do not supply an Ads object.
|
|
28
|
+
* The facade never derives state from dispatched events. Update state before dispatching corresponding events.
|
|
29
|
+
* An explicitly absent current ad break does not fall back to the content player's ad break.
|
|
30
|
+
*
|
|
31
|
+
* @returns The integration's ad state. Ignored when {@link ads} is supplied.
|
|
32
|
+
*/
|
|
33
|
+
getAdState?(): Pick<Ads, 'playing' | 'currentAds' | 'currentAdBreak'>;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Consumes backing Ads events only; integration-generated events bypass this hook.
|
|
37
|
+
*
|
|
38
|
+
* @param event - The content player's advertising event.
|
|
39
|
+
* @returns `true` to hide the event from all facade Ads listeners, or `false` to forward it.
|
|
40
|
+
*
|
|
41
|
+
* @remarks
|
|
42
|
+
* Called once per subscribed event, not once per listener. Events from {@link ads} bypass this hook.
|
|
43
|
+
*/
|
|
44
|
+
shouldConsumeAdEvent?(event: PlayerFacadeAdsEventMap[keyof PlayerFacadeAdsEventMap]): boolean;
|
|
45
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { AdEvent, Ads, AdsEventMap, EventDispatcher, PlayerEventMap } from 'theoplayer';
|
|
2
|
+
|
|
3
|
+
export type { IntegrationRegistration } from './IntegrationRegistration';
|
|
4
|
+
export type { PlayerFacadeAPI as PlayerFacade } from './PlayerFacadeAPI';
|
|
5
|
+
export type { PlayerFacadeIntegration } from './PlayerFacadeIntegration';
|
|
6
|
+
|
|
7
|
+
/** Advertising events supported by the facade, including integration-generated clicks. */
|
|
8
|
+
export type PlayerFacadeAdsEventMap = AdsEventMap & { adclicked: AdEvent<'adclicked'> };
|
|
9
|
+
|
|
10
|
+
/** The Web Ads API with event subscriptions extended to support facade advertising events. */
|
|
11
|
+
export type PlayerFacadeAds = Omit<Ads, 'addEventListener' | 'removeEventListener'> & EventDispatcher<PlayerFacadeAdsEventMap>;
|
|
12
|
+
|
|
13
|
+
/** A native Web player or advertising event that an integration can dispatch through its registration. */
|
|
14
|
+
export type PlayerFacadeEvent = PlayerEventMap[keyof PlayerEventMap] | PlayerFacadeAdsEventMap[keyof PlayerFacadeAdsEventMap];
|
|
@@ -35,7 +35,7 @@ interface ExtractFaiplayContentIdEvent extends NativeContentProtectionEvent {
|
|
|
35
35
|
export class NativeContentProtectionRegistry implements ContentProtectionAPI {
|
|
36
36
|
private emitter: NativeEventEmitter;
|
|
37
37
|
private registeredFactories: WrappedContentProtectionIntegrationFactory[] = [];
|
|
38
|
-
private
|
|
38
|
+
private integrations: Map<string, WrappedContentProtectionIntegration> = new Map();
|
|
39
39
|
|
|
40
40
|
constructor() {
|
|
41
41
|
this.emitter = new NativeEventEmitter(NativeContentProtectionModule);
|
|
@@ -45,14 +45,20 @@ export class NativeContentProtectionRegistry implements ContentProtectionAPI {
|
|
|
45
45
|
this.emitter.addListener('onLicenseRequest', this.onLicenseRequest);
|
|
46
46
|
this.emitter.addListener('onLicenseResponse', this.onLicenseResponse);
|
|
47
47
|
this.emitter.addListener('onExtractFairplayContentId', this.onExtractFairplayContentId);
|
|
48
|
+
this.emitter.addListener('onIntegrationDisposed', this.onIntegrationDisposed);
|
|
48
49
|
}
|
|
49
50
|
|
|
50
51
|
registerContentProtectionIntegration(integrationId: string, keySystemId: KeySystemId, integrationFactory: ContentProtectionIntegrationFactory) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
52
|
+
// Replace a previous registration for the same (integrationId, keySystemId) pair:
|
|
53
|
+
// getFactory() matches the first entry, so pushing duplicates would leave stale
|
|
54
|
+
// factories active while the newly registered factory would never be used.
|
|
55
|
+
const existingIndex = this.registeredFactories.findIndex((f) => f.integrationId === integrationId && f.keySystemId === keySystemId);
|
|
56
|
+
const registration = { integrationId, keySystemId, integrationFactory };
|
|
57
|
+
if (existingIndex === -1) {
|
|
58
|
+
this.registeredFactories.push(registration);
|
|
59
|
+
} else {
|
|
60
|
+
this.registeredFactories[existingIndex] = registration;
|
|
61
|
+
}
|
|
56
62
|
NativeContentProtectionModule.registerContentProtectionIntegration(integrationId, keySystemId);
|
|
57
63
|
}
|
|
58
64
|
|
|
@@ -60,10 +66,18 @@ export class NativeContentProtectionRegistry implements ContentProtectionAPI {
|
|
|
60
66
|
return this.registeredFactories.find((init) => init.integrationId === integrationId && init.keySystemId === keySystemId)?.integrationFactory;
|
|
61
67
|
}
|
|
62
68
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
69
|
+
// Each native content protection integration instance gets its own registry entry,
|
|
70
|
+
// keyed by the integrationInstanceId emitted in bridge events. Events from native builds
|
|
71
|
+
// that predate per-instance routing do not carry an integrationInstanceId; these share a
|
|
72
|
+
// single legacy slot, matching the previous single-integration behaviour.
|
|
73
|
+
private integrationKey(event: NativeContentProtectionEvent): string {
|
|
74
|
+
return event.integrationInstanceId ?? '';
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
private getIntegration(event: NativeContentProtectionEvent): ContentProtectionIntegration | undefined {
|
|
78
|
+
const { integrationId, keySystemId } = event;
|
|
79
|
+
const wrapped = this.integrations.get(this.integrationKey(event));
|
|
80
|
+
return wrapped?.integrationId === integrationId && wrapped?.keySystemId === keySystemId ? wrapped?.integration : undefined;
|
|
67
81
|
}
|
|
68
82
|
|
|
69
83
|
private onBuildIntegrationRequest = (event: BuildEvent) => {
|
|
@@ -71,11 +85,11 @@ export class NativeContentProtectionRegistry implements ContentProtectionAPI {
|
|
|
71
85
|
console.log('NativeContentProtectionModule', `onBuildIntegrationRequest ${integrationId} ${keySystemId}`);
|
|
72
86
|
const factory = this.getFactory(integrationId, keySystemId);
|
|
73
87
|
if (factory) {
|
|
74
|
-
this.
|
|
88
|
+
this.integrations.set(this.integrationKey(event), {
|
|
75
89
|
integrationId,
|
|
76
90
|
keySystemId,
|
|
77
91
|
integration: factory.build(drmConfig),
|
|
78
|
-
};
|
|
92
|
+
});
|
|
79
93
|
NativeContentProtectionModule.onBuildProcessed({ requestId, resultString: 'success' });
|
|
80
94
|
} else {
|
|
81
95
|
NativeContentProtectionModule.onBuildProcessed({
|
|
@@ -88,7 +102,7 @@ export class NativeContentProtectionRegistry implements ContentProtectionAPI {
|
|
|
88
102
|
private onCertificateRequest = async (request: NativeCertificateRequest) => {
|
|
89
103
|
const { requestId, integrationId, keySystemId } = request;
|
|
90
104
|
console.log('NativeContentProtectionModule', `onCertificateRequest ${integrationId} ${keySystemId}`);
|
|
91
|
-
const integration = this.getIntegration(
|
|
105
|
+
const integration = this.getIntegration(request);
|
|
92
106
|
if (integration?.onCertificateRequest) {
|
|
93
107
|
const result = await integration.onCertificateRequest(fromNativeCertificateRequest(request));
|
|
94
108
|
// TODO: we also want to support ArrayBufferView results
|
|
@@ -107,7 +121,7 @@ export class NativeContentProtectionRegistry implements ContentProtectionAPI {
|
|
|
107
121
|
private onCertificateResponse = async (response: NativeCertificateResponse) => {
|
|
108
122
|
const { requestId, integrationId, keySystemId } = response;
|
|
109
123
|
console.log('NativeContentProtectionModule', `onCertificateResponse ${integrationId} ${keySystemId}`);
|
|
110
|
-
const integration = this.getIntegration(
|
|
124
|
+
const integration = this.getIntegration(response);
|
|
111
125
|
if (integration?.onCertificateResponse) {
|
|
112
126
|
const responseResult = await integration.onCertificateResponse(fromNativeCertificateResponse(response));
|
|
113
127
|
// TODO: we also want to support ArrayBufferView results
|
|
@@ -121,7 +135,7 @@ export class NativeContentProtectionRegistry implements ContentProtectionAPI {
|
|
|
121
135
|
private onLicenseRequest = async (request: NativeLicenseRequest) => {
|
|
122
136
|
const { requestId, integrationId, keySystemId } = request;
|
|
123
137
|
console.log('NativeContentProtectionModule', `onLicenseRequest ${integrationId} ${keySystemId}`);
|
|
124
|
-
const integration = this.getIntegration(
|
|
138
|
+
const integration = this.getIntegration(request);
|
|
125
139
|
// Optionally let the custom integration modify the request.
|
|
126
140
|
if (integration?.onLicenseRequest) {
|
|
127
141
|
const result = await integration.onLicenseRequest(fromNativeLicenseRequest(request));
|
|
@@ -141,7 +155,7 @@ export class NativeContentProtectionRegistry implements ContentProtectionAPI {
|
|
|
141
155
|
private onLicenseResponse = async (response: NativeLicenseResponse) => {
|
|
142
156
|
const { requestId, integrationId, keySystemId } = response;
|
|
143
157
|
console.log('NativeContentProtectionModule', `onLicenseResponse ${integrationId} ${keySystemId}`);
|
|
144
|
-
const integration = this.getIntegration(
|
|
158
|
+
const integration = this.getIntegration(response);
|
|
145
159
|
if (integration?.onLicenseResponse) {
|
|
146
160
|
const responseResult = await integration.onLicenseResponse(fromNativeLicenseResponse(response));
|
|
147
161
|
// TODO: we also want to support ArrayBufferView results
|
|
@@ -155,7 +169,7 @@ export class NativeContentProtectionRegistry implements ContentProtectionAPI {
|
|
|
155
169
|
private onExtractFairplayContentId = async (event: ExtractFaiplayContentIdEvent) => {
|
|
156
170
|
const { integrationId, keySystemId, fairplaySkdUrl, requestId } = event;
|
|
157
171
|
console.log('NativeContentProtectionModule', `onExtractFairplayContentId ${integrationId} ${keySystemId}`);
|
|
158
|
-
const integration = this.getIntegration(
|
|
172
|
+
const integration = this.getIntegration(event);
|
|
159
173
|
if (integration?.extractFairplayContentId) {
|
|
160
174
|
const contentId = await integration.extractFairplayContentId(fairplaySkdUrl);
|
|
161
175
|
NativeContentProtectionModule.onExtractFairplayContentIdProcessed({
|
|
@@ -170,6 +184,10 @@ export class NativeContentProtectionRegistry implements ContentProtectionAPI {
|
|
|
170
184
|
});
|
|
171
185
|
}
|
|
172
186
|
};
|
|
187
|
+
|
|
188
|
+
private onIntegrationDisposed = (event: NativeContentProtectionEvent) => {
|
|
189
|
+
this.integrations.delete(this.integrationKey(event));
|
|
190
|
+
};
|
|
173
191
|
}
|
|
174
192
|
|
|
175
193
|
/**
|
|
@@ -2,4 +2,9 @@ export interface NativeContentProtectionEvent {
|
|
|
2
2
|
requestId: string;
|
|
3
3
|
integrationId: string;
|
|
4
4
|
keySystemId: string;
|
|
5
|
+
/**
|
|
6
|
+
* Unique identifier of the native content protection integration instance that emitted the event.
|
|
7
|
+
* Absent on events emitted by native builds predating per-instance routing.
|
|
8
|
+
*/
|
|
9
|
+
integrationInstanceId?: string;
|
|
5
10
|
}
|
package/src/manifest.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"11.
|
|
1
|
+
{"version":"11.8.0","buildDate":"2026-10-21T13:28:57.701Z"}
|