Browse Source

Expose connection state in LocalCallParticipantModel

When the MCU is used there will be a sender peer connection (the so
called "own peer"). The ICE connection state of that peer connection is
now exposed in LocalCallParticipantModel in the same way as in
CallParticipantModel. However, unlike the CallParticipantModel, the
LocalCallParticipantModel is always set and the peer object set or unset
on it as needed; if there is no peer object set the connection state
will not be set.

When the MCU is not used there is no sender peer connection (nor any
other peer associated to the LocalCallParticipantModel), so in that case
the connection state attribute will not be set either.

Besides that some logs were also added for the ICE connection state
changes of the own peer, similar to the logs already present for the
peer connection of the other participants.

Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
pull/5779/head
Daniel Calviño Sánchez 4 years ago
parent
commit
5f1c447085
  1. 51
      src/utils/webrtc/models/LocalCallParticipantModel.js
  2. 39
      src/utils/webrtc/webrtc.js

51
src/utils/webrtc/models/LocalCallParticipantModel.js

@ -21,6 +21,8 @@
import store from '../../../store/index.js'
import { ConnectionState } from './CallParticipantModel'
export default function LocalCallParticipantModel() {
this.attributes = {
@ -28,11 +30,13 @@ export default function LocalCallParticipantModel() {
peer: null,
screenPeer: null,
guestName: null,
connectionState: null,
}
this._handlers = []
this._handleForcedMuteBound = this._handleForcedMute.bind(this)
this._handleExtendedIceConnectionStateChangeBound = this._handleExtendedIceConnectionStateChange.bind(this)
}
@ -107,7 +111,22 @@ LocalCallParticipantModel.prototype = {
console.warn('Mismatch between stored peer ID and ID of given peer: ', this.get('peerId'), peer.id)
}
if (this.get('peer')) {
this.get('peer').off('extendedIceConnectionStateChange', this._handleExtendedIceConnectionStateChangeBound)
}
this.set('peer', peer)
if (!this.get('peer')) {
this.set('connectionState', null)
return
}
// Reset state that depends on the Peer object.
this._handleExtendedIceConnectionStateChange(this.get('peer').pc.iceConnectionState)
this.get('peer').on('extendedIceConnectionStateChange', this._handleExtendedIceConnectionStateChangeBound)
},
setScreenPeer(screenPeer) {
@ -132,4 +151,36 @@ LocalCallParticipantModel.prototype = {
this._trigger('forcedMute')
},
_handleExtendedIceConnectionStateChange(extendedIceConnectionState) {
switch (extendedIceConnectionState) {
case 'new':
this.set('connectionState', ConnectionState.NEW)
break
case 'checking':
this.set('connectionState', ConnectionState.CHECKING)
break
case 'connected':
this.set('connectionState', ConnectionState.CONNECTED)
break
case 'completed':
this.set('connectionState', ConnectionState.COMPLETED)
break
case 'disconnected':
this.set('connectionState', ConnectionState.DISCONNECTED)
break
case 'disconnected-long':
this.set('connectionState', ConnectionState.DISCONNECTED_LONG)
break
case 'failed':
this.set('connectionState', ConnectionState.FAILED)
break
// 'failed-no-restart' is not emitted by own peer
case 'closed':
this.set('connectionState', ConnectionState.CLOSED)
break
default:
console.error('Unexpected (extended) ICE connection state: ', extendedIceConnectionState)
}
},
}

39
src/utils/webrtc/webrtc.js

@ -691,6 +691,43 @@ export default function initWebRtc(signaling, _callParticipantCollection, _local
})
}
function setHandlerForOwnIceConnectionStateChange(peer) {
peer.pc.addEventListener('iceconnectionstatechange', function() {
peer.emit('extendedIceConnectionStateChange', peer.pc.iceConnectionState)
switch (peer.pc.iceConnectionState) {
case 'checking':
console.debug('Connecting own peer...', peer)
break
case 'connected':
case 'completed':
console.debug('Connection established (own peer).', peer)
break
case 'disconnected':
console.debug('Disconnected (own peer).', peer)
setTimeout(function() {
if (peer.pc.iceConnectionState !== 'disconnected') {
return
}
peer.emit('extendedIceConnectionStateChange', 'disconnected-long')
}, 5000)
break
case 'failed':
console.debug('Connection failed (own peer).', peer)
break
case 'closed':
console.debug('Connection closed (own peer).', peer)
break
}
})
}
const forceReconnect = function(signaling, flags) {
if (ownPeer) {
webrtc.removePeers(ownPeer.id)
@ -856,7 +893,7 @@ export default function initWebRtc(signaling, _callParticipantCollection, _local
if (peer.type === 'video') {
if (peer.id === signaling.getSessionId()) {
console.debug('Not adding ICE connection state handler for own peer', peer)
setHandlerForOwnIceConnectionStateChange(peer)
} else {
setHandlerForIceConnectionStateChange(peer)
}

Loading…
Cancel
Save