Last active
February 26, 2024 09:20
-
-
Save Tushkiz/c68ea866da359a8d2af4dc3ec9dbedb4 to your computer and use it in GitHub Desktop.
Sample for creating Breakout rooms using Dyte
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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