From d4bc49f0969cfaa1a2a6b79fa1aa577db321bde3 Mon Sep 17 00:00:00 2001 From: Jeremy Kahn Date: Sat, 20 Aug 2022 17:14:50 -0500 Subject: [PATCH] refactor: allow for full trystero configuration --- src/components/Room/Room.tsx | 10 ++++++---- src/hooks/usePeerRoom/usePeerRoom.ts | 11 ++++------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/components/Room/Room.tsx b/src/components/Room/Room.tsx index 93eec37..2bbf1a4 100644 --- a/src/components/Room/Room.tsx +++ b/src/components/Room/Room.tsx @@ -28,10 +28,12 @@ export function Room({ [] ) - const peerRoom = usePeerRoom({ - appId, - roomId, - }) + const peerRoom = usePeerRoom( + { + appId, + }, + roomId + ) const [sendMessage, receiveMessage] = usePeerRoomAction( peerRoom, diff --git a/src/hooks/usePeerRoom/usePeerRoom.ts b/src/hooks/usePeerRoom/usePeerRoom.ts index 1b02344..3752334 100644 --- a/src/hooks/usePeerRoom/usePeerRoom.ts +++ b/src/hooks/usePeerRoom/usePeerRoom.ts @@ -1,14 +1,11 @@ import { useEffect, useState } from 'react' +import { RoomConfig } from 'trystero' import { getPeerRoom } from 'services/PeerRoom' -interface UsePeerRoomProps { - appId: string - roomId: string -} - -export function usePeerRoom({ appId, roomId }: UsePeerRoomProps) { - const [peerRoom, setPeerRoom] = useState(getPeerRoom({ appId }, roomId)) +export function usePeerRoom(roomConfig: RoomConfig, roomId: string) { + const { appId } = roomConfig + const [peerRoom, setPeerRoom] = useState(getPeerRoom(roomConfig, roomId)) useEffect(() => { setPeerRoom(getPeerRoom({ appId }, roomId))