react-native-theoplayer 8.15.0 → 8.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (145) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/README.md +1 -0
  3. package/android/src/main/java/com/theoplayer/ReactTHEOplayerContext.kt +6 -2
  4. package/android/src/main/java/com/theoplayer/ReactTHEOplayerView.kt +2 -2
  5. package/android/src/main/java/com/theoplayer/drm/ContentProtectionAdapter.kt +39 -9
  6. package/android/src/main/java/com/theoplayer/player/PlayerModule.kt +7 -0
  7. package/android/src/main/java/com/theoplayer/source/SourceAdapter.kt +7 -5
  8. package/android/src/main/java/com/theoplayer/util/BridgeUtils.kt +2 -2
  9. package/ios/THEOplayerRCTBridge.m +6 -0
  10. package/ios/THEOplayerRCTPlayerAPI.swift +27 -0
  11. package/ios/THEOplayerRCTSourceDescriptionBuilder.swift +5 -1
  12. package/ios/THEOplayerRCTTypeUtils.swift +2 -2
  13. package/ios/THEOplayerRCTView.swift +2 -0
  14. package/ios/ads/THEOplayerRCTAdsEventHandler.swift +2 -2
  15. package/ios/backgroundAudio/THEOplayerRCTView+BackgroundAudioConfig.swift +1 -1
  16. package/ios/pip/THEOplayerRCTPipControlsManager.swift +5 -1
  17. package/ios/pip/THEOplayerRCTView+PipConfig.swift +2 -1
  18. package/ios/presentationMode/THEOplayerRCTPresentationModeManager.swift +8 -0
  19. package/ios/theoAds/THEOplayerRCTSourceDescriptionBuilder+TheoAds.swift +3 -1
  20. package/lib/commonjs/api/barrel.js +11 -0
  21. package/lib/commonjs/api/barrel.js.map +1 -1
  22. package/lib/commonjs/api/event/TheoAdsEvent.js +15 -0
  23. package/lib/commonjs/api/event/TheoAdsEvent.js.map +1 -0
  24. package/lib/commonjs/api/event/barrel.js +11 -0
  25. package/lib/commonjs/api/event/barrel.js.map +1 -1
  26. package/lib/commonjs/api/player/PlayerEventMap.js +1 -0
  27. package/lib/commonjs/api/player/PlayerEventMap.js.map +1 -1
  28. package/lib/commonjs/api/source/ads/TheoAdDescription.js.map +1 -1
  29. package/lib/commonjs/api/theoads/TheoAdsAPI.js +6 -0
  30. package/lib/commonjs/api/theoads/TheoAdsAPI.js.map +1 -0
  31. package/lib/commonjs/api/theoads/barrel.js +50 -0
  32. package/lib/commonjs/api/theoads/barrel.js.map +1 -0
  33. package/lib/commonjs/api/theoads/interstitial/AdBreakInterstitial.js +6 -0
  34. package/lib/commonjs/api/theoads/interstitial/AdBreakInterstitial.js.map +1 -0
  35. package/lib/commonjs/api/theoads/interstitial/Interstitial.js +2 -0
  36. package/lib/commonjs/api/theoads/interstitial/Interstitial.js.map +1 -0
  37. package/lib/commonjs/api/theoads/interstitial/OverlayInterstitial.js +6 -0
  38. package/lib/commonjs/api/theoads/interstitial/OverlayInterstitial.js.map +1 -0
  39. package/lib/commonjs/internal/adapter/THEOplayerAdapter.js +3 -20
  40. package/lib/commonjs/internal/adapter/THEOplayerAdapter.js.map +1 -1
  41. package/lib/commonjs/internal/adapter/THEOplayerWebAdapter.js +7 -2
  42. package/lib/commonjs/internal/adapter/THEOplayerWebAdapter.js.map +1 -1
  43. package/lib/commonjs/internal/adapter/WebEventForwarder.js +6 -4
  44. package/lib/commonjs/internal/adapter/WebEventForwarder.js.map +1 -1
  45. package/lib/commonjs/internal/adapter/event/PlayerEvents.js +9 -1
  46. package/lib/commonjs/internal/adapter/event/PlayerEvents.js.map +1 -1
  47. package/lib/commonjs/internal/adapter/theoads/THEOAdsWebAdapter.js +22 -0
  48. package/lib/commonjs/internal/adapter/theoads/THEOAdsWebAdapter.js.map +1 -0
  49. package/lib/commonjs/internal/adapter/web/WebMediaSession.js +40 -27
  50. package/lib/commonjs/internal/adapter/web/WebMediaSession.js.map +1 -1
  51. package/lib/commonjs/internal/adapter/web/WebPresentationModeManager.js +5 -1
  52. package/lib/commonjs/internal/adapter/web/WebPresentationModeManager.js.map +1 -1
  53. package/lib/commonjs/manifest.json +1 -1
  54. package/lib/module/api/barrel.js +1 -0
  55. package/lib/module/api/barrel.js.map +1 -1
  56. package/lib/module/api/event/TheoAdsEvent.js +9 -0
  57. package/lib/module/api/event/TheoAdsEvent.js.map +1 -0
  58. package/lib/module/api/event/barrel.js +1 -0
  59. package/lib/module/api/event/barrel.js.map +1 -1
  60. package/lib/module/api/player/PlayerEventMap.js +1 -0
  61. package/lib/module/api/player/PlayerEventMap.js.map +1 -1
  62. package/lib/module/api/source/ads/TheoAdDescription.js.map +1 -1
  63. package/lib/module/api/theoads/TheoAdsAPI.js +2 -0
  64. package/lib/module/api/theoads/TheoAdsAPI.js.map +1 -0
  65. package/lib/module/api/theoads/barrel.js +5 -0
  66. package/lib/module/api/theoads/barrel.js.map +1 -0
  67. package/lib/module/api/theoads/interstitial/AdBreakInterstitial.js +2 -0
  68. package/lib/module/api/theoads/interstitial/AdBreakInterstitial.js.map +1 -0
  69. package/lib/module/api/theoads/interstitial/Interstitial.js +2 -0
  70. package/lib/module/api/theoads/interstitial/Interstitial.js.map +1 -0
  71. package/lib/module/api/theoads/interstitial/OverlayInterstitial.js +2 -0
  72. package/lib/module/api/theoads/interstitial/OverlayInterstitial.js.map +1 -0
  73. package/lib/module/internal/adapter/THEOplayerAdapter.js +3 -20
  74. package/lib/module/internal/adapter/THEOplayerAdapter.js.map +1 -1
  75. package/lib/module/internal/adapter/THEOplayerWebAdapter.js +7 -2
  76. package/lib/module/internal/adapter/THEOplayerWebAdapter.js.map +1 -1
  77. package/lib/module/internal/adapter/WebEventForwarder.js +8 -6
  78. package/lib/module/internal/adapter/WebEventForwarder.js.map +1 -1
  79. package/lib/module/internal/adapter/event/PlayerEvents.js +7 -0
  80. package/lib/module/internal/adapter/event/PlayerEvents.js.map +1 -1
  81. package/lib/module/internal/adapter/theoads/THEOAdsWebAdapter.js +15 -0
  82. package/lib/module/internal/adapter/theoads/THEOAdsWebAdapter.js.map +1 -0
  83. package/lib/module/internal/adapter/web/WebMediaSession.js +40 -27
  84. package/lib/module/internal/adapter/web/WebMediaSession.js.map +1 -1
  85. package/lib/module/internal/adapter/web/WebPresentationModeManager.js +5 -1
  86. package/lib/module/internal/adapter/web/WebPresentationModeManager.js.map +1 -1
  87. package/lib/module/manifest.json +1 -1
  88. package/lib/typescript/api/barrel.d.ts +1 -0
  89. package/lib/typescript/api/barrel.d.ts.map +1 -1
  90. package/lib/typescript/api/event/TheoAdsEvent.d.ts +35 -0
  91. package/lib/typescript/api/event/TheoAdsEvent.d.ts.map +1 -0
  92. package/lib/typescript/api/event/barrel.d.ts +1 -0
  93. package/lib/typescript/api/event/barrel.d.ts.map +1 -1
  94. package/lib/typescript/api/pip/PiPConfiguration.d.ts +8 -1
  95. package/lib/typescript/api/pip/PiPConfiguration.d.ts.map +1 -1
  96. package/lib/typescript/api/player/PlayerEventMap.d.ts +6 -0
  97. package/lib/typescript/api/player/PlayerEventMap.d.ts.map +1 -1
  98. package/lib/typescript/api/player/THEOplayer.d.ts +1 -1
  99. package/lib/typescript/api/source/ads/TheoAdDescription.d.ts +16 -0
  100. package/lib/typescript/api/source/ads/TheoAdDescription.d.ts.map +1 -1
  101. package/lib/typescript/api/theoads/TheoAdsAPI.d.ts +30 -0
  102. package/lib/typescript/api/theoads/TheoAdsAPI.d.ts.map +1 -0
  103. package/lib/typescript/api/theoads/barrel.d.ts +5 -0
  104. package/lib/typescript/api/theoads/barrel.d.ts.map +1 -0
  105. package/lib/typescript/api/theoads/interstitial/AdBreakInterstitial.d.ts +34 -0
  106. package/lib/typescript/api/theoads/interstitial/AdBreakInterstitial.d.ts.map +1 -0
  107. package/lib/typescript/api/theoads/interstitial/Interstitial.d.ts +33 -0
  108. package/lib/typescript/api/theoads/interstitial/Interstitial.d.ts.map +1 -0
  109. package/lib/typescript/api/theoads/interstitial/OverlayInterstitial.d.ts +49 -0
  110. package/lib/typescript/api/theoads/interstitial/OverlayInterstitial.d.ts.map +1 -0
  111. package/lib/typescript/internal/adapter/THEOplayerAdapter.d.ts +0 -2
  112. package/lib/typescript/internal/adapter/THEOplayerAdapter.d.ts.map +1 -1
  113. package/lib/typescript/internal/adapter/THEOplayerWebAdapter.d.ts +3 -0
  114. package/lib/typescript/internal/adapter/THEOplayerWebAdapter.d.ts.map +1 -1
  115. package/lib/typescript/internal/adapter/WebEventForwarder.d.ts +1 -1
  116. package/lib/typescript/internal/adapter/WebEventForwarder.d.ts.map +1 -1
  117. package/lib/typescript/internal/adapter/event/PlayerEvents.d.ts +7 -0
  118. package/lib/typescript/internal/adapter/event/PlayerEvents.d.ts.map +1 -1
  119. package/lib/typescript/internal/adapter/theoads/THEOAdsWebAdapter.d.ts +11 -0
  120. package/lib/typescript/internal/adapter/theoads/THEOAdsWebAdapter.d.ts.map +1 -0
  121. package/lib/typescript/internal/adapter/web/WebMediaSession.d.ts +4 -6
  122. package/lib/typescript/internal/adapter/web/WebMediaSession.d.ts.map +1 -1
  123. package/lib/typescript/internal/adapter/web/WebPresentationModeManager.d.ts.map +1 -1
  124. package/package.json +2 -2
  125. package/react-native-theoplayer.podspec +6 -6
  126. package/src/api/barrel.ts +1 -0
  127. package/src/api/event/TheoAdsEvent.ts +41 -0
  128. package/src/api/event/barrel.ts +1 -0
  129. package/src/api/pip/PiPConfiguration.ts +9 -1
  130. package/src/api/player/PlayerEventMap.ts +7 -0
  131. package/src/api/player/THEOplayer.ts +1 -1
  132. package/src/api/source/ads/TheoAdDescription.ts +19 -0
  133. package/src/api/theoads/TheoAdsAPI.ts +33 -0
  134. package/src/api/theoads/barrel.ts +4 -0
  135. package/src/api/theoads/interstitial/AdBreakInterstitial.ts +39 -0
  136. package/src/api/theoads/interstitial/Interstitial.ts +36 -0
  137. package/src/api/theoads/interstitial/OverlayInterstitial.ts +55 -0
  138. package/src/internal/adapter/THEOplayerAdapter.ts +3 -22
  139. package/src/internal/adapter/THEOplayerWebAdapter.ts +10 -2
  140. package/src/internal/adapter/WebEventForwarder.ts +18 -8
  141. package/src/internal/adapter/event/PlayerEvents.ts +11 -0
  142. package/src/internal/adapter/theoads/THEOAdsWebAdapter.ts +23 -0
  143. package/src/internal/adapter/web/WebMediaSession.ts +39 -30
  144. package/src/internal/adapter/web/WebPresentationModeManager.ts +6 -1
  145. package/src/manifest.json +1 -1
@@ -0,0 +1,36 @@
1
+ /**
2
+ * The type of the interstitial.
3
+ *
4
+ * @category THEOads
5
+ * @public
6
+ */
7
+ export type InterstitialType = 'adbreak' | 'overlay';
8
+
9
+ /**
10
+ * The THEOads interstitial.
11
+ *
12
+ * @category THEOads
13
+ * @public
14
+ */
15
+ export interface Interstitial {
16
+ /**
17
+ * The type of the interstitial.
18
+ */
19
+ type: InterstitialType;
20
+
21
+ /**
22
+ * The identifier of the interstitial.
23
+ */
24
+ id: string;
25
+
26
+ /**
27
+ * The start time at which the interstitial will start.
28
+ */
29
+ startTime: number;
30
+
31
+ /**
32
+ * The duration of the interstitial, in seconds.
33
+ *
34
+ */
35
+ duration: number | undefined;
36
+ }
@@ -0,0 +1,55 @@
1
+ import { Interstitial } from './Interstitial';
2
+
3
+ /**
4
+ * The THEOads interstitial that corresponds with overlay playback.
5
+ *
6
+ * @category THEOads
7
+ * @public
8
+ */
9
+ export interface OverlayInterstitial extends Interstitial {
10
+ type: 'overlay';
11
+
12
+ /**
13
+ * The url of the image of the overlay.
14
+ */
15
+ imageUrl: string | undefined;
16
+
17
+ /**
18
+ * The clickThrough url of the overlay.
19
+ */
20
+ clickThrough: string | undefined;
21
+
22
+ /**
23
+ * The position of the overlay.
24
+ */
25
+ position: OverlayPosition;
26
+
27
+ /**
28
+ * The size of the overlay.
29
+ */
30
+ size: OverlaySize;
31
+ }
32
+
33
+ /**
34
+ * The position information of the overlay.
35
+ *
36
+ * @category THEOads
37
+ * @public
38
+ */
39
+ export interface OverlayPosition {
40
+ left?: number;
41
+ right?: number;
42
+ top?: number;
43
+ bottom?: number;
44
+ }
45
+
46
+ /**
47
+ * The size information of the overlay.
48
+ *
49
+ * @category THEOads
50
+ * @public
51
+ */
52
+ export interface OverlaySize {
53
+ width?: number;
54
+ height?: number;
55
+ }
@@ -68,7 +68,6 @@ export class THEOplayerAdapter extends DefaultEventDispatcher<PlayerEventMap> im
68
68
  this._abrAdapter = new AbrAdapter(this._view);
69
69
  this._textTrackStyleAdapter = new TextTrackStyleAdapter(this._view);
70
70
 
71
- this.addEventListener(PlayerEventType.SOURCE_CHANGE, this.onSourceChange);
72
71
  this.addEventListener(PlayerEventType.LOADED_METADATA, this.onLoadedMetadata);
73
72
  this.addEventListener(PlayerEventType.PAUSE, this.onPause);
74
73
  this.addEventListener(PlayerEventType.PLAYING, this.onPlaying);
@@ -84,10 +83,6 @@ export class THEOplayerAdapter extends DefaultEventDispatcher<PlayerEventMap> im
84
83
  this.addEventListener(PlayerEventType.RESIZE, this.onResize);
85
84
  }
86
85
 
87
- private onSourceChange = () => {
88
- this.applyAutoplay();
89
- };
90
-
91
86
  private hasValidSource(): boolean {
92
87
  return this._state.source !== undefined;
93
88
  }
@@ -206,21 +201,9 @@ export class THEOplayerAdapter extends DefaultEventDispatcher<PlayerEventMap> im
206
201
  return this._adsAdapter;
207
202
  }
208
203
 
209
- private applyAutoplay() {
210
- if (!this.hasValidSource()) {
211
- return;
212
- }
213
- if (this._state.autoplay) {
214
- this.play();
215
- }
216
- }
217
-
218
204
  set autoplay(autoplay: boolean) {
219
205
  this._state.autoplay = autoplay;
220
-
221
- // Apply autoplay in case a source was already set.
222
- // If autoplay is changed before setting a source, `onSourceChange` applies autoplay.
223
- this.applyAutoplay();
206
+ NativePlayerModule.setAutoplay(this._view.nativeHandle, autoplay);
224
207
  }
225
208
 
226
209
  get autoplay(): boolean {
@@ -463,10 +446,8 @@ export class THEOplayerAdapter extends DefaultEventDispatcher<PlayerEventMap> im
463
446
  }
464
447
 
465
448
  set keepScreenOn(value: boolean) {
466
- if (Platform.OS === 'android') {
467
- this._state.keepScreenOn = value;
468
- NativePlayerModule.setKeepScreenOn(this._view.nativeHandle, value);
469
- }
449
+ this._state.keepScreenOn = value;
450
+ NativePlayerModule.setKeepScreenOn(this._view.nativeHandle, value);
470
451
  }
471
452
 
472
453
  pause(): void {
@@ -28,6 +28,8 @@ import { BaseEvent } from './event/BaseEvent';
28
28
  import { EventBroadcastAdapter } from './broadcast/EventBroadcastAdapter';
29
29
  import { TextTrackState } from './NativePlayerState';
30
30
  import { DefaultTextTrackState } from './DefaultTextTrackState';
31
+ import { TheoAdsAPI } from '../../api/theoads/TheoAdsAPI';
32
+ import { THEOAdsWebAdapter } from './theoads/THEOAdsWebAdapter';
31
33
 
32
34
  const defaultBackgroundAudioConfiguration: BackgroundAudioConfiguration = {
33
35
  enabled: false,
@@ -40,6 +42,7 @@ const defaultPipConfiguration: PiPConfiguration = {
40
42
  export class THEOplayerWebAdapter extends DefaultEventDispatcher<PlayerEventMap> implements THEOplayer {
41
43
  private readonly _adsAdapter: THEOplayerWebAdsAdapter;
42
44
  private readonly _castAdapter: THEOplayerWebCastAdapter;
45
+ private readonly _theoAdsAdapter: THEOAdsWebAdapter;
43
46
  private readonly _textTrackState: TextTrackState;
44
47
  private readonly _presentationModeManager: WebPresentationModeManager;
45
48
  private _player: NativeChromelessPlayer | undefined;
@@ -55,6 +58,7 @@ export class THEOplayerWebAdapter extends DefaultEventDispatcher<PlayerEventMap>
55
58
  this._player = player;
56
59
  this._adsAdapter = new THEOplayerWebAdsAdapter(this._player);
57
60
  this._castAdapter = new THEOplayerWebCastAdapter(this._player);
61
+ this._theoAdsAdapter = new THEOAdsWebAdapter(this._player);
58
62
  this._textTrackState = new DefaultTextTrackState(this);
59
63
  this._eventForwarder = new WebEventForwarder(this._player, this);
60
64
  this._presentationModeManager = new WebPresentationModeManager(this._player, this);
@@ -155,7 +159,7 @@ export class THEOplayerWebAdapter extends DefaultEventDispatcher<PlayerEventMap>
155
159
  this._backgroundAudioConfiguration = config;
156
160
 
157
161
  // Notify media session
158
- this._mediaSession?.updateActionHandlers();
162
+ this._mediaSession?.updateMediaSession();
159
163
  }
160
164
 
161
165
  get volume(): number {
@@ -312,6 +316,10 @@ export class THEOplayerWebAdapter extends DefaultEventDispatcher<PlayerEventMap>
312
316
  return this._adsAdapter;
313
317
  }
314
318
 
319
+ public get theoads(): TheoAdsAPI {
320
+ return this._theoAdsAdapter;
321
+ }
322
+
315
323
  public get cast(): CastAPI {
316
324
  return this._castAdapter;
317
325
  }
@@ -345,7 +353,7 @@ export class THEOplayerWebAdapter extends DefaultEventDispatcher<PlayerEventMap>
345
353
  }
346
354
  }
347
355
  // Apply media session controls
348
- this._mediaSession?.updateActionHandlers();
356
+ this._mediaSession?.updateMediaSession();
349
357
  };
350
358
 
351
359
  get nativeHandle(): NativeHandleType {
@@ -7,7 +7,6 @@ import type {
7
7
  ErrorEvent as NativeErrorEvent,
8
8
  Event as NativeEvent,
9
9
  MediaTrack as NativeMediaTrack,
10
- PresentationModeChangeEvent,
11
10
  RateChangeEvent as NativeRateChangeEvent,
12
11
  ReadyStateChangeEvent as NativeReadyStateChangeEvent,
13
12
  RemoveTrackEvent,
@@ -17,6 +16,8 @@ import type {
17
16
  TrackChangeEvent,
18
17
  VolumeChangeEvent as NativeVolumeChangeEvent,
19
18
  DimensionChangeEvent as NativeDimensionChangeEvent,
19
+ TheoAdsEventsMap as NativeTheoAdsEventMap,
20
+ InterstitialEvent,
20
21
  } from 'theoplayer';
21
22
  import type { AdEvent, MediaTrack, TimeRange } from 'react-native-theoplayer';
22
23
  import {
@@ -25,11 +26,11 @@ import {
25
26
  MediaTrackEventType,
26
27
  MediaTrackType,
27
28
  PlayerEventType,
28
- PresentationMode,
29
29
  TextTrackEventType,
30
30
  TextTrackKind,
31
31
  TextTrackMode,
32
32
  TrackListEventType,
33
+ TheoAdsEventType,
33
34
  } from 'react-native-theoplayer';
34
35
  import type { THEOplayerWebAdapter } from './THEOplayerWebAdapter';
35
36
  import { BaseEvent } from './event/BaseEvent';
@@ -43,7 +44,6 @@ import {
43
44
  DefaultLoadedMetadataEvent,
44
45
  DefaultMediaTrackEvent,
45
46
  DefaultMediaTrackListEvent,
46
- DefaultPresentationModeChangeEvent,
47
47
  DefaultProgressEvent,
48
48
  DefaultRateChangeEvent,
49
49
  DefaultReadyStateChangeEvent,
@@ -51,6 +51,7 @@ import {
51
51
  DefaultSegmentNotFoundEvent,
52
52
  DefaultTextTrackEvent,
53
53
  DefaultTextTrackListEvent,
54
+ DefaultTheoAdsEvent,
54
55
  DefaultTimeupdateEvent,
55
56
  DefaultVolumeChangeEvent,
56
57
  } from './event/PlayerEvents';
@@ -106,6 +107,7 @@ export class WebEventForwarder {
106
107
  this._player.cast?.airplay?.addEventListener('statechange', this.onAirplayStateChange);
107
108
 
108
109
  this._player.ads?.addEventListener(FORWARDED_AD_EVENTS, this.onAdEvent);
110
+ this._player.theoads?.addEventListener(FORWARDED_THEOADS_EVENTS, this.onTheoAdsEvent);
109
111
  }
110
112
 
111
113
  unload(): void {
@@ -133,7 +135,6 @@ export class WebEventForwarder {
133
135
  this._player.removeEventListener('ratechange', this.onPlaybackRateChange);
134
136
  this._player.removeEventListener('segmentnotfound', this.onSegmentNotFound);
135
137
  this._player.removeEventListener('volumechange', this.onVolumeChangeEvent);
136
- this._player.presentation.removeEventListener('presentationmodechange', this.onPresentationModeChange);
137
138
 
138
139
  this._player.textTracks.removeEventListener('addtrack', this.onAddTextTrack);
139
140
  this._player.textTracks.removeEventListener('removetrack', this.onRemoveTextTrack);
@@ -152,6 +153,7 @@ export class WebEventForwarder {
152
153
  this._player.cast?.airplay?.removeEventListener('statechange', this.onAirplayStateChange);
153
154
 
154
155
  this._player.ads?.removeEventListener(FORWARDED_AD_EVENTS, this.onAdEvent);
156
+ this._player.theoads?.removeEventListener(FORWARDED_THEOADS_EVENTS, this.onTheoAdsEvent);
155
157
  }
156
158
 
157
159
  private readonly onSourceChange = () => {
@@ -249,10 +251,6 @@ export class WebEventForwarder {
249
251
  this._facade.dispatchEvent(new DefaultVolumeChangeEvent(event.volume, this._player.muted));
250
252
  };
251
253
 
252
- private readonly onPresentationModeChange = (event: PresentationModeChangeEvent) => {
253
- this._facade.dispatchEvent(new DefaultPresentationModeChangeEvent(event.presentationMode as PresentationMode, PresentationMode.inline)); // TODO: move to extended event
254
- };
255
-
256
254
  private readonly onDimensionChange = (event: NativeDimensionChangeEvent) => {
257
255
  this._facade.dispatchEvent(new DefaultResizeEvent(event.width, event.height));
258
256
  };
@@ -340,6 +338,10 @@ export class WebEventForwarder {
340
338
  this._facade.dispatchEvent(new DefaultAdEvent(event.type as AdEventType, castedEvent.ad));
341
339
  };
342
340
 
341
+ private readonly onTheoAdsEvent = (event: InterstitialEvent<any>) => {
342
+ this._facade.dispatchEvent(new DefaultTheoAdsEvent(event.type as TheoAdsEventType, event.interstitial));
343
+ };
344
+
343
345
  private readonly onAddTextTrackCue = (track: NativeTextTrack) => (event: NativeEvent<'addcue'>) => {
344
346
  const { cue } = event as unknown as { cue: NativeTextTrackCue };
345
347
  if (cue) {
@@ -398,6 +400,14 @@ const FORWARDED_AD_EVENTS = [
398
400
  AdEventType.AD_BUFFERING,
399
401
  ] as (keyof NativeAdsEventMap)[];
400
402
 
403
+ const FORWARDED_THEOADS_EVENTS = [
404
+ TheoAdsEventType.ADD_INTERSTITIAL,
405
+ TheoAdsEventType.INTERSTITIAL_BEGIN,
406
+ TheoAdsEventType.INTERSTITIAL_END,
407
+ TheoAdsEventType.INTERSTITIAL_UPDATE,
408
+ TheoAdsEventType.INTERSTITIAL_ERROR,
409
+ ] as (keyof NativeTheoAdsEventMap)[];
410
+
401
411
  function fromTimeRanges(timeRanges: TimeRanges): TimeRange[] {
402
412
  const result: TimeRange[] = [];
403
413
  for (let i = 0; i < timeRanges.length; i++) {
@@ -39,6 +39,8 @@ import {
39
39
  TrackListEventType,
40
40
  VolumeChangeEvent,
41
41
  } from 'react-native-theoplayer';
42
+ import { TheoAdsEvent, TheoAdsEventType } from '../../../api/event/TheoAdsEvent';
43
+ import { Interstitial } from '../../../api/theoads/interstitial/Interstitial';
42
44
 
43
45
  export class DefaultLoadedMetadataEvent extends BaseEvent<PlayerEventType.LOADED_METADATA> implements LoadedMetadataEvent {
44
46
  constructor(
@@ -183,6 +185,15 @@ export class DefaultAdEvent extends BaseEvent<PlayerEventType.AD_EVENT> implemen
183
185
  }
184
186
  }
185
187
 
188
+ export class DefaultTheoAdsEvent extends BaseEvent<PlayerEventType.THEOADS_EVENT> implements TheoAdsEvent {
189
+ constructor(
190
+ public subType: TheoAdsEventType,
191
+ public interstitial: Interstitial,
192
+ ) {
193
+ super(PlayerEventType.THEOADS_EVENT);
194
+ }
195
+ }
196
+
186
197
  export class DefaultChromecastChangeEvent extends BaseEvent<PlayerEventType.CAST_EVENT> implements ChromecastChangeEvent {
187
198
  readonly subType: CastEventType.CHROMECAST_STATE_CHANGE;
188
199
 
@@ -0,0 +1,23 @@
1
+ import type { ChromelessPlayer } from 'theoplayer';
2
+ import { TheoAdsAPI } from '../../../api/theoads/TheoAdsAPI';
3
+ import { Interstitial } from '../../../api/theoads/interstitial/Interstitial';
4
+
5
+ export class THEOAdsWebAdapter implements TheoAdsAPI {
6
+ private readonly _player: ChromelessPlayer;
7
+
8
+ constructor(player: ChromelessPlayer) {
9
+ this._player = player;
10
+ }
11
+
12
+ get currentInterstitials(): readonly Interstitial[] {
13
+ return this._player.theoads?.currentInterstitials ?? [];
14
+ }
15
+
16
+ get scheduledInterstitials(): readonly Interstitial[] {
17
+ return this._player.theoads?.scheduledInterstitials ?? [];
18
+ }
19
+
20
+ replaceAdTagParameters(adTagParameters?: Record<string, string>): void {
21
+ this._player.theoads?.replaceAdTagParameters(adTagParameters);
22
+ }
23
+ }
@@ -38,30 +38,36 @@ export class WebMediaSession {
38
38
  this._player = player;
39
39
  this._webAdapter = adapter;
40
40
  this._config = config;
41
-
42
41
  this._player.addEventListener('sourcechange', this.onSourceChange);
43
- this._player.addEventListener('loadedmetadata', this.onLoadedMetadata);
44
- this._player.addEventListener('durationchange', this.onDurationChange);
45
- this._player.ads?.addEventListener('adbreakbegin', this.onAdbreakBegin);
46
- this._player.ads?.addEventListener('adbreakend', this.onAdbreakEnd);
47
- this.updateActionHandlers();
48
42
  }
49
43
 
50
- updateActionHandlers() {
51
- if (this.isTrickplayEnabled()) {
44
+ updateMediaSession() {
45
+ // update trickplay capabilities
46
+ if (this.isTrickPlayEnabled()) {
52
47
  mediaSession.setActionHandler('seekbackward', (event) => {
53
48
  const skipTime = event.seekOffset || this._config.skipBackwardInterval || DEFAULT_SKIP_BACKWARD_INTERVAL;
54
49
  this._player.currentTime = Math.max(this._player.currentTime - skipTime, 0);
50
+ this.updatePositionState();
55
51
  });
56
52
  mediaSession.setActionHandler('seekforward', (event) => {
57
53
  const skipTime = event.seekOffset || this._config.skipForwardInterval || DEFAULT_SKIP_FORWARD_INTERVAL;
58
54
  this._player.currentTime = Math.min(this._player.currentTime + skipTime, this._player.duration);
55
+ this.updatePositionState();
56
+ });
57
+ mediaSession.setActionHandler('seekto', (event) => {
58
+ const seekTime = event.seekTime;
59
+ if (seekTime !== undefined) {
60
+ this._player.currentTime = seekTime;
61
+ }
62
+ this.updatePositionState();
59
63
  });
60
64
  } else {
61
65
  mediaSession.setActionHandler('seekbackward', NoOp);
62
66
  mediaSession.setActionHandler('seekforward', NoOp);
67
+ mediaSession.setActionHandler('seekto', NoOp);
63
68
  }
64
69
 
70
+ // update play/pause capabilities
65
71
  if (this.isPlayPauseEnabled()) {
66
72
  mediaSession.setActionHandler('play', () => {
67
73
  this._player?.play();
@@ -73,32 +79,43 @@ export class WebMediaSession {
73
79
  mediaSession.setActionHandler('play', NoOp);
74
80
  mediaSession.setActionHandler('pause', NoOp);
75
81
  }
82
+
83
+ // update playbackState
84
+ mediaSession.playbackState = this._player.paused ? 'paused' : 'playing';
85
+
86
+ // update position
87
+ this.updatePositionState();
76
88
  }
77
89
 
78
90
  destroy() {
79
- this._player.removeEventListener('sourcechange', this.onSourceChange);
80
- this._player.removeEventListener('loadedmetadata', this.onLoadedMetadata);
81
- this._player.removeEventListener('durationchange', this.onDurationChange);
82
- this._player.ads?.removeEventListener('adbreakbegin', this.onAdbreakBegin);
83
- this._player.ads?.removeEventListener('adbreakend', this.onAdbreakEnd);
91
+ this._player.removeEventListener(['play', 'playing'], this.onFirstPlaying);
92
+ this._player.removeEventListener(['play', 'pause', 'loadedmetadata', 'durationchange', 'ratechange'], this.update);
93
+ this._player.ads?.removeEventListener(['adbreakbegin', 'adbreakend'], this.update);
84
94
  mediaSession.setActionHandler('play', NoOp);
85
95
  mediaSession.setActionHandler('pause', NoOp);
86
96
  mediaSession.setActionHandler('seekbackward', NoOp);
87
97
  mediaSession.setActionHandler('seekforward', NoOp);
98
+ mediaSession.setActionHandler('seekto', NoOp);
88
99
  }
89
100
 
90
- private onSourceChange = () => {
91
- this.updateMetadata();
92
- this.updatePositionState();
93
- this.updateActionHandlers();
101
+ private update = () => {
102
+ this.updateMediaSession();
94
103
  };
95
104
 
96
- private onLoadedMetadata = () => {
97
- this.updateActionHandlers();
105
+ private onFirstPlaying = () => {
106
+ this._player.removeEventListener(['play', 'playing'], this.onFirstPlaying);
107
+ this.updateMetadata();
108
+ this._player.addEventListener(['play', 'pause', 'loadedmetadata', 'durationchange', 'ratechange'], this.update);
109
+ this._player.ads?.addEventListener(['adbreakbegin', 'adbreakend'], this.update);
98
110
  };
99
111
 
100
- private onDurationChange = () => {
101
- this.updateActionHandlers();
112
+ private onSourceChange = () => {
113
+ this._player.removeEventListener(['play', 'playing'], this.onFirstPlaying);
114
+ this._player.removeEventListener(['play', 'pause', 'loadedmetadata', 'durationchange', 'ratechange'], this.update);
115
+ this._player.ads?.removeEventListener(['adbreakbegin', 'adbreakend'], this.update);
116
+ mediaSession.metadata = null;
117
+ mediaSession.playbackState = 'none';
118
+ this._player.addEventListener(['play', 'playing'], this.onFirstPlaying);
102
119
  };
103
120
 
104
121
  private updateMetadata = () => {
@@ -140,14 +157,6 @@ export class WebMediaSession {
140
157
  }
141
158
  };
142
159
 
143
- private onAdbreakBegin = () => {
144
- this.updateActionHandlers();
145
- };
146
-
147
- private onAdbreakEnd = () => {
148
- this.updateActionHandlers();
149
- };
150
-
151
160
  private isLive(): boolean {
152
161
  return !isFinite(this._player.duration);
153
162
  }
@@ -163,7 +172,7 @@ export class WebMediaSession {
163
172
  // By default, only show trick-play buttons if:
164
173
  // - backgroundAudio is enabled, or the player is in foreground;
165
174
  // - and, the current asset is neither a live stream, nor an ad.
166
- private isTrickplayEnabled(): boolean {
175
+ private isTrickPlayEnabled(): boolean {
167
176
  return (this.isBackgroundAudioEnabled() || !this.isInBackground()) && !this.isLive() && !this.isInAd();
168
177
  }
169
178
 
@@ -68,7 +68,12 @@ export class WebPresentationModeManager {
68
68
  private updatePresentationMode = () => {
69
69
  // detect new presentation mode
70
70
  let newPresentationMode: PresentationMode = PresentationMode.inline;
71
- if (fullscreenAPI !== undefined && document[fullscreenAPI.fullscreenElement_] !== null) {
71
+ if (
72
+ // Check if we went into fullscreen using the fullscreen API.
73
+ (fullscreenAPI !== undefined && document[fullscreenAPI.fullscreenElement_] !== null) ||
74
+ // or otherwise using player APi
75
+ this._player.presentation.currentMode === PresentationMode.fullscreen
76
+ ) {
72
77
  newPresentationMode = PresentationMode.fullscreen;
73
78
  } else if (this._player.presentation.currentMode === 'native-picture-in-picture') {
74
79
  newPresentationMode = PresentationMode.pip;
package/src/manifest.json CHANGED
@@ -1 +1 @@
1
- {"version":"8.15.0","buildDate":"2025-02-12T15:09:50.188Z"}
1
+ {"version":"8.17.0","buildDate":"2025-03-20T22:23:49.173Z"}