Skip to content

Commit

Permalink
feat(app): handle default microphonePublication value
Browse files Browse the repository at this point in the history
  • Loading branch information
momenthana committed Mar 6, 2024
1 parent 1b454ba commit 637b2a5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
18 changes: 13 additions & 5 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { StyleSheet, View } from 'react-native';
import { WebView } from 'react-native-webview';
import { registerGlobals } from '@livekit/react-native';
import { registerGlobals, useParticipant } from '@livekit/react-native';
import { useAudioRoom } from './room';
import React, { useCallback, useLayoutEffect, useRef, useState } from 'react';

Expand All @@ -16,9 +16,12 @@ interface FunctionalProps {
export function Functional(props: FunctionalProps) {
const { roomId, accessToken, readonly, onEvent } = props;
const webViewRef = useRef<WebView>(null);
const [defaultMic, setDefaultMic] = useState(false);
const [defaultReadonly, setDefaultReadonly] = useState(false);

const { connect, disconnect, microphonePublication } = useAudioRoom();
const { room, connect, disconnect } = useAudioRoom();

const { microphonePublication } = useParticipant(room.localParticipant);

const onMessage = (event: { nativeEvent: { data: string } }) => {
//receive message from the web page. working here until here
Expand All @@ -39,18 +42,23 @@ export function Functional(props: FunctionalProps) {
break;

case 'app.event.mute':
microphonePublication?.handleMuted();
setDefaultMic(false);
break;

case 'app.event.unmute':
microphonePublication?.handleUnmuted();
setDefaultMic(true);
break;

default:
break;
}
};

useLayoutEffect(() => {
if (defaultMic) microphonePublication?.handleUnmuted();
else microphonePublication?.handleMuted();
}, [defaultMic, microphonePublication]);

const handleDefaultValues = useCallback(() => {
if (!defaultReadonly) setDefaultReadonly(!!readonly);
}, [defaultReadonly, readonly]);
Expand All @@ -72,7 +80,7 @@ export function Functional(props: FunctionalProps) {
style={styles.container}
originWhitelist={['*']}
source={{
uri: `http://localhost:3000/whiteboard?room_id=${roomId}&access_token=${accessToken}&readonly=${defaultReadonly}`,
uri: `https://draw.seoltab.com/whiteboard?room_id=${roomId}&access_token=${accessToken}&readonly=${defaultReadonly}`,
}}
allowsInlineMediaPlayback={true}
onMessage={onMessage}
Expand Down
7 changes: 6 additions & 1 deletion src/room.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,10 @@ export const useAudioRoom = () => {
};
}, [connect, disconnect]);

return { connect, disconnect, microphonePublication };
return {
room,
connect,
disconnect,
microphonePublication,
};
};

0 comments on commit 637b2a5

Please sign in to comment.