Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 45 additions & 2 deletions src/utils/signaling.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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