From 7948b51cc8a779b35344c0c97e71b06e3315c2e6 Mon Sep 17 00:00:00 2001 From: Jeremy Kahn Date: Sun, 14 Aug 2022 21:49:14 -0500 Subject: [PATCH] refactor: remove joinRoom method --- src/hooks/usePeerRoom/usePeerRoom.ts | 9 ++------- src/services/PeerRoom/PeerRoom.ts | 11 ++--------- 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/src/hooks/usePeerRoom/usePeerRoom.ts b/src/hooks/usePeerRoom/usePeerRoom.ts index 40e1f1f..11124bc 100644 --- a/src/hooks/usePeerRoom/usePeerRoom.ts +++ b/src/hooks/usePeerRoom/usePeerRoom.ts @@ -9,8 +9,7 @@ interface PeerRoomProps { export function usePeerRoom({ appId, roomId }: PeerRoomProps) { const peerRoom = useMemo(() => { - const peerRoom = new PeerRoom({ appId }) - peerRoom.joinRoom(roomId) + const peerRoom = new PeerRoom({ appId }, roomId) return peerRoom }, [appId, roomId]) @@ -21,9 +20,5 @@ export function usePeerRoom({ appId, roomId }: PeerRoomProps) { } }, [appId, peerRoom, roomId]) - const { makeAction } = peerRoom - - return { - makeAction, - } + return peerRoom } diff --git a/src/services/PeerRoom/PeerRoom.ts b/src/services/PeerRoom/PeerRoom.ts index fb40ef5..8767f40 100644 --- a/src/services/PeerRoom/PeerRoom.ts +++ b/src/services/PeerRoom/PeerRoom.ts @@ -1,15 +1,12 @@ import { joinRoom, Room, RoomConfig } from 'trystero' export class PeerRoom { - private room?: Room + private room: Room private roomConfig: RoomConfig - constructor(config: RoomConfig) { + constructor(config: RoomConfig, roomId: string) { this.roomConfig = config - } - - joinRoom = (roomId: string) => { this.room = joinRoom(this.roomConfig, roomId) } @@ -20,10 +17,6 @@ export class PeerRoom { } makeAction = (namespace: string) => { - if (!this.room) { - throw new Error('PeerRoom: Called makeAction before joinRoom') - } - return this.room.makeAction(namespace) } }