Skip to content

Commit

Permalink
refactor(#141): cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyckahn committed Dec 4, 2024
1 parent feac11f commit 3f3dde6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Open https://chitchatter.im/ and join a room to start chatting with anyone else
- Public and private rooms.
- Video and audio chatting.
- Screen sharing.
- Direct messaging.
- File sharing:
- Unlimited file size transfers.
- Files are encrypted prior to sending and decrypted by the receiver (the key is the room name).
Expand Down
10 changes: 5 additions & 5 deletions src/hooks/usePeerAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ export const usePeerAction = <T extends DataPayload>({
onReceive: Parameters<ActionReceiver<T>>[0]
namespace: string
}): [ActionSender<T>, ActionProgress] => {
const [[sender, dispatchReceiver, progress, detatchReceiver]] = useState(() =>
peerRoom.makeAction<T>(peerAction, namespace)
const [[sender, connectReceiver, progress, disconnectReceiver]] = useState(
() => peerRoom.makeAction<T>(peerAction, namespace)
)

useEffect(() => {
dispatchReceiver(onReceive)
connectReceiver(onReceive)

return () => {
detatchReceiver()
disconnectReceiver()
}
}, [detatchReceiver, onReceive, dispatchReceiver])
}, [disconnectReceiver, onReceive, connectReceiver])

return [sender, progress]
}
6 changes: 3 additions & 3 deletions src/lib/PeerRoom/PeerRoom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ export class PeerRoom {
peerAction: PeerAction,
namespace: string
): PeerRoomAction<T> => {
const actionName = `${namespace ?? '_'}.${peerAction}`
const actionName = `${namespace}.${peerAction}`

if (actionName in this.actions) {
return this.actions[actionName] as PeerRoomAction<T>
Expand All @@ -208,7 +208,7 @@ export class PeerRoom {

let handler: EventListenerOrEventListenerObject | null = null

const dispatchReceiver: ActionReceiver<T> = callback => {
const connectReceiver: ActionReceiver<T> = callback => {
handler = (event: Event): void => {
// @ts-expect-error
callback(...event.detail)
Expand All @@ -231,7 +231,7 @@ export class PeerRoom {

const action: PeerRoomAction<T> = [
sender,
dispatchReceiver,
connectReceiver,
progress,
detatchDispatchReceiver,
]
Expand Down

0 comments on commit 3f3dde6

Please sign in to comment.