Skip to content

Commit

Permalink
feat: Introduces connection event for custom properties. (jitsi#2493)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
damencho authored and subhamcyara committed Jul 19, 2024
1 parent f5792c6 commit 6f1c52e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
3 changes: 3 additions & 0 deletions JitsiConnectionEvents.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ describe( "/JitsiConnectionEvents members", () => {
CONNECTION_REDIRECTED,
WRONG_STATE,
DISPLAY_NAME_REQUIRED,
PROPERTIES_UPDATED,
JitsiConnectionEvents,
...others
} = exported;
Expand All @@ -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();

Expand All @@ -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", () => {
Expand Down
9 changes: 8 additions & 1 deletion JitsiConnectionEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
11 changes: 11 additions & 0 deletions modules/xmpp/xmpp.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
})));
}

}
}

0 comments on commit 6f1c52e

Please sign in to comment.