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) {
|
export function usePeerRoom({ appId, roomId }: PeerRoomProps) {
|
||||||
const peerRoom = useMemo(() => {
|
const peerRoom = useMemo(() => {
|
||||||
const peerRoom = new PeerRoom({ appId })
|
const peerRoom = new PeerRoom({ appId }, roomId)
|
||||||
peerRoom.joinRoom(roomId)
|
|
||||||
|
|
||||||
return peerRoom
|
return peerRoom
|
||||||
}, [appId, roomId])
|
}, [appId, roomId])
|
||||||
@ -21,9 +20,5 @@ export function usePeerRoom({ appId, roomId }: PeerRoomProps) {
|
|||||||
}
|
}
|
||||||
}, [appId, peerRoom, roomId])
|
}, [appId, peerRoom, roomId])
|
||||||
|
|
||||||
const { makeAction } = peerRoom
|
return peerRoom
|
||||||
|
|
||||||
return {
|
|
||||||
makeAction,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,12 @@
|
|||||||
import { joinRoom, Room, RoomConfig } from 'trystero'
|
import { joinRoom, Room, RoomConfig } from 'trystero'
|
||||||
|
|
||||||
export class PeerRoom {
|
export class PeerRoom {
|
||||||
private room?: Room
|
private room: Room
|
||||||
|
|
||||||
private roomConfig: RoomConfig
|
private roomConfig: RoomConfig
|
||||||
|
|
||||||
constructor(config: RoomConfig) {
|
constructor(config: RoomConfig, roomId: string) {
|
||||||
this.roomConfig = config
|
this.roomConfig = config
|
||||||
}
|
|
||||||
|
|
||||||
joinRoom = (roomId: string) => {
|
|
||||||
this.room = joinRoom(this.roomConfig, roomId)
|
this.room = joinRoom(this.roomConfig, roomId)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -20,10 +17,6 @@ export class PeerRoom {
|
|||||||
}
|
}
|
||||||
|
|
||||||
makeAction = <T>(namespace: string) => {
|
makeAction = <T>(namespace: string) => {
|
||||||
if (!this.room) {
|
|
||||||
throw new Error('PeerRoom: Called makeAction before joinRoom')
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.room.makeAction<T>(namespace)
|
return this.room.makeAction<T>(namespace)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user