@@ -13,6 +13,7 @@ const socket = io(`/`, {
13
13
14
14
function CommsPanel ( { className, roomId } : Props ) {
15
15
const [ stream , setStream ] = useState < MediaStream > ( ) ;
16
+ const [ callStarts , setCallStarts ] = useState < boolean > ( false ) ;
16
17
17
18
const myVideo = useRef < HTMLVideoElement > ( null ) ;
18
19
const userVideo = useRef < HTMLVideoElement > ( null ) ;
@@ -81,10 +82,10 @@ function CommsPanel({ className, roomId }: Props) {
81
82
82
83
// when we receive the first peer connection, we immediately send out
83
84
// a peer connection request.
84
- attachSocketInitiator ( stream , roomId , userVideo , connectionRef ) ;
85
+ attachSocketInitiator ( stream , roomId , userVideo , setCallStarts , connectionRef ) ;
85
86
86
87
// as the receiver, I will propagate my data outwards now.
87
- attachSocketReceiver ( stream , roomId , userVideo , connectionRef ) ;
88
+ attachSocketReceiver ( stream , roomId , userVideo , setCallStarts , connectionRef ) ;
88
89
89
90
socket . on ( "endCall" , ( ) => {
90
91
// immediately destroy the socket listeners
@@ -96,13 +97,14 @@ function CommsPanel({ className, roomId }: Props) {
96
97
tracks . stop ( ) ;
97
98
} ) ;
98
99
userVideo . current . srcObject = null ;
100
+ setCallStarts ( false ) ;
99
101
}
100
102
if ( connectionRef . current && ! connectionRef . current . destroyed ) {
101
103
connectionRef . current . destroy ( ) ;
102
104
}
103
105
// 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 ) ;
106
108
// rejoin the room
107
109
socket . emit ( "joinRoom" , {
108
110
target : roomId ,
@@ -127,6 +129,11 @@ function CommsPanel({ className, roomId }: Props) {
127
129
/>
128
130
</ div >
129
131
< 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 > }
130
137
< video
131
138
playsInline
132
139
ref = { userVideo }
@@ -148,6 +155,7 @@ function attachSocketReceiver(
148
155
stream : MediaStream ,
149
156
roomId : string ,
150
157
userVideo : React . RefObject < HTMLVideoElement > ,
158
+ setCallStarts : React . Dispatch < React . SetStateAction < boolean > > ,
151
159
connectionRef : React . MutableRefObject < Peer . Instance | undefined > ,
152
160
) {
153
161
socket . on ( "startCall" , ( data ) => {
@@ -168,6 +176,7 @@ function attachSocketReceiver(
168
176
if ( userVideo . current ) {
169
177
console . log ( "user video exists" ) ;
170
178
userVideo . current . srcObject = stream ;
179
+ setCallStarts ( true ) ;
171
180
}
172
181
} ) ;
173
182
@@ -181,6 +190,7 @@ function attachSocketInitiator(
181
190
stream : MediaStream ,
182
191
roomId : string ,
183
192
userVideo : React . RefObject < HTMLVideoElement > ,
193
+ setCallStarts : React . Dispatch < React . SetStateAction < boolean > > ,
184
194
connectionRef : React . MutableRefObject < Peer . Instance | undefined > ,
185
195
) {
186
196
socket . on ( "peerConnected" , ( ) => {
@@ -200,6 +210,7 @@ function attachSocketInitiator(
200
210
if ( userVideo . current ) {
201
211
console . log ( "setting stream for handshake" ) ;
202
212
userVideo . current . srcObject = stream ;
213
+ setCallStarts ( true ) ;
203
214
}
204
215
} ) ;
205
216
0 commit comments