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) {
|
export function usePeerRoom({ appId, roomId }: PeerRoomProps) {
|
||||||
const peerRoom = useMemo(() => {
|
const peerRoom = useMemo(() => {
|
||||||
return new PeerRoom()
|
return new PeerRoom({ appId })
|
||||||
}, [])
|
}, [appId])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
peerRoom.joinRoom(appId, roomId)
|
peerRoom.joinRoom(roomId)
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
peerRoom.leaveRoom()
|
peerRoom.leaveRoom()
|
||||||
|
@ -1,10 +1,16 @@
|
|||||||
import { joinRoom, Room } from 'trystero'
|
import { joinRoom, Room, RoomConfig } from 'trystero'
|
||||||
|
|
||||||
export class PeerRoom {
|
export class PeerRoom {
|
||||||
private room?: Room
|
private room?: Room
|
||||||
|
|
||||||
joinRoom(appId: string, roomId: string) {
|
private roomConfig: RoomConfig
|
||||||
this.room = joinRoom({ appId }, roomId)
|
|
||||||
|
constructor(config: RoomConfig) {
|
||||||
|
this.roomConfig = config
|
||||||
|
}
|
||||||
|
|
||||||
|
joinRoom(roomId: string) {
|
||||||
|
this.room = joinRoom(this.roomConfig, roomId)
|
||||||
}
|
}
|
||||||
|
|
||||||
leaveRoom() {
|
leaveRoom() {
|
||||||
|
Loading…
Reference in New Issue
Block a user