Skip to content

Commit 2cef699

Browse files
authored
Merge pull request #8427 from nextcloud/fix-using-signaling-settings-while-being-refetched
Fix using signaling settings while being refetched
2 parents 3bbcb9c + 0a14a20 commit 2cef699

File tree

2 files changed

+46
-3
lines changed

2 files changed

+46
-3
lines changed

src/utils/signaling.js

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,20 @@ Signaling.Base.prototype._trigger = function(ev, args) {
143143
EventBus.$emit('signaling-' + kebabCase(ev), args)
144144
}
145145

146+
Signaling.Base.prototype.setSettings = function(settings) {
147+
if (!settings) {
148+
// Signaling object is expected to always have a settings object
149+
return
150+
}
151+
152+
this.settings = settings
153+
154+
if (this._pendingUpdateSettingsPromise) {
155+
this._pendingUpdateSettingsPromise.resolve()
156+
delete this._pendingUpdateSettingsPromise
157+
}
158+
}
159+
146160
Signaling.Base.prototype.isNoMcuWarningEnabled = function() {
147161
return !this.settings.hideWarning
148162
}
@@ -658,6 +672,19 @@ Signaling.Standalone.prototype.connect = function() {
658672
}, 2000)
659673
}
660674

675+
if (this._pendingUpdateSettingsPromise) {
676+
console.info('Deferring establishing signaling connection until signaling settings are updated')
677+
678+
this._pendingUpdateSettingsPromise.then(() => {
679+
// "reconnect()" is called instead of "connect()", even if that
680+
// slightly delays the connection, as "reconnect()" prevents
681+
// duplicated connection requests.
682+
this.reconnect()
683+
})
684+
685+
return
686+
}
687+
661688
console.debug('Connecting to ' + this.url + ' for ' + this.settings.token)
662689
this.callbacks = {}
663690
this.id = 1
@@ -776,8 +803,7 @@ Signaling.Standalone.prototype.connect = function() {
776803
console.error('An error occurred processing the signaling message, please ask your server administrator to check the log file')
777804
break
778805
case 'token_expired':
779-
console.info('The signaling token is expired, need to update settings')
780-
this._trigger('updateSettings')
806+
this.processErrorTokenExpired()
781807
break
782808
default:
783809
console.error('Ignore unknown error', data)
@@ -1439,6 +1465,23 @@ Signaling.Standalone.prototype.processRoomParticipantsEvent = function(data) {
14391465
}
14401466
}
14411467

1468+
Signaling.Standalone.prototype.processErrorTokenExpired = function() {
1469+
console.info('The signaling token is expired, need to update settings')
1470+
1471+
if (!this._pendingUpdateSettingsPromise) {
1472+
let pendingUpdateSettingsPromiseResolve
1473+
this._pendingUpdateSettingsPromise = new Promise((resolve, reject) => {
1474+
// The Promise executor is run even before the Promise constructor has
1475+
// finished, so "this._pendingUpdateSettingsPromise" is not available
1476+
// yet.
1477+
pendingUpdateSettingsPromiseResolve = resolve
1478+
})
1479+
this._pendingUpdateSettingsPromise.resolve = pendingUpdateSettingsPromiseResolve
1480+
}
1481+
1482+
this._trigger('updateSettings')
1483+
}
1484+
14421485
Signaling.Standalone.prototype.requestOffer = function(sessionid, roomType, sid = undefined) {
14431486
if (!this.hasFeature('mcu')) {
14441487
console.warn("Can't request an offer without a MCU.")

src/utils/webrtc/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ async function connectSignaling(token) {
134134
signaling.on('updateSettings', async function() {
135135
const settings = await getSignalingSettings(token)
136136
console.debug('Received updated settings', settings)
137-
signaling.settings = settings
137+
signaling.setSettings(settings)
138138
})
139139

140140
signalingTypingHandler?.setSignaling(signaling)

0 commit comments

Comments
 (0)