Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable26] Fix using signaling settings while being refetched #10259

Merged
merged 2 commits into from Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
47 changes: 45 additions & 2 deletions src/utils/signaling.js
Expand Up @@ -141,6 +141,20 @@ Signaling.Base.prototype._trigger = function(ev, args) {
EventBus.$emit('signaling-' + kebabCase(ev), args)
}

Signaling.Base.prototype.setSettings = function(settings) {
if (!settings) {
// Signaling object is expected to always have a settings object
return
}

this.settings = settings

if (this._pendingUpdateSettingsPromise) {
this._pendingUpdateSettingsPromise.resolve()
delete this._pendingUpdateSettingsPromise
}
}

Signaling.Base.prototype.isNoMcuWarningEnabled = function() {
return !this.settings.hideWarning
}
Expand Down Expand Up @@ -654,6 +668,19 @@ Signaling.Standalone.prototype.connect = function() {
}, 2000)
}

if (this._pendingUpdateSettingsPromise) {
console.info('Deferring establishing signaling connection until signaling settings are updated')

this._pendingUpdateSettingsPromise.then(() => {
// "reconnect()" is called instead of "connect()", even if that
// slightly delays the connection, as "reconnect()" prevents
// duplicated connection requests.
this.reconnect()
})

return
}

console.debug('Connecting to ' + this.url + ' for ' + this.settings.token)
this.callbacks = {}
this.id = 1
Expand Down Expand Up @@ -772,8 +799,7 @@ Signaling.Standalone.prototype.connect = function() {
console.error('An error occurred processing the signaling message, please ask your server administrator to check the log file')
break
case 'token_expired':
console.info('The signaling token is expired, need to update settings')
this._trigger('updateSettings')
this.processErrorTokenExpired()
break
default:
console.error('Ignore unknown error', data)
Expand Down Expand Up @@ -1421,6 +1447,23 @@ Signaling.Standalone.prototype.processRoomParticipantsEvent = function(data) {
}
}

Signaling.Standalone.prototype.processErrorTokenExpired = function() {
console.info('The signaling token is expired, need to update settings')

if (!this._pendingUpdateSettingsPromise) {
let pendingUpdateSettingsPromiseResolve
this._pendingUpdateSettingsPromise = new Promise((resolve, reject) => {
// The Promise executor is run even before the Promise constructor has
// finished, so "this._pendingUpdateSettingsPromise" is not available
// yet.
pendingUpdateSettingsPromiseResolve = resolve
})
this._pendingUpdateSettingsPromise.resolve = pendingUpdateSettingsPromiseResolve
}

this._trigger('updateSettings')
}

Signaling.Standalone.prototype.requestOffer = function(sessionid, roomType, sid = undefined) {
if (!this.hasFeature('mcu')) {
console.warn("Can't request an offer without a MCU.")
Expand Down
2 changes: 1 addition & 1 deletion src/utils/webrtc/index.js
Expand Up @@ -123,7 +123,7 @@ async function connectSignaling(token) {
signaling.on('updateSettings', async function() {
const settings = await getSignalingSettings(token)
console.debug('Received updated settings', settings)
signaling.settings = settings
signaling.setSettings(settings)
})

}
Expand Down