Skip to content

Commit 5237dbf

Browse files
authoredMar 26, 2024
feat: Introduces connection event for custom properties. (jitsi#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
1 parent 49ff6eb commit 5237dbf

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed
 

‎JitsiConnectionEvents.spec.ts

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ describe( "/JitsiConnectionEvents members", () => {
1010
CONNECTION_REDIRECTED,
1111
WRONG_STATE,
1212
DISPLAY_NAME_REQUIRED,
13+
PROPERTIES_UPDATED,
1314
JitsiConnectionEvents,
1415
...others
1516
} = exported;
@@ -21,6 +22,7 @@ describe( "/JitsiConnectionEvents members", () => {
2122
expect( CONNECTION_REDIRECTED ).toBe( 'connection.redirected' );
2223
expect( WRONG_STATE ).toBe( 'connection.wrongState' );
2324
expect( DISPLAY_NAME_REQUIRED ).toBe( 'connection.display_name_required' );
25+
expect( PROPERTIES_UPDATED ).toBe( 'connection.propertiesUpdated' );
2426

2527
expect( JitsiConnectionEvents ).toBeDefined();
2628

@@ -30,6 +32,7 @@ describe( "/JitsiConnectionEvents members", () => {
3032
expect( JitsiConnectionEvents.CONNECTION_REDIRECTED ).toBe( 'connection.redirected' );
3133
expect( JitsiConnectionEvents.WRONG_STATE ).toBe( 'connection.wrongState' );
3234
expect( JitsiConnectionEvents.DISPLAY_NAME_REQUIRED ).toBe( 'connection.display_name_required' );
35+
expect( JitsiConnectionEvents.PROPERTIES_UPDATED ).toBe( 'connection.propertiesUpdated' );
3336
} );
3437

3538
it( "unknown members", () => {

‎JitsiConnectionEvents.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,13 @@ export enum JitsiConnectionEvents {
5050
* joining the room.
5151
* There are cases like lobby room where display name is required.
5252
*/
53-
DISPLAY_NAME_REQUIRED = 'connection.display_name_required'
53+
DISPLAY_NAME_REQUIRED = 'connection.display_name_required',
54+
55+
/**
56+
* Indicates that the connection properties have been updated.
57+
* @param properties {object} - All available connection properties (e.g. shard, region).
58+
*/
59+
PROPERTIES_UPDATED = 'connection.propertiesUpdated'
5460
}
5561

5662
// exported for backward compatibility
@@ -60,3 +66,4 @@ export const CONNECTION_FAILED = JitsiConnectionEvents.CONNECTION_FAILED;
6066
export const CONNECTION_REDIRECTED = JitsiConnectionEvents.CONNECTION_REDIRECTED;
6167
export const WRONG_STATE = JitsiConnectionEvents.WRONG_STATE;
6268
export const DISPLAY_NAME_REQUIRED = JitsiConnectionEvents.DISPLAY_NAME_REQUIRED;
69+
export const PROPERTIES_UPDATED = JitsiConnectionEvents.PROPERTIES_UPDATED;

‎modules/xmpp/xmpp.js

+11
Original file line numberDiff line numberDiff line change
@@ -1110,5 +1110,16 @@ export default class XMPP extends Listenable {
11101110
}
11111111

11121112
this.sendDeploymentInfo = false;
1113+
1114+
const { region, shard } = aprops;
1115+
1116+
if (region || shard) {
1117+
// avoids sending empty values
1118+
this.eventEmitter.emit(JitsiConnectionEvents.PROPERTIES_UPDATED, JSON.parse(JSON.stringify({
1119+
region,
1120+
shard
1121+
})));
1122+
}
1123+
11131124
}
11141125
}

0 commit comments

Comments
 (0)
Please sign in to comment.