fix(breakout-rooms) make sure the default name is monotonically increasing

This commit is contained in:
Saúl Ibarra Corretgé 2021-11-25 12:43:42 +01:00 committed by Saúl Ibarra Corretgé
parent fc16bfa6cb
commit 4a5982da1f
5 changed files with 39 additions and 17 deletions

View File

@ -5,3 +5,8 @@
* *
*/ */
export const UPDATE_BREAKOUT_ROOMS = 'UPDATE_BREAKOUT_ROOMS'; export const UPDATE_BREAKOUT_ROOMS = 'UPDATE_BREAKOUT_ROOMS';
/**
* The type of (redux) action to update the room counter locally.
*/
export const _UPDATE_ROOM_COUNTER = '_UPDATE_ROOM_COUNTER';

View File

@ -15,6 +15,8 @@ import { setAudioMuted, setVideoMuted } from '../base/media';
import { getRemoteParticipants } from '../base/participants'; import { getRemoteParticipants } from '../base/participants';
import { clearNotifications } from '../notifications'; import { clearNotifications } from '../notifications';
import { _UPDATE_ROOM_COUNTER } from './actionTypes';
import { FEATURE_KEY } from './constants';
import { import {
getBreakoutRooms, getBreakoutRooms,
getMainRoom getMainRoom
@ -31,16 +33,19 @@ declare var APP: Object;
*/ */
export function createBreakoutRoom(name?: string) { export function createBreakoutRoom(name?: string) {
return (dispatch: Dispatch<any>, getState: Function) => { return (dispatch: Dispatch<any>, getState: Function) => {
const rooms = getBreakoutRooms(getState); const state = getState();
let { roomCounter } = state[FEATURE_KEY];
// TODO: remove this once we add UI to customize the name. const subject = name || i18next.t('breakoutRooms.defaultName', { index: ++roomCounter });
const index = Object.keys(rooms).length;
const subject = name || i18next.t('breakoutRooms.defaultName', { index });
sendAnalytics(createBreakoutRoomsEvent('create')); sendAnalytics(createBreakoutRoomsEvent('create'));
dispatch({
type: _UPDATE_ROOM_COUNTER,
roomCounter
});
// $FlowExpectedError // $FlowExpectedError
getCurrentConference(getState)?.getBreakoutRooms() getCurrentConference(state)?.getBreakoutRooms()
?.createBreakoutRoom(subject); ?.createBreakoutRoom(subject);
}; };
} }

View File

@ -20,11 +20,12 @@ StateListenerRegistry.register(
dispatch(moveToRoom(roomId)); dispatch(moveToRoom(roomId));
}); });
conference.on(JitsiConferenceEvents.BREAKOUT_ROOMS_UPDATED, rooms => { conference.on(JitsiConferenceEvents.BREAKOUT_ROOMS_UPDATED, ({ rooms, roomCounter }) => {
logger.debug('Room list updated'); logger.debug('Room list updated');
dispatch({ dispatch({
type: UPDATE_BREAKOUT_ROOMS, type: UPDATE_BREAKOUT_ROOMS,
rooms rooms,
roomCounter
}); });
}); });
} }

View File

@ -2,20 +2,33 @@
import { ReducerRegistry } from '../base/redux'; import { ReducerRegistry } from '../base/redux';
import { UPDATE_BREAKOUT_ROOMS } from './actionTypes'; import {
_UPDATE_ROOM_COUNTER,
UPDATE_BREAKOUT_ROOMS
} from './actionTypes';
import { FEATURE_KEY } from './constants'; import { FEATURE_KEY } from './constants';
const DEFAULT_STATE = {
rooms: {},
roomCounter: 0
};
/** /**
* Listen for actions for the breakout-rooms feature. * Listen for actions for the breakout-rooms feature.
*/ */
ReducerRegistry.register(FEATURE_KEY, (state = { rooms: {} }, action) => { ReducerRegistry.register(FEATURE_KEY, (state = DEFAULT_STATE, action) => {
switch (action.type) { switch (action.type) {
case _UPDATE_ROOM_COUNTER:
return {
...state,
roomCounter: action.roomCounter
};
case UPDATE_BREAKOUT_ROOMS: { case UPDATE_BREAKOUT_ROOMS: {
const { nextIndex, rooms } = action; const { roomCounter, rooms } = action;
return { return {
...state, ...state,
nextIndex, roomCounter,
rooms rooms
}; };
} }

View File

@ -11,11 +11,6 @@
-- Component "breakout.jitmeet.example.com" "muc" -- Component "breakout.jitmeet.example.com" "muc"
-- restrict_room_creation = true -- restrict_room_creation = true
-- storage = "memory" -- storage = "memory"
-- modules_enabled = {
-- "muc_meeting_id";
-- "muc_domain_mapper";
-- --"token_verification";
-- }
-- admins = { "focusUser@auth.jitmeet.example.com" } -- admins = { "focusUser@auth.jitmeet.example.com" }
-- muc_room_locking = false -- muc_room_locking = false
-- muc_room_default_public_jids = true -- muc_room_default_public_jids = true
@ -161,6 +156,7 @@ function broadcast_breakout_rooms(room_jid)
local json_msg = json.encode({ local json_msg = json.encode({
type = BREAKOUT_ROOMS_IDENTITY_TYPE, type = BREAKOUT_ROOMS_IDENTITY_TYPE,
event = JSON_TYPE_UPDATE_BREAKOUT_ROOMS, event = JSON_TYPE_UPDATE_BREAKOUT_ROOMS,
roomCounter = main_room._data.breakout_rooms_counter,
rooms = rooms rooms = rooms
}); });
@ -192,7 +188,9 @@ function create_breakout_room(room_jid, subject)
if not main_room._data.breakout_rooms then if not main_room._data.breakout_rooms then
main_room._data.breakout_rooms = {}; main_room._data.breakout_rooms = {};
main_room._data.breakout_rooms_counter = 0;
end end
main_room._data.breakout_rooms_counter = main_room._data.breakout_rooms_counter + 1;
main_room._data.breakout_rooms[breakout_room_jid] = subject; main_room._data.breakout_rooms[breakout_room_jid] = subject;
main_room._data.breakout_rooms_active = true; main_room._data.breakout_rooms_active = true;
-- Make room persistent - not to be destroyed - if all participants join breakout rooms. -- Make room persistent - not to be destroyed - if all participants join breakout rooms.