@@ -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+
146160Signaling . 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+
14421485Signaling . Standalone . prototype . requestOffer = function ( sessionid , roomType , sid = undefined ) {
14431486 if ( ! this . hasFeature ( 'mcu' ) ) {
14441487 console . warn ( "Can't request an offer without a MCU." )
0 commit comments