From e63e168b3702e2ba61e08ea97d640aa6bfd4871c Mon Sep 17 00:00:00 2001 From: Bram del Canho Date: Wed, 17 Apr 2024 11:52:45 +0200 Subject: [PATCH 1/3] Add suspendSessionsWhenBackgrounded option to withIosGoogleCast --- .../src/withGoogleCast.ts | 8 ++++++-- .../src/withIosGoogleCast.ts | 18 ++++++++++-------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/packages/react-native-google-cast/src/withGoogleCast.ts b/packages/react-native-google-cast/src/withGoogleCast.ts index ce2ba06d..3ce8e452 100644 --- a/packages/react-native-google-cast/src/withGoogleCast.ts +++ b/packages/react-native-google-cast/src/withGoogleCast.ts @@ -19,20 +19,24 @@ const withGoogleCast: ConfigPlugin< * ?? */ androidReceiverAppId?: string; + /** + * @default true + */ + iosSuspendSessionsWhenBackgrounded?: boolean; } | void > = (config, _props) => { const props = _props || {}; // TODO: Are the Android and iOS receiverAppId values the same? config = withIosGoogleCast(config, { receiverAppId: props.iosReceiverAppId, + suspendSessionsWhenBackgrounded: props.iosSuspendSessionsWhenBackgrounded, // disableDiscoveryAutostart?: boolean; // startDiscoveryAfterFirstTapOnCastButton?: boolean; }); config = withAndroidGoogleCast(config, { receiverAppId: props.androidReceiverAppId, - androidPlayServicesCastFrameworkVersion: - props.androidPlayServicesCastFrameworkVersion, + androidPlayServicesCastFrameworkVersion: props.androidPlayServicesCastFrameworkVersion, }); return config; diff --git a/packages/react-native-google-cast/src/withIosGoogleCast.ts b/packages/react-native-google-cast/src/withIosGoogleCast.ts index 49b461d1..fb0994d8 100644 --- a/packages/react-native-google-cast/src/withIosGoogleCast.ts +++ b/packages/react-native-google-cast/src/withIosGoogleCast.ts @@ -102,6 +102,10 @@ export const withIosGoogleCast: ConfigPlugin<{ * @default 'CC1AD845' */ receiverAppId?: string; + /** + * @default true + */ + suspendSessionsWhenBackgrounded?: boolean; }> = (config, props) => { config = withIosWifiEntitlements(config); config = withIosLocalNetworkPermissions(config, { @@ -109,6 +113,7 @@ export const withIosGoogleCast: ConfigPlugin<{ }); config = withIosAppDelegateLoaded(config, { receiverAppId: props.receiverAppId, + suspendSessionsWhenBackgrounded: props.suspendSessionsWhenBackgrounded, // disableDiscoveryAutostart?: boolean; // startDiscoveryAfterFirstTapOnCastButton?: boolean; }); @@ -125,6 +130,7 @@ export const MATCH_INIT = type IosProps = { receiverAppId?: string | null; + suspendSessionsWhenBackgrounded?: boolean; disableDiscoveryAutostart?: boolean; startDiscoveryAfterFirstTapOnCastButton?: boolean; }; @@ -133,6 +139,7 @@ export function addGoogleCastAppDelegateDidFinishLaunchingWithOptions( src: string, { receiverAppId = null, + suspendSessionsWhenBackgrounded = true, disableDiscoveryAutostart = false, startDiscoveryAfterFirstTapOnCastButton = true, }: IosProps = {}, @@ -142,18 +149,13 @@ export function addGoogleCastAppDelegateDidFinishLaunchingWithOptions( // For extra safety "#if __has_include()", // TODO: This should probably read safely from a static file like the Info.plist - ` NSString *receiverAppID = ${ - receiverAppId - ? `@"${receiverAppId}"` - : "kGCKDefaultMediaReceiverApplicationID" - };`, + ` NSString *receiverAppID = ${receiverAppId ? `@"${receiverAppId}"` : "kGCKDefaultMediaReceiverApplicationID"};`, " GCKDiscoveryCriteria *criteria = [[GCKDiscoveryCriteria alloc] initWithApplicationID:receiverAppID];", " GCKCastOptions* options = [[GCKCastOptions alloc] initWithDiscoveryCriteria:criteria];", // TODO: Same as above, read statically // ` options.disableDiscoveryAutostart = ${String(!!disableDiscoveryAutostart)};`, - ` options.startDiscoveryAfterFirstTapOnCastButton = ${String( - !!startDiscoveryAfterFirstTapOnCastButton, - )};`, + ` options.startDiscoveryAfterFirstTapOnCastButton = ${String(!!startDiscoveryAfterFirstTapOnCastButton,)};`, + ` options.suspendSessionsWhenBackgrounded = ${String(!!suspendSessionsWhenBackgrounded,)};`, " [GCKCastContext setSharedInstanceWithOptions:options];", "#endif", ); From f6ab240d476f2e766ec59ab13604b1c5dfc0bb7d Mon Sep 17 00:00:00 2001 From: Bram del Canho Date: Wed, 17 Apr 2024 13:17:04 +0200 Subject: [PATCH 2/3] Add suspendSessionsWhenBackgrounded option to withIosGoogleCast --- .../__tests__/__snapshots__/withIosGoogleCast-test.ts.snap | 3 ++- .../src/__tests__/withIosGoogleCast-test.ts | 1 + packages/react-native-google-cast/src/withIosGoogleCast.ts | 4 ++-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/react-native-google-cast/src/__tests__/__snapshots__/withIosGoogleCast-test.ts.snap b/packages/react-native-google-cast/src/__tests__/__snapshots__/withIosGoogleCast-test.ts.snap index c0346caa..0030d2a9 100644 --- a/packages/react-native-google-cast/src/__tests__/__snapshots__/withIosGoogleCast-test.ts.snap +++ b/packages/react-native-google-cast/src/__tests__/__snapshots__/withIosGoogleCast-test.ts.snap @@ -10,12 +10,13 @@ exports[`addGoogleCastAppDelegateDidFinishLaunchingWithOptions adds maps import - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { -// @generated begin react-native-google-cast-didFinishLaunchingWithOptions - expo prebuild (DO NOT MODIFY) sync-daa990ca400f82a13f41d1ebc1f1fe9f511f3d6d +// @generated begin react-native-google-cast-didFinishLaunchingWithOptions - expo prebuild (DO NOT MODIFY) sync-7c4d7719024c020cbdbdec17652c4a5824b61c18 #if __has_include() NSString *receiverAppID = @"foobar-bacon"; GCKDiscoveryCriteria *criteria = [[GCKDiscoveryCriteria alloc] initWithApplicationID:receiverAppID]; GCKCastOptions* options = [[GCKCastOptions alloc] initWithDiscoveryCriteria:criteria]; options.startDiscoveryAfterFirstTapOnCastButton = true; + options.suspendSessionsWhenBackgrounded = false; [GCKCastContext setSharedInstanceWithOptions:options]; #endif // @generated end react-native-google-cast-didFinishLaunchingWithOptions diff --git a/packages/react-native-google-cast/src/__tests__/withIosGoogleCast-test.ts b/packages/react-native-google-cast/src/__tests__/withIosGoogleCast-test.ts index 6902a8d7..9a5ece6e 100644 --- a/packages/react-native-google-cast/src/__tests__/withIosGoogleCast-test.ts +++ b/packages/react-native-google-cast/src/__tests__/withIosGoogleCast-test.ts @@ -7,6 +7,7 @@ describe(addGoogleCastAppDelegateDidFinishLaunchingWithOptions, () => { getFixture("AppDelegate.mm"), { receiverAppId: "foobar-bacon", + suspendSessionsWhenBackgrounded: false, }, ); // matches a static snapshot diff --git a/packages/react-native-google-cast/src/withIosGoogleCast.ts b/packages/react-native-google-cast/src/withIosGoogleCast.ts index fb0994d8..b2f1927a 100644 --- a/packages/react-native-google-cast/src/withIosGoogleCast.ts +++ b/packages/react-native-google-cast/src/withIosGoogleCast.ts @@ -154,8 +154,8 @@ export function addGoogleCastAppDelegateDidFinishLaunchingWithOptions( " GCKCastOptions* options = [[GCKCastOptions alloc] initWithDiscoveryCriteria:criteria];", // TODO: Same as above, read statically // ` options.disableDiscoveryAutostart = ${String(!!disableDiscoveryAutostart)};`, - ` options.startDiscoveryAfterFirstTapOnCastButton = ${String(!!startDiscoveryAfterFirstTapOnCastButton,)};`, - ` options.suspendSessionsWhenBackgrounded = ${String(!!suspendSessionsWhenBackgrounded,)};`, + ` options.startDiscoveryAfterFirstTapOnCastButton = ${String(!!startDiscoveryAfterFirstTapOnCastButton)};`, + ` options.suspendSessionsWhenBackgrounded = ${String(!!suspendSessionsWhenBackgrounded)};`, " [GCKCastContext setSharedInstanceWithOptions:options];", "#endif", ); From a2663bc184bd1fab5417c9896d1b4a2b90eff605 Mon Sep 17 00:00:00 2001 From: Bram del Canho Date: Wed, 17 Apr 2024 13:23:16 +0200 Subject: [PATCH 3/3] fixed linting errors --- packages/react-native-google-cast/src/withGoogleCast.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/react-native-google-cast/src/withGoogleCast.ts b/packages/react-native-google-cast/src/withGoogleCast.ts index 3ce8e452..f868e900 100644 --- a/packages/react-native-google-cast/src/withGoogleCast.ts +++ b/packages/react-native-google-cast/src/withGoogleCast.ts @@ -36,7 +36,8 @@ const withGoogleCast: ConfigPlugin< config = withAndroidGoogleCast(config, { receiverAppId: props.androidReceiverAppId, - androidPlayServicesCastFrameworkVersion: props.androidPlayServicesCastFrameworkVersion, + androidPlayServicesCastFrameworkVersion: + props.androidPlayServicesCastFrameworkVersion, }); return config;