Skip to content

Commit 185dc0f

Browse files
authored
Merge pull request #70 from CS3219-AY2425S1/minor-add-status-msg
Add a simple status message indicating no call started
2 parents 78011ce + 9572fb7 commit 185dc0f

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

peerprep/components/questionpage/CommsPanel.tsx

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const socket = io(`/`, {
1313

1414
function CommsPanel({ className, roomId }: Props) {
1515
const [stream, setStream] = useState<MediaStream>();
16+
const [callStarts, setCallStarts] = useState<boolean>(false);
1617

1718
const myVideo = useRef<HTMLVideoElement>(null);
1819
const userVideo = useRef<HTMLVideoElement>(null);
@@ -81,10 +82,10 @@ function CommsPanel({ className, roomId }: Props) {
8182

8283
// when we receive the first peer connection, we immediately send out
8384
// a peer connection request.
84-
attachSocketInitiator(stream, roomId, userVideo, connectionRef);
85+
attachSocketInitiator(stream, roomId, userVideo, setCallStarts, connectionRef);
8586

8687
// as the receiver, I will propagate my data outwards now.
87-
attachSocketReceiver(stream, roomId, userVideo, connectionRef);
88+
attachSocketReceiver(stream, roomId, userVideo, setCallStarts, connectionRef);
8889

8990
socket.on("endCall", () => {
9091
// immediately destroy the socket listeners
@@ -96,13 +97,14 @@ function CommsPanel({ className, roomId }: Props) {
9697
tracks.stop();
9798
});
9899
userVideo.current.srcObject = null;
100+
setCallStarts(false);
99101
}
100102
if (connectionRef.current && !connectionRef.current.destroyed) {
101103
connectionRef.current.destroy();
102104
}
103105
// reattach the sockets
104-
attachSocketInitiator(stream, roomId, userVideo, connectionRef);
105-
attachSocketReceiver(stream, roomId, userVideo, connectionRef);
106+
attachSocketInitiator(stream, roomId, userVideo, setCallStarts, connectionRef);
107+
attachSocketReceiver(stream, roomId, userVideo, setCallStarts, connectionRef);
106108
// rejoin the room
107109
socket.emit("joinRoom", {
108110
target: roomId,
@@ -127,6 +129,11 @@ function CommsPanel({ className, roomId }: Props) {
127129
/>
128130
</div>
129131
<div className="video">
132+
{!callStarts &&
133+
<p>
134+
No signal from other user.
135+
(Don't worry - the call doesn't start until we get a signal from both users!)
136+
</p>}
130137
<video
131138
playsInline
132139
ref={userVideo}
@@ -148,6 +155,7 @@ function attachSocketReceiver(
148155
stream: MediaStream,
149156
roomId: string,
150157
userVideo: React.RefObject<HTMLVideoElement>,
158+
setCallStarts: React.Dispatch<React.SetStateAction<boolean>>,
151159
connectionRef: React.MutableRefObject<Peer.Instance | undefined>,
152160
) {
153161
socket.on("startCall", (data) => {
@@ -168,6 +176,7 @@ function attachSocketReceiver(
168176
if (userVideo.current) {
169177
console.log("user video exists");
170178
userVideo.current.srcObject = stream;
179+
setCallStarts(true);
171180
}
172181
});
173182

@@ -181,6 +190,7 @@ function attachSocketInitiator(
181190
stream: MediaStream,
182191
roomId: string,
183192
userVideo: React.RefObject<HTMLVideoElement>,
193+
setCallStarts: React.Dispatch<React.SetStateAction<boolean>>,
184194
connectionRef: React.MutableRefObject<Peer.Instance | undefined>,
185195
) {
186196
socket.on("peerConnected", () => {
@@ -200,6 +210,7 @@ function attachSocketInitiator(
200210
if (userVideo.current) {
201211
console.log("setting stream for handshake");
202212
userVideo.current.srcObject = stream;
213+
setCallStarts(true);
203214
}
204215
});
205216

0 commit comments

Comments
 (0)