Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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