Skip to content

Commit f65404f

Browse files
committed
more visualization changes
1 parent 8f12f71 commit f65404f

File tree

4 files changed

+58
-9
lines changed

4 files changed

+58
-9
lines changed
Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useVoiceAssistant } from "@livekit/components-react";
2-
import { BarVisualizer } from "@livekit/react-native";
2+
import { BarVisualizer, VideoTrack } from "@livekit/react-native";
33
import { StyleProp, StyleSheet, View, ViewStyle } from "react-native";
44

55
type AgentVisualizationProps = {
@@ -10,32 +10,47 @@ export default function AgentVisualization({
1010
style
1111
}: AgentVisualizationProps) {
1212
const { state, audioTrack, videoTrack } = useVoiceAssistant();
13+
14+
let videoView = ( videoTrack
15+
? <VideoTrack
16+
trackRef={videoTrack}
17+
style={styles.videoTrack}
18+
/>
19+
: null
20+
)
1321
return (
14-
<View style={style} >
22+
<View style={[style, styles.container]} >
1523

1624
<BarVisualizer
1725
state={state}
18-
barCount={7}
26+
barCount={5}
1927
options={{
20-
minHeight: 0.5,
28+
minHeight: 0.1,
29+
barWidth: 12,
2130
}}
2231
trackRef={audioTrack}
2332
style={styles.voiceAssistant}
2433
/>
25-
34+
{videoView}
2635
</View>
2736
);
2837
};
2938

3039

3140
const styles = StyleSheet.create({
3241
container: {
42+
alignItems: 'center',
43+
justifyContent: 'center',
44+
},
45+
videoTrack: {
46+
position: 'absolute',
3347
width: '100%',
3448
height: '100%',
35-
alignItems: 'center',
49+
zIndex: 1,
3650
},
3751
voiceAssistant: {
3852
width: '100%',
39-
height: '100%',
53+
height: '30%',
54+
zIndex: 0,
4055
},
4156
});

app/assistant/ui/ControlBar.tsx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import { TrackReference, useEnsureRoom, useLocalParticipant } from "@livekit/components-react";
2+
import { BarVisualizer } from "@livekit/react-native";
3+
import { useEffect, useState } from "react";
14
import { ViewStyle, StyleSheet, View, Image, TouchableOpacity, StyleProp } from "react-native"
25

36
type ControlBarProps = {
@@ -22,6 +25,22 @@ export default function ControlBar({
2225
options,
2326
}: ControlBarProps) {
2427

28+
const room = useEnsureRoom();
29+
const { microphoneTrack, localParticipant } = useLocalParticipant();
30+
const [trackRef, setTrackRef] = useState<TrackReference | undefined>(undefined);
31+
32+
useEffect(() => {
33+
if (microphoneTrack) {
34+
setTrackRef({
35+
participant: localParticipant,
36+
publication: microphoneTrack,
37+
source: microphoneTrack.source,
38+
})
39+
} else {
40+
setTrackRef(undefined)
41+
}
42+
}, [microphoneTrack, localParticipant])
43+
2544
// Images
2645
var micImage = options.isMicEnabled
2746
? require('@/assets/images/mic_24dp.png')
@@ -46,6 +65,16 @@ export default function ControlBar({
4665
onPress={() => options.onMicClick()}
4766
>
4867
<Image style={styles.icon} source={micImage} />
68+
<BarVisualizer
69+
barCount={3}
70+
trackRef={trackRef}
71+
style={styles.micVisualizer}
72+
options= {{
73+
minHeight: 0.1,
74+
barColor: '#CCCCCC',
75+
barWidth: 2,
76+
}}
77+
/>
4978
</TouchableOpacity>
5079

5180
<TouchableOpacity
@@ -93,6 +122,7 @@ const styles = StyleSheet.create({
93122
},
94123
button: {
95124
flex: 1,
125+
flexDirection: 'row',
96126
height: 44,
97127
padding: 10,
98128
marginHorizontal: 4,
@@ -107,4 +137,8 @@ const styles = StyleSheet.create({
107137
icon: {
108138
width: 20,
109139
},
140+
micVisualizer: {
141+
width: 20,
142+
height: 20,
143+
}
110144
});

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"@config-plugins/react-native-webrtc": "12.0.0",
2121
"@expo/vector-icons": "^14.1.0",
2222
"@livekit/components-react": "^2.8.1",
23-
"@livekit/react-native": "^2.7.3",
23+
"@livekit/react-native": "^2.7.6",
2424
"@livekit/react-native-expo-plugin": "^1.0.1",
2525
"@livekit/react-native-webrtc": "^125.0.9",
2626
"@react-navigation/bottom-tabs": "^7.2.0",

0 commit comments

Comments
 (0)