Skip to content

Commit

Permalink
fix: room generate (#438)
Browse files Browse the repository at this point in the history
  • Loading branch information
hmbanan666 authored Jan 18, 2025
1 parent 9b4bc3f commit 08b2b46
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
5 changes: 3 additions & 2 deletions apps/website/server/core/rooms/wagon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,11 @@ export class WagonRoom extends BaseRoom {
}

async reboot() {
await WagonRoom.generate({ chunksCount: 6, roomId: this.id })
if (this.status !== 'ACTIVE') {
return
}

sendMessage({ type: 'ROOM_DESTROYED', data: { id: this.id } }, this.token)

this.status = 'FINISHED'
}

Expand Down
11 changes: 6 additions & 5 deletions apps/website/server/plugins/04.startWagonRoom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ export default defineNitroPlugin(async () => {
}

if (!activeRooms.find((room) => room.id === wagonRoomId)) {
rebootRoom()
void rebootRoom()

setInterval(() => {
const room = activeRooms.find((room) => room.id === wagonRoomId) as WagonRoom
if (room.status === 'FINISHED') {
rebootRoom()
void rebootRoom()
}
}, 5000)
}
Expand All @@ -36,11 +36,12 @@ export default defineNitroPlugin(async () => {
logger.success('Wagon rooms created')
})

function rebootRoom() {
const room = new WagonRoom({ id: wagonRoomId, token: wagonRoomId })
async function rebootRoom() {
if (activeRooms.find((room) => room.id === wagonRoomId)) {
activeRooms.splice(activeRooms.findIndex((room) => room.id === wagonRoomId), 1)
}

activeRooms.push(room)
await WagonRoom.generate({ chunksCount: 6, roomId: wagonRoomId })

activeRooms.push(new WagonRoom({ id: wagonRoomId, token: wagonRoomId }))
}

0 comments on commit 08b2b46

Please sign in to comment.