Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(react-native-google-cast): add suspendSessionsWhenBackgrounded option to IOS #231

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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(<GoogleCast/GoogleCast.h>)
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ describe(addGoogleCastAppDelegateDidFinishLaunchingWithOptions, () => {
getFixture("AppDelegate.mm"),
{
receiverAppId: "foobar-bacon",
suspendSessionsWhenBackgrounded: false,
},
);
// matches a static snapshot
Expand Down
5 changes: 5 additions & 0 deletions packages/react-native-google-cast/src/withGoogleCast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,17 @@ 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;
});
Expand Down
18 changes: 10 additions & 8 deletions packages/react-native-google-cast/src/withIosGoogleCast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,18 @@ export const withIosGoogleCast: ConfigPlugin<{
* @default 'CC1AD845'
*/
receiverAppId?: string;
/**
* @default true
*/
suspendSessionsWhenBackgrounded?: boolean;
}> = (config, props) => {
config = withIosWifiEntitlements(config);
config = withIosLocalNetworkPermissions(config, {
receiverAppId: props.receiverAppId,
});
config = withIosAppDelegateLoaded(config, {
receiverAppId: props.receiverAppId,
suspendSessionsWhenBackgrounded: props.suspendSessionsWhenBackgrounded,
// disableDiscoveryAutostart?: boolean;
// startDiscoveryAfterFirstTapOnCastButton?: boolean;
});
Expand All @@ -125,6 +130,7 @@ export const MATCH_INIT =

type IosProps = {
receiverAppId?: string | null;
suspendSessionsWhenBackgrounded?: boolean;
disableDiscoveryAutostart?: boolean;
startDiscoveryAfterFirstTapOnCastButton?: boolean;
};
Expand All @@ -133,6 +139,7 @@ export function addGoogleCastAppDelegateDidFinishLaunchingWithOptions(
src: string,
{
receiverAppId = null,
suspendSessionsWhenBackgrounded = true,
disableDiscoveryAutostart = false,
startDiscoveryAfterFirstTapOnCastButton = true,
}: IosProps = {},
Expand All @@ -142,18 +149,13 @@ export function addGoogleCastAppDelegateDidFinishLaunchingWithOptions(
// For extra safety
"#if __has_include(<GoogleCast/GoogleCast.h>)",
// 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",
);
Expand Down
Loading