Skip to content

Commit

Permalink
refactor(variables): rename PeerActions to PeerAction
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyckahn committed Nov 22, 2024
1 parent ff54d0b commit 9c84b82
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 20 deletions.
6 changes: 3 additions & 3 deletions src/components/Room/usePeerVerification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ShellContext } from 'contexts/ShellContext'
import { Peer, PeerVerificationState } from 'models/chat'
import { encryption } from 'services/Encryption'
import { PeerRoom } from 'lib/PeerRoom'
import { PeerActions } from 'models/network'
import { PeerAction } from 'models/network'
import { verificationTimeout } from 'config/messaging'
import { usePeerNameDisplay } from 'components/PeerNameDisplay'

Expand All @@ -23,10 +23,10 @@ export const usePeerVerification = ({
const { getDisplayUsername } = usePeerNameDisplay()

const [sendVerificationTokenEncrypted, receiveVerificationTokenEncrypted] =
peerRoom.makeAction<ArrayBuffer>(PeerActions.VERIFICATION_TOKEN_ENCRYPTED)
peerRoom.makeAction<ArrayBuffer>(PeerAction.VERIFICATION_TOKEN_ENCRYPTED)

const [sendVerificationTokenRaw, receiveVerificationTokenRaw] =
peerRoom.makeAction<string>(PeerActions.VERIFICATION_TOKEN_RAW)
peerRoom.makeAction<string>(PeerAction.VERIFICATION_TOKEN_RAW)

const initPeerVerification = useCallback(
async (peer: Peer) => {
Expand Down
12 changes: 6 additions & 6 deletions src/components/Room/useRoom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useDebounce } from '@react-hook/debounce'

import { ShellContext } from 'contexts/ShellContext'
import { SettingsContext } from 'contexts/SettingsContext'
import { PeerActions } from 'models/network'
import { PeerAction } from 'models/network'
import {
AudioState,
Message,
Expand Down Expand Up @@ -175,7 +175,7 @@ export function useRoom(
)

const [sendTypingStatusChange, receiveTypingStatusChange] =
peerRoom.makeAction<TypingStatus>(PeerActions.TYPING_STATUS_CHANGE)
peerRoom.makeAction<TypingStatus>(PeerAction.TYPING_STATUS_CHANGE)

const [isTyping, setIsTypingDebounced, setIsTyping] = useDebounce(
false,
Expand Down Expand Up @@ -219,17 +219,17 @@ export function useRoom(
}, [isShowingMessages, setUnreadMessages])

const [sendPeerMetadata, receivePeerMetadata] =
peerRoom.makeAction<UserMetadata>(PeerActions.PEER_METADATA)
peerRoom.makeAction<UserMetadata>(PeerAction.PEER_METADATA)

const [sendMessageTranscript, receiveMessageTranscript] = peerRoom.makeAction<
Array<ReceivedMessage | ReceivedInlineMedia>
>(PeerActions.MESSAGE_TRANSCRIPT)
>(PeerAction.MESSAGE_TRANSCRIPT)

const [sendPeerMessage, receivePeerMessage] =
peerRoom.makeAction<UnsentMessage>(PeerActions.MESSAGE)
peerRoom.makeAction<UnsentMessage>(PeerAction.MESSAGE)

const [sendPeerInlineMedia, receivePeerInlineMedia] =
peerRoom.makeAction<UnsentInlineMedia>(PeerActions.MEDIA_MESSAGE)
peerRoom.makeAction<UnsentInlineMedia>(PeerAction.MEDIA_MESSAGE)

const { privateKey } = settingsContext.getUserSettings()

Expand Down
4 changes: 2 additions & 2 deletions src/components/Room/useRoomAudio.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useContext, useEffect, useCallback, useState } from 'react'

import { ShellContext } from 'contexts/ShellContext'
import { PeerActions } from 'models/network'
import { PeerAction } from 'models/network'
import {
AudioState,
Peer,
Expand Down Expand Up @@ -40,7 +40,7 @@ export function useRoomAudio({ peerRoom }: UseRoomAudioConfig) {

const [sendAudioChange, receiveAudioChange] = peerRoom.makeAction<
Partial<PeerAudioChannelState>
>(PeerActions.AUDIO_CHANGE)
>(PeerAction.AUDIO_CHANGE)

receiveAudioChange((peerAudioChannelState, peerId) => {
setPeerList(peerList => {
Expand Down
4 changes: 2 additions & 2 deletions src/components/Room/useRoomFileShare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useContext, useEffect, useState } from 'react'
import { sleep } from 'lib/sleep'
import { RoomContext } from 'contexts/RoomContext'
import { ShellContext } from 'contexts/ShellContext'
import { PeerActions } from 'models/network'
import { PeerAction } from 'models/network'
import { FileOfferMetadata, Peer } from 'models/chat'
import { PeerRoom, PeerHookType } from 'lib/PeerRoom'
import { fileTransfer } from 'lib/FileTransfer'
Expand Down Expand Up @@ -33,7 +33,7 @@ export function useRoomFileShare({
const { peerOfferedFileMetadata, setPeerOfferedFileMetadata } = roomContext

const [sendFileOfferMetadata, receiveFileOfferMetadata] =
peerRoom.makeAction<FileOfferMetadata | null>(PeerActions.FILE_OFFER)
peerRoom.makeAction<FileOfferMetadata | null>(PeerAction.FILE_OFFER)

receiveFileOfferMetadata((fileOfferMetadata, peerId) => {
if (fileOfferMetadata) {
Expand Down
4 changes: 2 additions & 2 deletions src/components/Room/useRoomScreenShare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useContext, useEffect, useCallback, useState } from 'react'
import { isRecord } from 'lib/type-guards'
import { RoomContext } from 'contexts/RoomContext'
import { ShellContext } from 'contexts/ShellContext'
import { PeerActions } from 'models/network'
import { PeerAction } from 'models/network'
import {
ScreenShareState,
Peer,
Expand Down Expand Up @@ -38,7 +38,7 @@ export function useRoomScreenShare({ peerRoom }: UseRoomScreenShareConfig) {
} = roomContext

const [sendScreenShare, receiveScreenShare] =
peerRoom.makeAction<ScreenShareState>(PeerActions.SCREEN_SHARE)
peerRoom.makeAction<ScreenShareState>(PeerAction.SCREEN_SHARE)

receiveScreenShare((screenState, peerId) => {
const newPeerList = peerList.map(peer => {
Expand Down
4 changes: 2 additions & 2 deletions src/components/Room/useRoomVideo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useContext, useEffect, useCallback, useState } from 'react'

import { RoomContext } from 'contexts/RoomContext'
import { ShellContext } from 'contexts/ShellContext'
import { PeerActions } from 'models/network'
import { PeerAction } from 'models/network'
import { VideoState, Peer, StreamType } from 'models/chat'
import { PeerRoom, PeerHookType, PeerStreamType } from 'lib/PeerRoom'
import { isRecord } from 'lib/type-guards'
Expand Down Expand Up @@ -69,7 +69,7 @@ export function useRoomVideo({ peerRoom }: UseRoomVideoConfig) {
}, [peerRoom, selfVideoStream, setSelfVideoStream])

const [sendVideoChange, receiveVideoChange] = peerRoom.makeAction<VideoState>(
PeerActions.VIDEO_CHANGE
PeerAction.VIDEO_CHANGE
)

receiveVideoChange((videoState, peerId) => {
Expand Down
5 changes: 3 additions & 2 deletions src/lib/PeerRoom/PeerRoom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { RelayConfig } from 'trystero/torrent'

import { sleep } from 'lib/sleep'
import { StreamType } from 'models/chat'
import { PeerAction } from 'models/network'

export enum PeerHookType {
NEW_PEER = 'NEW_PEER',
Expand Down Expand Up @@ -168,8 +169,8 @@ export class PeerRoom {
return peerConnections
}

makeAction = <T extends DataPayload>(namespace: string) => {
return this.room.makeAction<T>(namespace)
makeAction = <T extends DataPayload>(peerAction: PeerAction) => {
return this.room.makeAction<T>(peerAction)
}

addStream = (
Expand Down
2 changes: 1 addition & 1 deletion src/models/network.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// NOTE: Action names are limited to 12 characters, otherwise Trystero breaks.
export enum PeerActions {
export enum PeerAction {
MESSAGE = 'MESSAGE',
MEDIA_MESSAGE = 'MEDIA_MSG',
MESSAGE_TRANSCRIPT = 'MSG_XSCRIPT',
Expand Down

0 comments on commit 9c84b82

Please sign in to comment.