chore(deps): upgrade to Trystero@0.18.0

This commit is contained in:
Jeremy Kahn 2024-03-14 21:35:51 -05:00
parent 5d4619965c
commit d81e930da6
7 changed files with 3055 additions and 874 deletions

3891
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -42,7 +42,7 @@
"sdp": "^3.2.0", "sdp": "^3.2.0",
"secure-file-transfer": "^0.0.7", "secure-file-transfer": "^0.0.7",
"streamsaver": "^2.0.6", "streamsaver": "^2.0.6",
"trystero": "^0.15.0", "trystero": "^0.18.0",
"typeface-public-sans": "^1.1.13", "typeface-public-sans": "^1.1.13",
"typeface-roboto": "^1.1.13", "typeface-roboto": "^1.1.13",
"typescript": "^5.4.2", "typescript": "^5.4.2",

View File

@ -60,10 +60,10 @@ export function Room({
} = useRoom( } = useRoom(
{ {
appId, appId,
trackerUrls, relayUrls: trackerUrls,
rtcConfig, rtcConfig,
password, password,
trackerRedundancy: 4, relayRedundancy: 4,
}, },
{ {
roomId, roomId,

View File

@ -1,6 +1,6 @@
import { useContext, useEffect, useMemo, useState } from 'react' import { useContext, useEffect, useMemo, useState } from 'react'
import { BaseRoomConfig } from 'trystero' import { BaseRoomConfig } from 'trystero'
import { TorrentRoomConfig } from 'trystero/torrent' import { RelayConfig } from 'trystero/torrent'
import { v4 as uuid } from 'uuid' import { v4 as uuid } from 'uuid'
import { useDebounce } from '@react-hook/debounce' import { useDebounce } from '@react-hook/debounce'
@ -45,14 +45,14 @@ interface UseRoomConfig {
timeService?: typeof time timeService?: typeof time
} }
interface UserMetadata { interface UserMetadata extends Record<string, any> {
userId: string userId: string
customUsername: string customUsername: string
publicKeyString: string publicKeyString: string
} }
export function useRoom( export function useRoom(
{ password, ...roomConfig }: BaseRoomConfig & TorrentRoomConfig, { password, ...roomConfig }: BaseRoomConfig & RelayConfig,
{ {
roomId, roomId,
userId, userId,

View File

@ -1,4 +1,4 @@
import { getTrackers } from 'trystero/torrent' import { getRelaySockets } from 'trystero/torrent'
import { rtcConfig } from 'config/rtcConfig' import { rtcConfig } from 'config/rtcConfig'
import { parseCandidate } from 'sdp' import { parseCandidate } from 'sdp'
@ -104,17 +104,15 @@ export class ConnectionTest extends EventTarget {
} }
testTrackerConnection() { testTrackerConnection() {
const trackers = getTrackers() const relaySockets = Object.values(getRelaySockets())
const trackerSockets = Object.values(trackers) if (relaySockets.length === 0) {
if (trackerSockets.length === 0) {
// Trystero has not yet initialized tracker sockets // Trystero has not yet initialized tracker sockets
this.trackerConnection = TrackerConnection.SEARCHING this.trackerConnection = TrackerConnection.SEARCHING
return this.trackerConnection return this.trackerConnection
} }
const readyStates = trackerSockets.map(({ readyState }) => readyState) const readyStates = relaySockets.map(({ readyState }) => readyState)
const haveAllTrackerConnectionsFailed = readyStates.every( const haveAllTrackerConnectionsFailed = readyStates.every(
readyState => readyState === WebSocket.CLOSED readyState => readyState === WebSocket.CLOSED

View File

@ -1,5 +1,5 @@
import { joinRoom, Room, BaseRoomConfig } from 'trystero' import { joinRoom, Room, BaseRoomConfig, DataPayload } from 'trystero'
import { TorrentRoomConfig } from 'trystero/torrent' import { RelayConfig } from 'trystero/torrent'
import { sleep } from 'lib/sleep' import { sleep } from 'lib/sleep'
@ -27,7 +27,7 @@ const streamQueueAddDelay = 1000
export class PeerRoom { export class PeerRoom {
private room: Room private room: Room
private roomConfig: TorrentRoomConfig & BaseRoomConfig private roomConfig: RelayConfig & BaseRoomConfig
private peerJoinHandlers: Map< private peerJoinHandlers: Map<
PeerHookType, PeerHookType,
@ -60,7 +60,7 @@ export class PeerRoom {
this.isProcessingPendingStreams = false this.isProcessingPendingStreams = false
} }
constructor(config: TorrentRoomConfig & BaseRoomConfig, roomId: string) { constructor(config: RelayConfig & BaseRoomConfig, roomId: string) {
this.roomConfig = config this.roomConfig = config
this.room = joinRoom(this.roomConfig, roomId) this.room = joinRoom(this.roomConfig, roomId)
@ -167,7 +167,7 @@ export class PeerRoom {
return peerConnections return peerConnections
} }
makeAction = <T>(namespace: string) => { makeAction = <T extends DataPayload>(namespace: string) => {
return this.room.makeAction<T>(namespace) return this.room.makeAction<T>(namespace)
} }

View File

@ -1,4 +1,4 @@
export interface UnsentMessage { export interface UnsentMessage extends Record<string, any> {
id: string id: string
text: string text: string
timeSent: number timeSent: number
@ -73,11 +73,11 @@ export const isInlineMedia = (
return 'magnetURI' in message return 'magnetURI' in message
} }
export interface FileOfferMetadata { export interface FileOfferMetadata extends Record<string, any> {
magnetURI: string magnetURI: string
isAllInlineMedia: boolean isAllInlineMedia: boolean
} }
export interface TypingStatus { export interface TypingStatus extends Record<string, any> {
isTyping: boolean isTyping: boolean
} }