@castlabs/react-native-prestoplay-ios-avplayerviewcontroller 1.1.4 → 1.2.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.
@@ -4,6 +4,10 @@
4
4
  #import <React/RCTEventEmitter.h>
5
5
 
6
6
 
7
+ @interface RCT_EXTERN_MODULE(RNPrestoplayAVPlayerViewControllerPluginFactory, NSObject)
8
+
9
+ @end
10
+
7
11
  @interface RCT_EXTERN_MODULE(RNPrestoplayApplePlayerControlsModule, NSObject)
8
12
 
9
13
  RCT_EXTERN_METHOD(
@@ -0,0 +1,19 @@
1
+ //
2
+ // RCTNativeApplePlayerControlsFactoryModule.h
3
+ // Pods
4
+ //
5
+ #ifdef RCT_NEW_ARCH_ENABLED
6
+
7
+ #import <NativePrestoPlayReactApplePlayerControlsSpec/NativePrestoPlayReactApplePlayerControlsSpec.h>
8
+ #import <react-native-prestoplay/PluginFactoryProtocol.h>
9
+
10
+ NS_ASSUME_NONNULL_BEGIN
11
+
12
+ @interface RCTNativeApplePlayerControlsFactoryModule : NativeApplePlayerControlsFactoryModuleSpecBase <NativeApplePlayerControlsFactoryModuleSpec, PluginFactoryProtocolNewArch>
13
+
14
+
15
+ @end
16
+
17
+ NS_ASSUME_NONNULL_END
18
+
19
+ #endif
@@ -0,0 +1,35 @@
1
+ #ifdef RCT_NEW_ARCH_ENABLED
2
+
3
+ #import "RCTNativeApplePlayerControlsFactoryModule.h"
4
+ #import "react_native_prestoplay_ios_avplayerviewcontroller-Swift.h"
5
+
6
+ @interface RCTNativeApplePlayerControlsFactoryModule ()
7
+ @property (nonatomic, strong) RCTNativeApplePlayerControlsFactoryModuleSwift *instance;
8
+ @end
9
+
10
+ @implementation RCTNativeApplePlayerControlsFactoryModule
11
+
12
+ + (NSString *)moduleName {
13
+ return @"NativeApplePlayerControlsFactoryModule";
14
+ }
15
+
16
+ + (BOOL)requiresMainQueueSetup {
17
+ return YES;
18
+ }
19
+
20
+ - (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:(const facebook::react::ObjCTurboModule::InitParams &)params {
21
+ return std::make_shared<facebook::react::NativeApplePlayerControlsFactoryModuleSpecJSI>(params);
22
+ }
23
+
24
+ - (void)initialize {
25
+ self.instance = [[RCTNativeApplePlayerControlsFactoryModuleSwift alloc] init];
26
+ }
27
+
28
+ - (RCTNativeApplePlayerControlsFactoryModuleSwift*)getSwiftInstance {
29
+ return self.instance;
30
+ }
31
+
32
+
33
+ @end
34
+
35
+ #endif
@@ -0,0 +1,18 @@
1
+ import react_native_prestoplay
2
+
3
+ @available(tvOS 14.0, *)
4
+ @objc(RCTNativeApplePlayerControlsFactoryModuleSwift)
5
+ public class RCTNativeApplePlayerControlsFactoryModuleSwift: NSObject, PluginFactoryProtocol {
6
+
7
+ private var instance: RNPrestoplayAVPlayerViewControllerPluginFactory!
8
+
9
+ @objc
10
+ override public init()
11
+ {
12
+ self.instance = RNPrestoplayAVPlayerViewControllerPluginFactory()
13
+ }
14
+
15
+ public func getPlugin() -> PluginProtocol {
16
+ return self.instance.getPlugin()
17
+ }
18
+ }
@@ -0,0 +1,14 @@
1
+ //
2
+ // RCTNativeApplePlayerControlsModule.h
3
+ // Pods
4
+ //
5
+ #import <NativePrestoPlayReactApplePlayerControlsSpec/NativePrestoPlayReactApplePlayerControlsSpec.h>
6
+
7
+ NS_ASSUME_NONNULL_BEGIN
8
+
9
+ @interface RCTNativeApplePlayerControlsModule : NativeApplePlayerControlsModuleSpecBase <NativeApplePlayerControlsModuleSpec>
10
+
11
+
12
+ @end
13
+
14
+ NS_ASSUME_NONNULL_END
@@ -0,0 +1,30 @@
1
+ #import "RCTNativeApplePlayerControlsModule.h"
2
+ #import "react_native_prestoplay_ios_avplayerviewcontroller-Swift.h"
3
+
4
+ @interface RCTNativeApplePlayerControlsModule ()
5
+ @property (nonatomic, strong) RCTNativeApplePlayerControlsModuleSwift *instance;
6
+ @end
7
+
8
+ @implementation RCTNativeApplePlayerControlsModule
9
+
10
+ + (NSString *)moduleName {
11
+ return @"NativeApplePlayerControlsModule";
12
+ }
13
+
14
+ - (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:(const facebook::react::ObjCTurboModule::InitParams &)params {
15
+ return std::make_shared<facebook::react::NativeApplePlayerControlsModuleSpecJSI>(params);
16
+ }
17
+
18
+ - (void)initialize {
19
+ self.instance = [[RCTNativeApplePlayerControlsModuleSwift alloc] init];
20
+ }
21
+
22
+ - (void)setAppleTvActions:(nonnull NSString *)playerId transportBarActions:(nonnull NSArray *)transportBarActions infoBarActions:(nonnull NSArray *)infoBarActions contextualActions:(nonnull NSArray *)contextualActions resolve:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject {
23
+ [self.instance setAppleTvActions:playerId transportBarActions:transportBarActions infoBarActions:infoBarActions contextualActions:contextualActions resolve:^(){ resolve(nil); } reject:^(NSString* prestoPlayErrorJson){ reject(nil, prestoPlayErrorJson, nil);}];
24
+ }
25
+
26
+ - (void)setActionStateAndUi:(nonnull NSString *)playerId actionId:(nonnull NSString *)actionId state:(BOOL)state uiInfo:(nonnull NSDictionary *)uiInfo resolve:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject {
27
+ [self.instance setActionStateAndUi:playerId actionId:actionId state:state uiInfo:uiInfo resolve:^(){ resolve(nil); } reject:^(NSString* prestoPlayErrorJson){ reject(nil, prestoPlayErrorJson, nil);}];
28
+ }
29
+
30
+ @end
@@ -0,0 +1,48 @@
1
+ @available(tvOS 14.0, *)
2
+ @objc(RCTNativeApplePlayerControlsModuleSwift)
3
+ public class RCTNativeApplePlayerControlsModuleSwift: NSObject {
4
+
5
+ private var instance: RNPrestoplayApplePlayerControlsModule!
6
+
7
+ @objc
8
+ override public init()
9
+ {
10
+ self.instance = RNPrestoplayApplePlayerControlsModule()
11
+ }
12
+
13
+ @objc
14
+ public func setAppleTvActions(
15
+ _ playerId: String,
16
+ transportBarActions: NSArray,
17
+ infoBarActions: NSArray,
18
+ contextualActions: NSArray,
19
+ resolve: @escaping () -> Void,
20
+ reject: @escaping (String?) -> Void
21
+ ) {
22
+ self.instance.setAppleTvActions(
23
+ playerId,
24
+ transportBarActions as? [NSDictionary],
25
+ infoBarActions as? [NSDictionary],
26
+ contextualActions as? [NSDictionary],
27
+ resolver: { result in resolve() },
28
+ rejecter: { code, message, error in reject(message) })
29
+ }
30
+
31
+ @objc
32
+ public func setActionStateAndUi(
33
+ _ playerId: String,
34
+ actionId: String,
35
+ state: Bool,
36
+ uiInfo: NSDictionary,
37
+ resolve: @escaping () -> Void,
38
+ reject: @escaping (String?) -> Void
39
+ ) {
40
+ self.instance.setActionStateAndUi(
41
+ playerId,
42
+ actionId,
43
+ state: state,
44
+ uiInfo: uiInfo,
45
+ resolver: { result in resolve() },
46
+ rejecter: { code, message, error in reject(message) })
47
+ }
48
+ }
@@ -1,5 +1,5 @@
1
1
  import { PlayerExtension, rethrowAsPrestoPlayErrorIfPossible, Logger, BaseEventEmitter, } from '@castlabs/react-native-prestoplay';
2
- import { NativeModules } from 'react-native';
2
+ import { NativeModules, TurboModuleRegistry } from 'react-native';
3
3
  import { ActionType } from './types/ActionType';
4
4
  import { EventType as LocalEventType } from './events/EventType';
5
5
  export class AVPlayerViewControllerExtension extends PlayerExtension {
@@ -119,7 +119,9 @@ export class AVPlayerViewControllerExtension extends PlayerExtension {
119
119
  title: title,
120
120
  imageName: icon,
121
121
  };
122
- await NativeModules.RNPrestoplayApplePlayerControlsModule.setActionStateAndUi(this.player.id, actionId, state, update);
122
+ const controlsModule = TurboModuleRegistry.get('NativeApplePlayerControlsModule') ??
123
+ NativeModules.RNPrestoplayApplePlayerControlsModule;
124
+ await controlsModule.setActionStateAndUi(this.player.id, actionId, state, update);
123
125
  }
124
126
  onContentLoaded() {
125
127
  /**
@@ -137,7 +139,10 @@ export class AVPlayerViewControllerExtension extends PlayerExtension {
137
139
  this.popUpMenus.forEach((menu, _id) => {
138
140
  transportBarActions.push(menu);
139
141
  });
140
- NativeModules.RNPrestoplayApplePlayerControlsModule.setAppleTvActions(this.player.id, transportBarActions, this.infoBarActions, this.contextualActions)
142
+ const controlsModule = TurboModuleRegistry.get('NativeApplePlayerControlsModule') ??
143
+ NativeModules.RNPrestoplayApplePlayerControlsModule;
144
+ controlsModule
145
+ .setAppleTvActions(this.player.id, transportBarActions, this.infoBarActions, this.contextualActions)
141
146
  .then(() => {
142
147
  this.logger.debug('AVPlayerViewControllerExtension: submitActions done');
143
148
  })
@@ -1,4 +1,5 @@
1
1
  import { Plugin } from '@castlabs/react-native-prestoplay';
2
+ import { TurboModuleRegistry } from 'react-native';
2
3
  /**
3
4
  * Provides {@link AVPlayerViewControllerProvider} integration for iOS and tvOS.
4
5
  *
@@ -10,7 +11,13 @@ import { Plugin } from '@castlabs/react-native-prestoplay';
10
11
  export default class AVPlayerViewControllerPlugin extends Plugin {
11
12
  /** @hidden */
12
13
  getNativePluginFactoryModuleName() {
13
- return 'RNPrestoplayAVPlayerViewControllerPluginFactory';
14
+ try {
15
+ TurboModuleRegistry.getEnforcing('NativeApplePlayerControlsFactoryModule');
16
+ return 'NativeApplePlayerControlsFactoryModule';
17
+ }
18
+ catch (e) {
19
+ return 'RNPrestoplayAVPlayerViewControllerPluginFactory';
20
+ }
14
21
  }
15
22
  /** @hidden */
16
23
  onPlayerCreated(_player) {
@@ -1,5 +1,5 @@
1
1
  import React, { memo, useEffect, useMemo } from 'react';
2
- import { EventType, PlayerContext, } from '@castlabs/react-native-prestoplay';
2
+ import { EventType, Logger, PlayerContext, } from '@castlabs/react-native-prestoplay';
3
3
  import { Player } from '@castlabs/react-native-prestoplay';
4
4
  import { AVPlayerViewControllerExtension } from '../AVPlayerViewControllerExtension';
5
5
  /**
@@ -12,6 +12,7 @@ import { AVPlayerViewControllerExtension } from '../AVPlayerViewControllerExtens
12
12
  * @group Components
13
13
  */
14
14
  export const AVPlayerViewControllerProvider = memo(function ({ playerConfig, onClose, children, }) {
15
+ const logger = new Logger('AVPlayerViewControllerProvider');
15
16
  const player = useMemo(() => {
16
17
  const player_ = new Player(true);
17
18
  player_.addExtension(new AVPlayerViewControllerExtension(player_));
@@ -33,7 +34,7 @@ export const AVPlayerViewControllerProvider = memo(function ({ playerConfig, onC
33
34
  useEffect(() => {
34
35
  if (playerConfig) {
35
36
  player.open(playerConfig).catch(error => {
36
- console.error('Error opening player:', error);
37
+ logger.error('Error opening player:', error);
37
38
  });
38
39
  }
39
40
  },
@@ -1,5 +1,5 @@
1
1
  import React, { createContext } from 'react';
2
- import { BaseEventEmitter, usePlayer } from '@castlabs/react-native-prestoplay';
2
+ import { BaseEventEmitter, ErrorCode, Logger, usePlayer, } from '@castlabs/react-native-prestoplay';
3
3
  import { AVPlayerViewControllerExtension } from '../AVPlayerViewControllerExtension';
4
4
  export const AppleTvPlayerControlsContext = createContext({
5
5
  eventEmitter: new BaseEventEmitter(),
@@ -29,32 +29,45 @@ export const AppleTvPlayerControlsContext = createContext({
29
29
  * @group Components
30
30
  */
31
31
  const AppleTvPlayerControls = React.memo(({ children }) => {
32
- const player = usePlayer();
33
- const avPlayerExtension = player.getExtension(AVPlayerViewControllerExtension);
34
- const addAction = (type, actionId, props) => {
35
- avPlayerExtension.addAction(type, actionId, props);
36
- };
37
- const removeAction = (type, actionId) => {
38
- avPlayerExtension.removeAction(type, actionId);
39
- };
40
- const updateAction = (actionId, state, title, icon) => {
41
- avPlayerExtension.updateAction(actionId, state, title, icon);
42
- };
43
- const setPopupMenu = (menuId, popUpMenu) => {
44
- avPlayerExtension.setPopupMenu(menuId, popUpMenu);
45
- };
46
- const removePopupMenu = (menuId) => {
47
- avPlayerExtension.removePopupMenu(menuId);
48
- };
49
- return (<AppleTvPlayerControlsContext.Provider value={{
50
- eventEmitter: avPlayerExtension.eventEmitter,
51
- updateAction,
52
- addAction,
53
- removeAction,
54
- setPopupMenu: setPopupMenu,
55
- removePopupMenu,
56
- }}>
57
- {children}
58
- </AppleTvPlayerControlsContext.Provider>);
32
+ try {
33
+ const player = usePlayer();
34
+ const avPlayerExtension = player.getExtension(AVPlayerViewControllerExtension);
35
+ const addAction = (type, actionId, props) => {
36
+ avPlayerExtension.addAction(type, actionId, props);
37
+ };
38
+ const removeAction = (type, actionId) => {
39
+ avPlayerExtension.removeAction(type, actionId);
40
+ };
41
+ const updateAction = (actionId, state, title, icon) => {
42
+ avPlayerExtension.updateAction(actionId, state, title, icon);
43
+ };
44
+ const setPopupMenu = (menuId, popUpMenu) => {
45
+ avPlayerExtension.setPopupMenu(menuId, popUpMenu);
46
+ };
47
+ const removePopupMenu = (menuId) => {
48
+ avPlayerExtension.removePopupMenu(menuId);
49
+ };
50
+ return (<AppleTvPlayerControlsContext.Provider value={{
51
+ eventEmitter: avPlayerExtension.eventEmitter,
52
+ updateAction,
53
+ addAction,
54
+ removeAction,
55
+ setPopupMenu: setPopupMenu,
56
+ removePopupMenu,
57
+ }}>
58
+ {children}
59
+ </AppleTvPlayerControlsContext.Provider>);
60
+ }
61
+ catch (e) {
62
+ const logger = new Logger('AppleTvPlayerControls');
63
+ const error = e;
64
+ if (error.code === ErrorCode.PlayerNotFound) {
65
+ logger.error(`${error.message} Ensure that <AppleTvPlayerControls> is within the <AVPlayerViewControllerProvider> hierarchy.`);
66
+ }
67
+ else {
68
+ logger.error(`<AppleTvPlayerControls>: Unexpected error ${error}`);
69
+ }
70
+ return null;
71
+ }
59
72
  });
60
73
  export default AppleTvPlayerControls;
@@ -0,0 +1,5 @@
1
+ import type { TurboModule } from 'react-native';
2
+ export interface Spec extends TurboModule {
3
+ }
4
+ declare const _default: Spec;
5
+ export default _default;
@@ -0,0 +1,2 @@
1
+ import { TurboModuleRegistry } from 'react-native';
2
+ export default TurboModuleRegistry.getEnforcing('NativeApplePlayerControlsFactoryModule');
@@ -0,0 +1,7 @@
1
+ import type { TurboModule } from 'react-native';
2
+ export interface Spec extends TurboModule {
3
+ setAppleTvActions(playerId: string, transportBarActions: Object[], infoBarActions: Object[], contextualActions: Object[]): Promise<void>;
4
+ setActionStateAndUi(playerId: string, actionId: string, state: boolean, uiInfo: Object): Promise<void>;
5
+ }
6
+ declare const _default: Spec;
7
+ export default _default;
@@ -0,0 +1,2 @@
1
+ import { TurboModuleRegistry } from 'react-native';
2
+ export default TurboModuleRegistry.getEnforcing('NativeApplePlayerControlsModule');
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@castlabs/react-native-prestoplay-ios-avplayerviewcontroller",
3
- "version": "1.1.4",
4
- "prestoplayAppleSdkVersion": "4.0.25.1",
3
+ "version": "1.2.0",
4
+ "prestoplayAppleSdkVersion": "4.0.27",
5
5
  "prestoplayAndroidSdkVersion": "4.4.8",
6
6
  "prestoplayWebSdkVersion": "6.26.0",
7
7
  "description": "PRESTOplay for React Native",
@@ -46,7 +46,7 @@
46
46
  "typescript": "5.0.4"
47
47
  },
48
48
  "dependencies": {
49
- "@castlabs/react-native-prestoplay": "1.1.4"
49
+ "@castlabs/react-native-prestoplay": "1.2.0"
50
50
  },
51
51
  "keywords": [
52
52
  "react native player",
@@ -85,5 +85,16 @@
85
85
  "bracketSpacing": false,
86
86
  "singleQuote": true,
87
87
  "trailingComma": "all"
88
+ },
89
+ "codegenConfig": {
90
+ "name": "NativePrestoPlayReactApplePlayerControlsSpec",
91
+ "type": "modules",
92
+ "jsSrcsDir": "src/specs",
93
+ "ios": {
94
+ "modulesProvider": {
95
+ "NativeApplePlayerControlsFactoryModule": "RCTNativeApplePlayerControlsFactoryModule",
96
+ "NativeApplePlayerControlsModule": "RCTNativeApplePlayerControlsModule"
97
+ }
98
+ }
88
99
  }
89
100
  }
@@ -14,6 +14,10 @@ Pod::Spec.new do |s|
14
14
  s.source = { :git => "https://github.com/castlabs/prestoplay-react.git", :tag => "#{s.version}" }
15
15
  s.source_files = "ios/**/*.{h,m,mm,swift}"
16
16
  s.exclude_files = "ios/**/*.xcframework/**/*.h"
17
+ s.private_header_files = [
18
+ "ios/**/RCTNativeApplePlayerControlsFactoryModule.h",
19
+ "ios/**/RCTNativeApplePlayerControlsModule.h"
20
+ ]
17
21
 
18
22
  s.dependency "react-native-prestoplay", package["version"]
19
23