Skip to content

Instantly share code, notes, and snippets.

@Tushkiz
Last active February 26, 2024 09:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tushkiz/c68ea866da359a8d2af4dc3ec9dbedb4 to your computer and use it in GitHub Desktop.
Save Tushkiz/c68ea866da359a8d2af4dc3ec9dbedb4 to your computer and use it in GitHub Desktop.
Sample for creating Breakout rooms using Dyte
import { BreakoutRoomsManager } from '@dytesdk/ui-kit';
import DyteClient from '@dytesdk/web-core';
class BreakoutRooms {
private manager: BreakoutRoomsManager;
private meeting: DyteClient;
constructor(meeting: DyteClient) {
this.manager = new BreakoutRoomsManager();
this.meeting = meeting;
this.meeting.connectedMeetings.addListener('stateUpdate', this.updateLocalState);
// fetch rooms state
this.meeting.connectedMeetings.getConnectedMeetings();
}
private cleanup() {
this.meeting.connectedMeetings.removeListener('stateUpdate', this.updateLocalState);
}
private updateLocalState = (payload) => {
this.manager.updateCurrentState(payload);
// access the current state of rooms
console.log('current state: ', this.manager.currentState);
};
async start() {
// create three rooms
this.manager.addNewMeetings(3);
// assign participants randomly to the three rooms
this.manager.assignParticipantsRandomly();
// start breakout session
await this.manager.applyChanges(this.meeting);
}
async stop() {
this.manager.allConnectedMeetings.forEach((meeting) =>
this.manager.deleteMeeting(meeting.id),
);
await this.manager.applyChanges(this.meeting);
this.cleanup();
}
}
// sample usage
async function main() {
const meeting = await DyteClient.init({ authToken: '' });
const breakout = new BreakoutRooms(meeting);
breakout.start();
breakout.stop();
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment