livekit-client 0.15.3 → 0.16.2
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/dist/api/SignalClient.d.ts +6 -3
- package/dist/api/SignalClient.js +70 -28
- package/dist/api/SignalClient.js.map +1 -1
- package/dist/options.d.ts +5 -0
- package/dist/proto/livekit_models.d.ts +30 -0
- package/dist/proto/livekit_models.js +219 -1
- package/dist/proto/livekit_models.js.map +1 -1
- package/dist/proto/livekit_rtc.d.ts +15 -10
- package/dist/proto/livekit_rtc.js +36 -22
- package/dist/proto/livekit_rtc.js.map +1 -1
- package/dist/room/RTCEngine.d.ts +11 -2
- package/dist/room/RTCEngine.js +196 -44
- package/dist/room/RTCEngine.js.map +1 -1
- package/dist/room/Room.d.ts +7 -0
- package/dist/room/Room.js +70 -16
- package/dist/room/Room.js.map +1 -1
- package/dist/room/events.d.ts +5 -3
- package/dist/room/events.js +5 -3
- package/dist/room/events.js.map +1 -1
- package/dist/room/participant/LocalParticipant.d.ts +1 -2
- package/dist/room/participant/LocalParticipant.js +7 -6
- package/dist/room/participant/LocalParticipant.js.map +1 -1
- package/dist/room/participant/RemoteParticipant.js +3 -0
- package/dist/room/participant/RemoteParticipant.js.map +1 -1
- package/dist/room/participant/publishUtils.js +1 -1
- package/dist/room/participant/publishUtils.js.map +1 -1
- package/dist/room/participant/publishUtils.test.js +9 -0
- package/dist/room/participant/publishUtils.test.js.map +1 -1
- package/dist/room/track/LocalTrackPublication.d.ts +2 -0
- package/dist/room/track/LocalTrackPublication.js.map +1 -1
- package/dist/room/track/RemoteTrackPublication.d.ts +2 -1
- package/dist/room/track/RemoteTrackPublication.js +22 -8
- package/dist/room/track/RemoteTrackPublication.js.map +1 -1
- package/dist/room/track/RemoteVideoTrack.js +12 -7
- package/dist/room/track/RemoteVideoTrack.js.map +1 -1
- package/dist/room/track/Track.js +28 -20
- package/dist/room/track/Track.js.map +1 -1
- package/dist/room/track/create.js +5 -0
- package/dist/room/track/create.js.map +1 -1
- package/dist/room/utils.d.ts +3 -0
- package/dist/room/utils.js +16 -1
- package/dist/room/utils.js.map +1 -1
- package/dist/version.d.ts +2 -2
- package/dist/version.js +2 -2
- package/package.json +3 -3
- package/src/api/SignalClient.ts +444 -0
- package/src/connect.ts +100 -0
- package/src/index.ts +47 -0
- package/src/logger.ts +22 -0
- package/src/options.ts +152 -0
- package/src/proto/livekit_models.ts +1863 -0
- package/src/proto/livekit_rtc.ts +3415 -0
- package/src/room/DeviceManager.ts +57 -0
- package/src/room/PCTransport.ts +86 -0
- package/src/room/RTCEngine.ts +598 -0
- package/src/room/Room.ts +840 -0
- package/src/room/errors.ts +65 -0
- package/src/room/events.ts +398 -0
- package/src/room/participant/LocalParticipant.ts +685 -0
- package/src/room/participant/Participant.ts +214 -0
- package/src/room/participant/ParticipantTrackPermission.ts +32 -0
- package/src/room/participant/RemoteParticipant.ts +241 -0
- package/src/room/participant/publishUtils.test.ts +105 -0
- package/src/room/participant/publishUtils.ts +180 -0
- package/src/room/stats.ts +130 -0
- package/src/room/track/LocalAudioTrack.ts +112 -0
- package/src/room/track/LocalTrack.ts +124 -0
- package/src/room/track/LocalTrackPublication.ts +66 -0
- package/src/room/track/LocalVideoTrack.test.ts +70 -0
- package/src/room/track/LocalVideoTrack.ts +416 -0
- package/src/room/track/RemoteAudioTrack.ts +58 -0
- package/src/room/track/RemoteTrack.ts +59 -0
- package/src/room/track/RemoteTrackPublication.ts +198 -0
- package/src/room/track/RemoteVideoTrack.ts +220 -0
- package/src/room/track/Track.ts +307 -0
- package/src/room/track/TrackPublication.ts +120 -0
- package/src/room/track/create.ts +120 -0
- package/src/room/track/defaults.ts +23 -0
- package/src/room/track/options.ts +229 -0
- package/src/room/track/types.ts +8 -0
- package/src/room/track/utils.test.ts +93 -0
- package/src/room/track/utils.ts +76 -0
- package/src/room/utils.ts +62 -0
- package/src/version.ts +2 -0
- package/.github/workflows/publish.yaml +0 -55
- package/.github/workflows/test.yaml +0 -36
- package/example/index.html +0 -247
- package/example/sample.ts +0 -632
- package/example/styles.css +0 -144
- package/example/webpack.config.js +0 -33
@@ -0,0 +1,57 @@
|
|
1
|
+
const defaultId = 'default';
|
2
|
+
|
3
|
+
export default class DeviceManager {
|
4
|
+
private static instance?: DeviceManager;
|
5
|
+
|
6
|
+
static mediaDeviceKinds: MediaDeviceKind[] = [
|
7
|
+
'audioinput',
|
8
|
+
'audiooutput',
|
9
|
+
'videoinput',
|
10
|
+
];
|
11
|
+
|
12
|
+
static getInstance(): DeviceManager {
|
13
|
+
if (this.instance === undefined) {
|
14
|
+
this.instance = new DeviceManager();
|
15
|
+
}
|
16
|
+
return this.instance;
|
17
|
+
}
|
18
|
+
|
19
|
+
async getDevices(kind: MediaDeviceKind): Promise<MediaDeviceInfo[]> {
|
20
|
+
let devices = await navigator.mediaDevices.enumerateDevices();
|
21
|
+
devices = devices.filter((device) => device.kind === kind);
|
22
|
+
// Chrome returns 'default' devices, we would filter them out, but put the default
|
23
|
+
// device at first
|
24
|
+
// we would only do this if there are more than 1 device though
|
25
|
+
if (devices.length > 1 && devices[0].deviceId === defaultId) {
|
26
|
+
// find another device with matching group id, and move that to 0
|
27
|
+
const defaultDevice = devices[0];
|
28
|
+
for (let i = 1; i < devices.length; i += 1) {
|
29
|
+
if (devices[i].groupId === defaultDevice.groupId) {
|
30
|
+
const temp = devices[0];
|
31
|
+
devices[0] = devices[i];
|
32
|
+
devices[i] = temp;
|
33
|
+
break;
|
34
|
+
}
|
35
|
+
}
|
36
|
+
return devices.filter((device) => device !== defaultDevice);
|
37
|
+
}
|
38
|
+
|
39
|
+
return devices;
|
40
|
+
}
|
41
|
+
|
42
|
+
async normalizeDeviceId(
|
43
|
+
kind: MediaDeviceKind, deviceId?: string, groupId?: string,
|
44
|
+
): Promise<string | undefined> {
|
45
|
+
if (deviceId !== defaultId) {
|
46
|
+
return deviceId;
|
47
|
+
}
|
48
|
+
|
49
|
+
// resolve actual device id if it's 'default': Chrome returns it when no
|
50
|
+
// device has been chosen
|
51
|
+
const devices = await this.getDevices(kind);
|
52
|
+
|
53
|
+
const device = devices.find((d) => d.groupId === groupId && d.deviceId !== defaultId);
|
54
|
+
|
55
|
+
return device?.deviceId;
|
56
|
+
}
|
57
|
+
}
|
@@ -0,0 +1,86 @@
|
|
1
|
+
import { debounce } from 'ts-debounce';
|
2
|
+
import log from '../logger';
|
3
|
+
|
4
|
+
/** @internal */
|
5
|
+
export default class PCTransport {
|
6
|
+
pc: RTCPeerConnection;
|
7
|
+
|
8
|
+
pendingCandidates: RTCIceCandidateInit[] = [];
|
9
|
+
|
10
|
+
restartingIce: boolean = false;
|
11
|
+
|
12
|
+
renegotiate: boolean = false;
|
13
|
+
|
14
|
+
onOffer?: (offer: RTCSessionDescriptionInit) => void;
|
15
|
+
|
16
|
+
constructor(config?: RTCConfiguration) {
|
17
|
+
this.pc = new RTCPeerConnection(config);
|
18
|
+
}
|
19
|
+
|
20
|
+
get isICEConnected(): boolean {
|
21
|
+
return this.pc.iceConnectionState === 'connected' || this.pc.iceConnectionState === 'completed';
|
22
|
+
}
|
23
|
+
|
24
|
+
async addIceCandidate(candidate: RTCIceCandidateInit): Promise<void> {
|
25
|
+
if (this.pc.remoteDescription && !this.restartingIce) {
|
26
|
+
return this.pc.addIceCandidate(candidate);
|
27
|
+
}
|
28
|
+
this.pendingCandidates.push(candidate);
|
29
|
+
}
|
30
|
+
|
31
|
+
async setRemoteDescription(sd: RTCSessionDescriptionInit): Promise<void> {
|
32
|
+
await this.pc.setRemoteDescription(sd);
|
33
|
+
|
34
|
+
this.pendingCandidates.forEach((candidate) => {
|
35
|
+
this.pc.addIceCandidate(candidate);
|
36
|
+
});
|
37
|
+
this.pendingCandidates = [];
|
38
|
+
this.restartingIce = false;
|
39
|
+
|
40
|
+
if (this.renegotiate) {
|
41
|
+
this.renegotiate = false;
|
42
|
+
this.createAndSendOffer();
|
43
|
+
}
|
44
|
+
}
|
45
|
+
|
46
|
+
// debounced negotiate interface
|
47
|
+
negotiate = debounce(() => { this.createAndSendOffer(); }, 100);
|
48
|
+
|
49
|
+
async createAndSendOffer(options?: RTCOfferOptions) {
|
50
|
+
if (this.onOffer === undefined) {
|
51
|
+
return;
|
52
|
+
}
|
53
|
+
|
54
|
+
if (options?.iceRestart) {
|
55
|
+
log.debug('restarting ICE');
|
56
|
+
this.restartingIce = true;
|
57
|
+
}
|
58
|
+
|
59
|
+
if (this.pc.signalingState === 'have-local-offer') {
|
60
|
+
// we're waiting for the peer to accept our offer, so we'll just wait
|
61
|
+
// the only exception to this is when ICE restart is needed
|
62
|
+
const currentSD = this.pc.remoteDescription;
|
63
|
+
if (options?.iceRestart && currentSD) {
|
64
|
+
// TODO: handle when ICE restart is needed but we don't have a remote description
|
65
|
+
// the best thing to do is to recreate the peerconnection
|
66
|
+
await this.pc.setRemoteDescription(currentSD);
|
67
|
+
} else {
|
68
|
+
this.renegotiate = true;
|
69
|
+
return;
|
70
|
+
}
|
71
|
+
} else if (this.pc.signalingState === 'closed') {
|
72
|
+
log.warn('could not createOffer with closed peer connection');
|
73
|
+
return;
|
74
|
+
}
|
75
|
+
|
76
|
+
// actually negotiate
|
77
|
+
log.debug('starting to negotiate');
|
78
|
+
const offer = await this.pc.createOffer(options);
|
79
|
+
await this.pc.setLocalDescription(offer);
|
80
|
+
this.onOffer(offer);
|
81
|
+
}
|
82
|
+
|
83
|
+
close() {
|
84
|
+
this.pc.close();
|
85
|
+
}
|
86
|
+
}
|