Skip to content

Commit

Permalink
feat(silent): track if participant joined without audio (#2534)
Browse files Browse the repository at this point in the history
* feat(silent): track if participant joined without audio

* Fix failing tests, use jitsi.org namespace

---------

Co-authored-by: Дамян Минков <[email protected]>
  • Loading branch information
nbeckindy and damencho authored Jul 1, 2024
1 parent ea523fc commit fc115be
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 7 deletions.
28 changes: 28 additions & 0 deletions JitsiConference.js
Original file line number Diff line number Diff line change
Expand Up @@ -1052,6 +1052,19 @@ JitsiConference.prototype.setDisplayName = function(name) {
}
};

/**
* Set join without audio
* @param silent whether user joined without audio
*/
JitsiConference.prototype.setIsSilent = function(silent) {
if (this.room) {
this.room.addOrReplaceInPresence('silent', {
attributes: { xmlns: 'http://jitsi.org/protocol/silent' },
value: silent
}) && this.room.sendPresence();
}
};

/**
* Set new subject for this conference. (available only for moderator)
* @param {string} subject new subject
Expand Down Expand Up @@ -1997,6 +2010,21 @@ JitsiConference.prototype.onDisplayNameChanged = function(jid, displayName) {
displayName);
};

JitsiConference.prototype.onSilentStatusChanged = function(jid, isSilent) {
const id = Strophe.getResourceFromJid(jid);
const participant = this.getParticipantById(id);

if (!participant) {
return;
}

participant.setIsSilent(isSilent);
this.eventEmitter.emit(
JitsiConferenceEvents.SILENT_STATUS_CHANGED,
id,
isSilent);
};

/**
* Notifies this JitsiConference that a JitsiRemoteTrack was added to the conference.
*
Expand Down
3 changes: 3 additions & 0 deletions JitsiConferenceEventManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,9 @@ JitsiConferenceEventManager.prototype.setupChatRoomListeners = function() {
chatRoom.addListener(XMPPEvents.DISPLAY_NAME_CHANGED,
conference.onDisplayNameChanged.bind(conference));

chatRoom.addListener(XMPPEvents.SILENT_STATUS_CHANGED,
conference.onSilentStatusChanged.bind(conference));

chatRoom.addListener(XMPPEvents.LOCAL_ROLE_CHANGED, role => {
conference.onLocalRoleChanged(role);
});
Expand Down
3 changes: 3 additions & 0 deletions JitsiConferenceEvents.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ describe( "/JitsiConferenceEvents members", () => {
BREAKOUT_ROOMS_MOVE_TO_ROOM,
BREAKOUT_ROOMS_UPDATED,
METADATA_UPDATED,
SILENT_STATUS_CHANGED,
JitsiConferenceEvents,
...others
} = exported;
Expand Down Expand Up @@ -167,6 +168,7 @@ describe( "/JitsiConferenceEvents members", () => {
expect( BREAKOUT_ROOMS_MOVE_TO_ROOM ).toBe( 'conference.breakout-rooms.move-to-room' );
expect( BREAKOUT_ROOMS_UPDATED ).toBe( 'conference.breakout-rooms.updated' );
expect( METADATA_UPDATED ).toBe( 'conference.metadata.updated' );
expect( SILENT_STATUS_CHANGED ).toBe( 'conference.silentStatusChanged' );
expect( ENCODE_TIME_STATS_RECEIVED ).toBe( 'conference.encode_time_stats_received' );

expect( JitsiConferenceEvents ).toBeDefined();
Expand Down Expand Up @@ -245,6 +247,7 @@ describe( "/JitsiConferenceEvents members", () => {
expect( JitsiConferenceEvents.BREAKOUT_ROOMS_MOVE_TO_ROOM ).toBe( 'conference.breakout-rooms.move-to-room' );
expect( JitsiConferenceEvents.BREAKOUT_ROOMS_UPDATED ).toBe( 'conference.breakout-rooms.updated' );
expect( JitsiConferenceEvents.METADATA_UPDATED ).toBe( 'conference.metadata.updated' );
expect( JitsiConferenceEvents.SILENT_STATUS_CHANGED ).toBe( 'conference.silentStatusChanged' );
expect( JitsiConferenceEvents.E2EE_VERIFICATION_READY ).toBe( 'conference.e2ee.verification.ready' );
expect( JitsiConferenceEvents.E2EE_VERIFICATION_COMPLETED ).toBe( 'conference.e2ee.verification.completed' );
expect( JitsiConferenceEvents.E2EE_VERIFICATION_AVAILABLE ).toBe( 'conference.e2ee.verification.available' );
Expand Down
6 changes: 6 additions & 0 deletions JitsiConferenceEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,11 @@ export enum JitsiConferenceEvents {
*/
SERVER_REGION_CHANGED = 'conference.server_region_changed',

/**
* Indicates a user has joined without audio
*/
SILENT_STATUS_CHANGED = 'conference.silentStatusChanged',

/**
* Indicates that start muted settings changed.
*/
Expand Down Expand Up @@ -550,6 +555,7 @@ export const PHONE_NUMBER_CHANGED = JitsiConferenceEvents.PHONE_NUMBER_CHANGED;
export const PROPERTIES_CHANGED = JitsiConferenceEvents.PROPERTIES_CHANGED;
export const RECORDER_STATE_CHANGED = JitsiConferenceEvents.RECORDER_STATE_CHANGED;
export const SERVER_REGION_CHANGED = JitsiConferenceEvents.SERVER_REGION_CHANGED;
export const SILENT_STATUS_CHANGED = JitsiConferenceEvents.SILENT_STATUS_CHANGED;
export const START_MUTED_POLICY_CHANGED = JitsiConferenceEvents.START_MUTED_POLICY_CHANGED;
export const STARTED_MUTED = JitsiConferenceEvents.STARTED_MUTED;
export const SUBJECT_CHANGED = JitsiConferenceEvents.SUBJECT_CHANGED;
Expand Down
19 changes: 18 additions & 1 deletion JitsiParticipant.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ export default class JitsiParticipant {
* @param {object} identity - the xmpp identity
* @param {boolean?} isReplacing - whether this is a participant replacing another into the meeting.
* @param {boolean?} isReplaced - whether this is a participant to be kicked and replaced into the meeting.
* @param {boolean?} isSilent - whether participant has joined without audio
*/
constructor(jid, conference, displayName, hidden, statsID, status, identity, isReplacing, isReplaced) {
constructor(jid, conference, displayName, hidden, statsID, status, identity, isReplacing, isReplaced, isSilent) {
this._jid = jid;
this._id = Strophe.getResourceFromJid(jid);
this._conference = conference;
Expand All @@ -42,6 +43,7 @@ export default class JitsiParticipant {
this._identity = identity;
this._isReplacing = isReplacing;
this._isReplaced = isReplaced;
this._isSilent = isSilent;
this._features = new Set();

/**
Expand Down Expand Up @@ -276,6 +278,13 @@ export default class JitsiParticipant {
return this._isReplacing;
}

/**
* @returns {Boolean} Whether this participant has joined without audio.
*/
isSilent() {
return this._isSilent;
}

/**
* @returns {Boolean} Whether this participant has muted their video.
*/
Expand Down Expand Up @@ -323,6 +332,14 @@ export default class JitsiParticipant {
this._isReplacing = newIsReplacing;
}

/**
* Sets whether participant has joined without audio.
* @param {boolean} newIsSilent - whether is silent.
*/
setIsSilent(newIsSilent) {
this._isSilent = newIsSilent;
}

/**
* Sets the value of a property of this participant, and fires an event if
* the value has changed.
Expand Down
17 changes: 16 additions & 1 deletion modules/xmpp/ChatRoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,9 @@ export default class ChatRoom extends Listenable {
case 'nick':
member.nick = node.value;
break;
case 'silent':
member.isSilent = node.value;
break;
case 'userId':
member.id = node.value;
break;
Expand Down Expand Up @@ -685,7 +688,8 @@ export default class ChatRoom extends Listenable {
member.botType,
member.jid,
member.features,
member.isReplaceParticipant);
member.isReplaceParticipant,
member.isSilent);

// we are reporting the status with the join
// so we do not want a second event about status update
Expand Down Expand Up @@ -740,6 +744,11 @@ export default class ChatRoom extends Listenable {
memberOfThis.displayName = member.displayName;
}

// join without audio
if (member.isSilent) {
memberOfThis.isSilent = member.isSilent;
}

// update stored status message to be able to detect changes
if (memberOfThis.status !== member.status) {
hasStatusUpdate = true;
Expand Down Expand Up @@ -776,6 +785,12 @@ export default class ChatRoom extends Listenable {
displayName);
}
break;
case 'silent':
this.eventEmitter.emit(
XMPPEvents.SILENT_STATUS_CHANGED,
from,
member.isSilent);
break;
case 'bridgeNotAvailable':
if (member.isFocus && !this.noBridgeAvailable) {
this.noBridgeAvailable = true;
Expand Down
15 changes: 10 additions & 5 deletions modules/xmpp/ChatRoom.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ describe('ChatRoom', () => {
undefined,
'fulljid',
undefined, // features
0 // isReplaceParticipant
0, // isReplaceParticipant
undefined // isSilent
]);
});

Expand Down Expand Up @@ -220,7 +221,8 @@ describe('ChatRoom', () => {
undefined,
'jid=attr',
undefined, // features
0); // isReplaceParticipant
0, // isReplaceParticipant
undefined); // isSilent
});

it('parses muc user replacing other user correctly', () => {
Expand Down Expand Up @@ -254,7 +256,8 @@ describe('ChatRoom', () => {
undefined,
'jid=attr',
undefined, // features
1); // isReplaceParticipant
1, // isReplaceParticipant
undefined); // isSilent
});

it('parses identity correctly', () => {
Expand Down Expand Up @@ -305,7 +308,8 @@ describe('ChatRoom', () => {
undefined,
'fulljid',
undefined, // features
0 // isReplaceParticipant
0, // isReplaceParticipant
undefined // isSilent
]);
});

Expand Down Expand Up @@ -342,7 +346,8 @@ describe('ChatRoom', () => {
expectedBotType,
'fulljid',
undefined, // features
0 // isReplaceParticipant
0, // isReplaceParticipant
undefined // isSilent
]);
});

Expand Down
5 changes: 5 additions & 0 deletions service/xmpp/XMPPEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,11 @@ export enum XMPPEvents {
*/
SESSION_ACCEPT_TIMEOUT = 'xmpp.session_accept_timeout',

/**
* Event fired when participant joins a meeting without audio.
*/
SILENT_STATUS_CHANGED = 'xmpp.silent_status_changed',

/**
* Event fired after successful sending of jingle source-add.
*/
Expand Down

0 comments on commit fc115be

Please sign in to comment.