Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
1a09ea7
Add analyzer for the quality of peer connections
danxuliu Jun 22, 2020
5c45e23
Take round trip time into account when calculating the quality
danxuliu Jul 7, 2020
949f10a
Trigger events when the quality changes
danxuliu Jun 22, 2020
e2aa17d
Make possible to enable and disable the analysis of audio or video
danxuliu Jul 3, 2020
97e12ca
Guard against null screen peer
danxuliu Jul 2, 2020
a205ca4
Move peer and screenPeer to attributes in CallParticipantModel
danxuliu Jul 3, 2020
790c981
Add peer and screenPeer attributes to LocalCallParticipantModel
danxuliu Jul 3, 2020
ca4fdd1
Add analyzer for participants
danxuliu Jul 3, 2020
b5e724e
Add analyzer for calls
danxuliu Jul 3, 2020
58fc1f5
Show warning when the quality of the connection is bad
danxuliu Jul 3, 2020
d4ec4d9
Add a grace period before hiding the quality warning
danxuliu Jul 3, 2020
581d68a
Show tooltip only if the quality warning has not been recently shown
danxuliu Jul 3, 2020
6cb8de5
Take video and screen quality into account in the quality warning
danxuliu Jul 6, 2020
ffe3cf6
Move setting class attributes to its own method
danxuliu Jul 9, 2020
a6b897a
Increase grace period for quality tooltip
danxuliu Jul 9, 2020
087330b
Fix duplicated event listeners in ParticipantAnalyzer
danxuliu Jul 16, 2020
ad27de1
Dedicated connection warning icon
nickvergessen Jul 15, 2020
e12ca19
Add buttons to disable video and screen share to quality warning tooltip
Jul 17, 2020
1bff844
Add button to explicitly dismiss the quality warning tooltip
Jul 17, 2020
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
Prev Previous commit
Next Next commit
Add analyzer for calls
Signed-off-by: Daniel Calviño Sánchez <[email protected]>
  • Loading branch information
danxuliu committed Jul 21, 2020
commit b5e724ec16f837495620e0f29d435bd9108c3020
145 changes: 145 additions & 0 deletions src/utils/webrtc/analyzers/CallAnalyzer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
/**
*
* @copyright Copyright (c) 2020, Daniel Calviño Sánchez ([email protected])
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

import {
ParticipantAnalyzer,
} from './ParticipantAnalyzer'

/**
* Analyzer for the quality of the connections of a call.
*
* After a CallAnalyzer is created the analysis will be automatically started.
*
* When the quality of the connections change different events will be triggered
* depending on the case:
* - 'change:senderConnectionQualityAudio'
* - 'change:senderConnectionQualityVideo'
* - 'change:senderConnectionQualityScreen'
*
* The reported values are based on CONNECTION_QUALITY values of
* PeerConnectionAnalyzer.
*
* Besides the event themselves, the quality can be known too using
* "get(valueName)" or even directly from the "attributes" object.
*
* Once the CallAnalyzer is no longer needed "destroy()" must be called to stop
* the analysis.
*
* @param {LocalMediaModel} localMediaModel the model for the local media.
* @param {LocalCallParticipantModel} localCallParticipantModel the model for
* the local participant; null if an MCU is not used.
* @param {CallParticipantCollection} callParticipantCollection the collection
* for the remote participants.
*/
export default function CallAnalyzer(localMediaModel, localCallParticipantModel, callParticipantCollection) {
this.attributes = {
senderConnectionQualityAudio: null,
senderConnectionQualityVideo: null,
senderConnectionQualityScreen: null,
}

this._handlers = []

this._localMediaModel = localMediaModel
this._localCallParticipantModel = localCallParticipantModel
this._callParticipantCollection = callParticipantCollection

this._handleSenderConnectionQualityAudioChangeBound = this._handleSenderConnectionQualityAudioChange.bind(this)
this._handleSenderConnectionQualityVideoChangeBound = this._handleSenderConnectionQualityVideoChange.bind(this)
this._handleSenderConnectionQualityScreenChangeBound = this._handleSenderConnectionQualityScreenChange.bind(this)

if (localCallParticipantModel) {
this._localParticipantAnalyzer = new ParticipantAnalyzer()
this._localParticipantAnalyzer.setSenderParticipant(localMediaModel, localCallParticipantModel)

this._localParticipantAnalyzer.on('change:senderConnectionQualityAudio', this._handleSenderConnectionQualityAudioChangeBound)
this._localParticipantAnalyzer.on('change:senderConnectionQualityVideo', this._handleSenderConnectionQualityVideoChangeBound)
this._localParticipantAnalyzer.on('change:senderConnectionQualityScreen', this._handleSenderConnectionQualityScreenChangeBound)
}
}
CallAnalyzer.prototype = {

get: function(key) {
return this.attributes[key]
},

set: function(key, value) {
this.attributes[key] = value

this._trigger('change:' + key, [value])
},

on: function(event, handler) {
if (!this._handlers.hasOwnProperty(event)) {
this._handlers[event] = [handler]
} else {
this._handlers[event].push(handler)
}
},

off: function(event, handler) {
const handlers = this._handlers[event]
if (!handlers) {
return
}

const index = handlers.indexOf(handler)
if (index !== -1) {
handlers.splice(index, 1)
}
},

_trigger: function(event, args) {
let handlers = this._handlers[event]
if (!handlers) {
return
}

args.unshift(this)

handlers = handlers.slice(0)
for (let i = 0; i < handlers.length; i++) {
const handler = handlers[i]
handler.apply(handler, args)
}
},

destroy: function() {
if (this._localParticipantAnalyzer) {
this._localParticipantAnalyzer.off('change:senderConnectionQualityAudio', this._handleSenderConnectionQualityAudioChangeBound)

this._localParticipantAnalyzer.destroy()
}
},

_handleSenderConnectionQualityAudioChange: function(participantAnalyzer, senderConnectionQualityAudio) {
this.set('senderConnectionQualityAudio', senderConnectionQualityAudio)
},

_handleSenderConnectionQualityVideoChange: function(participantAnalyzer, senderConnectionQualityVideo) {
this.set('senderConnectionQualityVideo', senderConnectionQualityVideo)
},

_handleSenderConnectionQualityScreenChange: function(participantAnalyzer, senderConnectionQualityScreen) {
this.set('senderConnectionQualityScreen', senderConnectionQualityScreen)
},

}
13 changes: 13 additions & 0 deletions src/utils/webrtc/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import Signaling from '../signaling'
import initWebRtc from './webrtc'
import CallAnalyzer from './analyzers/CallAnalyzer'
import CallParticipantCollection from './models/CallParticipantCollection'
import LocalCallParticipantModel from './models/LocalCallParticipantModel'
import LocalMediaModel from './models/LocalMediaModel'
Expand All @@ -33,6 +34,7 @@ let webRtc = null
const callParticipantCollection = new CallParticipantCollection()
const localCallParticipantModel = new LocalCallParticipantModel()
const localMediaModel = new LocalMediaModel()
let callAnalyzer = null
let sentVideoQualityThrottler = null

let pendingConnectSignaling = null
Expand Down Expand Up @@ -129,6 +131,12 @@ async function signalingJoinCall(token) {

sentVideoQualityThrottler = new SentVideoQualityThrottler(localMediaModel, callParticipantCollection)

if (signaling.hasFeature('mcu')) {
callAnalyzer = new CallAnalyzer(localMediaModel, localCallParticipantModel, callParticipantCollection)
} else {
callAnalyzer = new CallAnalyzer(localMediaModel, null, callParticipantCollection)
}

return new Promise((resolve, reject) => {
startedCall = resolve

Expand All @@ -146,6 +154,9 @@ async function signalingLeaveCall(token) {
sentVideoQualityThrottler.destroy()
sentVideoQualityThrottler = null

callAnalyzer.destroy()
callAnalyzer = null

await getSignaling()
await signaling.leaveCall(token)
}
Expand Down Expand Up @@ -176,6 +187,8 @@ export {
localCallParticipantModel,
localMediaModel,

callAnalyzer,

connectSignaling,

signalingJoinConversation,
Expand Down