Skip to content

Commit

Permalink
feat(visitors): Checks for visitors support per room.
Browse files Browse the repository at this point in the history
  • Loading branch information
damencho committed Feb 28, 2024
1 parent 639ad56 commit f3b2eda
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 2 deletions.
9 changes: 9 additions & 0 deletions JitsiConference.js
Original file line number Diff line number Diff line change
Expand Up @@ -3890,6 +3890,15 @@ JitsiConference.prototype.isMembersOnly = function() {
return Boolean(this.room && this.room.membersOnlyEnabled);
};

/**
* Returns <tt>true</tt> if the room supports visitors feature.
*
* @returns {boolean} whether conference room has visitors support.
*/
JitsiConference.prototype.isVisitorsSupported = function() {
return Boolean(this.room && this.room.visitorsSupported);
};

/**
* Enables lobby by moderators
*
Expand Down
2 changes: 2 additions & 0 deletions JitsiConferenceEventManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,8 @@ JitsiConferenceEventManager.prototype.setupChatRoomListeners = function() {

this.chatRoomForwarder.forward(XMPPEvents.MUC_MEMBERS_ONLY_CHANGED,
JitsiConferenceEvents.MEMBERS_ONLY_CHANGED);
this.chatRoomForwarder.forward(XMPPEvents.MUC_VISITORS_SUPPORTED_CHANGED,
JitsiConferenceEvents.VISITORS_SUPPORTED_CHANGED);

chatRoom.addListener(XMPPEvents.MUC_MEMBER_JOINED,
conference.onMemberJoined.bind(conference));
Expand Down
4 changes: 3 additions & 1 deletion JitsiConferenceEvents.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as exported from "./JitsiConferenceEvents";
import {VISITORS_MESSAGE, VISITORS_REJECTION} from "./JitsiConferenceEvents";

// this test is brittle on purpose because it's designed to ensure that the TypeScript conversion maintains backward compatibility

Expand Down Expand Up @@ -71,6 +70,7 @@ describe( "/JitsiConferenceEvents members", () => {
VIDEO_UNMUTE_PERMISSIONS_CHANGED,
VISITORS_MESSAGE,
VISITORS_REJECTION,
VISITORS_SUPPORTED_CHANGED,
BOT_TYPE_CHANGED,
LOBBY_USER_JOINED,
LOBBY_USER_UPDATED,
Expand Down Expand Up @@ -133,6 +133,7 @@ describe( "/JitsiConferenceEvents members", () => {
expect( RECORDER_STATE_CHANGED ).toBe( 'conference.recorderStateChanged' );
expect( VIDEO_SIP_GW_AVAILABILITY_CHANGED ).toBe( 'conference.videoSIPGWAvailabilityChanged' );
expect( VIDEO_SIP_GW_SESSION_STATE_CHANGED ).toBe( 'conference.videoSIPGWSessionStateChanged' );
expect( VISITORS_SUPPORTED_CHANGED ).toBe( 'conference.visitorsSupported' );
expect( START_MUTED_POLICY_CHANGED ).toBe( 'conference.start_muted_policy_changed' );
expect( STARTED_MUTED ).toBe( 'conference.started_muted' );
expect( SUBJECT_CHANGED ).toBe( 'conference.subjectChanged' );
Expand Down Expand Up @@ -226,6 +227,7 @@ describe( "/JitsiConferenceEvents members", () => {
expect( JitsiConferenceEvents.USER_ROLE_CHANGED ).toBe( 'conference.roleChanged' );
expect( JitsiConferenceEvents.USER_STATUS_CHANGED ).toBe( 'conference.statusChanged' );
expect( JitsiConferenceEvents.VIDEO_UNMUTE_PERMISSIONS_CHANGED ).toBe( 'conference.video_unmute_permissions_changed' );
expect( JitsiConferenceEvents.VISITORS_SUPPORTED_CHANGED ).toBe( 'conference.visitorsSupported' );
expect( JitsiConferenceEvents.BOT_TYPE_CHANGED ).toBe( 'conference.bot_type_changed' );
expect( JitsiConferenceEvents.LOBBY_USER_JOINED ).toBe( 'conference.lobby.userJoined' );
expect( JitsiConferenceEvents.LOBBY_USER_UPDATED ).toBe( 'conference.lobby.userUpdated' );
Expand Down
6 changes: 6 additions & 0 deletions JitsiConferenceEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,11 @@ export enum JitsiConferenceEvents {
*/
VIDEO_UNMUTE_PERMISSIONS_CHANGED = 'conference.video_unmute_permissions_changed',

/**
* Indicates that the conference has support for visitors.
*/
VISITORS_SUPPORTED_CHANGED = 'conference.visitorsSupported',

/**
* Event indicating we have received a message from the visitors component.
*/
Expand Down Expand Up @@ -551,5 +556,6 @@ export const USER_STATUS_CHANGED = JitsiConferenceEvents.USER_STATUS_CHANGED;
export const VIDEO_SIP_GW_AVAILABILITY_CHANGED = JitsiConferenceEvents.VIDEO_SIP_GW_AVAILABILITY_CHANGED;
export const VIDEO_SIP_GW_SESSION_STATE_CHANGED = JitsiConferenceEvents.VIDEO_SIP_GW_SESSION_STATE_CHANGED;
export const VIDEO_UNMUTE_PERMISSIONS_CHANGED = JitsiConferenceEvents.VIDEO_UNMUTE_PERMISSIONS_CHANGED;
export const VISITORS_SUPPORTED_CHANGED = JitsiConferenceEvents.VISITORS_SUPPORTED_CHANGED;
export const VISITORS_MESSAGE = JitsiConferenceEvents.VISITORS_MESSAGE;
export const VISITORS_REJECTION = JitsiConferenceEvents.VISITORS_REJECTION;
8 changes: 8 additions & 0 deletions modules/xmpp/ChatRoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,14 @@ export default class ChatRoom extends Listenable {
this.eventEmitter.emit(XMPPEvents.MUC_MEMBERS_ONLY_CHANGED, membersOnly);
}

const visitorsSupported = $(result)
.find('>query>x[type="result"]>field[var="muc#roominfo_visitorsEnabled"]>value').text() === '1';

if (visitorsSupported !== this.visitorsSupported) {
this.visitorsSupported = visitorsSupported;
this.eventEmitter.emit(XMPPEvents.MUC_VISITORS_SUPPORTED_CHANGED, visitorsSupported);
}

const roomMetadataEl
= $(result).find('>query>x[type="result"]>field[var="muc#roominfo_jitsimetadata"]>value');
const roomMetadataText = roomMetadataEl?.text();
Expand Down
3 changes: 2 additions & 1 deletion service/xmpp/XMPPEvents.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ describe( "/service/xmpp/XMPPEvents members", () => {
expect( XMPPEvents.MUC_ROLE_CHANGED ).toBe( 'xmpp.muc_role_changed' );
expect( XMPPEvents.MUC_LOCK_CHANGED ).toBe( 'xmpp.muc_lock_changed' );
expect( XMPPEvents.MUC_MEMBERS_ONLY_CHANGED ).toBe( 'xmpp.muc_members_only_changed' );
expect( XMPPEvents.MUC_VISITORS_SUPPORTED_CHANGED ).toBe( 'xmpp.muc_visitors_supported_changed' );
expect( XMPPEvents.PARTICIPANT_AUDIO_MUTED ).toBe( 'xmpp.audio_muted' );
expect( XMPPEvents.PARTICIPANT_VIDEO_MUTED ).toBe( 'xmpp.video_muted' );
expect( XMPPEvents.PARTICIPANT_VIDEO_TYPE_CHANGED ).toBe( 'xmpp.video_type' );
Expand Down Expand Up @@ -114,4 +115,4 @@ describe( "/service/xmpp/XMPPEvents members", () => {
const keys = Object.keys( others );
expect( keys ).withContext( `Extra members: ${ keys.join( ", " ) }` ).toEqual( [] );
} );
} );
} );
3 changes: 3 additions & 0 deletions service/xmpp/XMPPEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ export enum XMPPEvents {
// Designates an event indicating that the MUC members only config has changed.
MUC_MEMBERS_ONLY_CHANGED = 'xmpp.muc_members_only_changed',

// Designates an event indicating that the MUC visitors support has changed.
MUC_VISITORS_SUPPORTED_CHANGED = 'xmpp.muc_visitors_supported_changed',

// Designates an event indicating that a participant in the XMPP MUC has
// advertised that they have audio muted (or unmuted).
PARTICIPANT_AUDIO_MUTED = 'xmpp.audio_muted',
Expand Down

0 comments on commit f3b2eda

Please sign in to comment.