Skip to content

Commit

Permalink
show google cast only on mobile
Browse files Browse the repository at this point in the history
  • Loading branch information
locksten committed Oct 1, 2024
1 parent 80efe6d commit 34ef2cc
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 32 deletions.
36 changes: 36 additions & 0 deletions packages/app-harness/src/components/CastButton/index.mobile.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { Button, View } from 'react-native';
import { CastButton, CastContext } from 'react-native-google-cast';
import { testProps } from '../../config';
import { useLoggerContext } from '../../context';

export function CastComponent() {
const { logDebug } = useLoggerContext();
return (
<View style={{ flexDirection: 'row', alignItems: 'center', justifyContent: 'space-around' }}>
<CastButton
{...testProps('app-harness-home-cast-support-button')}
style={{ width: 24, height: 24, tintColor: 'black' }}
/>
<Button
title="Load Media"
onPress={async () => {
try {
const client = (await CastContext.getSessionManager().getCurrentCastSession())?.client;
if (!client) {
logDebug(`Cast: client is "${client}"`);
return;
}
await client.loadMedia({
mediaInfo: {
contentUrl:
'https://commondatastorage.googleapis.com/gtv-videos-bucket/CastVideos/mp4/BigBuckBunny.mp4',
},
});
} catch (e) {
logDebug(`Cast: ${e}`);
}
}}
/>
</View>
);
}
38 changes: 6 additions & 32 deletions packages/app-harness/src/components/CastButton/index.tsx
Original file line number Diff line number Diff line change
@@ -1,36 +1,10 @@
import { Button, View } from 'react-native';
import { CastButton, CastContext } from 'react-native-google-cast';
import { Text } from 'react-native';
import { testProps } from '../../config';
import { useLoggerContext } from '../../context';

export function CastComponent() {
const { logDebug } = useLoggerContext();
export const CastComponent = () => {
return (
<View style={{ flexDirection: 'row', alignItems: 'center', justifyContent: 'space-around' }}>
<CastButton
{...testProps('app-harness-home-cast-support-button')}
style={{ width: 24, height: 24, tintColor: 'black' }}
/>
<Button
title="Load Media"
onPress={async () => {
try {
const client = (await CastContext.getSessionManager().getCurrentCastSession())?.client;
if (!client) {
logDebug(`Cast: client is "${client}"`);
return;
}
await client.loadMedia({
mediaInfo: {
contentUrl:
'https://commondatastorage.googleapis.com/gtv-videos-bucket/CastVideos/mp4/BigBuckBunny.mp4',
},
});
} catch (e) {
logDebug(`Cast: ${e}`);
}
}}
/>
</View>
<Text style={{ color: 'black' }} {...testProps('app-harness-home-cast-support-text')}>
Not supported
</Text>
);
}
};

0 comments on commit 34ef2cc

Please sign in to comment.