Skip to content

Commit

Permalink
Merge pull request #6082 from nextcloud/backport/3732/stable22.1
Browse files Browse the repository at this point in the history
[stable22.1] Send offer again when own peer is not initially connected
  • Loading branch information
danxuliu authored Aug 5, 2021
2 parents 34685b4 + 0f3e1bd commit 03e6f40
Showing 1 changed file with 60 additions and 18 deletions.
78 changes: 60 additions & 18 deletions src/utils/webrtc/webrtc.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,26 +129,49 @@ function checkStartPublishOwnPeer(signaling) {
}

if (ownPeer) {
webrtc.removePeers(ownPeer.id)
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 @@ -478,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 @@ -735,7 +770,10 @@ export default function initWebRtc(signaling, _callParticipantCollection, _local

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

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

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

ownPeer.end()
ownPeer = null

Expand Down

0 comments on commit 03e6f40

Please sign in to comment.