-
Notifications
You must be signed in to change notification settings - Fork 29
/
Tray.js
118 lines (105 loc) · 3.98 KB
/
Tray.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import React, { useCallback, useState } from 'react';
import {
useAppMessage,
useAudioTrack,
useDaily,
useLocalSessionId,
useScreenShare,
useVideoTrack,
} from '@daily-co/daily-react';
import MeetingInformation from '../MeetingInformation/MeetingInformation';
import Chat from '../Chat/Chat';
import './Tray.css';
import {
CameraOn,
Leave,
CameraOff,
MicrophoneOff,
MicrophoneOn,
Screenshare,
Info,
ChatIcon,
ChatHighlighted,
} from './Icons';
export default function Tray({ leaveCall }) {
const callObject = useDaily();
const { isSharingScreen, startScreenShare, stopScreenShare } = useScreenShare();
const [showMeetingInformation, setShowMeetingInformation] = useState(false);
const [showChat, setShowChat] = useState(false);
const [newChatMessage, setNewChatMessage] = useState(false);
const localSessionId = useLocalSessionId();
const localVideo = useVideoTrack(localSessionId);
const localAudio = useAudioTrack(localSessionId);
const mutedVideo = localVideo.isOff;
const mutedAudio = localAudio.isOff;
/* When a remote participant sends a message in the chat, we want to display a differently colored
* chat icon in the Tray as a notification. By listening for the `"app-message"` event we'll know
* when someone has sent a message. */
useAppMessage({
onAppMessage: useCallback(() => {
/* Only light up the chat icon if the chat isn't already open. */
if (!showChat) {
setNewChatMessage(true);
}
}, [showChat])
});
const toggleVideo = useCallback(() => {
callObject.setLocalVideo(mutedVideo);
}, [callObject, mutedVideo]);
const toggleAudio = useCallback(() => {
callObject.setLocalAudio(mutedAudio);
}, [callObject, mutedAudio]);
const toggleScreenShare = () => isSharingScreen ? stopScreenShare() : startScreenShare();
const toggleMeetingInformation = () => {
setShowMeetingInformation(!showMeetingInformation);
};
const toggleChat = () => {
setShowChat(!showChat);
if (newChatMessage) {
setNewChatMessage(!newChatMessage);
}
};
return (
<div className="tray">
{showMeetingInformation && <MeetingInformation />}
{/* The chat messages 'live' in the <Chat/> component's state. We can't just remove the component */}
{/* from the DOM when hiding the chat, because that would cause us to lose that state. So we're */}
{/* choosing a slightly different approach of toggling the chat: always render the component, but only */}
{/* render its HTML when showChat is set to true. */}
{/* We're also passing down the toggleChat() function to the component, so we can open and close the chat */}
{/* from the chat UI and not just the Tray. */}
<Chat showChat={showChat} toggleChat={toggleChat} />
<div className="tray-buttons-container">
<div className="controls">
<button onClick={toggleVideo} type="button">
{mutedVideo ? <CameraOff /> : <CameraOn />}
{mutedVideo ? 'Turn camera on' : 'Turn camera off'}
</button>
<button onClick={toggleAudio} type="button">
{mutedAudio ? <MicrophoneOff /> : <MicrophoneOn />}
{mutedAudio ? 'Unmute mic' : 'Mute mic'}
</button>
</div>
<div className="actions">
<button onClick={toggleScreenShare} type="button">
<Screenshare />
{isSharingScreen ? 'Stop sharing screen' : 'Share screen'}
</button>
<button onClick={toggleMeetingInformation} type="button">
<Info />
{showMeetingInformation ? 'Hide info' : 'Show info'}
</button>
<button onClick={toggleChat} type="button">
{newChatMessage ? <ChatHighlighted /> : <ChatIcon />}
{showChat ? 'Hide chat' : 'Show chat'}
</button>
</div>
<div className="leave">
<button onClick={leaveCall} type="button">
<Leave /> Leave call
</button>
</div>
</div>
</div>
);
}