Skip to content

Commit

Permalink
feat: Detects different not-allowed errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
damencho committed May 3, 2024
1 parent 58a9144 commit ec98b02
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
6 changes: 6 additions & 0 deletions JitsiConferenceErrors.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as exported from "./JitsiConferenceErrors";

describe( "/JitsiConferenceErrors members", () => {
const {
AUTH_ERROR_TYPES,
AUTHENTICATION_REQUIRED,
CHAT_ERROR,
SETTINGS_ERROR,
Expand All @@ -30,6 +31,11 @@ describe( "/JitsiConferenceErrors members", () => {
} = exported;

it( "known members", () => {
expect( AUTH_ERROR_TYPES.GENERAL ).toBe( 'general' );
expect( AUTH_ERROR_TYPES.NO_MAIN_PARTICIPANTS ).toBe( 'no-main-participants' );
expect( AUTH_ERROR_TYPES.NO_VISITORS_LOBBY ).toBe( 'no-visitors-lobby' );
expect( AUTH_ERROR_TYPES.PROMOTION_NOT_ALLOWED ).toBe( 'promotion-not-allowed' );
expect( AUTH_ERROR_TYPES.ROOM_CREATION_RESTRICTION ).toBe( 'room-creation-restriction' );
expect( AUTHENTICATION_REQUIRED ).toBe( 'conference.authenticationRequired' );
expect( CHAT_ERROR ).toBe( 'conference.chatError' );
expect( SETTINGS_ERROR ).toBe( 'conference.settingsError' );
Expand Down
11 changes: 11 additions & 0 deletions JitsiConferenceErrors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,17 @@ export enum JitsiConferenceErrors {
VIDEOBRIDGE_NOT_AVAILABLE = 'conference.videobridgeNotAvailable'
}

/**
* Types that are passed for NOT_ALLOWED_ERROR.
*/
export enum AUTH_ERROR_TYPES {
GENERAL = 'general',
NO_MAIN_PARTICIPANTS = 'no-main-participants',
NO_VISITORS_LOBBY = 'no-visitors-lobby',
PROMOTION_NOT_ALLOWED = 'promotion-not-allowed',
ROOM_CREATION_RESTRICTION = 'room-creation-restriction'
}

// exported for backward compatibility
export const AUTHENTICATION_REQUIRED = JitsiConferenceErrors.AUTHENTICATION_REQUIRED;
export const CHAT_ERROR = JitsiConferenceErrors.CHAT_ERROR;
Expand Down
1 change: 0 additions & 1 deletion JitsiMeetJS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { TrackStreamingStatus } from './modules/connectivity/TrackStreamingStatu
import getActiveAudioDevice from './modules/detection/ActiveDeviceDetector';
import * as DetectionEvents from './modules/detection/DetectionEvents';
import TrackVADEmitter from './modules/detection/TrackVADEmitter';
import FeatureFlags from './modules/flags/FeatureFlags';
import ProxyConnectionService
from './modules/proxyconnection/ProxyConnectionService';
import recordingConstants from './modules/recording/recordingConstants';
Expand Down
15 changes: 14 additions & 1 deletion modules/xmpp/ChatRoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import $ from 'jquery';
import isEqual from 'lodash.isequal';
import { $iq, $msg, $pres, Strophe } from 'strophe.js';

import { AUTH_ERROR_TYPES } from '../../JitsiConferenceErrors';
import * as JitsiTranscriptionStatus from '../../JitsiTranscriptionStatus';
import { MediaType } from '../../service/RTC/MediaType';
import { VideoType } from '../../service/RTC/VideoType';
Expand Down Expand Up @@ -1254,11 +1255,14 @@ export default class ChatRoom extends Listenable {

const txtNode = $(pres).find('>error[type="cancel"]>text[xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"]');
const txt = txtNode.length && txtNode.text();
let type = AUTH_ERROR_TYPES.GENERAL;

// a race where we have sent a conference request to jicofo and jicofo was about to leave or just left
// because of no participants in the room, and we tried to create the room, without having
// permissions for that (only jicofo creates rooms)
if (txt === 'Room creation is restricted') {
type = AUTH_ERROR_TYPES.ROOM_CREATION_RESTRICTION;

if (!this._roomCreationRetries) {
this._roomCreationRetries = 0;
}
Expand All @@ -1275,9 +1279,18 @@ export default class ChatRoom extends Listenable {

return;
}
} else if ($(pres).find(
'>error[type="cancel"]>no-main-participants[xmlns="jitsi:visitors"]').length > 0) {
type = AUTH_ERROR_TYPES.NO_MAIN_PARTICIPANTS;
} else if ($(pres).find(
'>error[type="cancel"]>promotion-not-allowed[xmlns="jitsi:visitors"]').length > 0) {
type = AUTH_ERROR_TYPES.PROMOTION_NOT_ALLOWED;
} else if ($(pres).find(
'>error[type="cancel"]>no-visitors-lobby[xmlns="jitsi:visitors"]').length > 0) {
type = AUTH_ERROR_TYPES.NO_VISITORS_LOBBY;
}

this.eventEmitter.emit(XMPPEvents.ROOM_CONNECT_NOT_ALLOWED_ERROR, txt);
this.eventEmitter.emit(XMPPEvents.ROOM_CONNECT_NOT_ALLOWED_ERROR, type, txt);
}
} else if ($(pres).find('>error>service-unavailable').length) {
logger.warn('Maximum users limit for the room has been reached',
Expand Down

0 comments on commit ec98b02

Please sign in to comment.