Skip to content
Prev Previous commit
Next Next commit
Repeat initial state messages when the HPB is used
When the HPB is used it is possible to know when the local participant
has established a connection with a remote participant, but it is not
possible to know when a remote participant established a connection with
the local one. The initial state (audio and video on or off) was sent
just once when the local participant establishes a connection with the
remote one, which caused that, in some cases, the message was received
by the remote participant before a connection was established with the
local one and thus ignored.

Even if there is code to try to locally detect the initial media state
of the remote participant it has shown to not be as reliable as
desirable, which causes a wrong media state to be sometimes shown for
remote participants until the participant changes it again (or another
user joins and the messages are sent again to everyone).

However, even if it is not possible to know when a remote participant
established a connection with the local one it is safe to assume that it
happened in a "reasonable" amount of time since the local participant
has established a connection with the remote one.

Due to this now the initial media state is first sent when that happens,
and then it is sent again several times (with an increasing interval) in
the next 31 seconds. If a connection is established with another
participant in the meantime the cycle starts again.

Signed-off-by: Daniel Calviño Sánchez <[email protected]>
  • Loading branch information
danxuliu committed Sep 25, 2020
commit 25f3cd5efab39341881a7aefe5693add4b55869e
32 changes: 31 additions & 1 deletion src/utils/webrtc/webrtc.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const delayedConnectionToPeer = []
let callParticipantCollection = null
let localCallParticipantModel = null
let showedTURNWarning = false
let sendCurrentMediaStateWithRepetitionTimeout = null

function arrayDiff(a, b) {
return a.filter(function(i) {
Expand Down Expand Up @@ -154,6 +155,31 @@ function sendCurrentMediaState() {
}
}

function sendCurrentMediaStateWithRepetition(timeout) {
if (!timeout) {
timeout = 0

clearTimeout(sendCurrentMediaStateWithRepetitionTimeout)
}

sendCurrentMediaStateWithRepetitionTimeout = setTimeout(function() {
sendCurrentMediaState()

if (!timeout) {
timeout = 1000
} else {
timeout *= 2
}

if (timeout > 16000) {
sendCurrentMediaStateWithRepetitionTimeout = null
return
}

sendCurrentMediaStateWithRepetition(timeout)
}, timeout)
}

function userHasStreams(user) {
let flags = user
if (flags.hasOwnProperty('inCall')) {
Expand Down Expand Up @@ -498,7 +524,11 @@ export default function initWebRTC(signaling, _callParticipantCollection, _local
function handleIceConnectionStateConnected(peer) {
// Send the current information about the video and microphone
// state.
sendCurrentMediaState()
if (!signaling.hasFeature('mcu')) {
sendCurrentMediaState()
} else {
sendCurrentMediaStateWithRepetition()
}

if (signaling.settings.userId === null) {
const currentGuestNick = store.getters.getDisplayName()
Expand Down