react-native-theoplayer 2.16.1 → 3.0.0-pre1

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 (316) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/README.md +1 -0
  3. package/android/build.gradle +19 -22
  4. package/android/src/main/java/com/theoplayer/PlayerConfigAdapter.kt +87 -101
  5. package/android/src/main/java/com/theoplayer/ReactTHEOplayerContext.kt +30 -30
  6. package/android/src/main/java/com/theoplayer/ReactTHEOplayerPackage.kt +3 -1
  7. package/android/src/main/java/com/theoplayer/ReactTHEOplayerView.kt +1 -1
  8. package/android/src/main/java/com/theoplayer/cache/CacheAdapter.kt +127 -0
  9. package/android/src/main/java/com/theoplayer/cache/CacheModule.kt +238 -0
  10. package/android/src/main/java/com/theoplayer/player/PlayerModule.kt +27 -12
  11. package/android/src/main/java/com/theoplayer/source/SourceAdapter.kt +16 -37
  12. package/android/src/main/java/com/theoplayer/util/BridgeUtils.kt +60 -0
  13. package/android/src/main/java/com/theoplayer/util/PayloadBuilder.kt +10 -10
  14. package/ios/THEOplayerRCTBridge.m +22 -0
  15. package/ios/THEOplayerRCTDebug.swift +7 -1
  16. package/ios/THEOplayerRCTMainEventHandler.swift +25 -27
  17. package/ios/THEOplayerRCTSourceDescriptionAggregator.swift +41 -0
  18. package/ios/THEOplayerRCTSourceDescriptionBuilder.swift +3 -2
  19. package/ios/THEOplayerRCTTypeUtils.swift +37 -0
  20. package/ios/THEOplayerRCTView.swift +1 -2
  21. package/ios/ads/THEOplayerRCTAdsAPI+DAI.swift +3 -13
  22. package/ios/ads/THEOplayerRCTAdsAPI.swift +14 -48
  23. package/ios/ads/THEOplayerRCTView+AdsConfig.swift +0 -13
  24. package/ios/backgroundAudio/THEOplayerRCTNowPlayingManager.swift +24 -36
  25. package/ios/backgroundAudio/THEOplayerRCTRemoteCommandsManager.swift +2 -10
  26. package/ios/cache/THEOplayerRCTCacheAPI.swift +202 -0
  27. package/ios/cache/THEOplayerRCTCacheAggregator.swift +87 -0
  28. package/ios/cache/THEOplayerRCTCachingParametersBuilder.swift +27 -0
  29. package/ios/pip/THEOplayerRCTPipControlsManager.swift +2 -4
  30. package/lib/commonjs/api/abr/ABRConfiguration.js +21 -7
  31. package/lib/commonjs/api/abr/ABRConfiguration.js.map +1 -1
  32. package/lib/commonjs/api/ads/GoogleImaConfiguration.js.map +1 -1
  33. package/lib/commonjs/api/barrel.js +30 -19
  34. package/lib/commonjs/api/barrel.js.map +1 -1
  35. package/lib/commonjs/api/cache/CachingPreferredTrackSelection.js +2 -0
  36. package/lib/commonjs/api/cache/CachingPreferredTrackSelection.js.map +1 -0
  37. package/lib/commonjs/api/cache/CachingTask.js +30 -0
  38. package/lib/commonjs/api/cache/CachingTask.js.map +1 -0
  39. package/lib/commonjs/api/cache/CachingTaskLicense.js +6 -0
  40. package/lib/commonjs/api/cache/CachingTaskLicense.js.map +1 -0
  41. package/lib/commonjs/api/cache/CachingTaskList.js +6 -0
  42. package/lib/commonjs/api/cache/CachingTaskList.js.map +1 -0
  43. package/lib/commonjs/api/cache/CachingTaskParameters.js +6 -0
  44. package/lib/commonjs/api/cache/CachingTaskParameters.js.map +1 -0
  45. package/lib/commonjs/api/cache/MediaCacheAPI.js +24 -0
  46. package/lib/commonjs/api/cache/MediaCacheAPI.js.map +1 -0
  47. package/lib/commonjs/api/cache/barrel.js +83 -0
  48. package/lib/commonjs/api/cache/barrel.js.map +1 -0
  49. package/lib/commonjs/api/cache/events/CacheEvent.js +28 -0
  50. package/lib/commonjs/api/cache/events/CacheEvent.js.map +1 -0
  51. package/lib/commonjs/api/cache/events/CachingTaskEvent.js +17 -0
  52. package/lib/commonjs/api/cache/events/CachingTaskEvent.js.map +1 -0
  53. package/lib/commonjs/api/cache/events/barrel.js +28 -0
  54. package/lib/commonjs/api/cache/events/barrel.js.map +1 -0
  55. package/lib/commonjs/api/cache/hooks/barrel.js +39 -0
  56. package/lib/commonjs/api/cache/hooks/barrel.js.map +1 -0
  57. package/lib/commonjs/api/cache/hooks/useCachingTaskList.js +31 -0
  58. package/lib/commonjs/api/cache/hooks/useCachingTaskList.js.map +1 -0
  59. package/lib/commonjs/api/cache/hooks/useCachingTaskProgress.js +28 -0
  60. package/lib/commonjs/api/cache/hooks/useCachingTaskProgress.js.map +1 -0
  61. package/lib/commonjs/api/cache/hooks/useCachingTaskStatus.js +28 -0
  62. package/lib/commonjs/api/cache/hooks/useCachingTaskStatus.js.map +1 -0
  63. package/lib/commonjs/api/cast/CastState.js +3 -4
  64. package/lib/commonjs/api/cast/CastState.js.map +1 -1
  65. package/lib/commonjs/api/config/PlayerConfiguration.js.map +1 -1
  66. package/lib/commonjs/api/event/AdEvent.js +3 -4
  67. package/lib/commonjs/api/event/AdEvent.js.map +1 -1
  68. package/lib/commonjs/api/event/CastEvent.js +3 -4
  69. package/lib/commonjs/api/event/CastEvent.js.map +1 -1
  70. package/lib/commonjs/api/event/PlayerEvent.js +3 -4
  71. package/lib/commonjs/api/event/PlayerEvent.js.map +1 -1
  72. package/lib/commonjs/api/event/TrackEvent.js +12 -16
  73. package/lib/commonjs/api/event/TrackEvent.js.map +1 -1
  74. package/lib/commonjs/api/player/PlayerEventMap.js +7 -8
  75. package/lib/commonjs/api/player/PlayerEventMap.js.map +1 -1
  76. package/lib/commonjs/api/player/THEOplayer.js +6 -4
  77. package/lib/commonjs/api/player/THEOplayer.js.map +1 -1
  78. package/lib/commonjs/api/presentation/PresentationMode.js +3 -4
  79. package/lib/commonjs/api/presentation/PresentationMode.js.map +1 -1
  80. package/lib/commonjs/api/source/ads/Ads.js +3 -4
  81. package/lib/commonjs/api/source/ads/Ads.js.map +1 -1
  82. package/lib/commonjs/api/track/TextTrack.js +9 -12
  83. package/lib/commonjs/api/track/TextTrack.js.map +1 -1
  84. package/lib/commonjs/api/track/TextTrackStyle.js +3 -4
  85. package/lib/commonjs/api/track/TextTrackStyle.js.map +1 -1
  86. package/lib/commonjs/index.js +9 -1
  87. package/lib/commonjs/index.js.map +1 -1
  88. package/lib/commonjs/internal/THEOplayerView.js +1 -1
  89. package/lib/commonjs/internal/THEOplayerView.js.map +1 -1
  90. package/lib/commonjs/internal/THEOplayerView.style.js +1 -2
  91. package/lib/commonjs/internal/THEOplayerView.style.js.map +1 -1
  92. package/lib/commonjs/internal/THEOplayerView.web.js +5 -5
  93. package/lib/commonjs/internal/THEOplayerView.web.js.map +1 -1
  94. package/lib/commonjs/internal/adapter/THEOplayerAdapter.js.map +1 -1
  95. package/lib/commonjs/internal/adapter/THEOplayerWebAdapter.js +12 -13
  96. package/lib/commonjs/internal/adapter/THEOplayerWebAdapter.js.map +1 -1
  97. package/lib/commonjs/internal/adapter/WebEventForwarder.js +10 -10
  98. package/lib/commonjs/internal/adapter/WebEventForwarder.js.map +1 -1
  99. package/lib/commonjs/internal/adapter/abr/AbrAdapter.js.map +1 -1
  100. package/lib/commonjs/internal/adapter/ads/THEOplayerWebAdsAdapter.js +2 -2
  101. package/lib/commonjs/internal/adapter/ads/THEOplayerWebAdsAdapter.js.map +1 -1
  102. package/lib/commonjs/internal/adapter/cast/THEOplayerNativeCastAdapter.js +1 -1
  103. package/lib/commonjs/internal/adapter/cast/THEOplayerNativeCastAdapter.js.map +1 -1
  104. package/lib/commonjs/internal/adapter/cast/THEOplayerWebCastAdapter.js.map +1 -1
  105. package/lib/commonjs/internal/adapter/event/BaseEvent.js.map +1 -1
  106. package/lib/commonjs/internal/adapter/event/DefaultEventDispatcher.js +1 -1
  107. package/lib/commonjs/internal/adapter/event/DefaultEventDispatcher.js.map +1 -1
  108. package/lib/commonjs/internal/adapter/event/native/NativeTrackEvent.js +12 -16
  109. package/lib/commonjs/internal/adapter/event/native/NativeTrackEvent.js.map +1 -1
  110. package/lib/commonjs/internal/adapter/track/TextTrackStyleAdapter.js.map +1 -1
  111. package/lib/commonjs/internal/adapter/web/FullscreenAPI.js +1 -2
  112. package/lib/commonjs/internal/adapter/web/FullscreenAPI.js.map +1 -1
  113. package/lib/commonjs/internal/adapter/web/WebMediaSession.js +9 -11
  114. package/lib/commonjs/internal/adapter/web/WebMediaSession.js.map +1 -1
  115. package/lib/commonjs/internal/adapter/web/WebPresentationModeManager.js +4 -4
  116. package/lib/commonjs/internal/adapter/web/WebPresentationModeManager.js.map +1 -1
  117. package/lib/commonjs/internal/cache/MediaCache.js +117 -0
  118. package/lib/commonjs/internal/cache/MediaCache.js.map +1 -0
  119. package/lib/commonjs/internal/cache/MediaCache.web.js +54 -0
  120. package/lib/commonjs/internal/cache/MediaCache.web.js.map +1 -0
  121. package/lib/commonjs/internal/cache/NativeCachingTaskAdapter.js +59 -0
  122. package/lib/commonjs/internal/cache/NativeCachingTaskAdapter.js.map +1 -0
  123. package/lib/commonjs/internal/cache/NativeCachingTaskParametersAdapter.js +27 -0
  124. package/lib/commonjs/internal/cache/NativeCachingTaskParametersAdapter.js.map +1 -0
  125. package/lib/commonjs/internal/cache/WebCachingTaskAdapter.js +71 -0
  126. package/lib/commonjs/internal/cache/WebCachingTaskAdapter.js.map +1 -0
  127. package/lib/commonjs/internal/drm/ContentProtectionRegistry.js +1 -2
  128. package/lib/commonjs/internal/drm/ContentProtectionRegistry.js.map +1 -1
  129. package/lib/commonjs/internal/drm/ContentProtectionRegistry.web.js +1 -2
  130. package/lib/commonjs/internal/drm/ContentProtectionRegistry.web.js.map +1 -1
  131. package/lib/commonjs/internal/drm/NativeCertificateResponse.js.map +1 -1
  132. package/lib/commonjs/internal/drm/NativeLicenseResponse.js.map +1 -1
  133. package/lib/commonjs/internal/utils/TypeUtils.js +2 -4
  134. package/lib/commonjs/internal/utils/TypeUtils.js.map +1 -1
  135. package/lib/module/api/abr/ABRConfiguration.js +24 -6
  136. package/lib/module/api/abr/ABRConfiguration.js.map +1 -1
  137. package/lib/module/api/ads/GoogleImaConfiguration.js.map +1 -1
  138. package/lib/module/api/barrel.js +1 -0
  139. package/lib/module/api/barrel.js.map +1 -1
  140. package/lib/module/api/cache/CachingPreferredTrackSelection.js +2 -0
  141. package/lib/module/api/cache/CachingPreferredTrackSelection.js.map +1 -0
  142. package/lib/module/api/cache/CachingTask.js +25 -0
  143. package/lib/module/api/cache/CachingTask.js.map +1 -0
  144. package/lib/module/api/cache/CachingTaskLicense.js +2 -0
  145. package/lib/module/api/cache/CachingTaskLicense.js.map +1 -0
  146. package/lib/module/api/cache/CachingTaskList.js +2 -0
  147. package/lib/module/api/cache/CachingTaskList.js.map +1 -0
  148. package/lib/module/api/cache/CachingTaskParameters.js +2 -0
  149. package/lib/module/api/cache/CachingTaskParameters.js.map +1 -0
  150. package/lib/module/api/cache/MediaCacheAPI.js +19 -0
  151. package/lib/module/api/cache/MediaCacheAPI.js.map +1 -0
  152. package/lib/module/api/cache/barrel.js +8 -0
  153. package/lib/module/api/cache/barrel.js.map +1 -0
  154. package/lib/module/api/cache/events/CacheEvent.js +25 -0
  155. package/lib/module/api/cache/events/CacheEvent.js.map +1 -0
  156. package/lib/module/api/cache/events/CachingTaskEvent.js +12 -0
  157. package/lib/module/api/cache/events/CachingTaskEvent.js.map +1 -0
  158. package/lib/module/api/cache/events/barrel.js +3 -0
  159. package/lib/module/api/cache/events/barrel.js.map +1 -0
  160. package/lib/module/api/cache/hooks/barrel.js +4 -0
  161. package/lib/module/api/cache/hooks/barrel.js.map +1 -0
  162. package/lib/module/api/cache/hooks/useCachingTaskList.js +24 -0
  163. package/lib/module/api/cache/hooks/useCachingTaskList.js.map +1 -0
  164. package/lib/module/api/cache/hooks/useCachingTaskProgress.js +21 -0
  165. package/lib/module/api/cache/hooks/useCachingTaskProgress.js.map +1 -0
  166. package/lib/module/api/cache/hooks/useCachingTaskStatus.js +21 -0
  167. package/lib/module/api/cache/hooks/useCachingTaskStatus.js.map +1 -0
  168. package/lib/module/api/cast/CastState.js +3 -3
  169. package/lib/module/api/cast/CastState.js.map +1 -1
  170. package/lib/module/api/config/PlayerConfiguration.js.map +1 -1
  171. package/lib/module/api/event/AdEvent.js +3 -3
  172. package/lib/module/api/event/AdEvent.js.map +1 -1
  173. package/lib/module/api/event/CastEvent.js +3 -3
  174. package/lib/module/api/event/CastEvent.js.map +1 -1
  175. package/lib/module/api/event/PlayerEvent.js +3 -3
  176. package/lib/module/api/event/PlayerEvent.js.map +1 -1
  177. package/lib/module/api/event/TrackEvent.js +12 -12
  178. package/lib/module/api/event/TrackEvent.js.map +1 -1
  179. package/lib/module/api/player/PlayerEventMap.js +8 -8
  180. package/lib/module/api/player/PlayerEventMap.js.map +1 -1
  181. package/lib/module/api/player/THEOplayer.js +7 -3
  182. package/lib/module/api/player/THEOplayer.js.map +1 -1
  183. package/lib/module/api/presentation/PresentationMode.js +3 -3
  184. package/lib/module/api/presentation/PresentationMode.js.map +1 -1
  185. package/lib/module/api/source/ads/Ads.js +3 -3
  186. package/lib/module/api/source/ads/Ads.js.map +1 -1
  187. package/lib/module/api/track/TextTrack.js +9 -9
  188. package/lib/module/api/track/TextTrack.js.map +1 -1
  189. package/lib/module/api/track/TextTrackStyle.js +3 -3
  190. package/lib/module/api/track/TextTrackStyle.js.map +1 -1
  191. package/lib/module/index.js +1 -0
  192. package/lib/module/index.js.map +1 -1
  193. package/lib/module/internal/THEOplayerView.js +1 -1
  194. package/lib/module/internal/THEOplayerView.js.map +1 -1
  195. package/lib/module/internal/THEOplayerView.web.js +5 -5
  196. package/lib/module/internal/THEOplayerView.web.js.map +1 -1
  197. package/lib/module/internal/adapter/THEOplayerAdapter.js.map +1 -1
  198. package/lib/module/internal/adapter/THEOplayerWebAdapter.js +12 -11
  199. package/lib/module/internal/adapter/THEOplayerWebAdapter.js.map +1 -1
  200. package/lib/module/internal/adapter/WebEventForwarder.js +10 -10
  201. package/lib/module/internal/adapter/WebEventForwarder.js.map +1 -1
  202. package/lib/module/internal/adapter/abr/AbrAdapter.js.map +1 -1
  203. package/lib/module/internal/adapter/ads/THEOplayerWebAdsAdapter.js +2 -2
  204. package/lib/module/internal/adapter/ads/THEOplayerWebAdsAdapter.js.map +1 -1
  205. package/lib/module/internal/adapter/cast/THEOplayerNativeCastAdapter.js +1 -1
  206. package/lib/module/internal/adapter/cast/THEOplayerNativeCastAdapter.js.map +1 -1
  207. package/lib/module/internal/adapter/cast/THEOplayerWebCastAdapter.js.map +1 -1
  208. package/lib/module/internal/adapter/event/BaseEvent.js.map +1 -1
  209. package/lib/module/internal/adapter/event/DefaultEventDispatcher.js +1 -1
  210. package/lib/module/internal/adapter/event/DefaultEventDispatcher.js.map +1 -1
  211. package/lib/module/internal/adapter/event/native/NativeTrackEvent.js +12 -12
  212. package/lib/module/internal/adapter/event/native/NativeTrackEvent.js.map +1 -1
  213. package/lib/module/internal/adapter/track/TextTrackStyleAdapter.js.map +1 -1
  214. package/lib/module/internal/adapter/web/FullscreenAPI.js.map +1 -1
  215. package/lib/module/internal/adapter/web/WebMediaSession.js +8 -9
  216. package/lib/module/internal/adapter/web/WebMediaSession.js.map +1 -1
  217. package/lib/module/internal/adapter/web/WebPresentationModeManager.js +4 -4
  218. package/lib/module/internal/adapter/web/WebPresentationModeManager.js.map +1 -1
  219. package/lib/module/internal/cache/MediaCache.js +110 -0
  220. package/lib/module/internal/cache/MediaCache.js.map +1 -0
  221. package/lib/module/internal/cache/MediaCache.web.js +45 -0
  222. package/lib/module/internal/cache/MediaCache.web.js.map +1 -0
  223. package/lib/module/internal/cache/NativeCachingTaskAdapter.js +52 -0
  224. package/lib/module/internal/cache/NativeCachingTaskAdapter.js.map +1 -0
  225. package/lib/module/internal/cache/NativeCachingTaskParametersAdapter.js +20 -0
  226. package/lib/module/internal/cache/NativeCachingTaskParametersAdapter.js.map +1 -0
  227. package/lib/module/internal/cache/WebCachingTaskAdapter.js +64 -0
  228. package/lib/module/internal/cache/WebCachingTaskAdapter.js.map +1 -0
  229. package/lib/module/internal/drm/ContentProtectionRegistry.js.map +1 -1
  230. package/lib/module/internal/drm/ContentProtectionRegistry.web.js.map +1 -1
  231. package/lib/module/internal/drm/NativeCertificateResponse.js.map +1 -1
  232. package/lib/module/internal/drm/NativeLicenseResponse.js.map +1 -1
  233. package/lib/typescript/api/abr/ABRConfiguration.d.ts +1 -1
  234. package/lib/typescript/api/ads/Ad.d.ts +2 -2
  235. package/lib/typescript/api/ads/AdsConfiguration.d.ts +2 -2
  236. package/lib/typescript/api/ads/GoogleImaConfiguration.d.ts +1 -0
  237. package/lib/typescript/api/barrel.d.ts +1 -0
  238. package/lib/typescript/api/cache/CachingPreferredTrackSelection.d.ts +23 -0
  239. package/lib/typescript/api/cache/CachingTask.d.ts +93 -0
  240. package/lib/typescript/api/cache/CachingTaskLicense.d.ts +14 -0
  241. package/lib/typescript/api/cache/CachingTaskList.d.ts +7 -0
  242. package/lib/typescript/api/cache/CachingTaskParameters.d.ts +57 -0
  243. package/lib/typescript/api/cache/MediaCacheAPI.d.ts +39 -0
  244. package/lib/typescript/api/cache/barrel.d.ts +7 -0
  245. package/lib/typescript/api/cache/events/CacheEvent.d.ts +55 -0
  246. package/lib/typescript/api/cache/events/CachingTaskEvent.d.ts +22 -0
  247. package/lib/typescript/api/cache/events/barrel.d.ts +2 -0
  248. package/lib/typescript/api/cache/hooks/barrel.d.ts +3 -0
  249. package/lib/typescript/api/cache/hooks/useCachingTaskList.d.ts +1 -0
  250. package/lib/typescript/api/cache/hooks/useCachingTaskProgress.d.ts +2 -0
  251. package/lib/typescript/api/cache/hooks/useCachingTaskStatus.d.ts +2 -0
  252. package/lib/typescript/api/cast/CastConfiguration.d.ts +1 -1
  253. package/lib/typescript/api/config/PlayerConfiguration.d.ts +4 -1
  254. package/lib/typescript/api/drm/ContentProtectionIntegration.d.ts +2 -2
  255. package/lib/typescript/api/drm/ContentProtectionRequest.d.ts +1 -1
  256. package/lib/typescript/api/error/ChromecastError.d.ts +1 -1
  257. package/lib/typescript/api/event/CastEvent.d.ts +1 -1
  258. package/lib/typescript/api/event/EventDispatcher.d.ts +2 -2
  259. package/lib/typescript/api/event/EventListener.d.ts +1 -1
  260. package/lib/typescript/api/player/THEOplayer.d.ts +2 -2
  261. package/lib/typescript/api/source/SourceDescription.d.ts +3 -3
  262. package/lib/typescript/api/source/ads/Ads.d.ts +1 -1
  263. package/lib/typescript/api/source/ads/FreeWheelAdDescription.d.ts +1 -1
  264. package/lib/typescript/api/source/ads/ssai/GoogleDAIConfiguration.d.ts +2 -2
  265. package/lib/typescript/api/source/ads/ssai/ImagineServerSideAdInsertionConfiguration.d.ts +1 -1
  266. package/lib/typescript/api/source/ads/ssai/ServerSideAdInsertionConfiguration.d.ts +1 -1
  267. package/lib/typescript/api/source/ads/ssai/YospaceServerSideAdInsertionConfiguration.d.ts +2 -2
  268. package/lib/typescript/api/source/dash/DashPlaybackConfiguration.d.ts +1 -1
  269. package/lib/typescript/api/source/drm/DRMConfiguration.d.ts +3 -3
  270. package/lib/typescript/api/source/hls/HlsPlaybackConfiguration.d.ts +1 -1
  271. package/lib/typescript/api/track/MediaTrack.d.ts +1 -1
  272. package/lib/typescript/index.d.ts +1 -0
  273. package/lib/typescript/internal/THEOplayerView.web.d.ts +1 -1
  274. package/lib/typescript/internal/adapter/THEOplayerWebAdapter.d.ts +2 -2
  275. package/lib/typescript/internal/adapter/WebEventForwarder.d.ts +2 -2
  276. package/lib/typescript/internal/adapter/ads/THEOplayerWebAdsAdapter.d.ts +2 -2
  277. package/lib/typescript/internal/adapter/cast/THEOplayerWebCastAdapter.d.ts +2 -2
  278. package/lib/typescript/internal/adapter/event/native/NativeCastEvent.d.ts +1 -1
  279. package/lib/typescript/internal/adapter/web/WebPresentationModeManager.d.ts +2 -2
  280. package/lib/typescript/internal/cache/MediaCache.d.ts +25 -0
  281. package/lib/typescript/internal/cache/MediaCache.web.d.ts +16 -0
  282. package/lib/typescript/internal/cache/NativeCachingTaskAdapter.d.ts +33 -0
  283. package/lib/typescript/internal/cache/NativeCachingTaskParametersAdapter.d.ts +11 -0
  284. package/lib/typescript/internal/cache/WebCachingTaskAdapter.d.ts +25 -0
  285. package/package.json +16 -15
  286. package/react-native-theoplayer.podspec +4 -4
  287. package/src/api/ads/GoogleImaConfiguration.ts +1 -0
  288. package/src/api/barrel.ts +1 -0
  289. package/src/api/cache/CachingPreferredTrackSelection.ts +24 -0
  290. package/src/api/cache/CachingTask.ts +107 -0
  291. package/src/api/cache/CachingTaskLicense.ts +15 -0
  292. package/src/api/cache/CachingTaskList.ts +8 -0
  293. package/src/api/cache/CachingTaskParameters.ts +62 -0
  294. package/src/api/cache/MediaCacheAPI.ts +43 -0
  295. package/src/api/cache/barrel.ts +7 -0
  296. package/src/api/cache/events/CacheEvent.ts +62 -0
  297. package/src/api/cache/events/CachingTaskEvent.ts +27 -0
  298. package/src/api/cache/events/barrel.ts +2 -0
  299. package/src/api/cache/hooks/barrel.ts +3 -0
  300. package/src/api/cache/hooks/useCachingTaskList.ts +23 -0
  301. package/src/api/cache/hooks/useCachingTaskProgress.ts +20 -0
  302. package/src/api/cache/hooks/useCachingTaskStatus.ts +20 -0
  303. package/src/api/config/PlayerConfiguration.ts +3 -0
  304. package/src/index.tsx +1 -0
  305. package/src/internal/THEOplayerView.web.tsx +5 -5
  306. package/src/internal/adapter/THEOplayerWebAdapter.ts +6 -6
  307. package/src/internal/adapter/WebEventForwarder.ts +3 -3
  308. package/src/internal/adapter/ads/THEOplayerWebAdsAdapter.ts +3 -3
  309. package/src/internal/adapter/cast/THEOplayerWebCastAdapter.ts +3 -3
  310. package/src/internal/adapter/web/WebPresentationModeManager.ts +3 -3
  311. package/src/internal/cache/MediaCache.ts +151 -0
  312. package/src/internal/cache/MediaCache.web.ts +54 -0
  313. package/src/internal/cache/NativeCachingTaskAdapter.ts +81 -0
  314. package/src/internal/cache/NativeCachingTaskParametersAdapter.ts +32 -0
  315. package/src/internal/cache/WebCachingTaskAdapter.ts +95 -0
  316. package/android/src/main/java/com/theoplayer/track/QualityListFilter.kt +0 -28
@@ -0,0 +1,8 @@
1
+ /**
2
+ * List of caching tasks.
3
+ *
4
+ * @public
5
+ */
6
+ import type { CachingTask } from './CachingTask';
7
+
8
+ export type CachingTaskList = CachingTask[];
@@ -0,0 +1,62 @@
1
+ import type { CachingPreferredTrackSelection } from "./CachingPreferredTrackSelection";
2
+
3
+ /**
4
+ * Describes the configuration of a caching task.
5
+ *
6
+ * @public
7
+ */
8
+ export interface CachingTaskParameters {
9
+ /**
10
+ * The amount of data to cache for the given stream.
11
+ *
12
+ * @remarks
13
+ * <br/> - Available only on Web and Android. On iOS this value we always be '100%'.
14
+ *
15
+ * Possible formats:
16
+ * <br/> - A number in seconds.
17
+ * <br/> - A percentage string (XX%) for a proportion of the content duration.
18
+ *
19
+ */
20
+ readonly amount: number | string;
21
+
22
+ /**
23
+ * The expiration date of the cached data.
24
+ *
25
+ * @remarks
26
+ * <br/> - Must be a date in the future.
27
+ * <br/> - Data might be removed by the browser if it runs out of disk space.
28
+ *
29
+ * @defaultValue 30 minutes after starting the caching task.
30
+ */
31
+ readonly expirationDate?: Date;
32
+
33
+ /**
34
+ * Upper bandwidth limit of the quality to cache.
35
+ *
36
+ * @remarks
37
+ * <br/> - This will take the quality with the highest bandwidth that is lower than the specified bandwidth.
38
+ * <br/> - It should be a value between zero and infinity.
39
+ *
40
+ * @defaultValue Infinity
41
+ */
42
+ readonly bandwidth?: number;
43
+
44
+ /**
45
+ * The preferred audio/text tracks to cache.
46
+ *
47
+ * @remarks
48
+ * <br/> - Available only on iOS and Android.
49
+ * <br/> - By default, the first track will be picked.
50
+ */
51
+ readonly preferredTrackSelection?: CachingPreferredTrackSelection;
52
+
53
+ /**
54
+ * An indication of whether the data should be cached on a cellular network, or only on WIFI. Defaults to true.
55
+ *
56
+ * @remarks
57
+ * <br/> - Available only on iOS.
58
+ * <br/> - The value can not be changed on a scheduled asset.
59
+ * <br/> - If the download is scheduled/started on WIFI-only mode, and suddenly we would like allow Cellular Network download too, the `CachingTask` has to be removed and scheduled again with the new `CachingParamaters`.
60
+ */
61
+ readonly allowsCellularAccess?: boolean;
62
+ }
@@ -0,0 +1,43 @@
1
+ import type { EventDispatcher } from '../event/EventDispatcher';
2
+ import type { SourceDescription } from 'react-native-theoplayer';
3
+ import type { CachingTaskParameters } from './CachingTaskParameters';
4
+ import type { CachingTask } from './CachingTask';
5
+ import type { CacheEventMap } from './events/CacheEvent';
6
+ import type { CachingTaskList } from './CachingTaskList';
7
+
8
+ /**
9
+ * The cache status, represented by a value from the following list:
10
+ * <br/> - `'uninitialised'`: Previously stored caching tasks are unavailable.
11
+ * <br/> - `'initialised'`: Previously stored caching tasks are now available.
12
+ *
13
+ * @public
14
+ */
15
+ export enum CacheStatus {
16
+ uninitialised = 'uninitialised',
17
+ initialised = 'initialised',
18
+ }
19
+
20
+ /**
21
+ * The media cache API.
22
+ *
23
+ * @public
24
+ */
25
+ export interface MediaCacheAPI extends EventDispatcher<CacheEventMap> {
26
+ /**
27
+ * List of caching tasks which control the caching of media.
28
+ */
29
+ readonly tasks: CachingTaskList;
30
+
31
+ /**
32
+ * The current status of the cache.
33
+ */
34
+ readonly status: CacheStatus;
35
+
36
+ /**
37
+ * Create a caching task which controls the caching of media.
38
+ *
39
+ * @param source - Describes the media source to be cached.
40
+ * @param parameters - Contains caching task related options.
41
+ */
42
+ createTask(source: SourceDescription, parameters: CachingTaskParameters): Promise<CachingTask>;
43
+ }
@@ -0,0 +1,7 @@
1
+ export * from './CachingTask';
2
+ export * from './CachingTaskLicense';
3
+ export * from './CachingTaskList';
4
+ export * from './CachingTaskParameters';
5
+ export * from './MediaCacheAPI';
6
+ export * from './events/barrel';
7
+ export * from './hooks/barrel';
@@ -0,0 +1,62 @@
1
+ import type { Event } from '../../event/Event';
2
+ import type { CacheStatus } from '../MediaCacheAPI';
3
+ import type { CachingTask } from '../CachingTask';
4
+
5
+ export enum CacheEventType {
6
+ statechange = 'statechange',
7
+ addtask = 'addtask',
8
+ removetask = 'removetask',
9
+ }
10
+
11
+ /**
12
+ * The events dispatched by the {@link Cache | cache API}.
13
+ *
14
+ * @public
15
+ */
16
+ export interface CacheEventMap {
17
+ /**
18
+ * Dispatched when {@link Cache.status} changes.
19
+ */
20
+ [CacheEventType.statechange]: Event<CacheEventType.statechange>;
21
+
22
+ /**
23
+ * {@inheritDoc AddCachingTaskEvent}
24
+ */
25
+ [CacheEventType.addtask]: AddCachingTaskEvent;
26
+
27
+ /**
28
+ * {@inheritDoc AddCachingTaskEvent}
29
+ */
30
+ [CacheEventType.removetask]: RemoveCachingTaskEvent;
31
+ }
32
+
33
+ export interface CacheStatusChangeEvent extends Event<CacheEventType.statechange> {
34
+ /**
35
+ * The cache's new status.
36
+ */
37
+ readonly status: CacheStatus;
38
+ }
39
+
40
+ /**
41
+ * Dispatched when a caching task is added.
42
+ *
43
+ * @public
44
+ */
45
+ export interface AddCachingTaskEvent extends Event<CacheEventType.addtask> {
46
+ /**
47
+ * The task which has been added.
48
+ */
49
+ readonly task: CachingTask;
50
+ }
51
+
52
+ /**
53
+ * Dispatched when a caching task is removed.
54
+ *
55
+ * @public
56
+ */
57
+ export interface RemoveCachingTaskEvent extends Event<CacheEventType.removetask> {
58
+ /**
59
+ * The task which has been removed.
60
+ */
61
+ readonly task: CachingTask;
62
+ }
@@ -0,0 +1,27 @@
1
+ import type { Event } from '../../event/Event';
2
+
3
+ export enum CachingTaskEventType {
4
+ progress = 'progress',
5
+ statechange = 'statechange',
6
+ }
7
+
8
+ /**
9
+ * The events dispatched by the {@link CachingTask}.
10
+ *
11
+ * @public
12
+ */
13
+ export interface CachingTaskEventMap {
14
+ /**
15
+ * Dispatched when a segment is added to the cache.
16
+ */
17
+ [CachingTaskEventType.progress]: Event<CachingTaskEventType.progress>;
18
+
19
+ /**
20
+ * Dispatched when {@link CachingTask.status} changes.
21
+ */
22
+ [CachingTaskEventType.statechange]: Event<CachingTaskEventType.statechange>;
23
+ }
24
+
25
+ export type CachingTaskProgressEvent = Event<CachingTaskEventType.progress>;
26
+
27
+ export type CachingTaskStatusChangeEvent = Event<CachingTaskEventType.statechange>;
@@ -0,0 +1,2 @@
1
+ export * from './CacheEvent';
2
+ export * from './CachingTaskEvent';
@@ -0,0 +1,3 @@
1
+ export * from './useCachingTaskList';
2
+ export * from './useCachingTaskProgress';
3
+ export * from './useCachingTaskStatus';
@@ -0,0 +1,23 @@
1
+ import { CacheEventType, MediaCache } from 'react-native-theoplayer';
2
+ import { useEffect, useState } from 'react';
3
+
4
+ export const useCachingTaskList = (debug = false) => {
5
+ const [tasks, setTasks] = useState([...MediaCache.tasks]);
6
+ useEffect(() => {
7
+ const taskListChangeListener = () => {
8
+ if (debug) {
9
+ console.log('[MediaCache] task list changed: ', MediaCache.tasks);
10
+ }
11
+ setTasks([...MediaCache.tasks]);
12
+ };
13
+ MediaCache.addEventListener(CacheEventType.addtask, taskListChangeListener);
14
+ MediaCache.addEventListener(CacheEventType.removetask, taskListChangeListener);
15
+ MediaCache.addEventListener(CacheEventType.statechange, taskListChangeListener);
16
+ return () => {
17
+ MediaCache.removeEventListener(CacheEventType.addtask, taskListChangeListener);
18
+ MediaCache.removeEventListener(CacheEventType.removetask, taskListChangeListener);
19
+ MediaCache.addEventListener(CacheEventType.statechange, taskListChangeListener);
20
+ };
21
+ }, []);
22
+ return tasks;
23
+ };
@@ -0,0 +1,20 @@
1
+ import { CachingTask, CachingTaskEventType } from 'react-native-theoplayer';
2
+ import { useEffect, useState } from 'react';
3
+
4
+ export const useCachingTaskProgress = (task: CachingTask, debug = true) => {
5
+ const [progress, setProgress] = useState<number | undefined>(task.percentageCached);
6
+ useEffect(() => {
7
+ const onProgress = () => {
8
+ const percentageCached = task.percentageCached;
9
+ if (debug) {
10
+ console.log('[MediaCache] progress change', percentageCached);
11
+ }
12
+ setProgress(percentageCached);
13
+ };
14
+ task.addEventListener(CachingTaskEventType.progress, onProgress);
15
+ return () => {
16
+ task.removeEventListener(CachingTaskEventType.progress, onProgress);
17
+ };
18
+ }, []);
19
+ return progress;
20
+ };
@@ -0,0 +1,20 @@
1
+ import { CacheTaskStatus, CachingTask, CachingTaskEventType } from 'react-native-theoplayer';
2
+ import { useEffect, useState } from 'react';
3
+
4
+ export const useCachingTaskStatus = (task: CachingTask, debug = false) => {
5
+ const [status, setStatus] = useState<CacheTaskStatus | undefined>(task.status);
6
+ useEffect(() => {
7
+ const onStateChange = () => {
8
+ const status = task.status;
9
+ if (debug) {
10
+ console.log('[MediaCache] state change', status);
11
+ }
12
+ setStatus(status);
13
+ };
14
+ task.addEventListener(CachingTaskEventType.statechange, onStateChange);
15
+ return () => {
16
+ task.removeEventListener(CachingTaskEventType.statechange, onStateChange);
17
+ };
18
+ }, []);
19
+ return status;
20
+ };
@@ -53,6 +53,9 @@ export interface PlayerConfiguration {
53
53
 
54
54
  /**
55
55
  * Sets whether the native player is chromeless (without UI).
56
+ *
57
+ * @remarks
58
+ * <br/> - This parameter only applies to Web platforms.
56
59
  */
57
60
  readonly chromeless?: boolean;
58
61
 
package/src/index.tsx CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './api/barrel';
2
2
  export { THEOplayerView } from './internal/THEOplayerView';
3
3
  export { ContentProtectionRegistry } from './internal/drm/ContentProtectionRegistry';
4
+ export { MediaCache } from './internal/cache/MediaCache';
@@ -1,11 +1,11 @@
1
1
  import React, { useEffect, useRef } from 'react';
2
2
  import type { THEOplayerViewProps } from 'react-native-theoplayer';
3
- import * as THEOplayer from 'theoplayer';
3
+ import { Player, ChromelessPlayer, PlayerConfiguration } from 'theoplayer';
4
4
  import { THEOplayerWebAdapter } from './adapter/THEOplayerWebAdapter';
5
5
 
6
6
  export function THEOplayerView(props: React.PropsWithChildren<THEOplayerViewProps>) {
7
7
  const { config, children } = props;
8
- const player = useRef<THEOplayer.ChromelessPlayer | null>(null);
8
+ const player = useRef<ChromelessPlayer | null>(null);
9
9
  const adapter = useRef<THEOplayerWebAdapter | null>(null);
10
10
  const container = useRef<null | HTMLDivElement>(null);
11
11
 
@@ -15,14 +15,14 @@ export function THEOplayerView(props: React.PropsWithChildren<THEOplayerViewProp
15
15
  const chromeless = config?.chromeless === true || config?.chromeless === undefined;
16
16
  const updatedConfig = { ...config, allowNativeFullscreen: true };
17
17
  if (chromeless) {
18
- player.current = new THEOplayer.ChromelessPlayer(container.current, updatedConfig);
18
+ player.current = new ChromelessPlayer(container.current, updatedConfig);
19
19
  } else {
20
- player.current = new THEOplayer.Player(container.current, {
20
+ player.current = new Player(container.current, {
21
21
  ...updatedConfig,
22
22
  ui: {
23
23
  fluid: true,
24
24
  },
25
- } as THEOplayer.PlayerConfiguration);
25
+ } as PlayerConfiguration);
26
26
  }
27
27
 
28
28
  // Adapt native player to react-native player.
@@ -15,7 +15,7 @@ import type {
15
15
  import { AspectRatio, PlayerEventType, PresentationMode } from 'react-native-theoplayer';
16
16
  import { THEOplayerWebAdsAdapter } from './ads/THEOplayerWebAdsAdapter';
17
17
  import { THEOplayerWebCastAdapter } from './cast/THEOplayerWebCastAdapter';
18
- import * as THEOplayerWeb from 'theoplayer';
18
+ import { ChromelessPlayer as NativeChromelessPlayer, SourceDescription as NativeSourceDescription, version as nativeVersion } from 'theoplayer';
19
19
  import type { MediaTrack as NativeMediaTrack, TextTrack as NativeTextTrack } from 'theoplayer';
20
20
  import { findNativeQualitiesByUid, fromNativeMediaTrackList, fromNativeTextTrackList } from './web/TrackUtils';
21
21
  import type { ABRConfiguration, SourceDescription } from 'src/api/barrel';
@@ -38,14 +38,14 @@ export class THEOplayerWebAdapter extends DefaultEventDispatcher<PlayerEventMap>
38
38
  private readonly _adsAdapter: THEOplayerWebAdsAdapter;
39
39
  private readonly _castAdapter: THEOplayerWebCastAdapter;
40
40
  private readonly _presentationModeManager: WebPresentationModeManager;
41
- private _player: THEOplayerWeb.ChromelessPlayer | undefined;
41
+ private _player: NativeChromelessPlayer | undefined;
42
42
  private _eventForwarder: WebEventForwarder | undefined;
43
43
  private _mediaSession: WebMediaSession | undefined = undefined;
44
44
  private _targetVideoQuality: number | number[] | undefined = undefined;
45
45
  private _backgroundAudioConfiguration: BackgroundAudioConfiguration = defaultBackgroundAudioConfiguration;
46
46
  private _pipConfiguration: PiPConfiguration = defaultPipConfiguration;
47
47
 
48
- constructor(player: THEOplayerWeb.ChromelessPlayer, config?: PlayerConfiguration) {
48
+ constructor(player: NativeChromelessPlayer, config?: PlayerConfiguration) {
49
49
  super();
50
50
  this._player = player;
51
51
  this._adsAdapter = new THEOplayerWebAdsAdapter(this._player);
@@ -71,7 +71,7 @@ export class THEOplayerWebAdapter extends DefaultEventDispatcher<PlayerEventMap>
71
71
  set source(source: SourceDescription | undefined) {
72
72
  this._targetVideoQuality = undefined;
73
73
  if (this._player) {
74
- this._player.source = source as THEOplayerWeb.SourceDescription;
74
+ this._player.source = source as NativeSourceDescription;
75
75
  }
76
76
  }
77
77
 
@@ -302,8 +302,8 @@ export class THEOplayerWebAdapter extends DefaultEventDispatcher<PlayerEventMap>
302
302
 
303
303
  public get version(): PlayerVersion {
304
304
  return {
305
- version: THEOplayerWeb.version,
306
- playerSuiteVersion: THEOplayerWeb.playerSuiteVersion,
305
+ version: nativeVersion,
306
+ playerSuiteVersion: '', // deprecated
307
307
  };
308
308
  }
309
309
 
@@ -1,4 +1,4 @@
1
- import type * as THEOplayer from 'theoplayer';
1
+ import type { ChromelessPlayer } from 'theoplayer';
2
2
  import type {
3
3
  AddTrackEvent,
4
4
  CastStateChangeEvent,
@@ -53,10 +53,10 @@ import {
53
53
  import { fromNativeCue, fromNativeMediaTrack, fromNativeTextTrack } from './web/TrackUtils';
54
54
 
55
55
  export class WebEventForwarder {
56
- private readonly _player: THEOplayer.ChromelessPlayer;
56
+ private readonly _player: ChromelessPlayer;
57
57
  private readonly _facade: THEOplayerWebAdapter;
58
58
 
59
- constructor(player: THEOplayer.ChromelessPlayer, facade: THEOplayerWebAdapter) {
59
+ constructor(player: ChromelessPlayer, facade: THEOplayerWebAdapter) {
60
60
  this._player = player;
61
61
  this._facade = facade;
62
62
  this.addEventListeners();
@@ -1,12 +1,12 @@
1
1
  import type { Ad, AdBreak, AdDescription, AdsAPI, GoogleDAI } from 'react-native-theoplayer';
2
2
  import { THEOplayerWebGoogleDAI } from './THEOplayerWebGoogleDAI';
3
- import type * as THEOplayer from 'theoplayer';
3
+ import type { ChromelessPlayer } from 'theoplayer';
4
4
 
5
5
  export class THEOplayerWebAdsAdapter implements AdsAPI {
6
- private readonly _player: THEOplayer.ChromelessPlayer;
6
+ private readonly _player: ChromelessPlayer;
7
7
  private _dai: GoogleDAI | undefined;
8
8
 
9
- constructor(player: THEOplayer.ChromelessPlayer) {
9
+ constructor(player: ChromelessPlayer) {
10
10
  this._player = player;
11
11
  }
12
12
 
@@ -1,10 +1,10 @@
1
1
  import type { Airplay, CastAPI, Chromecast } from 'react-native-theoplayer';
2
- import type * as THEOplayer from 'theoplayer';
2
+ import type { ChromelessPlayer } from 'theoplayer';
3
3
 
4
4
  export class THEOplayerWebCastAdapter implements CastAPI {
5
- private readonly _player: THEOplayer.ChromelessPlayer;
5
+ private readonly _player: ChromelessPlayer;
6
6
 
7
- constructor(player: THEOplayer.ChromelessPlayer) {
7
+ constructor(player: ChromelessPlayer) {
8
8
  this._player = player;
9
9
  }
10
10
 
@@ -1,18 +1,18 @@
1
1
  import type { PlayerEventMap } from 'react-native-theoplayer';
2
2
  import { PresentationMode } from 'react-native-theoplayer';
3
- import type * as THEOplayerWeb from 'theoplayer';
3
+ import type { ChromelessPlayer } from 'theoplayer';
4
4
  import { DefaultPresentationModeChangeEvent } from '../event/PlayerEvents';
5
5
  import type { DefaultEventDispatcher } from '../event/DefaultEventDispatcher';
6
6
  import { fullscreenAPI } from './FullscreenAPI';
7
7
  import { noOp } from '../../utils/CommonUtils';
8
8
 
9
9
  export class WebPresentationModeManager {
10
- private readonly _player: THEOplayerWeb.ChromelessPlayer;
10
+ private readonly _player: ChromelessPlayer;
11
11
  private _presentationMode: PresentationMode = PresentationMode.inline;
12
12
  private _element: HTMLVideoElement | undefined = undefined;
13
13
  private _eventForwarder: DefaultEventDispatcher<PlayerEventMap>;
14
14
 
15
- constructor(player: THEOplayerWeb.ChromelessPlayer, eventForwarder: DefaultEventDispatcher<PlayerEventMap>) {
15
+ constructor(player: ChromelessPlayer, eventForwarder: DefaultEventDispatcher<PlayerEventMap>) {
16
16
  this._player = player;
17
17
  this._eventForwarder = eventForwarder;
18
18
  }
@@ -0,0 +1,151 @@
1
+ import { CacheStatus, MediaCacheAPI } from '../../api/cache/MediaCacheAPI';
2
+ import type { CachingTaskList } from '../../api/cache/CachingTaskList';
3
+ import { DefaultEventDispatcher } from '../adapter/event/DefaultEventDispatcher';
4
+ import type { CacheEventMap } from '../../api/cache/events/CacheEvent';
5
+ import { CacheEventType } from '../../api/cache/events/CacheEvent';
6
+ import type { CachingTaskProgressEvent, CachingTaskStatusChangeEvent, SourceDescription } from 'react-native-theoplayer';
7
+ import { CacheTaskStatus, CachingTaskEventType, TimeRange } from 'react-native-theoplayer';
8
+ import type { CachingTaskParameters } from '../../api/cache/CachingTaskParameters';
9
+ import type { CachingTask } from '../../api/cache/CachingTask';
10
+ import { NativeEventEmitter, NativeModules } from 'react-native';
11
+ import { NativeCachingTask, NativeCachingTaskAdapter } from './NativeCachingTaskAdapter';
12
+ import { toNativeCachingTaskParameters } from "./NativeCachingTaskParametersAdapter";
13
+
14
+ const TAG = "NativeMediaCache";
15
+
16
+ interface NativeCachingStatusChangeEvent {
17
+ readonly id: string;
18
+ readonly status: CacheTaskStatus;
19
+ }
20
+
21
+ interface NativeCacheStatusChangeEvent {
22
+ readonly status: CacheStatus;
23
+ }
24
+
25
+ interface NativeAddCachingTaskEvent {
26
+ readonly task: NativeCachingTask;
27
+ }
28
+
29
+ interface NativeRemoveCachingTaskEvent {
30
+ readonly task: NativeCachingTask;
31
+ }
32
+
33
+ interface NativeCachingTaskProgressEvent {
34
+ id: string;
35
+ progress: {
36
+ readonly duration: number;
37
+ readonly cached: TimeRange[];
38
+ readonly secondsCached: number;
39
+ readonly percentageCached: number;
40
+ readonly bytes: number;
41
+ readonly bytesCached: number;
42
+ };
43
+ }
44
+
45
+ export class NativeMediaCache extends DefaultEventDispatcher<CacheEventMap> implements MediaCacheAPI {
46
+ private _emitter: NativeEventEmitter = new NativeEventEmitter(NativeModules.CacheModule);
47
+ private _status: CacheStatus = CacheStatus.uninitialised;
48
+ private _tasks: NativeCachingTaskAdapter[] = [];
49
+
50
+ constructor() {
51
+ super();
52
+ this._emitter.addListener('onCacheStatusChange', this.onCacheStatusChange);
53
+ this._emitter.addListener('onAddCachingTaskEvent', this.onAddCachingTaskEvent);
54
+ this._emitter.addListener('onRemoveCachingTaskEvent', this.onRemoveCachingTaskEvent);
55
+ this._emitter.addListener('onCachingTaskProgressEvent', this.onCachingTaskProgressEvent);
56
+ this._emitter.addListener('onCachingTaskStatusChangeEvent', this.onCachingTaskStatusChangeEvent);
57
+ void this.initialize();
58
+ }
59
+
60
+ async createTask(source: SourceDescription, parameters: CachingTaskParameters): Promise<CachingTask> {
61
+ return NativeModules.CacheModule.createTask(source, toNativeCachingTaskParameters(parameters));
62
+ }
63
+
64
+ get status(): CacheStatus {
65
+ return this._status;
66
+ }
67
+
68
+ get tasks(): CachingTaskList {
69
+ return this._tasks;
70
+ }
71
+
72
+ private async initialize(): Promise<void> {
73
+ await this.getInitialState();
74
+
75
+ // Dispatch status change event here
76
+ if (this._status === CacheStatus.initialised) {
77
+ await this.onCacheStatusChange({
78
+ status: this._status,
79
+ });
80
+ }
81
+ }
82
+
83
+ private async getInitialState(): Promise<void> {
84
+ const initialState = await NativeModules.CacheModule.getInitialState();
85
+ this._status = initialState.status;
86
+ this._tasks = initialState.tasks.map((task: NativeCachingTask) => new NativeCachingTaskAdapter(task));
87
+ }
88
+
89
+ private onCacheStatusChange = async (event: NativeCacheStatusChangeEvent) => {
90
+ if (this._status === CacheStatus.uninitialised) {
91
+ await this.getInitialState();
92
+ }
93
+ this._status = event.status;
94
+ this.dispatchEvent({
95
+ type: CacheEventType.statechange,
96
+ date: new Date()
97
+ });
98
+ };
99
+
100
+ private onAddCachingTaskEvent = (event: NativeAddCachingTaskEvent) => {
101
+ const task= new NativeCachingTaskAdapter(event.task);
102
+ this._tasks.push(task);
103
+ this.dispatchEvent({
104
+ type: CacheEventType.addtask,
105
+ task,
106
+ date: new Date(),
107
+ });
108
+ };
109
+
110
+ private onRemoveCachingTaskEvent = (event: NativeRemoveCachingTaskEvent) => {
111
+ const task = this.taskById(event.task.id);
112
+ if (task) {
113
+ this._tasks = this._tasks.filter((task) => task.id !== event.task.id);
114
+ this.dispatchEvent({
115
+ type: CacheEventType.removetask,
116
+ task,
117
+ date: new Date(),
118
+ });
119
+ } else {
120
+ console.warn(TAG, `onRemoveCachingTaskEvent: CachingTask with id ${event.task.id} not found.`)
121
+ }
122
+ };
123
+
124
+ private onCachingTaskProgressEvent = (event: NativeCachingTaskProgressEvent) => {
125
+ const task = this.taskById(event.id);
126
+ if (task) {
127
+ Object.assign(task, { ...event.progress });
128
+ task.dispatchEvent({
129
+ type: CachingTaskEventType.progress,
130
+ date: new Date(),
131
+ } as CachingTaskProgressEvent);
132
+ }
133
+ };
134
+
135
+ private onCachingTaskStatusChangeEvent = (event: NativeCachingStatusChangeEvent) => {
136
+ const task = this.taskById(event.id);
137
+ if (task) {
138
+ Object.assign(task, { ...event });
139
+ task.dispatchEvent({
140
+ type: CachingTaskEventType.statechange,
141
+ date: new Date(),
142
+ } as CachingTaskStatusChangeEvent);
143
+ }
144
+ };
145
+
146
+ private taskById(id: string): NativeCachingTaskAdapter | undefined {
147
+ return this._tasks.find((task) => task.id === id);
148
+ }
149
+ }
150
+
151
+ export const MediaCache = new NativeMediaCache();
@@ -0,0 +1,54 @@
1
+ import type { CacheStatus, MediaCacheAPI } from 'react-native-theoplayer';
2
+ import type { CachingTaskList } from 'react-native-theoplayer';
3
+ import { DefaultEventDispatcher } from '../adapter/event/DefaultEventDispatcher';
4
+ import type { CacheEventMap } from 'react-native-theoplayer';
5
+ import type { SourceDescription } from 'react-native-theoplayer';
6
+ import type { CachingTaskParameters } from 'react-native-theoplayer';
7
+ import type { CachingTask } from 'react-native-theoplayer';
8
+ import * as THEOplayerWeb from 'theoplayer';
9
+ import { WebCachingTaskAdapter } from './WebCachingTaskAdapter';
10
+ import type { AddCachingTaskEvent, RemoveCachingTaskEvent, SourceDescription as NativeSourceDescription } from 'theoplayer';
11
+ import { CacheEventType } from 'react-native-theoplayer';
12
+
13
+ export class WebMediaCache extends DefaultEventDispatcher<CacheEventMap> implements MediaCacheAPI {
14
+ constructor() {
15
+ super();
16
+ THEOplayerWeb.cache.tasks.addEventListener('addtask', this.onAddTask);
17
+ THEOplayerWeb.cache.tasks.addEventListener('removetask', this.onRemoveTask);
18
+ }
19
+
20
+ private onAddTask = (event: AddCachingTaskEvent) => {
21
+ this.dispatchEvent({
22
+ type: CacheEventType.addtask,
23
+ task: new WebCachingTaskAdapter(event.task),
24
+ date: event.date,
25
+ });
26
+ };
27
+
28
+ private onRemoveTask = (event: RemoveCachingTaskEvent) => {
29
+ this.dispatchEvent({
30
+ type: CacheEventType.removetask,
31
+ task: new WebCachingTaskAdapter(event.task),
32
+ date: event.date,
33
+ });
34
+ };
35
+
36
+ createTask(source: SourceDescription, parameters: CachingTaskParameters): Promise<CachingTask> {
37
+ return Promise.resolve(new WebCachingTaskAdapter(THEOplayerWeb.cache.createTask(source as NativeSourceDescription, parameters)));
38
+ }
39
+
40
+ get status(): CacheStatus {
41
+ return THEOplayerWeb.cache.status as CacheStatus;
42
+ }
43
+
44
+ // @ts-ignore
45
+ get tasks(): CachingTaskList {
46
+ return THEOplayerWeb.cache.tasks.map((task) => new WebCachingTaskAdapter(task)) as CachingTaskList;
47
+ }
48
+ }
49
+
50
+ export const MediaCache = new WebMediaCache();
51
+
52
+ // Expose cache for easy access
53
+ // @ts-ignore
54
+ window.MediaCache = MediaCache;