forked from Shiloh/remnantchat
refactor: configure PeerRoom via constructor
This commit is contained in:
parent
4eb1d05b92
commit
2ec8c52f7c
@ -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()
|
||||
|
@ -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() {
|
||||
|
Loading…
Reference in New Issue
Block a user