Spaces:
Paused
Paused
| import { z } from "zod"; | |
| import { Context, Route } from "../hapticLinkServer"; | |
| export interface LeaveRoomPayload { | |
| roomId: string; | |
| } | |
| export const LeaveRoomSchema = z.object({ | |
| roomId: z.string(), | |
| }); | |
| export function LeaveRoomHandler(ctx: Context<LeaveRoomPayload>) { | |
| const room = ctx.user.currentRoom; | |
| if (!room) { | |
| return ctx.ws.send( | |
| JSON.stringify({ | |
| message: "leave_room_response", | |
| status: "you are not part of that room", | |
| }) | |
| ); | |
| } else { | |
| room.removeUserById(ctx.user.id); | |
| return ctx.ws.send( | |
| JSON.stringify({ | |
| message: "leave_room_response", | |
| status: "room left", | |
| }) | |
| ); | |
| } | |
| } | |