refactor: allow for full trystero configuration

This commit is contained in:
Jeremy Kahn 2022-08-20 17:14:50 -05:00
parent b8f8bb5bfd
commit d4bc49f096
2 changed files with 10 additions and 11 deletions

View File

@ -28,10 +28,12 @@ export function Room({
[] []
) )
const peerRoom = usePeerRoom({ const peerRoom = usePeerRoom(
appId, {
roomId, appId,
}) },
roomId
)
const [sendMessage, receiveMessage] = usePeerRoomAction<UnsentMessage>( const [sendMessage, receiveMessage] = usePeerRoomAction<UnsentMessage>(
peerRoom, peerRoom,

View File

@ -1,14 +1,11 @@
import { useEffect, useState } from 'react' import { useEffect, useState } from 'react'
import { RoomConfig } from 'trystero'
import { getPeerRoom } from 'services/PeerRoom' import { getPeerRoom } from 'services/PeerRoom'
interface UsePeerRoomProps { export function usePeerRoom(roomConfig: RoomConfig, roomId: string) {
appId: string const { appId } = roomConfig
roomId: string const [peerRoom, setPeerRoom] = useState(getPeerRoom(roomConfig, roomId))
}
export function usePeerRoom({ appId, roomId }: UsePeerRoomProps) {
const [peerRoom, setPeerRoom] = useState(getPeerRoom({ appId }, roomId))
useEffect(() => { useEffect(() => {
setPeerRoom(getPeerRoom({ appId }, roomId)) setPeerRoom(getPeerRoom({ appId }, roomId))