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 startDiscoveryAfterFirstTapOnCastButton and physicalVolumeButtonsWillControlDeviceVolume options to iOS #243

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
4 changes: 4 additions & 0 deletions packages/react-native-google-cast/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ Next, rebuild your app as described in the ["Adding custom native code"](https:/
The plugin provides props for extra customization. Every time you change the props or plugins, you'll need to rebuild (and `prebuild`) the native app. If no extra properties are added, defaults will be used.

- `iosReceiverAppId` (_string_): unknown. Default `CC1AD845`
- `iosStartDiscoveryAfterFirstTapOnCastButton` (_boolean_) Default `true`
- `iosPhysicalVolumeButtonsWillControlDeviceVolume` (\_boolean) Default `false`
- `androidReceiverAppId` (_string_): unknown.
- `androidPlayServicesCastFrameworkVersion` (_string_): Version for the gradle package. Default `+`

Expand All @@ -49,6 +51,8 @@ The plugin provides props for extra customization. Every time you change the pro
"@config-plugins/react-native-google-cast",
{
"iosReceiverAppId": "...",
"iosStartDiscoveryAfterFirstTapOnCastButton": "...",
"iosPhysicalVolumeButtonsWillControlDeviceVolume": "...",
"androidReceiverAppId": "...",
"androidPlayServicesCastFrameworkVersion": "..."
}
Expand Down
9 changes: 7 additions & 2 deletions packages/react-native-google-cast/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@config-plugins/react-native-google-cast",
"version": "8.0.0",
"version": "8.0.1",
"description": "Config plugin to auto configure Google Cast on prebuild",
"main": "build/withGoogleCast.js",
"types": "build/withGoogleCast.d.ts",
Expand Down Expand Up @@ -34,5 +34,10 @@
"devDependencies": {
"expo-module-scripts": "^3.5.1"
},
"upstreamPackage": "react-native-google-cast"
"upstreamPackage": "react-native-google-cast",
"bugs": {
"url": "https://github.com/expo/config-plugins/issues"
},
"homepage": "https://github.com/expo/config-plugins#readme",
"author": ""
}
15 changes: 14 additions & 1 deletion packages/react-native-google-cast/src/withGoogleCast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,27 @@ const withGoogleCast: ConfigPlugin<
* ??
*/
androidReceiverAppId?: string;

/**
* @default true
*/
iosStartDiscoveryAfterFirstTapOnCastButton?: boolean;

/**
* @default false
*/
iosPhysicalVolumeButtonsWillControlDeviceVolume?: boolean;
} | void
> = (config, _props) => {
const props = _props || {};
// TODO: Are the Android and iOS receiverAppId values the same?
config = withIosGoogleCast(config, {
receiverAppId: props.iosReceiverAppId,
// disableDiscoveryAutostart?: boolean;
// startDiscoveryAfterFirstTapOnCastButton?: boolean;
startDiscoveryAfterFirstTapOnCastButton:
props.iosStartDiscoveryAfterFirstTapOnCastButton,
physicalVolumeButtonsWillControlDeviceVolume:
props.iosPhysicalVolumeButtonsWillControlDeviceVolume,
});

config = withAndroidGoogleCast(config, {
Expand Down
36 changes: 27 additions & 9 deletions packages/react-native-google-cast/src/withIosGoogleCast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const withIosLocalNetworkPermissions: ConfigPlugin<{
// Add required values
config.modResults.NSBonjourServices.push(
"_googlecast._tcp",
`_${receiverAppId}._googlecast._tcp`,
`_${receiverAppId}._googlecast._tcp`
);

// Remove duplicates
Expand Down Expand Up @@ -81,16 +81,16 @@ const withIosAppDelegateLoaded: ConfigPlugin<IosProps> = (config, props) => {
return withAppDelegate(config, (config) => {
if (!["objc", "objcpp"].includes(config.modResults.language)) {
throw new Error(
"react-native-google-cast config plugin does not support AppDelegate' that aren't Objective-C(++) yet.",
"react-native-google-cast config plugin does not support AppDelegate' that aren't Objective-C(++) yet."
);
}
config.modResults.contents =
addGoogleCastAppDelegateDidFinishLaunchingWithOptions(
config.modResults.contents,
props,
props
).contents;
config.modResults.contents = addGoogleCastAppDelegateImport(
config.modResults.contents,
config.modResults.contents
).contents;

return config;
Expand All @@ -102,6 +102,16 @@ export const withIosGoogleCast: ConfigPlugin<{
* @default 'CC1AD845'
*/
receiverAppId?: string;

/**
* @default true
*/
startDiscoveryAfterFirstTapOnCastButton?: boolean;

/**
* @default false
*/
physicalVolumeButtonsWillControlDeviceVolume?: boolean;
}> = (config, props) => {
config = withIosWifiEntitlements(config);
config = withIosLocalNetworkPermissions(config, {
Expand All @@ -110,7 +120,10 @@ export const withIosGoogleCast: ConfigPlugin<{
config = withIosAppDelegateLoaded(config, {
receiverAppId: props.receiverAppId,
// disableDiscoveryAutostart?: boolean;
// startDiscoveryAfterFirstTapOnCastButton?: boolean;
startDiscoveryAfterFirstTapOnCastButton:
props.startDiscoveryAfterFirstTapOnCastButton,
physicalVolumeButtonsWillControlDeviceVolume:
props.physicalVolumeButtonsWillControlDeviceVolume,
});

// TODO
Expand All @@ -127,6 +140,7 @@ type IosProps = {
receiverAppId?: string | null;
disableDiscoveryAutostart?: boolean;
startDiscoveryAfterFirstTapOnCastButton?: boolean;
physicalVolumeButtonsWillControlDeviceVolume?: boolean;
};

export function addGoogleCastAppDelegateDidFinishLaunchingWithOptions(
Expand All @@ -135,7 +149,8 @@ export function addGoogleCastAppDelegateDidFinishLaunchingWithOptions(
receiverAppId = null,
disableDiscoveryAutostart = false,
startDiscoveryAfterFirstTapOnCastButton = true,
}: IosProps = {},
physicalVolumeButtonsWillControlDeviceVolume = false,
}: IosProps = {}
) {
let newSrc = [];
newSrc.push(
Expand All @@ -152,10 +167,13 @@ export function addGoogleCastAppDelegateDidFinishLaunchingWithOptions(
// TODO: Same as above, read statically
// ` options.disableDiscoveryAutostart = ${String(!!disableDiscoveryAutostart)};`,
` options.startDiscoveryAfterFirstTapOnCastButton = ${String(
!!startDiscoveryAfterFirstTapOnCastButton,
!!startDiscoveryAfterFirstTapOnCastButton
)};`,
` options.physicalVolumeButtonsWillControlDeviceVolume = ${String(
!!physicalVolumeButtonsWillControlDeviceVolume
)};`,
" [GCKCastContext setSharedInstanceWithOptions:options];",
"#endif",
"#endif"
);

newSrc = newSrc.filter(Boolean);
Expand All @@ -175,7 +193,7 @@ function addGoogleCastAppDelegateImport(src: string) {
newSrc.push(
"#if __has_include(<GoogleCast/GoogleCast.h>)",
"#import <GoogleCast/GoogleCast.h>",
"#endif",
"#endif"
);

return mergeContents({
Expand Down