From 2cd4f7b464e218bc1445fec0c77dc3a5634c1b27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BC=D1=8F=D0=BD=20=D0=9C=D0=B8=D0=BD=D0=BA?= =?UTF-8?q?=D0=BE=D0=B2?= Date: Tue, 26 Mar 2024 14:49:39 -0500 Subject: [PATCH] feat: Introduces connection event for custom properties. (#2493) * feat: Introduces connection event for custom properties. Used for shard and region values coming from the backend. * squash: Update JitsiConnectionEvents.ts * squash: Update JitsiConnectionEvents.ts --- JitsiConnectionEvents.spec.ts | 3 +++ JitsiConnectionEvents.ts | 9 ++++++++- modules/xmpp/xmpp.js | 11 +++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/JitsiConnectionEvents.spec.ts b/JitsiConnectionEvents.spec.ts index 1a6e3c2277..7a8cb23cd0 100644 --- a/JitsiConnectionEvents.spec.ts +++ b/JitsiConnectionEvents.spec.ts @@ -10,6 +10,7 @@ describe( "/JitsiConnectionEvents members", () => { CONNECTION_REDIRECTED, WRONG_STATE, DISPLAY_NAME_REQUIRED, + PROPERTIES_UPDATED, JitsiConnectionEvents, ...others } = exported; @@ -21,6 +22,7 @@ describe( "/JitsiConnectionEvents members", () => { expect( CONNECTION_REDIRECTED ).toBe( 'connection.redirected' ); expect( WRONG_STATE ).toBe( 'connection.wrongState' ); expect( DISPLAY_NAME_REQUIRED ).toBe( 'connection.display_name_required' ); + expect( PROPERTIES_UPDATED ).toBe( 'connection.propertiesUpdated' ); expect( JitsiConnectionEvents ).toBeDefined(); @@ -30,6 +32,7 @@ describe( "/JitsiConnectionEvents members", () => { expect( JitsiConnectionEvents.CONNECTION_REDIRECTED ).toBe( 'connection.redirected' ); expect( JitsiConnectionEvents.WRONG_STATE ).toBe( 'connection.wrongState' ); expect( JitsiConnectionEvents.DISPLAY_NAME_REQUIRED ).toBe( 'connection.display_name_required' ); + expect( JitsiConnectionEvents.PROPERTIES_UPDATED ).toBe( 'connection.propertiesUpdated' ); } ); it( "unknown members", () => { diff --git a/JitsiConnectionEvents.ts b/JitsiConnectionEvents.ts index 419128a088..0910e77358 100644 --- a/JitsiConnectionEvents.ts +++ b/JitsiConnectionEvents.ts @@ -50,7 +50,13 @@ export enum JitsiConnectionEvents { * joining the room. * There are cases like lobby room where display name is required. */ - DISPLAY_NAME_REQUIRED = 'connection.display_name_required' + DISPLAY_NAME_REQUIRED = 'connection.display_name_required', + + /** + * Indicates that the connection properties have been updated. + * @param properties {object} - All available connection properties (e.g. shard, region). + */ + PROPERTIES_UPDATED = 'connection.propertiesUpdated' } // exported for backward compatibility @@ -60,3 +66,4 @@ export const CONNECTION_FAILED = JitsiConnectionEvents.CONNECTION_FAILED; export const CONNECTION_REDIRECTED = JitsiConnectionEvents.CONNECTION_REDIRECTED; export const WRONG_STATE = JitsiConnectionEvents.WRONG_STATE; export const DISPLAY_NAME_REQUIRED = JitsiConnectionEvents.DISPLAY_NAME_REQUIRED; +export const PROPERTIES_UPDATED = JitsiConnectionEvents.PROPERTIES_UPDATED; diff --git a/modules/xmpp/xmpp.js b/modules/xmpp/xmpp.js index 6c20d33dc1..f0a69efc21 100644 --- a/modules/xmpp/xmpp.js +++ b/modules/xmpp/xmpp.js @@ -1110,5 +1110,16 @@ export default class XMPP extends Listenable { } this.sendDeploymentInfo = false; + + const { region, shard } = aprops; + + if (region || shard) { + // avoids sending empty values + this.eventEmitter.emit(JitsiConnectionEvents.PROPERTIES_UPDATED, JSON.parse(JSON.stringify({ + region, + shard + }))); + } + } }