Skip to content

Commit ac18654

Browse files
committed
Send offer again when own peer is not initially connected
Signed-off-by: Daniel Calviño Sánchez <[email protected]>
1 parent eb318ae commit ac18654

File tree

1 file changed

+48
-13
lines changed

1 file changed

+48
-13
lines changed

src/utils/webrtc/webrtc.js

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -117,22 +117,42 @@ function checkStartPublishOwnPeer(signaling) {
117117
}
118118

119119
if (ownPeer) {
120+
if (delayedConnectionToPeer[ownPeer.id]) {
121+
clearInterval(delayedConnectionToPeer[ownPeer.id]);
122+
delete delayedConnectionToPeer[ownPeer.id];
123+
}
120124
ownPeer.end()
121125
}
122126

123-
// Create own publishing stream.
124-
ownPeer = webrtc.webrtc.createPeer({
125-
id: currentSessionId,
126-
type: 'video',
127-
enableDataChannels: true,
128-
receiveMedia: {
129-
offerToReceiveAudio: 0,
130-
offerToReceiveVideo: 0,
131-
},
132-
sendVideoIfAvailable: signaling.getSendVideoIfAvailable(),
133-
})
134-
webrtc.emit('createdPeer', ownPeer)
135-
ownPeer.start()
127+
var createPeer = function() {
128+
// Create own publishing stream.
129+
ownPeer = webrtc.webrtc.createPeer({
130+
id: currentSessionId,
131+
type: 'video',
132+
enableDataChannels: true,
133+
receiveMedia: {
134+
offerToReceiveAudio: 0,
135+
offerToReceiveVideo: 0,
136+
},
137+
sendVideoIfAvailable: signaling.getSendVideoIfAvailable(),
138+
})
139+
webrtc.emit('createdPeer', ownPeer)
140+
ownPeer.start()
141+
}
142+
143+
createPeer();
144+
145+
delayedConnectionToPeer[ownPeer.id] = setInterval(function() {
146+
// New offers are periodically sent until a connection is established.
147+
// As an offer can not be sent again from an existing peer it must be
148+
// removed and a new one must be created from scratch.
149+
if (ownPeer) {
150+
ownPeer.end();
151+
}
152+
153+
console.debug('No answer received for own peer, sending offer again')
154+
createPeer();
155+
}, 10000);
136156
}
137157

138158
function userHasStreams(user) {
@@ -340,6 +360,17 @@ export default function initWebRTC(signaling, _callParticipantCollection) {
340360
return
341361
}
342362

363+
// The delayed connection for the own peer needs to be explicitly
364+
// stopped, as the current own session is not passed along with the
365+
// sessions of the other participants as "disconnected" to
366+
// "usersChanged" when a call is left.
367+
// The peer, on the other hand, is automatically ended by "leaveCall"
368+
// below.
369+
if (ownPeer && delayedConnectionToPeer[ownPeer.id]) {
370+
clearInterval(delayedConnectionToPeer[ownPeer.id]);
371+
delete delayedConnectionToPeer[ownPeer.id];
372+
}
373+
343374
webrtc.leaveCall()
344375
})
345376

@@ -729,6 +760,10 @@ export default function initWebRTC(signaling, _callParticipantCollection) {
729760

730761
const forceReconnect = function(signaling, flags) {
731762
if (ownPeer) {
763+
if (delayedConnectionToPeer[ownPeer.id]) {
764+
clearInterval(delayedConnectionToPeer[ownPeer.id]);
765+
delete delayedConnectionToPeer[ownPeer.id];
766+
}
732767
ownPeer.end()
733768
ownPeer = null
734769
}

0 commit comments

Comments
 (0)