forked from Shiloh/remnantchat
refactor: remove joinRoom method
This commit is contained in:
parent
33b25e204d
commit
7948b51cc8
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user