Skip to content

Commit

Permalink
Send offer again when own peer is not initially connected
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Calviño Sánchez <[email protected]>
  • Loading branch information
danxuliu authored and backportbot[bot] committed Aug 5, 2021
1 parent 375ce0f commit 0f3e1bd
Showing 1 changed file with 60 additions and 15 deletions.
75 changes: 60 additions & 15 deletions src/utils/webrtc/webrtc.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,25 +129,49 @@ function checkStartPublishOwnPeer(signaling) {
}

if (ownPeer) {
if (delayedConnectionToPeer[ownPeer.id]) {
clearInterval(delayedConnectionToPeer[ownPeer.id])
delete delayedConnectionToPeer[ownPeer.id]
}
ownPeer.end()

// The peer does not need to be nullified in the
// localCallParticipantModel as a new peer will be immediately set by
// createPeer() below.
}

// Create own publishing stream.
ownPeer = webrtc.webrtc.createPeer({
id: currentSessionId,
type: 'video',
enableDataChannels: true,
enableSimulcast: signaling.hasFeature('simulcast'),
receiveMedia: {
offerToReceiveAudio: 0,
offerToReceiveVideo: 0,
},
sendVideoIfAvailable: signaling.getSendVideoIfAvailable(),
})
webrtc.emit('createdPeer', ownPeer)
ownPeer.start()
const createPeer = function() {
// Create own publishing stream.
ownPeer = webrtc.webrtc.createPeer({
id: currentSessionId,
type: 'video',
enableDataChannels: true,
enableSimulcast: signaling.hasFeature('simulcast'),
receiveMedia: {
offerToReceiveAudio: 0,
offerToReceiveVideo: 0,
},
sendVideoIfAvailable: signaling.getSendVideoIfAvailable(),
})
webrtc.emit('createdPeer', ownPeer)
ownPeer.start()

localCallParticipantModel.setPeer(ownPeer)
localCallParticipantModel.setPeer(ownPeer)
}

createPeer()

delayedConnectionToPeer[ownPeer.id] = setInterval(function() {
// New offers are periodically sent until a connection is established.
// As an offer can not be sent again from an existing peer it must be
// removed and a new one must be created from scratch.
if (ownPeer) {
ownPeer.end()
}

console.debug('No answer received for own peer, sending offer again')
createPeer()
}, 10000)
}

function sendCurrentMediaState() {
Expand Down Expand Up @@ -477,6 +501,18 @@ export default function initWebRtc(signaling, _callParticipantCollection, _local

clearErrorNotification()
Sounds.playLeave(true)

// The delayed connection for the own peer needs to be explicitly
// stopped, as the current own session is not passed along with the
// sessions of the other participants as "disconnected" to
// "usersChanged" when a call is left.
// The peer, on the other hand, is automatically ended by "leaveCall"
// below.
if (ownPeer && delayedConnectionToPeer[ownPeer.id]) {
clearInterval(delayedConnectionToPeer[ownPeer.id])
delete delayedConnectionToPeer[ownPeer.id]
}

webrtc.leaveCall()
})

Expand Down Expand Up @@ -734,6 +770,10 @@ export default function initWebRtc(signaling, _callParticipantCollection, _local

const forceReconnect = function(signaling, flags) {
if (ownPeer) {
if (delayedConnectionToPeer[ownPeer.id]) {
clearInterval(delayedConnectionToPeer[ownPeer.id])
delete delayedConnectionToPeer[ownPeer.id]
}
ownPeer.end()
ownPeer = null

Expand Down Expand Up @@ -1339,6 +1379,11 @@ export default function initWebRtc(signaling, _callParticipantCollection, _local

webrtc.on('disconnected', function() {
if (ownPeer) {
if (delayedConnectionToPeer[ownPeer.id]) {
clearInterval(delayedConnectionToPeer[ownPeer.id])
delete delayedConnectionToPeer[ownPeer.id]
}

ownPeer.end()
ownPeer = null

Expand Down

0 comments on commit 0f3e1bd

Please sign in to comment.