Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Introduces connection event for custom properties. #2493

Merged
merged 3 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: use lodash clone or structuredClone.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That will drop the keys with undefined values?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. Do you want to?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. That was a quick hack to avoid if this and if that to not add the keys.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah then go ahead!

region,
shard
})));
}

}
}
Loading