@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,248 @@
|
|
|
1
|
+
import log from '../../logger';
|
|
2
|
+
import { TrackEvent } from '../events';
|
|
3
|
+
import { computeBitrate } from '../stats';
|
|
4
|
+
import type { AudioReceiverStats } from '../stats';
|
|
5
|
+
import { supportsSetSinkId } from '../utils';
|
|
6
|
+
import RemoteTrack from './RemoteTrack';
|
|
7
|
+
import { Track } from './Track';
|
|
8
|
+
import type { AudioOutputOptions } from './options';
|
|
9
|
+
|
|
10
|
+
export default class RemoteAudioTrack extends RemoteTrack {
|
|
11
|
+
private prevStats?: AudioReceiverStats;
|
|
12
|
+
|
|
13
|
+
private elementVolume: number | undefined;
|
|
14
|
+
|
|
15
|
+
private audioContext?: AudioContext;
|
|
16
|
+
|
|
17
|
+
private gainNode?: GainNode;
|
|
18
|
+
|
|
19
|
+
private sourceNode?: MediaStreamAudioSourceNode;
|
|
20
|
+
|
|
21
|
+
private webAudioPluginNodes: AudioNode[];
|
|
22
|
+
|
|
23
|
+
private sinkId?: string;
|
|
24
|
+
|
|
25
|
+
constructor(
|
|
26
|
+
mediaTrack: MediaStreamTrack,
|
|
27
|
+
sid: string,
|
|
28
|
+
receiver?: RTCRtpReceiver,
|
|
29
|
+
audioContext?: AudioContext,
|
|
30
|
+
audioOutput?: AudioOutputOptions,
|
|
31
|
+
) {
|
|
32
|
+
super(mediaTrack, sid, Track.Kind.Audio, receiver);
|
|
33
|
+
this.audioContext = audioContext;
|
|
34
|
+
this.webAudioPluginNodes = [];
|
|
35
|
+
if (audioOutput) {
|
|
36
|
+
this.sinkId = audioOutput.deviceId;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* sets the volume for all attached audio elements
|
|
42
|
+
*/
|
|
43
|
+
setVolume(volume: number) {
|
|
44
|
+
for (const el of this.attachedElements) {
|
|
45
|
+
if (this.audioContext) {
|
|
46
|
+
this.gainNode?.gain.setTargetAtTime(volume, 0, 0.1);
|
|
47
|
+
} else {
|
|
48
|
+
el.volume = volume;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
this.elementVolume = volume;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* gets the volume of attached audio elements (loudest)
|
|
56
|
+
*/
|
|
57
|
+
getVolume(): number {
|
|
58
|
+
if (this.elementVolume) {
|
|
59
|
+
return this.elementVolume;
|
|
60
|
+
}
|
|
61
|
+
let highestVolume = 0;
|
|
62
|
+
this.attachedElements.forEach((element) => {
|
|
63
|
+
if (element.volume > highestVolume) {
|
|
64
|
+
highestVolume = element.volume;
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
return highestVolume;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* calls setSinkId on all attached elements, if supported
|
|
72
|
+
* @param deviceId audio output device
|
|
73
|
+
*/
|
|
74
|
+
async setSinkId(deviceId: string) {
|
|
75
|
+
this.sinkId = deviceId;
|
|
76
|
+
await Promise.all(
|
|
77
|
+
this.attachedElements.map((elm) => {
|
|
78
|
+
if (!supportsSetSinkId(elm)) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
/* @ts-ignore */
|
|
82
|
+
return elm.setSinkId(deviceId) as Promise<void>;
|
|
83
|
+
}),
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
attach(): HTMLMediaElement;
|
|
88
|
+
attach(element: HTMLMediaElement): HTMLMediaElement;
|
|
89
|
+
attach(element?: HTMLMediaElement): HTMLMediaElement {
|
|
90
|
+
const needsNewWebAudioConnection = this.attachedElements.length === 0;
|
|
91
|
+
if (!element) {
|
|
92
|
+
element = super.attach();
|
|
93
|
+
} else {
|
|
94
|
+
super.attach(element);
|
|
95
|
+
}
|
|
96
|
+
if (this.elementVolume) {
|
|
97
|
+
element.volume = this.elementVolume;
|
|
98
|
+
}
|
|
99
|
+
if (this.sinkId && supportsSetSinkId(element)) {
|
|
100
|
+
/* @ts-ignore */
|
|
101
|
+
element.setSinkId(this.sinkId);
|
|
102
|
+
}
|
|
103
|
+
if (this.audioContext && needsNewWebAudioConnection) {
|
|
104
|
+
log.debug('using audio context mapping');
|
|
105
|
+
this.connectWebAudio(this.audioContext, element);
|
|
106
|
+
element.volume = 0;
|
|
107
|
+
element.muted = true;
|
|
108
|
+
}
|
|
109
|
+
return element;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Detaches from all attached elements
|
|
114
|
+
*/
|
|
115
|
+
detach(): HTMLMediaElement[];
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Detach from a single element
|
|
119
|
+
* @param element
|
|
120
|
+
*/
|
|
121
|
+
detach(element: HTMLMediaElement): HTMLMediaElement;
|
|
122
|
+
detach(element?: HTMLMediaElement): HTMLMediaElement | HTMLMediaElement[] {
|
|
123
|
+
let detached: HTMLMediaElement | HTMLMediaElement[];
|
|
124
|
+
if (!element) {
|
|
125
|
+
detached = super.detach();
|
|
126
|
+
this.disconnectWebAudio();
|
|
127
|
+
} else {
|
|
128
|
+
detached = super.detach(element);
|
|
129
|
+
// if there are still any attached elements after detaching, connect webaudio to the first element that's left
|
|
130
|
+
// disconnect webaudio otherwise
|
|
131
|
+
if (this.audioContext) {
|
|
132
|
+
if (this.attachedElements.length > 0) {
|
|
133
|
+
this.connectWebAudio(this.audioContext, this.attachedElements[0]);
|
|
134
|
+
} else {
|
|
135
|
+
this.disconnectWebAudio();
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return detached;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* @internal
|
|
144
|
+
* @experimental
|
|
145
|
+
*/
|
|
146
|
+
setAudioContext(audioContext: AudioContext | undefined) {
|
|
147
|
+
this.audioContext = audioContext;
|
|
148
|
+
if (audioContext && this.attachedElements.length > 0) {
|
|
149
|
+
this.connectWebAudio(audioContext, this.attachedElements[0]);
|
|
150
|
+
} else if (!audioContext) {
|
|
151
|
+
this.disconnectWebAudio();
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* @internal
|
|
157
|
+
* @experimental
|
|
158
|
+
* @param {AudioNode[]} nodes - An array of WebAudio nodes. These nodes should not be connected to each other when passed, as the sdk will take care of connecting them in the order of the array.
|
|
159
|
+
*/
|
|
160
|
+
setWebAudioPlugins(nodes: AudioNode[]) {
|
|
161
|
+
this.webAudioPluginNodes = nodes;
|
|
162
|
+
if (this.attachedElements.length > 0 && this.audioContext) {
|
|
163
|
+
this.connectWebAudio(this.audioContext, this.attachedElements[0]);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
private connectWebAudio(context: AudioContext, element: HTMLMediaElement) {
|
|
168
|
+
this.disconnectWebAudio();
|
|
169
|
+
// @ts-ignore attached elements always have a srcObject set
|
|
170
|
+
this.sourceNode = context.createMediaStreamSource(element.srcObject);
|
|
171
|
+
let lastNode: AudioNode = this.sourceNode;
|
|
172
|
+
this.webAudioPluginNodes.forEach((node) => {
|
|
173
|
+
lastNode.connect(node);
|
|
174
|
+
lastNode = node;
|
|
175
|
+
});
|
|
176
|
+
this.gainNode = context.createGain();
|
|
177
|
+
lastNode.connect(this.gainNode);
|
|
178
|
+
this.gainNode.connect(context.destination);
|
|
179
|
+
|
|
180
|
+
if (this.elementVolume) {
|
|
181
|
+
this.gainNode.gain.setTargetAtTime(this.elementVolume, 0, 0.1);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// try to resume the context if it isn't running already
|
|
185
|
+
if (context.state !== 'running') {
|
|
186
|
+
context
|
|
187
|
+
.resume()
|
|
188
|
+
.then(() => {
|
|
189
|
+
if (context.state !== 'running') {
|
|
190
|
+
this.emit(
|
|
191
|
+
TrackEvent.AudioPlaybackFailed,
|
|
192
|
+
new Error("Audio Context couldn't be started automatically"),
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
})
|
|
196
|
+
.catch((e) => {
|
|
197
|
+
this.emit(TrackEvent.AudioPlaybackFailed, e);
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
private disconnectWebAudio() {
|
|
203
|
+
this.gainNode?.disconnect();
|
|
204
|
+
this.sourceNode?.disconnect();
|
|
205
|
+
this.gainNode = undefined;
|
|
206
|
+
this.sourceNode = undefined;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
protected monitorReceiver = async () => {
|
|
210
|
+
if (!this.receiver) {
|
|
211
|
+
this._currentBitrate = 0;
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
const stats = await this.getReceiverStats();
|
|
215
|
+
|
|
216
|
+
if (stats && this.prevStats && this.receiver) {
|
|
217
|
+
this._currentBitrate = computeBitrate(stats, this.prevStats);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
this.prevStats = stats;
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
protected async getReceiverStats(): Promise<AudioReceiverStats | undefined> {
|
|
224
|
+
if (!this.receiver || !this.receiver.getStats) {
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
const stats = await this.receiver.getStats();
|
|
229
|
+
let receiverStats: AudioReceiverStats | undefined;
|
|
230
|
+
stats.forEach((v) => {
|
|
231
|
+
if (v.type === 'inbound-rtp') {
|
|
232
|
+
receiverStats = {
|
|
233
|
+
type: 'audio',
|
|
234
|
+
timestamp: v.timestamp,
|
|
235
|
+
jitter: v.jitter,
|
|
236
|
+
bytesReceived: v.bytesReceived,
|
|
237
|
+
concealedSamples: v.concealedSamples,
|
|
238
|
+
concealmentEvents: v.concealmentEvents,
|
|
239
|
+
silentConcealedSamples: v.silentConcealedSamples,
|
|
240
|
+
silentConcealmentEvents: v.silentConcealmentEvents,
|
|
241
|
+
totalAudioEnergy: v.totalAudioEnergy,
|
|
242
|
+
totalSamplesDuration: v.totalSamplesDuration,
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
return receiverStats;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { TrackEvent } from '../events';
|
|
2
|
+
import { monitorFrequency } from '../stats';
|
|
3
|
+
import { Track } from './Track';
|
|
4
|
+
|
|
5
|
+
export default abstract class RemoteTrack extends Track {
|
|
6
|
+
/** @internal */
|
|
7
|
+
receiver?: RTCRtpReceiver;
|
|
8
|
+
|
|
9
|
+
constructor(
|
|
10
|
+
mediaTrack: MediaStreamTrack,
|
|
11
|
+
sid: string,
|
|
12
|
+
kind: Track.Kind,
|
|
13
|
+
receiver?: RTCRtpReceiver,
|
|
14
|
+
) {
|
|
15
|
+
super(mediaTrack, kind);
|
|
16
|
+
this.sid = sid;
|
|
17
|
+
this.receiver = receiver;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** @internal */
|
|
21
|
+
setMuted(muted: boolean) {
|
|
22
|
+
if (this.isMuted !== muted) {
|
|
23
|
+
this.isMuted = muted;
|
|
24
|
+
this._mediaStreamTrack.enabled = !muted;
|
|
25
|
+
this.emit(muted ? TrackEvent.Muted : TrackEvent.Unmuted, this);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** @internal */
|
|
30
|
+
setMediaStream(stream: MediaStream) {
|
|
31
|
+
// this is needed to determine when the track is finished
|
|
32
|
+
// we send each track down in its own MediaStream, so we can assume the
|
|
33
|
+
// current track is the only one that can be removed.
|
|
34
|
+
this.mediaStream = stream;
|
|
35
|
+
stream.onremovetrack = () => {
|
|
36
|
+
this.receiver = undefined;
|
|
37
|
+
this._currentBitrate = 0;
|
|
38
|
+
this.emit(TrackEvent.Ended, this);
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
start() {
|
|
43
|
+
this.startMonitor();
|
|
44
|
+
// use `enabled` of track to enable re-use of transceiver
|
|
45
|
+
super.enable();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
stop() {
|
|
49
|
+
this.stopMonitor();
|
|
50
|
+
// use `enabled` of track to enable re-use of transceiver
|
|
51
|
+
super.disable();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/* @internal */
|
|
55
|
+
startMonitor() {
|
|
56
|
+
if (!this.monitorInterval) {
|
|
57
|
+
this.monitorInterval = setInterval(() => this.monitorReceiver(), monitorFrequency);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
protected abstract monitorReceiver(): void;
|
|
62
|
+
}
|
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
import log from '../../logger';
|
|
2
|
+
import {
|
|
3
|
+
ParticipantTracks,
|
|
4
|
+
SubscriptionError,
|
|
5
|
+
TrackInfo,
|
|
6
|
+
VideoQuality,
|
|
7
|
+
} from '../../proto/livekit_models_pb';
|
|
8
|
+
import { UpdateSubscription, UpdateTrackSettings } from '../../proto/livekit_rtc_pb';
|
|
9
|
+
import { TrackEvent } from '../events';
|
|
10
|
+
import type RemoteTrack from './RemoteTrack';
|
|
11
|
+
import RemoteVideoTrack from './RemoteVideoTrack';
|
|
12
|
+
import { Track } from './Track';
|
|
13
|
+
import { TrackPublication } from './TrackPublication';
|
|
14
|
+
|
|
15
|
+
export default class RemoteTrackPublication extends TrackPublication {
|
|
16
|
+
track?: RemoteTrack = undefined;
|
|
17
|
+
|
|
18
|
+
/** @internal */
|
|
19
|
+
protected allowed = true;
|
|
20
|
+
|
|
21
|
+
// keeps track of client's desire to subscribe to a track, also true if autoSubscribe is active
|
|
22
|
+
protected subscribed?: boolean;
|
|
23
|
+
|
|
24
|
+
protected disabled: boolean = false;
|
|
25
|
+
|
|
26
|
+
protected currentVideoQuality?: VideoQuality = VideoQuality.HIGH;
|
|
27
|
+
|
|
28
|
+
protected videoDimensions?: Track.Dimensions;
|
|
29
|
+
|
|
30
|
+
protected fps?: number;
|
|
31
|
+
|
|
32
|
+
protected subscriptionError?: SubscriptionError;
|
|
33
|
+
|
|
34
|
+
constructor(kind: Track.Kind, ti: TrackInfo, autoSubscribe: boolean | undefined) {
|
|
35
|
+
super(kind, ti.sid, ti.name);
|
|
36
|
+
this.subscribed = autoSubscribe;
|
|
37
|
+
this.updateInfo(ti);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Subscribe or unsubscribe to this remote track
|
|
42
|
+
* @param subscribed true to subscribe to a track, false to unsubscribe
|
|
43
|
+
*/
|
|
44
|
+
setSubscribed(subscribed: boolean) {
|
|
45
|
+
const prevStatus = this.subscriptionStatus;
|
|
46
|
+
const prevPermission = this.permissionStatus;
|
|
47
|
+
this.subscribed = subscribed;
|
|
48
|
+
// reset allowed status when desired subscription state changes
|
|
49
|
+
// server will notify client via signal message if it's not allowed
|
|
50
|
+
if (subscribed) {
|
|
51
|
+
this.allowed = true;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const sub = new UpdateSubscription({
|
|
55
|
+
trackSids: [this.trackSid],
|
|
56
|
+
subscribe: this.subscribed,
|
|
57
|
+
participantTracks: [
|
|
58
|
+
new ParticipantTracks({
|
|
59
|
+
// sending an empty participant id since TrackPublication doesn't keep it
|
|
60
|
+
// this is filled in by the participant that receives this message
|
|
61
|
+
participantSid: '',
|
|
62
|
+
trackSids: [this.trackSid],
|
|
63
|
+
}),
|
|
64
|
+
],
|
|
65
|
+
});
|
|
66
|
+
this.emit(TrackEvent.UpdateSubscription, sub);
|
|
67
|
+
this.emitSubscriptionUpdateIfChanged(prevStatus);
|
|
68
|
+
this.emitPermissionUpdateIfChanged(prevPermission);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
get subscriptionStatus(): TrackPublication.SubscriptionStatus {
|
|
72
|
+
if (this.subscribed === false) {
|
|
73
|
+
return TrackPublication.SubscriptionStatus.Unsubscribed;
|
|
74
|
+
}
|
|
75
|
+
if (!super.isSubscribed) {
|
|
76
|
+
return TrackPublication.SubscriptionStatus.Desired;
|
|
77
|
+
}
|
|
78
|
+
return TrackPublication.SubscriptionStatus.Subscribed;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
get permissionStatus(): TrackPublication.PermissionStatus {
|
|
82
|
+
return this.allowed
|
|
83
|
+
? TrackPublication.PermissionStatus.Allowed
|
|
84
|
+
: TrackPublication.PermissionStatus.NotAllowed;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Returns true if track is subscribed, and ready for playback
|
|
89
|
+
*/
|
|
90
|
+
get isSubscribed(): boolean {
|
|
91
|
+
if (this.subscribed === false) {
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
return super.isSubscribed;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// returns client's desire to subscribe to a track, also true if autoSubscribe is enabled
|
|
98
|
+
get isDesired(): boolean {
|
|
99
|
+
return this.subscribed !== false;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
get isEnabled(): boolean {
|
|
103
|
+
return !this.disabled;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* disable server from sending down data for this track. this is useful when
|
|
108
|
+
* the participant is off screen, you may disable streaming down their video
|
|
109
|
+
* to reduce bandwidth requirements
|
|
110
|
+
* @param enabled
|
|
111
|
+
*/
|
|
112
|
+
setEnabled(enabled: boolean) {
|
|
113
|
+
if (!this.isManualOperationAllowed() || this.disabled === !enabled) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
this.disabled = !enabled;
|
|
117
|
+
|
|
118
|
+
this.emitTrackUpdate();
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* for tracks that support simulcasting, adjust subscribed quality
|
|
123
|
+
*
|
|
124
|
+
* This indicates the highest quality the client can accept. if network
|
|
125
|
+
* bandwidth does not allow, server will automatically reduce quality to
|
|
126
|
+
* optimize for uninterrupted video
|
|
127
|
+
*/
|
|
128
|
+
setVideoQuality(quality: VideoQuality) {
|
|
129
|
+
if (!this.isManualOperationAllowed() || this.currentVideoQuality === quality) {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
this.currentVideoQuality = quality;
|
|
133
|
+
this.videoDimensions = undefined;
|
|
134
|
+
|
|
135
|
+
this.emitTrackUpdate();
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
setVideoDimensions(dimensions: Track.Dimensions) {
|
|
139
|
+
if (!this.isManualOperationAllowed()) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
if (
|
|
143
|
+
this.videoDimensions?.width === dimensions.width &&
|
|
144
|
+
this.videoDimensions?.height === dimensions.height
|
|
145
|
+
) {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
if (this.track instanceof RemoteVideoTrack) {
|
|
149
|
+
this.videoDimensions = dimensions;
|
|
150
|
+
}
|
|
151
|
+
this.currentVideoQuality = undefined;
|
|
152
|
+
|
|
153
|
+
this.emitTrackUpdate();
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
setVideoFPS(fps: number) {
|
|
157
|
+
if (!this.isManualOperationAllowed()) {
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if (!(this.track instanceof RemoteVideoTrack)) {
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
if (this.fps === fps) {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
this.fps = fps;
|
|
170
|
+
this.emitTrackUpdate();
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
get videoQuality(): VideoQuality | undefined {
|
|
174
|
+
return this.currentVideoQuality;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** @internal */
|
|
178
|
+
setTrack(track?: RemoteTrack) {
|
|
179
|
+
const prevStatus = this.subscriptionStatus;
|
|
180
|
+
const prevPermission = this.permissionStatus;
|
|
181
|
+
const prevTrack = this.track;
|
|
182
|
+
if (prevTrack === track) {
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
if (prevTrack) {
|
|
186
|
+
// unregister listener
|
|
187
|
+
prevTrack.off(TrackEvent.VideoDimensionsChanged, this.handleVideoDimensionsChange);
|
|
188
|
+
prevTrack.off(TrackEvent.VisibilityChanged, this.handleVisibilityChange);
|
|
189
|
+
prevTrack.off(TrackEvent.Ended, this.handleEnded);
|
|
190
|
+
prevTrack.detach();
|
|
191
|
+
prevTrack.stopMonitor();
|
|
192
|
+
this.emit(TrackEvent.Unsubscribed, prevTrack);
|
|
193
|
+
}
|
|
194
|
+
super.setTrack(track);
|
|
195
|
+
if (track) {
|
|
196
|
+
track.sid = this.trackSid;
|
|
197
|
+
track.on(TrackEvent.VideoDimensionsChanged, this.handleVideoDimensionsChange);
|
|
198
|
+
track.on(TrackEvent.VisibilityChanged, this.handleVisibilityChange);
|
|
199
|
+
track.on(TrackEvent.Ended, this.handleEnded);
|
|
200
|
+
this.emit(TrackEvent.Subscribed, track);
|
|
201
|
+
}
|
|
202
|
+
this.emitPermissionUpdateIfChanged(prevPermission);
|
|
203
|
+
this.emitSubscriptionUpdateIfChanged(prevStatus);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/** @internal */
|
|
207
|
+
setAllowed(allowed: boolean) {
|
|
208
|
+
const prevStatus = this.subscriptionStatus;
|
|
209
|
+
const prevPermission = this.permissionStatus;
|
|
210
|
+
this.allowed = allowed;
|
|
211
|
+
this.emitPermissionUpdateIfChanged(prevPermission);
|
|
212
|
+
this.emitSubscriptionUpdateIfChanged(prevStatus);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/** @internal */
|
|
216
|
+
setSubscriptionError(error: SubscriptionError) {
|
|
217
|
+
this.emit(TrackEvent.SubscriptionFailed, error);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/** @internal */
|
|
221
|
+
updateInfo(info: TrackInfo) {
|
|
222
|
+
super.updateInfo(info);
|
|
223
|
+
const prevMetadataMuted = this.metadataMuted;
|
|
224
|
+
this.metadataMuted = info.muted;
|
|
225
|
+
if (this.track) {
|
|
226
|
+
this.track.setMuted(info.muted);
|
|
227
|
+
} else if (prevMetadataMuted !== info.muted) {
|
|
228
|
+
this.emit(info.muted ? TrackEvent.Muted : TrackEvent.Unmuted);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
private emitSubscriptionUpdateIfChanged(previousStatus: TrackPublication.SubscriptionStatus) {
|
|
233
|
+
const currentStatus = this.subscriptionStatus;
|
|
234
|
+
if (previousStatus === currentStatus) {
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
this.emit(TrackEvent.SubscriptionStatusChanged, currentStatus, previousStatus);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
private emitPermissionUpdateIfChanged(
|
|
241
|
+
previousPermissionStatus: TrackPublication.PermissionStatus,
|
|
242
|
+
) {
|
|
243
|
+
const currentPermissionStatus = this.permissionStatus;
|
|
244
|
+
if (currentPermissionStatus !== previousPermissionStatus) {
|
|
245
|
+
this.emit(
|
|
246
|
+
TrackEvent.SubscriptionPermissionChanged,
|
|
247
|
+
this.permissionStatus,
|
|
248
|
+
previousPermissionStatus,
|
|
249
|
+
);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
private isManualOperationAllowed(): boolean {
|
|
254
|
+
if (this.kind === Track.Kind.Video && this.isAdaptiveStream) {
|
|
255
|
+
log.warn('adaptive stream is enabled, cannot change video track settings', {
|
|
256
|
+
trackSid: this.trackSid,
|
|
257
|
+
});
|
|
258
|
+
return false;
|
|
259
|
+
}
|
|
260
|
+
if (!this.isDesired) {
|
|
261
|
+
log.warn('cannot update track settings when not subscribed', { trackSid: this.trackSid });
|
|
262
|
+
return false;
|
|
263
|
+
}
|
|
264
|
+
return true;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
protected handleEnded = (track: RemoteTrack) => {
|
|
268
|
+
this.setTrack(undefined);
|
|
269
|
+
this.emit(TrackEvent.Ended, track);
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
protected get isAdaptiveStream(): boolean {
|
|
273
|
+
return this.track instanceof RemoteVideoTrack && this.track.isAdaptiveStream;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
protected handleVisibilityChange = (visible: boolean) => {
|
|
277
|
+
log.debug(`adaptivestream video visibility ${this.trackSid}, visible=${visible}`, {
|
|
278
|
+
trackSid: this.trackSid,
|
|
279
|
+
});
|
|
280
|
+
this.disabled = !visible;
|
|
281
|
+
this.emitTrackUpdate();
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
protected handleVideoDimensionsChange = (dimensions: Track.Dimensions) => {
|
|
285
|
+
log.debug(`adaptivestream video dimensions ${dimensions.width}x${dimensions.height}`, {
|
|
286
|
+
trackSid: this.trackSid,
|
|
287
|
+
});
|
|
288
|
+
this.videoDimensions = dimensions;
|
|
289
|
+
this.emitTrackUpdate();
|
|
290
|
+
};
|
|
291
|
+
|
|
292
|
+
/* @internal */
|
|
293
|
+
emitTrackUpdate() {
|
|
294
|
+
const settings: UpdateTrackSettings = new UpdateTrackSettings({
|
|
295
|
+
trackSids: [this.trackSid],
|
|
296
|
+
disabled: this.disabled,
|
|
297
|
+
fps: this.fps,
|
|
298
|
+
});
|
|
299
|
+
if (this.videoDimensions) {
|
|
300
|
+
settings.width = this.videoDimensions.width;
|
|
301
|
+
settings.height = this.videoDimensions.height;
|
|
302
|
+
} else if (this.currentVideoQuality !== undefined) {
|
|
303
|
+
settings.quality = this.currentVideoQuality;
|
|
304
|
+
} else {
|
|
305
|
+
// defaults to high quality
|
|
306
|
+
settings.quality = VideoQuality.HIGH;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
this.emit(TrackEvent.UpdateSettings, settings);
|
|
310
|
+
}
|
|
311
|
+
}
|