mirror of
https://github.com/zoriya/react-native-omni.git
synced 2026-08-05 21:58:54 +00:00
feat(android): support chromecast
This commit is contained in:
+3
-4
@@ -1,15 +1,14 @@
|
||||
import type { ConfigPlugin } from "@expo/config-plugins";
|
||||
import { createRunOncePlugin } from "@expo/config-plugins";
|
||||
import pkg from "../../package.json";
|
||||
import { withCast } from "./withCast";
|
||||
import { withMediaNotifications } from "./withMediaNotifications";
|
||||
import { withPip } from "./withPip";
|
||||
|
||||
const withOmni: ConfigPlugin = (config) => {
|
||||
let nextConfig = withPip(config);
|
||||
nextConfig = withMediaNotifications(nextConfig);
|
||||
return nextConfig;
|
||||
return withCast(withMediaNotifications(withPip(config)));
|
||||
};
|
||||
|
||||
export default createRunOncePlugin(withOmni, pkg.name, pkg.version);
|
||||
|
||||
export { withMediaNotifications, withPip };
|
||||
export { withCast, withMediaNotifications, withPip };
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
import {
|
||||
AndroidConfig,
|
||||
type ConfigPlugin,
|
||||
withAndroidManifest,
|
||||
} from "@expo/config-plugins";
|
||||
|
||||
const OPTIONS_PROVIDER_NAME =
|
||||
"com.google.android.gms.cast.framework.OPTIONS_PROVIDER_CLASS_NAME";
|
||||
const OPTIONS_PROVIDER_VALUE = "dev.zoriya.omni.OmniCastOptionsProvider";
|
||||
|
||||
function patchManifestForCast(
|
||||
androidManifest: AndroidConfig.Manifest.AndroidManifest,
|
||||
): AndroidConfig.Manifest.AndroidManifest {
|
||||
const mainApplication =
|
||||
AndroidConfig.Manifest.getMainApplication(androidManifest);
|
||||
if (!mainApplication) {
|
||||
console.warn(
|
||||
"AndroidManifest.xml is missing a <application> element - skipping Omni cast config.",
|
||||
);
|
||||
return androidManifest;
|
||||
}
|
||||
|
||||
const metaData = mainApplication["meta-data"] ?? [];
|
||||
const existing = metaData.find(
|
||||
(item) => item.$["android:name"] === OPTIONS_PROVIDER_NAME,
|
||||
);
|
||||
if (existing) {
|
||||
existing.$["android:value"] = OPTIONS_PROVIDER_VALUE;
|
||||
} else {
|
||||
metaData.push({
|
||||
$: {
|
||||
"android:name": OPTIONS_PROVIDER_NAME,
|
||||
"android:value": OPTIONS_PROVIDER_VALUE,
|
||||
},
|
||||
});
|
||||
}
|
||||
mainApplication["meta-data"] = metaData;
|
||||
|
||||
return androidManifest;
|
||||
}
|
||||
|
||||
export const withCast: ConfigPlugin = (config) => {
|
||||
return withAndroidManifest(config, (manifestConfig) => {
|
||||
manifestConfig.modResults = patchManifestForCast(manifestConfig.modResults);
|
||||
return manifestConfig;
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user