diff --git a/src/hooks/usePeerRoom/usePeerRoom.ts b/src/hooks/usePeerRoom/usePeerRoom.ts index de0b4af..e8ad7a9 100644 --- a/src/hooks/usePeerRoom/usePeerRoom.ts +++ b/src/hooks/usePeerRoom/usePeerRoom.ts @@ -9,11 +9,11 @@ interface PeerRoomProps { export function usePeerRoom({ appId, roomId }: PeerRoomProps) { const peerRoom = useMemo(() => { - return new PeerRoom() - }, []) + return new PeerRoom({ appId }) + }, [appId]) useEffect(() => { - peerRoom.joinRoom(appId, roomId) + peerRoom.joinRoom(roomId) return () => { peerRoom.leaveRoom() diff --git a/src/services/PeerRoom/PeerRoom.ts b/src/services/PeerRoom/PeerRoom.ts index e84bc02..6cf9586 100644 --- a/src/services/PeerRoom/PeerRoom.ts +++ b/src/services/PeerRoom/PeerRoom.ts @@ -1,10 +1,16 @@ -import { joinRoom, Room } from 'trystero' +import { joinRoom, Room, RoomConfig } from 'trystero' export class PeerRoom { private room?: Room - joinRoom(appId: string, roomId: string) { - this.room = joinRoom({ appId }, roomId) + private roomConfig: RoomConfig + + constructor(config: RoomConfig) { + this.roomConfig = config + } + + joinRoom(roomId: string) { + this.room = joinRoom(this.roomConfig, roomId) } leaveRoom() {