refactor: remove joinRoom method

This commit is contained in:
Jeremy Kahn 2022-08-14 21:49:14 -05:00
parent 33b25e204d
commit 7948b51cc8
2 changed files with 4 additions and 16 deletions

View File

@ -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
}

View File

@ -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 = <T>(namespace: string) => {
if (!this.room) {
throw new Error('PeerRoom: Called makeAction before joinRoom')
}
return this.room.makeAction<T>(namespace)
}
}