@@ -26,27 +26,30 @@ export default function ConnectToLivestreamScreen({ navigation }: Props) {
2626 const [ connectionError , setConnectionError ] = useState < string | null > ( null ) ;
2727 const [ loading , setLoading ] = useState ( false ) ;
2828
29- const [ livestreamUrl , setLivestreamUrl ] = useState ( '' ) ;
30- const [ viewerToken , setViewerToken ] = useState ( '' ) ;
29+ const [ fishjamId , setFishjamId ] = useState (
30+ process . env . EXPO_PUBLIC_FISHJAM_ID ?? '' ,
31+ ) ;
32+ const [ roomName , setRoomName ] = useState ( '' ) ;
3133
32- const onTapConnectButton = async ( ) => {
33- try {
34- if ( ! livestreamUrl ) {
35- setConnectionError ( 'Livestream URL is required' ) ;
36- return ;
37- }
34+ const validateInputs = ( ) => {
35+ if ( ! fishjamId ) {
36+ throw new Error ( 'Fishjam ID is required' ) ;
37+ }
3838
39- if ( ! viewerToken ) {
40- setConnectionError ( 'Viewer token is required') ;
41- return ;
42- }
39+ if ( ! roomName ) {
40+ throw new Error ( 'Room name is required') ;
41+ }
42+ } ;
4343
44+ const onTapConnectViewerButton = async ( ) => {
45+ try {
46+ validateInputs ( ) ;
4447 setConnectionError ( null ) ;
4548 setLoading ( true ) ;
4649
47- navigation . navigate ( 'LivestreamScreen ' , {
48- livestreamUrl ,
49- viewerToken ,
50+ navigation . navigate ( 'LivestreamViewerScreen ' , {
51+ fishjamId ,
52+ roomName ,
5053 } ) ;
5154 } catch ( e ) {
5255 const message =
@@ -56,7 +59,24 @@ export default function ConnectToLivestreamScreen({ navigation }: Props) {
5659 setLoading ( false ) ;
5760 }
5861 } ;
62+ const onTapConnectStreamerButton = async ( ) => {
63+ try {
64+ validateInputs ( ) ;
65+ setConnectionError ( null ) ;
66+ setLoading ( true ) ;
5967
68+ navigation . navigate ( 'LivestreamStreamerScreen' , {
69+ fishjamId,
70+ roomName,
71+ } ) ;
72+ } catch ( e ) {
73+ const message =
74+ 'message' in ( e as Error ) ? ( e as Error ) . message : 'Unknown error' ;
75+ setConnectionError ( message ) ;
76+ } finally {
77+ setLoading ( false ) ;
78+ }
79+ } ;
6080 return (
6181 < DismissKeyboard >
6282 < SafeAreaView style = { styles . safeArea } >
@@ -70,18 +90,23 @@ export default function ConnectToLivestreamScreen({ navigation }: Props) {
7090 resizeMode = "contain"
7191 />
7292 < TextInput
73- onChangeText = { setLivestreamUrl }
74- placeholder = "Livestream URL "
75- defaultValue = { livestreamUrl }
93+ onChangeText = { setFishjamId }
94+ placeholder = "Fishjam ID "
95+ defaultValue = { fishjamId }
7696 />
7797 < TextInput
78- onChangeText = { setViewerToken }
79- placeholder = "Viewer Token "
80- defaultValue = { viewerToken }
98+ onChangeText = { setRoomName }
99+ placeholder = "Room Name "
100+ defaultValue = { roomName }
81101 />
82102 < Button
83103 title = "Connect to Livestream"
84- onPress = { onTapConnectButton }
104+ onPress = { onTapConnectViewerButton }
105+ disabled = { loading }
106+ />
107+ < Button
108+ title = "Stream Livestream"
109+ onPress = { onTapConnectStreamerButton }
85110 disabled = { loading }
86111 />
87112 </ KeyboardAvoidingView >
0 commit comments