Skip to content

Commit

Permalink
Merge pull request #10257 from nextcloud/backport/8427/stable25
Browse files Browse the repository at this point in the history
[stable25] Fix using signaling settings while being refetched
  • Loading branch information
danxuliu committed Aug 18, 2023
2 parents 2cb21a2 + 1c1c408 commit c4d1683
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
47 changes: 45 additions & 2 deletions src/utils/signaling.js
Expand Up @@ -140,6 +140,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 @@ -646,6 +660,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 @@ -764,8 +791,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 @@ -1351,6 +1377,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 @@ -104,7 +104,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

0 comments on commit c4d1683

Please sign in to comment.