@dtelecom/livekit-client 1.12.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +175 -0
- package/README.md +315 -0
- package/dist/@dtelecom/livekit-client.e2ee.worker.js +2 -0
- package/dist/@dtelecom/livekit-client.e2ee.worker.js.map +1 -0
- package/dist/@dtelecom/livekit-client.e2ee.worker.mjs +1633 -0
- package/dist/@dtelecom/livekit-client.e2ee.worker.mjs.map +1 -0
- package/dist/@dtelecom/livekit-client.esm.mjs +22545 -0
- package/dist/@dtelecom/livekit-client.esm.mjs.map +1 -0
- package/dist/@dtelecom/livekit-client.umd.js +2 -0
- package/dist/@dtelecom/livekit-client.umd.js.map +1 -0
- package/dist/@dtelecom/src/api/SignalClient.d.ts +102 -0
- package/dist/@dtelecom/src/api/SignalClient.d.ts.map +1 -0
- package/dist/@dtelecom/src/connectionHelper/ConnectionCheck.d.ts +26 -0
- package/dist/@dtelecom/src/connectionHelper/ConnectionCheck.d.ts.map +1 -0
- package/dist/@dtelecom/src/connectionHelper/checks/Checker.d.ts +59 -0
- package/dist/@dtelecom/src/connectionHelper/checks/Checker.d.ts.map +1 -0
- package/dist/@dtelecom/src/connectionHelper/checks/publishAudio.d.ts +6 -0
- package/dist/@dtelecom/src/connectionHelper/checks/publishAudio.d.ts.map +1 -0
- package/dist/@dtelecom/src/connectionHelper/checks/publishVideo.d.ts +6 -0
- package/dist/@dtelecom/src/connectionHelper/checks/publishVideo.d.ts.map +1 -0
- package/dist/@dtelecom/src/connectionHelper/checks/reconnect.d.ts +6 -0
- package/dist/@dtelecom/src/connectionHelper/checks/reconnect.d.ts.map +1 -0
- package/dist/@dtelecom/src/connectionHelper/checks/turn.d.ts +6 -0
- package/dist/@dtelecom/src/connectionHelper/checks/turn.d.ts.map +1 -0
- package/dist/@dtelecom/src/connectionHelper/checks/webrtc.d.ts +6 -0
- package/dist/@dtelecom/src/connectionHelper/checks/webrtc.d.ts.map +1 -0
- package/dist/@dtelecom/src/connectionHelper/checks/websocket.d.ts +6 -0
- package/dist/@dtelecom/src/connectionHelper/checks/websocket.d.ts.map +1 -0
- package/dist/@dtelecom/src/e2ee/E2eeManager.d.ts +47 -0
- package/dist/@dtelecom/src/e2ee/E2eeManager.d.ts.map +1 -0
- package/dist/@dtelecom/src/e2ee/KeyProvider.d.ts +44 -0
- package/dist/@dtelecom/src/e2ee/KeyProvider.d.ts.map +1 -0
- package/dist/@dtelecom/src/e2ee/constants.d.ts +15 -0
- package/dist/@dtelecom/src/e2ee/constants.d.ts.map +1 -0
- package/dist/@dtelecom/src/e2ee/errors.d.ts +11 -0
- package/dist/@dtelecom/src/e2ee/errors.d.ts.map +1 -0
- package/dist/@dtelecom/src/e2ee/index.d.ts +4 -0
- package/dist/@dtelecom/src/e2ee/index.d.ts.map +1 -0
- package/dist/@dtelecom/src/e2ee/types.d.ts +130 -0
- package/dist/@dtelecom/src/e2ee/types.d.ts.map +1 -0
- package/dist/@dtelecom/src/e2ee/utils.d.ts +24 -0
- package/dist/@dtelecom/src/e2ee/utils.d.ts.map +1 -0
- package/dist/@dtelecom/src/e2ee/worker/FrameCryptor.d.ts +176 -0
- package/dist/@dtelecom/src/e2ee/worker/FrameCryptor.d.ts.map +1 -0
- package/dist/@dtelecom/src/e2ee/worker/ParticipantKeyHandler.d.ts +65 -0
- package/dist/@dtelecom/src/e2ee/worker/ParticipantKeyHandler.d.ts.map +1 -0
- package/dist/@dtelecom/src/e2ee/worker/e2ee.worker.d.ts +2 -0
- package/dist/@dtelecom/src/e2ee/worker/e2ee.worker.d.ts.map +1 -0
- package/dist/@dtelecom/src/index.d.ts +38 -0
- package/dist/@dtelecom/src/index.d.ts.map +1 -0
- package/dist/@dtelecom/src/logger.d.ts +29 -0
- package/dist/@dtelecom/src/logger.d.ts.map +1 -0
- package/dist/@dtelecom/src/options.d.ts +104 -0
- package/dist/@dtelecom/src/options.d.ts.map +1 -0
- package/dist/@dtelecom/src/proto/livekit_models_pb.d.ts +1264 -0
- package/dist/@dtelecom/src/proto/livekit_models_pb.d.ts.map +1 -0
- package/dist/@dtelecom/src/proto/livekit_rtc_pb.d.ts +1373 -0
- package/dist/@dtelecom/src/proto/livekit_rtc_pb.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/DefaultReconnectPolicy.d.ts +8 -0
- package/dist/@dtelecom/src/room/DefaultReconnectPolicy.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/DeviceManager.d.ts +9 -0
- package/dist/@dtelecom/src/room/DeviceManager.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/PCTransport.d.ts +41 -0
- package/dist/@dtelecom/src/room/PCTransport.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/RTCEngine.d.ts +143 -0
- package/dist/@dtelecom/src/room/RTCEngine.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/ReconnectPolicy.d.ts +24 -0
- package/dist/@dtelecom/src/room/ReconnectPolicy.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/RegionUrlProvider.d.ts +17 -0
- package/dist/@dtelecom/src/room/RegionUrlProvider.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/Room.d.ts +248 -0
- package/dist/@dtelecom/src/room/Room.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/defaults.d.ts +8 -0
- package/dist/@dtelecom/src/room/defaults.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/errors.d.ts +43 -0
- package/dist/@dtelecom/src/room/errors.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/events.d.ts +477 -0
- package/dist/@dtelecom/src/room/events.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/participant/LocalParticipant.d.ts +177 -0
- package/dist/@dtelecom/src/room/participant/LocalParticipant.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/participant/Participant.d.ts +95 -0
- package/dist/@dtelecom/src/room/participant/Participant.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/participant/ParticipantTrackPermission.d.ts +26 -0
- package/dist/@dtelecom/src/room/participant/ParticipantTrackPermission.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/participant/RemoteParticipant.d.ts +55 -0
- package/dist/@dtelecom/src/room/participant/RemoteParticipant.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/participant/publishUtils.d.ts +28 -0
- package/dist/@dtelecom/src/room/participant/publishUtils.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/stats.d.ts +67 -0
- package/dist/@dtelecom/src/room/stats.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/timers.d.ts +13 -0
- package/dist/@dtelecom/src/room/timers.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/track/LocalAudioTrack.d.ts +25 -0
- package/dist/@dtelecom/src/room/track/LocalAudioTrack.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/track/LocalTrack.d.ts +78 -0
- package/dist/@dtelecom/src/room/track/LocalTrack.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/track/LocalTrackPublication.d.ts +38 -0
- package/dist/@dtelecom/src/room/track/LocalTrackPublication.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/track/LocalVideoTrack.d.ts +54 -0
- package/dist/@dtelecom/src/room/track/LocalVideoTrack.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/track/RemoteAudioTrack.d.ts +53 -0
- package/dist/@dtelecom/src/room/track/RemoteAudioTrack.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/track/RemoteTrack.d.ts +15 -0
- package/dist/@dtelecom/src/room/track/RemoteTrack.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/track/RemoteTrackPublication.d.ts +64 -0
- package/dist/@dtelecom/src/room/track/RemoteTrackPublication.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/track/RemoteVideoTrack.d.ts +56 -0
- package/dist/@dtelecom/src/room/track/RemoteVideoTrack.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/track/Track.d.ts +125 -0
- package/dist/@dtelecom/src/room/track/Track.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/track/TrackPublication.d.ts +72 -0
- package/dist/@dtelecom/src/room/track/TrackPublication.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/track/create.d.ts +24 -0
- package/dist/@dtelecom/src/room/track/create.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/track/facingMode.d.ts +41 -0
- package/dist/@dtelecom/src/room/track/facingMode.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/track/options.d.ts +272 -0
- package/dist/@dtelecom/src/room/track/options.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/track/processor/types.d.ts +19 -0
- package/dist/@dtelecom/src/room/track/processor/types.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/track/types.d.ts +24 -0
- package/dist/@dtelecom/src/room/track/types.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/track/utils.d.ts +27 -0
- package/dist/@dtelecom/src/room/track/utils.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/types.d.ts +26 -0
- package/dist/@dtelecom/src/room/types.d.ts.map +1 -0
- package/dist/@dtelecom/src/room/utils.d.ts +92 -0
- package/dist/@dtelecom/src/room/utils.d.ts.map +1 -0
- package/dist/@dtelecom/src/test/MockMediaStreamTrack.d.ts +26 -0
- package/dist/@dtelecom/src/test/MockMediaStreamTrack.d.ts.map +1 -0
- package/dist/@dtelecom/src/test/mocks.d.ts +12 -0
- package/dist/@dtelecom/src/test/mocks.d.ts.map +1 -0
- package/dist/@dtelecom/src/utils/AsyncQueue.d.ts +23 -0
- package/dist/@dtelecom/src/utils/AsyncQueue.d.ts.map +1 -0
- package/dist/@dtelecom/src/utils/browserParser.d.ts +12 -0
- package/dist/@dtelecom/src/utils/browserParser.d.ts.map +1 -0
- package/dist/@dtelecom/src/version.d.ts +3 -0
- package/dist/@dtelecom/src/version.d.ts.map +1 -0
- package/dist/ts4.2/@dtelecom/src/api/SignalClient.d.ts +105 -0
- package/dist/ts4.2/@dtelecom/src/connectionHelper/ConnectionCheck.d.ts +26 -0
- package/dist/ts4.2/@dtelecom/src/connectionHelper/checks/Checker.d.ts +59 -0
- package/dist/ts4.2/@dtelecom/src/connectionHelper/checks/publishAudio.d.ts +6 -0
- package/dist/ts4.2/@dtelecom/src/connectionHelper/checks/publishVideo.d.ts +6 -0
- package/dist/ts4.2/@dtelecom/src/connectionHelper/checks/reconnect.d.ts +6 -0
- package/dist/ts4.2/@dtelecom/src/connectionHelper/checks/turn.d.ts +6 -0
- package/dist/ts4.2/@dtelecom/src/connectionHelper/checks/webrtc.d.ts +6 -0
- package/dist/ts4.2/@dtelecom/src/connectionHelper/checks/websocket.d.ts +6 -0
- package/dist/ts4.2/@dtelecom/src/e2ee/E2eeManager.d.ts +47 -0
- package/dist/ts4.2/@dtelecom/src/e2ee/KeyProvider.d.ts +44 -0
- package/dist/ts4.2/@dtelecom/src/e2ee/constants.d.ts +15 -0
- package/dist/ts4.2/@dtelecom/src/e2ee/errors.d.ts +11 -0
- package/dist/ts4.2/@dtelecom/src/e2ee/index.d.ts +4 -0
- package/dist/ts4.2/@dtelecom/src/e2ee/types.d.ts +130 -0
- package/dist/ts4.2/@dtelecom/src/e2ee/utils.d.ts +24 -0
- package/dist/ts4.2/@dtelecom/src/e2ee/worker/FrameCryptor.d.ts +176 -0
- package/dist/ts4.2/@dtelecom/src/e2ee/worker/ParticipantKeyHandler.d.ts +65 -0
- package/dist/ts4.2/@dtelecom/src/e2ee/worker/e2ee.worker.d.ts +2 -0
- package/dist/ts4.2/@dtelecom/src/index.d.ts +38 -0
- package/dist/ts4.2/@dtelecom/src/logger.d.ts +29 -0
- package/dist/ts4.2/@dtelecom/src/options.d.ts +104 -0
- package/dist/ts4.2/@dtelecom/src/proto/livekit_models_pb.d.ts +1264 -0
- package/dist/ts4.2/@dtelecom/src/proto/livekit_rtc_pb.d.ts +1373 -0
- package/dist/ts4.2/@dtelecom/src/room/DefaultReconnectPolicy.d.ts +8 -0
- package/dist/ts4.2/@dtelecom/src/room/DeviceManager.d.ts +9 -0
- package/dist/ts4.2/@dtelecom/src/room/PCTransport.d.ts +43 -0
- package/dist/ts4.2/@dtelecom/src/room/RTCEngine.d.ts +143 -0
- package/dist/ts4.2/@dtelecom/src/room/ReconnectPolicy.d.ts +24 -0
- package/dist/ts4.2/@dtelecom/src/room/RegionUrlProvider.d.ts +17 -0
- package/dist/ts4.2/@dtelecom/src/room/Room.d.ts +248 -0
- package/dist/ts4.2/@dtelecom/src/room/defaults.d.ts +8 -0
- package/dist/ts4.2/@dtelecom/src/room/errors.d.ts +43 -0
- package/dist/ts4.2/@dtelecom/src/room/events.d.ts +477 -0
- package/dist/ts4.2/@dtelecom/src/room/participant/LocalParticipant.d.ts +177 -0
- package/dist/ts4.2/@dtelecom/src/room/participant/Participant.d.ts +95 -0
- package/dist/ts4.2/@dtelecom/src/room/participant/ParticipantTrackPermission.d.ts +26 -0
- package/dist/ts4.2/@dtelecom/src/room/participant/RemoteParticipant.d.ts +55 -0
- package/dist/ts4.2/@dtelecom/src/room/participant/publishUtils.d.ts +28 -0
- package/dist/ts4.2/@dtelecom/src/room/stats.d.ts +67 -0
- package/dist/ts4.2/@dtelecom/src/room/timers.d.ts +13 -0
- package/dist/ts4.2/@dtelecom/src/room/track/LocalAudioTrack.d.ts +25 -0
- package/dist/ts4.2/@dtelecom/src/room/track/LocalTrack.d.ts +78 -0
- package/dist/ts4.2/@dtelecom/src/room/track/LocalTrackPublication.d.ts +38 -0
- package/dist/ts4.2/@dtelecom/src/room/track/LocalVideoTrack.d.ts +54 -0
- package/dist/ts4.2/@dtelecom/src/room/track/RemoteAudioTrack.d.ts +53 -0
- package/dist/ts4.2/@dtelecom/src/room/track/RemoteTrack.d.ts +15 -0
- package/dist/ts4.2/@dtelecom/src/room/track/RemoteTrackPublication.d.ts +64 -0
- package/dist/ts4.2/@dtelecom/src/room/track/RemoteVideoTrack.d.ts +56 -0
- package/dist/ts4.2/@dtelecom/src/room/track/Track.d.ts +125 -0
- package/dist/ts4.2/@dtelecom/src/room/track/TrackPublication.d.ts +72 -0
- package/dist/ts4.2/@dtelecom/src/room/track/create.d.ts +24 -0
- package/dist/ts4.2/@dtelecom/src/room/track/facingMode.d.ts +41 -0
- package/dist/ts4.2/@dtelecom/src/room/track/options.d.ts +280 -0
- package/dist/ts4.2/@dtelecom/src/room/track/processor/types.d.ts +19 -0
- package/dist/ts4.2/@dtelecom/src/room/track/types.d.ts +24 -0
- package/dist/ts4.2/@dtelecom/src/room/track/utils.d.ts +27 -0
- package/dist/ts4.2/@dtelecom/src/room/types.d.ts +26 -0
- package/dist/ts4.2/@dtelecom/src/room/utils.d.ts +92 -0
- package/dist/ts4.2/@dtelecom/src/test/MockMediaStreamTrack.d.ts +26 -0
- package/dist/ts4.2/@dtelecom/src/test/mocks.d.ts +12 -0
- package/dist/ts4.2/@dtelecom/src/utils/AsyncQueue.d.ts +23 -0
- package/dist/ts4.2/@dtelecom/src/utils/browserParser.d.ts +12 -0
- package/dist/ts4.2/@dtelecom/src/version.d.ts +3 -0
- package/package.json +102 -0
- package/src/api/SignalClient.ts +790 -0
- package/src/connectionHelper/ConnectionCheck.ts +90 -0
- package/src/connectionHelper/checks/Checker.ts +163 -0
- package/src/connectionHelper/checks/publishAudio.ts +33 -0
- package/src/connectionHelper/checks/publishVideo.ts +33 -0
- package/src/connectionHelper/checks/reconnect.ts +45 -0
- package/src/connectionHelper/checks/turn.ts +54 -0
- package/src/connectionHelper/checks/webrtc.ts +82 -0
- package/src/connectionHelper/checks/websocket.ts +27 -0
- package/src/e2ee/E2eeManager.ts +375 -0
- package/src/e2ee/KeyProvider.ts +78 -0
- package/src/e2ee/constants.ts +44 -0
- package/src/e2ee/errors.ts +16 -0
- package/src/e2ee/index.ts +3 -0
- package/src/e2ee/types.ts +161 -0
- package/src/e2ee/utils.ts +127 -0
- package/src/e2ee/worker/FrameCryptor.test.ts +19 -0
- package/src/e2ee/worker/FrameCryptor.ts +612 -0
- package/src/e2ee/worker/ParticipantKeyHandler.ts +175 -0
- package/src/e2ee/worker/e2ee.worker.ts +223 -0
- package/src/e2ee/worker/tsconfig.json +6 -0
- package/src/index.ts +85 -0
- package/src/logger.ts +64 -0
- package/src/options.ts +127 -0
- package/src/proto/livekit_models_pb.ts +2096 -0
- package/src/proto/livekit_rtc_pb.ts +2332 -0
- package/src/room/DefaultReconnectPolicy.ts +35 -0
- package/src/room/DeviceManager.ts +88 -0
- package/src/room/PCTransport.ts +452 -0
- package/src/room/RTCEngine.ts +1421 -0
- package/src/room/ReconnectPolicy.ts +27 -0
- package/src/room/RegionUrlProvider.ts +82 -0
- package/src/room/Room.test.ts +30 -0
- package/src/room/Room.ts +1907 -0
- package/src/room/defaults.ts +49 -0
- package/src/room/errors.ts +90 -0
- package/src/room/events.ts +535 -0
- package/src/room/participant/LocalParticipant.ts +1350 -0
- package/src/room/participant/Participant.ts +299 -0
- package/src/room/participant/ParticipantTrackPermission.ts +42 -0
- package/src/room/participant/RemoteParticipant.ts +359 -0
- package/src/room/participant/publishUtils.test.ts +189 -0
- package/src/room/participant/publishUtils.ts +399 -0
- package/src/room/stats.ts +136 -0
- package/src/room/timers.ts +16 -0
- package/src/room/track/LocalAudioTrack.ts +171 -0
- package/src/room/track/LocalTrack.ts +430 -0
- package/src/room/track/LocalTrackPublication.ts +87 -0
- package/src/room/track/LocalVideoTrack.test.ts +73 -0
- package/src/room/track/LocalVideoTrack.ts +513 -0
- package/src/room/track/RemoteAudioTrack.ts +248 -0
- package/src/room/track/RemoteTrack.ts +62 -0
- package/src/room/track/RemoteTrackPublication.ts +311 -0
- package/src/room/track/RemoteVideoTrack.test.ts +152 -0
- package/src/room/track/RemoteVideoTrack.ts +410 -0
- package/src/room/track/Track.ts +452 -0
- package/src/room/track/TrackPublication.ts +158 -0
- package/src/room/track/create.ts +143 -0
- package/src/room/track/facingMode.test.ts +31 -0
- package/src/room/track/facingMode.ts +103 -0
- package/src/room/track/options.ts +362 -0
- package/src/room/track/processor/types.ts +20 -0
- package/src/room/track/types.ts +25 -0
- package/src/room/track/utils.test.ts +111 -0
- package/src/room/track/utils.ts +183 -0
- package/src/room/types.ts +39 -0
- package/src/room/utils.test.ts +16 -0
- package/src/room/utils.ts +501 -0
- package/src/room/worker.d.ts +4 -0
- package/src/test/MockMediaStreamTrack.ts +84 -0
- package/src/test/mocks.ts +19 -0
- package/src/utils/AsyncQueue.test.ts +100 -0
- package/src/utils/AsyncQueue.ts +57 -0
- package/src/utils/browserParser.test.ts +88 -0
- package/src/utils/browserParser.ts +74 -0
- package/src/version.ts +4 -0
|
@@ -0,0 +1,790 @@
|
|
|
1
|
+
import { protoInt64 } from '@bufbuild/protobuf';
|
|
2
|
+
import log from '../logger';
|
|
3
|
+
import {
|
|
4
|
+
ClientInfo,
|
|
5
|
+
DisconnectReason,
|
|
6
|
+
ParticipantInfo,
|
|
7
|
+
ReconnectReason,
|
|
8
|
+
Room,
|
|
9
|
+
SpeakerInfo,
|
|
10
|
+
VideoLayer,
|
|
11
|
+
} from '../proto/livekit_models_pb';
|
|
12
|
+
import {
|
|
13
|
+
AddTrackRequest,
|
|
14
|
+
ConnectionQualityUpdate,
|
|
15
|
+
JoinResponse,
|
|
16
|
+
LeaveRequest,
|
|
17
|
+
MuteTrackRequest,
|
|
18
|
+
Ping,
|
|
19
|
+
ReconnectResponse,
|
|
20
|
+
SessionDescription,
|
|
21
|
+
SignalRequest,
|
|
22
|
+
SignalResponse,
|
|
23
|
+
SignalTarget,
|
|
24
|
+
SimulateScenario,
|
|
25
|
+
StreamStateUpdate,
|
|
26
|
+
SubscribedQualityUpdate,
|
|
27
|
+
SubscriptionPermission,
|
|
28
|
+
SubscriptionPermissionUpdate,
|
|
29
|
+
SubscriptionResponse,
|
|
30
|
+
SyncState,
|
|
31
|
+
TrackPermission,
|
|
32
|
+
TrackPublishedResponse,
|
|
33
|
+
TrackUnpublishedResponse,
|
|
34
|
+
TrickleRequest,
|
|
35
|
+
UpdateParticipantMetadata,
|
|
36
|
+
UpdateSubscription,
|
|
37
|
+
UpdateTrackSettings,
|
|
38
|
+
UpdateVideoLayers,
|
|
39
|
+
} from '../proto/livekit_rtc_pb';
|
|
40
|
+
import { ConnectionError, ConnectionErrorReason } from '../room/errors';
|
|
41
|
+
import CriticalTimers from '../room/timers';
|
|
42
|
+
import { Mutex, getClientInfo, isReactNative, sleep, toWebsocketUrl } from '../room/utils';
|
|
43
|
+
import { AsyncQueue } from '../utils/AsyncQueue';
|
|
44
|
+
|
|
45
|
+
// internal options
|
|
46
|
+
interface ConnectOpts {
|
|
47
|
+
autoSubscribe: boolean;
|
|
48
|
+
/** internal */
|
|
49
|
+
reconnect?: boolean;
|
|
50
|
+
|
|
51
|
+
/** internal */
|
|
52
|
+
reconnectReason?: number;
|
|
53
|
+
|
|
54
|
+
/** internal */
|
|
55
|
+
sid?: string;
|
|
56
|
+
|
|
57
|
+
/** @deprecated */
|
|
58
|
+
publishOnly?: string;
|
|
59
|
+
|
|
60
|
+
adaptiveStream?: boolean;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// public options
|
|
64
|
+
export interface SignalOptions {
|
|
65
|
+
autoSubscribe: boolean;
|
|
66
|
+
/** @deprecated */
|
|
67
|
+
publishOnly?: string;
|
|
68
|
+
adaptiveStream?: boolean;
|
|
69
|
+
maxRetries: number;
|
|
70
|
+
e2eeEnabled: boolean;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
type SignalMessage = SignalRequest['message'];
|
|
74
|
+
|
|
75
|
+
type SignalKind = NonNullable<SignalMessage>['case'];
|
|
76
|
+
|
|
77
|
+
const passThroughQueueSignals: Array<SignalKind> = [
|
|
78
|
+
'syncState',
|
|
79
|
+
'trickle',
|
|
80
|
+
'offer',
|
|
81
|
+
'answer',
|
|
82
|
+
'simulate',
|
|
83
|
+
'leave',
|
|
84
|
+
];
|
|
85
|
+
|
|
86
|
+
function canPassThroughQueue(req: SignalMessage): boolean {
|
|
87
|
+
const canPass = passThroughQueueSignals.indexOf(req!.case) >= 0;
|
|
88
|
+
log.trace('request allowed to bypass queue:', { canPass, req });
|
|
89
|
+
return canPass;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** @internal */
|
|
93
|
+
export class SignalClient {
|
|
94
|
+
isConnected: boolean;
|
|
95
|
+
|
|
96
|
+
isReconnecting: boolean;
|
|
97
|
+
|
|
98
|
+
requestQueue: AsyncQueue;
|
|
99
|
+
|
|
100
|
+
queuedRequests: Array<() => Promise<void>>;
|
|
101
|
+
|
|
102
|
+
useJSON: boolean;
|
|
103
|
+
|
|
104
|
+
/** signal rtt in milliseconds */
|
|
105
|
+
rtt: number = 0;
|
|
106
|
+
|
|
107
|
+
/** simulate signaling latency by delaying messages */
|
|
108
|
+
signalLatency?: number;
|
|
109
|
+
|
|
110
|
+
onClose?: (reason: string) => void;
|
|
111
|
+
|
|
112
|
+
onAnswer?: (sd: RTCSessionDescriptionInit) => void;
|
|
113
|
+
|
|
114
|
+
onOffer?: (sd: RTCSessionDescriptionInit) => void;
|
|
115
|
+
|
|
116
|
+
// when a new ICE candidate is made available
|
|
117
|
+
onTrickle?: (sd: RTCIceCandidateInit, target: SignalTarget) => void;
|
|
118
|
+
|
|
119
|
+
onParticipantUpdate?: (updates: ParticipantInfo[]) => void;
|
|
120
|
+
|
|
121
|
+
onLocalTrackPublished?: (res: TrackPublishedResponse) => void;
|
|
122
|
+
|
|
123
|
+
onNegotiateRequested?: () => void;
|
|
124
|
+
|
|
125
|
+
onSpeakersChanged?: (res: SpeakerInfo[]) => void;
|
|
126
|
+
|
|
127
|
+
onRemoteMuteChanged?: (trackSid: string, muted: boolean) => void;
|
|
128
|
+
|
|
129
|
+
onRoomUpdate?: (room: Room) => void;
|
|
130
|
+
|
|
131
|
+
onConnectionQuality?: (update: ConnectionQualityUpdate) => void;
|
|
132
|
+
|
|
133
|
+
onStreamStateUpdate?: (update: StreamStateUpdate) => void;
|
|
134
|
+
|
|
135
|
+
onSubscribedQualityUpdate?: (update: SubscribedQualityUpdate) => void;
|
|
136
|
+
|
|
137
|
+
onSubscriptionPermissionUpdate?: (update: SubscriptionPermissionUpdate) => void;
|
|
138
|
+
|
|
139
|
+
onSubscriptionError?: (update: SubscriptionResponse) => void;
|
|
140
|
+
|
|
141
|
+
onLocalTrackUnpublished?: (res: TrackUnpublishedResponse) => void;
|
|
142
|
+
|
|
143
|
+
onTokenRefresh?: (token: string) => void;
|
|
144
|
+
|
|
145
|
+
onLeave?: (leave: LeaveRequest) => void;
|
|
146
|
+
|
|
147
|
+
connectOptions?: ConnectOpts;
|
|
148
|
+
|
|
149
|
+
ws?: WebSocket;
|
|
150
|
+
|
|
151
|
+
private options?: SignalOptions;
|
|
152
|
+
|
|
153
|
+
private pingTimeout: ReturnType<typeof setTimeout> | undefined;
|
|
154
|
+
|
|
155
|
+
private pingTimeoutDuration: number | undefined;
|
|
156
|
+
|
|
157
|
+
private pingIntervalDuration: number | undefined;
|
|
158
|
+
|
|
159
|
+
private pingInterval: ReturnType<typeof setInterval> | undefined;
|
|
160
|
+
|
|
161
|
+
private closingLock: Mutex;
|
|
162
|
+
|
|
163
|
+
constructor(useJSON: boolean = false) {
|
|
164
|
+
this.isConnected = false;
|
|
165
|
+
this.isReconnecting = false;
|
|
166
|
+
this.useJSON = useJSON;
|
|
167
|
+
this.requestQueue = new AsyncQueue();
|
|
168
|
+
this.queuedRequests = [];
|
|
169
|
+
this.closingLock = new Mutex();
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
async join(
|
|
173
|
+
url: string,
|
|
174
|
+
token: string,
|
|
175
|
+
opts: SignalOptions,
|
|
176
|
+
abortSignal?: AbortSignal,
|
|
177
|
+
): Promise<JoinResponse> {
|
|
178
|
+
// during a full reconnect, we'd want to start the sequence even if currently
|
|
179
|
+
// connected
|
|
180
|
+
this.isConnected = false;
|
|
181
|
+
this.options = opts;
|
|
182
|
+
const res = await this.connect(url, token, opts, abortSignal);
|
|
183
|
+
return res as JoinResponse;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
async reconnect(
|
|
187
|
+
url: string,
|
|
188
|
+
token: string,
|
|
189
|
+
sid?: string,
|
|
190
|
+
reason?: ReconnectReason,
|
|
191
|
+
): Promise<ReconnectResponse | void> {
|
|
192
|
+
if (!this.options) {
|
|
193
|
+
log.warn('attempted to reconnect without signal options being set, ignoring');
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
this.isReconnecting = true;
|
|
197
|
+
// clear ping interval and restart it once reconnected
|
|
198
|
+
this.clearPingInterval();
|
|
199
|
+
|
|
200
|
+
const res = await this.connect(url, token, {
|
|
201
|
+
...this.options,
|
|
202
|
+
reconnect: true,
|
|
203
|
+
sid,
|
|
204
|
+
reconnectReason: reason,
|
|
205
|
+
});
|
|
206
|
+
return res;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
private connect(
|
|
210
|
+
url: string,
|
|
211
|
+
token: string,
|
|
212
|
+
opts: ConnectOpts,
|
|
213
|
+
abortSignal?: AbortSignal,
|
|
214
|
+
): Promise<JoinResponse | ReconnectResponse | void> {
|
|
215
|
+
this.connectOptions = opts;
|
|
216
|
+
url = toWebsocketUrl(url);
|
|
217
|
+
// strip trailing slash
|
|
218
|
+
url = url.replace(/\/$/, '');
|
|
219
|
+
url += '/rtc';
|
|
220
|
+
|
|
221
|
+
const clientInfo = getClientInfo();
|
|
222
|
+
const params = createConnectionParams(token, clientInfo, opts);
|
|
223
|
+
|
|
224
|
+
return new Promise<JoinResponse | ReconnectResponse | void>(async (resolve, reject) => {
|
|
225
|
+
const abortHandler = async () => {
|
|
226
|
+
this.close();
|
|
227
|
+
reject(new ConnectionError('room connection has been cancelled (signal)'));
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
if (abortSignal?.aborted) {
|
|
231
|
+
abortHandler();
|
|
232
|
+
}
|
|
233
|
+
abortSignal?.addEventListener('abort', abortHandler);
|
|
234
|
+
log.debug(`connecting to ${url + params}`);
|
|
235
|
+
if (this.ws) {
|
|
236
|
+
await this.close();
|
|
237
|
+
}
|
|
238
|
+
this.ws = new WebSocket(url + params);
|
|
239
|
+
this.ws.binaryType = 'arraybuffer';
|
|
240
|
+
|
|
241
|
+
this.ws.onerror = async (ev: Event) => {
|
|
242
|
+
if (!this.isConnected) {
|
|
243
|
+
try {
|
|
244
|
+
const resp = await fetch(`http${url.substring(2)}/validate${params}`);
|
|
245
|
+
if (resp.status.toFixed(0).startsWith('4')) {
|
|
246
|
+
const msg = await resp.text();
|
|
247
|
+
reject(new ConnectionError(msg, ConnectionErrorReason.NotAllowed, resp.status));
|
|
248
|
+
} else {
|
|
249
|
+
reject(
|
|
250
|
+
new ConnectionError(
|
|
251
|
+
'Internal error',
|
|
252
|
+
ConnectionErrorReason.InternalError,
|
|
253
|
+
resp.status,
|
|
254
|
+
),
|
|
255
|
+
);
|
|
256
|
+
}
|
|
257
|
+
} catch (e) {
|
|
258
|
+
reject(
|
|
259
|
+
new ConnectionError(
|
|
260
|
+
'server was not reachable',
|
|
261
|
+
ConnectionErrorReason.ServerUnreachable,
|
|
262
|
+
),
|
|
263
|
+
);
|
|
264
|
+
}
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
// other errors, handle
|
|
268
|
+
this.handleWSError(ev);
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
this.ws.onmessage = async (ev: MessageEvent) => {
|
|
272
|
+
// not considered connected until JoinResponse is received
|
|
273
|
+
let resp: SignalResponse;
|
|
274
|
+
if (typeof ev.data === 'string') {
|
|
275
|
+
const json = JSON.parse(ev.data);
|
|
276
|
+
resp = SignalResponse.fromJson(json);
|
|
277
|
+
} else if (ev.data instanceof ArrayBuffer) {
|
|
278
|
+
resp = SignalResponse.fromBinary(new Uint8Array(ev.data));
|
|
279
|
+
} else {
|
|
280
|
+
log.error(`could not decode websocket message: ${typeof ev.data}`);
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
if (!this.isConnected) {
|
|
285
|
+
let shouldProcessMessage = false;
|
|
286
|
+
// handle join message only
|
|
287
|
+
if (resp.message?.case === 'join') {
|
|
288
|
+
this.isConnected = true;
|
|
289
|
+
abortSignal?.removeEventListener('abort', abortHandler);
|
|
290
|
+
this.pingTimeoutDuration = resp.message.value.pingTimeout;
|
|
291
|
+
this.pingIntervalDuration = resp.message.value.pingInterval;
|
|
292
|
+
|
|
293
|
+
if (this.pingTimeoutDuration && this.pingTimeoutDuration > 0) {
|
|
294
|
+
log.debug('ping config', {
|
|
295
|
+
timeout: this.pingTimeoutDuration,
|
|
296
|
+
interval: this.pingIntervalDuration,
|
|
297
|
+
});
|
|
298
|
+
this.startPingInterval();
|
|
299
|
+
}
|
|
300
|
+
resolve(resp.message.value);
|
|
301
|
+
} else if (opts.reconnect) {
|
|
302
|
+
// in reconnecting, any message received means signal reconnected
|
|
303
|
+
this.isConnected = true;
|
|
304
|
+
abortSignal?.removeEventListener('abort', abortHandler);
|
|
305
|
+
this.startPingInterval();
|
|
306
|
+
if (resp.message?.case === 'reconnect') {
|
|
307
|
+
resolve(resp.message?.value);
|
|
308
|
+
} else {
|
|
309
|
+
resolve();
|
|
310
|
+
shouldProcessMessage = true;
|
|
311
|
+
}
|
|
312
|
+
} else if (!opts.reconnect) {
|
|
313
|
+
// non-reconnect case, should receive join response first
|
|
314
|
+
reject(
|
|
315
|
+
new ConnectionError(
|
|
316
|
+
`did not receive join response, got ${resp.message?.case} instead`,
|
|
317
|
+
),
|
|
318
|
+
);
|
|
319
|
+
}
|
|
320
|
+
if (!shouldProcessMessage) {
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
if (this.signalLatency) {
|
|
326
|
+
await sleep(this.signalLatency);
|
|
327
|
+
}
|
|
328
|
+
this.handleSignalResponse(resp);
|
|
329
|
+
};
|
|
330
|
+
|
|
331
|
+
this.ws.onclose = (ev: CloseEvent) => {
|
|
332
|
+
log.warn(`websocket closed`, { ev });
|
|
333
|
+
this.handleOnClose(ev.reason);
|
|
334
|
+
};
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
/** @internal */
|
|
339
|
+
resetCallbacks = () => {
|
|
340
|
+
this.onAnswer = undefined;
|
|
341
|
+
this.onLeave = undefined;
|
|
342
|
+
this.onLocalTrackPublished = undefined;
|
|
343
|
+
this.onLocalTrackUnpublished = undefined;
|
|
344
|
+
this.onNegotiateRequested = undefined;
|
|
345
|
+
this.onOffer = undefined;
|
|
346
|
+
this.onRemoteMuteChanged = undefined;
|
|
347
|
+
this.onSubscribedQualityUpdate = undefined;
|
|
348
|
+
this.onTokenRefresh = undefined;
|
|
349
|
+
this.onTrickle = undefined;
|
|
350
|
+
this.onClose = undefined;
|
|
351
|
+
};
|
|
352
|
+
|
|
353
|
+
async close() {
|
|
354
|
+
const unlock = await this.closingLock.lock();
|
|
355
|
+
try {
|
|
356
|
+
this.isConnected = false;
|
|
357
|
+
if (this.ws) {
|
|
358
|
+
this.ws.onmessage = null;
|
|
359
|
+
this.ws.onopen = null;
|
|
360
|
+
this.ws.onclose = null;
|
|
361
|
+
|
|
362
|
+
// calling `ws.close()` only starts the closing handshake (CLOSING state), prefer to wait until state is actually CLOSED
|
|
363
|
+
const closePromise = new Promise<void>((resolve) => {
|
|
364
|
+
if (this.ws) {
|
|
365
|
+
this.ws.onclose = () => {
|
|
366
|
+
resolve();
|
|
367
|
+
};
|
|
368
|
+
} else {
|
|
369
|
+
resolve();
|
|
370
|
+
}
|
|
371
|
+
});
|
|
372
|
+
|
|
373
|
+
if (this.ws.readyState < this.ws.CLOSING) {
|
|
374
|
+
this.ws.close();
|
|
375
|
+
// 250ms grace period for ws to close gracefully
|
|
376
|
+
await Promise.race([closePromise, sleep(250)]);
|
|
377
|
+
}
|
|
378
|
+
this.ws = undefined;
|
|
379
|
+
}
|
|
380
|
+
} finally {
|
|
381
|
+
this.clearPingInterval();
|
|
382
|
+
unlock();
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
// initial offer after joining
|
|
387
|
+
sendOffer(offer: RTCSessionDescriptionInit) {
|
|
388
|
+
log.debug('sending offer', offer);
|
|
389
|
+
this.sendRequest({
|
|
390
|
+
case: 'offer',
|
|
391
|
+
value: toProtoSessionDescription(offer),
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
// answer a server-initiated offer
|
|
396
|
+
sendAnswer(answer: RTCSessionDescriptionInit) {
|
|
397
|
+
log.debug('sending answer');
|
|
398
|
+
return this.sendRequest({
|
|
399
|
+
case: 'answer',
|
|
400
|
+
value: toProtoSessionDescription(answer),
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
sendIceCandidate(candidate: RTCIceCandidateInit, target: SignalTarget) {
|
|
405
|
+
log.trace('sending ice candidate', candidate);
|
|
406
|
+
return this.sendRequest({
|
|
407
|
+
case: 'trickle',
|
|
408
|
+
value: new TrickleRequest({
|
|
409
|
+
candidateInit: JSON.stringify(candidate),
|
|
410
|
+
target,
|
|
411
|
+
}),
|
|
412
|
+
});
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
sendMuteTrack(trackSid: string, muted: boolean) {
|
|
416
|
+
return this.sendRequest({
|
|
417
|
+
case: 'mute',
|
|
418
|
+
value: new MuteTrackRequest({
|
|
419
|
+
sid: trackSid,
|
|
420
|
+
muted,
|
|
421
|
+
}),
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
sendAddTrack(req: AddTrackRequest) {
|
|
426
|
+
return this.sendRequest({
|
|
427
|
+
case: 'addTrack',
|
|
428
|
+
value: req,
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
sendUpdateLocalMetadata(metadata: string, name: string) {
|
|
433
|
+
return this.sendRequest({
|
|
434
|
+
case: 'updateMetadata',
|
|
435
|
+
value: new UpdateParticipantMetadata({
|
|
436
|
+
metadata,
|
|
437
|
+
name,
|
|
438
|
+
}),
|
|
439
|
+
});
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
sendUpdateTrackSettings(settings: UpdateTrackSettings) {
|
|
443
|
+
this.sendRequest({
|
|
444
|
+
case: 'trackSetting',
|
|
445
|
+
value: settings,
|
|
446
|
+
});
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
sendUpdateSubscription(sub: UpdateSubscription) {
|
|
450
|
+
return this.sendRequest({
|
|
451
|
+
case: 'subscription',
|
|
452
|
+
value: sub,
|
|
453
|
+
});
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
sendSyncState(sync: SyncState) {
|
|
457
|
+
return this.sendRequest({
|
|
458
|
+
case: 'syncState',
|
|
459
|
+
value: sync,
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
sendUpdateVideoLayers(trackSid: string, layers: VideoLayer[]) {
|
|
464
|
+
return this.sendRequest({
|
|
465
|
+
case: 'updateLayers',
|
|
466
|
+
value: new UpdateVideoLayers({
|
|
467
|
+
trackSid,
|
|
468
|
+
layers,
|
|
469
|
+
}),
|
|
470
|
+
});
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
sendUpdateSubscriptionPermissions(allParticipants: boolean, trackPermissions: TrackPermission[]) {
|
|
474
|
+
return this.sendRequest({
|
|
475
|
+
case: 'subscriptionPermission',
|
|
476
|
+
value: new SubscriptionPermission({
|
|
477
|
+
allParticipants,
|
|
478
|
+
trackPermissions,
|
|
479
|
+
}),
|
|
480
|
+
});
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
sendSimulateScenario(scenario: SimulateScenario) {
|
|
484
|
+
return this.sendRequest({
|
|
485
|
+
case: 'simulate',
|
|
486
|
+
value: scenario,
|
|
487
|
+
});
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
sendPing() {
|
|
491
|
+
/** send both of ping and pingReq for compatibility to old and new server */
|
|
492
|
+
return Promise.all([
|
|
493
|
+
this.sendRequest({
|
|
494
|
+
case: 'ping',
|
|
495
|
+
value: protoInt64.parse(Date.now()),
|
|
496
|
+
}),
|
|
497
|
+
this.sendRequest({
|
|
498
|
+
case: 'pingReq',
|
|
499
|
+
value: new Ping({
|
|
500
|
+
timestamp: protoInt64.parse(Date.now()),
|
|
501
|
+
rtt: protoInt64.parse(this.rtt),
|
|
502
|
+
}),
|
|
503
|
+
}),
|
|
504
|
+
]);
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
sendLeave() {
|
|
508
|
+
return this.sendRequest({
|
|
509
|
+
case: 'leave',
|
|
510
|
+
value: new LeaveRequest({
|
|
511
|
+
canReconnect: false,
|
|
512
|
+
reason: DisconnectReason.CLIENT_INITIATED,
|
|
513
|
+
}),
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
async sendRequest(message: SignalMessage, fromQueue: boolean = false) {
|
|
518
|
+
// capture all requests while reconnecting and put them in a queue
|
|
519
|
+
// unless the request originates from the queue, then don't enqueue again
|
|
520
|
+
const canQueue = !fromQueue && !canPassThroughQueue(message);
|
|
521
|
+
if (canQueue && this.isReconnecting) {
|
|
522
|
+
this.queuedRequests.push(async () => {
|
|
523
|
+
await this.sendRequest(message, true);
|
|
524
|
+
});
|
|
525
|
+
return;
|
|
526
|
+
}
|
|
527
|
+
// make sure previously queued requests are being sent first
|
|
528
|
+
if (!fromQueue) {
|
|
529
|
+
await this.requestQueue.flush();
|
|
530
|
+
}
|
|
531
|
+
if (this.signalLatency) {
|
|
532
|
+
await sleep(this.signalLatency);
|
|
533
|
+
}
|
|
534
|
+
if (!this.ws || this.ws.readyState !== this.ws.OPEN) {
|
|
535
|
+
log.error(`cannot send signal request before connected, type: ${message?.case}`);
|
|
536
|
+
return;
|
|
537
|
+
}
|
|
538
|
+
const req = new SignalRequest({ message });
|
|
539
|
+
|
|
540
|
+
try {
|
|
541
|
+
if (this.useJSON) {
|
|
542
|
+
this.ws.send(req.toJsonString());
|
|
543
|
+
} else {
|
|
544
|
+
this.ws.send(req.toBinary());
|
|
545
|
+
}
|
|
546
|
+
} catch (e) {
|
|
547
|
+
log.error('error sending signal message', { error: e });
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
private handleSignalResponse(res: SignalResponse) {
|
|
552
|
+
const msg = res.message;
|
|
553
|
+
if (msg == undefined) {
|
|
554
|
+
log.debug('received unsupported message');
|
|
555
|
+
return;
|
|
556
|
+
}
|
|
557
|
+
if (msg.case === 'answer') {
|
|
558
|
+
const sd = fromProtoSessionDescription(msg.value);
|
|
559
|
+
if (this.onAnswer) {
|
|
560
|
+
this.onAnswer(sd);
|
|
561
|
+
}
|
|
562
|
+
} else if (msg.case === 'offer') {
|
|
563
|
+
const sd = fromProtoSessionDescription(msg.value);
|
|
564
|
+
if (this.onOffer) {
|
|
565
|
+
this.onOffer(sd);
|
|
566
|
+
}
|
|
567
|
+
} else if (msg.case === 'trickle') {
|
|
568
|
+
const candidate: RTCIceCandidateInit = JSON.parse(msg.value.candidateInit!);
|
|
569
|
+
if (this.onTrickle) {
|
|
570
|
+
this.onTrickle(candidate, msg.value.target);
|
|
571
|
+
}
|
|
572
|
+
} else if (msg.case === 'update') {
|
|
573
|
+
if (this.onParticipantUpdate) {
|
|
574
|
+
this.onParticipantUpdate(msg.value.participants ?? []);
|
|
575
|
+
}
|
|
576
|
+
} else if (msg.case === 'trackPublished') {
|
|
577
|
+
if (this.onLocalTrackPublished) {
|
|
578
|
+
this.onLocalTrackPublished(msg.value);
|
|
579
|
+
}
|
|
580
|
+
} else if (msg.case === 'speakersChanged') {
|
|
581
|
+
if (this.onSpeakersChanged) {
|
|
582
|
+
this.onSpeakersChanged(msg.value.speakers ?? []);
|
|
583
|
+
}
|
|
584
|
+
} else if (msg.case === 'leave') {
|
|
585
|
+
if (this.onLeave) {
|
|
586
|
+
this.onLeave(msg.value);
|
|
587
|
+
}
|
|
588
|
+
} else if (msg.case === 'mute') {
|
|
589
|
+
if (this.onRemoteMuteChanged) {
|
|
590
|
+
this.onRemoteMuteChanged(msg.value.sid, msg.value.muted);
|
|
591
|
+
}
|
|
592
|
+
} else if (msg.case === 'roomUpdate') {
|
|
593
|
+
if (this.onRoomUpdate && msg.value.room) {
|
|
594
|
+
this.onRoomUpdate(msg.value.room);
|
|
595
|
+
}
|
|
596
|
+
} else if (msg.case === 'connectionQuality') {
|
|
597
|
+
if (this.onConnectionQuality) {
|
|
598
|
+
this.onConnectionQuality(msg.value);
|
|
599
|
+
}
|
|
600
|
+
} else if (msg.case === 'streamStateUpdate') {
|
|
601
|
+
if (this.onStreamStateUpdate) {
|
|
602
|
+
this.onStreamStateUpdate(msg.value);
|
|
603
|
+
}
|
|
604
|
+
} else if (msg.case === 'subscribedQualityUpdate') {
|
|
605
|
+
if (this.onSubscribedQualityUpdate) {
|
|
606
|
+
this.onSubscribedQualityUpdate(msg.value);
|
|
607
|
+
}
|
|
608
|
+
} else if (msg.case === 'subscriptionPermissionUpdate') {
|
|
609
|
+
if (this.onSubscriptionPermissionUpdate) {
|
|
610
|
+
this.onSubscriptionPermissionUpdate(msg.value);
|
|
611
|
+
}
|
|
612
|
+
} else if (msg.case === 'refreshToken') {
|
|
613
|
+
if (this.onTokenRefresh) {
|
|
614
|
+
this.onTokenRefresh(msg.value);
|
|
615
|
+
}
|
|
616
|
+
} else if (msg.case === 'trackUnpublished') {
|
|
617
|
+
if (this.onLocalTrackUnpublished) {
|
|
618
|
+
this.onLocalTrackUnpublished(msg.value);
|
|
619
|
+
}
|
|
620
|
+
} else if (msg.case === 'subscriptionResponse') {
|
|
621
|
+
if (this.onSubscriptionError) {
|
|
622
|
+
this.onSubscriptionError(msg.value);
|
|
623
|
+
}
|
|
624
|
+
} else if (msg.case === 'pong') {
|
|
625
|
+
this.resetPingTimeout();
|
|
626
|
+
} else if (msg.case === 'pongResp') {
|
|
627
|
+
this.rtt = Date.now() - Number.parseInt(msg.value.lastPingTimestamp.toString());
|
|
628
|
+
this.resetPingTimeout();
|
|
629
|
+
} else {
|
|
630
|
+
log.debug('unsupported message', msg);
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
setReconnected() {
|
|
635
|
+
while (this.queuedRequests.length > 0) {
|
|
636
|
+
const req = this.queuedRequests.shift();
|
|
637
|
+
if (req) {
|
|
638
|
+
this.requestQueue.run(req);
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
this.isReconnecting = false;
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
private async handleOnClose(reason: string) {
|
|
645
|
+
if (!this.isConnected) return;
|
|
646
|
+
const onCloseCallback = this.onClose;
|
|
647
|
+
await this.close();
|
|
648
|
+
log.debug(`websocket connection closed: ${reason}`);
|
|
649
|
+
if (onCloseCallback) {
|
|
650
|
+
onCloseCallback(reason);
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
private handleWSError(ev: Event) {
|
|
655
|
+
log.error('websocket error', ev);
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
/**
|
|
659
|
+
* Resets the ping timeout and starts a new timeout.
|
|
660
|
+
* Call this after receiving a pong message
|
|
661
|
+
*/
|
|
662
|
+
private resetPingTimeout() {
|
|
663
|
+
this.clearPingTimeout();
|
|
664
|
+
if (!this.pingTimeoutDuration) {
|
|
665
|
+
log.warn('ping timeout duration not set');
|
|
666
|
+
return;
|
|
667
|
+
}
|
|
668
|
+
this.pingTimeout = CriticalTimers.setTimeout(() => {
|
|
669
|
+
log.warn(
|
|
670
|
+
`ping timeout triggered. last pong received at: ${new Date(
|
|
671
|
+
Date.now() - this.pingTimeoutDuration! * 1000,
|
|
672
|
+
).toUTCString()}`,
|
|
673
|
+
);
|
|
674
|
+
this.handleOnClose('ping timeout');
|
|
675
|
+
}, this.pingTimeoutDuration * 1000);
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
/**
|
|
679
|
+
* Clears ping timeout (does not start a new timeout)
|
|
680
|
+
*/
|
|
681
|
+
private clearPingTimeout() {
|
|
682
|
+
if (this.pingTimeout) {
|
|
683
|
+
CriticalTimers.clearTimeout(this.pingTimeout);
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
private startPingInterval() {
|
|
688
|
+
this.clearPingInterval();
|
|
689
|
+
this.resetPingTimeout();
|
|
690
|
+
if (!this.pingIntervalDuration) {
|
|
691
|
+
log.warn('ping interval duration not set');
|
|
692
|
+
return;
|
|
693
|
+
}
|
|
694
|
+
log.debug('start ping interval');
|
|
695
|
+
this.pingInterval = CriticalTimers.setInterval(() => {
|
|
696
|
+
this.sendPing();
|
|
697
|
+
}, this.pingIntervalDuration * 1000);
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
private clearPingInterval() {
|
|
701
|
+
log.debug('clearing ping interval');
|
|
702
|
+
this.clearPingTimeout();
|
|
703
|
+
if (this.pingInterval) {
|
|
704
|
+
CriticalTimers.clearInterval(this.pingInterval);
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
function fromProtoSessionDescription(sd: SessionDescription): RTCSessionDescriptionInit {
|
|
710
|
+
const rsd: RTCSessionDescriptionInit = {
|
|
711
|
+
type: 'offer',
|
|
712
|
+
sdp: sd.sdp,
|
|
713
|
+
};
|
|
714
|
+
switch (sd.type) {
|
|
715
|
+
case 'answer':
|
|
716
|
+
case 'offer':
|
|
717
|
+
case 'pranswer':
|
|
718
|
+
case 'rollback':
|
|
719
|
+
rsd.type = sd.type;
|
|
720
|
+
break;
|
|
721
|
+
default:
|
|
722
|
+
break;
|
|
723
|
+
}
|
|
724
|
+
return rsd;
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
export function toProtoSessionDescription(
|
|
728
|
+
rsd: RTCSessionDescription | RTCSessionDescriptionInit,
|
|
729
|
+
): SessionDescription {
|
|
730
|
+
const sd = new SessionDescription({
|
|
731
|
+
sdp: rsd.sdp!,
|
|
732
|
+
type: rsd.type!,
|
|
733
|
+
});
|
|
734
|
+
return sd;
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
function createConnectionParams(token: string, info: ClientInfo, opts: ConnectOpts): string {
|
|
738
|
+
const params = new URLSearchParams();
|
|
739
|
+
params.set('access_token', token);
|
|
740
|
+
|
|
741
|
+
// opts
|
|
742
|
+
if (opts.reconnect) {
|
|
743
|
+
params.set('reconnect', '1');
|
|
744
|
+
if (opts.sid) {
|
|
745
|
+
params.set('sid', opts.sid);
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
params.set('auto_subscribe', opts.autoSubscribe ? '1' : '0');
|
|
750
|
+
|
|
751
|
+
// ClientInfo
|
|
752
|
+
params.set('sdk', isReactNative() ? 'reactnative' : 'js');
|
|
753
|
+
params.set('version', info.version!);
|
|
754
|
+
params.set('protocol', info.protocol!.toString());
|
|
755
|
+
if (info.deviceModel) {
|
|
756
|
+
params.set('device_model', info.deviceModel);
|
|
757
|
+
}
|
|
758
|
+
if (info.os) {
|
|
759
|
+
params.set('os', info.os);
|
|
760
|
+
}
|
|
761
|
+
if (info.osVersion) {
|
|
762
|
+
params.set('os_version', info.osVersion);
|
|
763
|
+
}
|
|
764
|
+
if (info.browser) {
|
|
765
|
+
params.set('browser', info.browser);
|
|
766
|
+
}
|
|
767
|
+
if (info.browserVersion) {
|
|
768
|
+
params.set('browser_version', info.browserVersion);
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
if (opts.publishOnly !== undefined) {
|
|
772
|
+
params.set('publish', opts.publishOnly);
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
if (opts.adaptiveStream) {
|
|
776
|
+
params.set('adaptive_stream', '1');
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
if (opts.reconnectReason) {
|
|
780
|
+
params.set('reconnect_reason', opts.reconnectReason.toString());
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
// @ts-ignore
|
|
784
|
+
if (navigator.connection?.type) {
|
|
785
|
+
// @ts-ignore
|
|
786
|
+
params.set('network', navigator.connection.type);
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
return `?${params.toString()}`;
|
|
790
|
+
}
|