livekit-client 0.15.1 → 0.16.0

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.
Files changed (120) hide show
  1. package/dist/api/SignalClient.d.ts +11 -3
  2. package/dist/api/SignalClient.js +92 -28
  3. package/dist/api/SignalClient.js.map +1 -1
  4. package/dist/index.d.ts +4 -2
  5. package/dist/index.js +5 -3
  6. package/dist/index.js.map +1 -1
  7. package/dist/options.d.ts +5 -0
  8. package/dist/proto/livekit_models.d.ts +48 -0
  9. package/dist/proto/livekit_models.js +367 -5
  10. package/dist/proto/livekit_models.js.map +1 -1
  11. package/dist/proto/livekit_rtc.d.ts +50 -11
  12. package/dist/proto/livekit_rtc.js +300 -22
  13. package/dist/proto/livekit_rtc.js.map +1 -1
  14. package/dist/room/PCTransport.js +4 -0
  15. package/dist/room/PCTransport.js.map +1 -1
  16. package/dist/room/RTCEngine.d.ts +10 -2
  17. package/dist/room/RTCEngine.js +182 -42
  18. package/dist/room/RTCEngine.js.map +1 -1
  19. package/dist/room/Room.d.ts +15 -0
  20. package/dist/room/Room.js +165 -20
  21. package/dist/room/Room.js.map +1 -1
  22. package/dist/room/events.d.ts +42 -20
  23. package/dist/room/events.js +41 -19
  24. package/dist/room/events.js.map +1 -1
  25. package/dist/room/participant/LocalParticipant.d.ts +25 -4
  26. package/dist/room/participant/LocalParticipant.js +50 -23
  27. package/dist/room/participant/LocalParticipant.js.map +1 -1
  28. package/dist/room/participant/Participant.d.ts +3 -1
  29. package/dist/room/participant/Participant.js +1 -0
  30. package/dist/room/participant/Participant.js.map +1 -1
  31. package/dist/room/participant/ParticipantTrackPermission.d.ts +19 -0
  32. package/dist/room/participant/ParticipantTrackPermission.js +16 -0
  33. package/dist/room/participant/ParticipantTrackPermission.js.map +1 -0
  34. package/dist/room/participant/RemoteParticipant.d.ts +2 -2
  35. package/dist/room/participant/RemoteParticipant.js +11 -16
  36. package/dist/room/participant/RemoteParticipant.js.map +1 -1
  37. package/dist/room/participant/publishUtils.js +1 -1
  38. package/dist/room/participant/publishUtils.js.map +1 -1
  39. package/dist/room/participant/publishUtils.test.js +9 -0
  40. package/dist/room/participant/publishUtils.test.js.map +1 -1
  41. package/dist/room/track/LocalTrack.d.ts +0 -3
  42. package/dist/room/track/LocalTrack.js +1 -6
  43. package/dist/room/track/LocalTrack.js.map +1 -1
  44. package/dist/room/track/LocalTrackPublication.d.ts +5 -1
  45. package/dist/room/track/LocalTrackPublication.js +15 -5
  46. package/dist/room/track/LocalTrackPublication.js.map +1 -1
  47. package/dist/room/track/LocalVideoTrack.d.ts +1 -1
  48. package/dist/room/track/LocalVideoTrack.js +7 -6
  49. package/dist/room/track/LocalVideoTrack.js.map +1 -1
  50. package/dist/room/track/RemoteAudioTrack.d.ts +5 -14
  51. package/dist/room/track/RemoteAudioTrack.js +7 -32
  52. package/dist/room/track/RemoteAudioTrack.js.map +1 -1
  53. package/dist/room/track/RemoteTrack.d.ts +14 -0
  54. package/dist/room/track/RemoteTrack.js +47 -0
  55. package/dist/room/track/RemoteTrack.js.map +1 -0
  56. package/dist/room/track/RemoteTrackPublication.d.ts +10 -2
  57. package/dist/room/track/RemoteTrackPublication.js +51 -12
  58. package/dist/room/track/RemoteTrackPublication.js.map +1 -1
  59. package/dist/room/track/RemoteVideoTrack.d.ts +3 -9
  60. package/dist/room/track/RemoteVideoTrack.js +8 -29
  61. package/dist/room/track/RemoteVideoTrack.js.map +1 -1
  62. package/dist/room/track/Track.d.ts +3 -0
  63. package/dist/room/track/Track.js +14 -5
  64. package/dist/room/track/Track.js.map +1 -1
  65. package/dist/room/track/TrackPublication.d.ts +14 -1
  66. package/dist/room/track/TrackPublication.js +24 -7
  67. package/dist/room/track/TrackPublication.js.map +1 -1
  68. package/dist/room/track/create.js +5 -0
  69. package/dist/room/track/create.js.map +1 -1
  70. package/dist/room/utils.d.ts +2 -0
  71. package/dist/room/utils.js +32 -1
  72. package/dist/room/utils.js.map +1 -1
  73. package/dist/version.d.ts +2 -2
  74. package/dist/version.js +2 -2
  75. package/package.json +5 -3
  76. package/src/api/SignalClient.ts +444 -0
  77. package/src/connect.ts +100 -0
  78. package/src/index.ts +47 -0
  79. package/src/logger.ts +22 -0
  80. package/src/options.ts +152 -0
  81. package/src/proto/livekit_models.ts +1863 -0
  82. package/src/proto/livekit_rtc.ts +3415 -0
  83. package/src/room/DeviceManager.ts +57 -0
  84. package/src/room/PCTransport.ts +86 -0
  85. package/src/room/RTCEngine.ts +582 -0
  86. package/src/room/Room.ts +840 -0
  87. package/src/room/errors.ts +65 -0
  88. package/src/room/events.ts +398 -0
  89. package/src/room/participant/LocalParticipant.ts +685 -0
  90. package/src/room/participant/Participant.ts +214 -0
  91. package/src/room/participant/ParticipantTrackPermission.ts +32 -0
  92. package/src/room/participant/RemoteParticipant.ts +241 -0
  93. package/src/room/participant/publishUtils.test.ts +105 -0
  94. package/src/room/participant/publishUtils.ts +180 -0
  95. package/src/room/stats.ts +130 -0
  96. package/src/room/track/LocalAudioTrack.ts +112 -0
  97. package/src/room/track/LocalTrack.ts +124 -0
  98. package/src/room/track/LocalTrackPublication.ts +66 -0
  99. package/src/room/track/LocalVideoTrack.test.ts +70 -0
  100. package/src/room/track/LocalVideoTrack.ts +416 -0
  101. package/src/room/track/RemoteAudioTrack.ts +58 -0
  102. package/src/room/track/RemoteTrack.ts +59 -0
  103. package/src/room/track/RemoteTrackPublication.ts +198 -0
  104. package/src/room/track/RemoteVideoTrack.ts +213 -0
  105. package/src/room/track/Track.ts +307 -0
  106. package/src/room/track/TrackPublication.ts +120 -0
  107. package/src/room/track/create.ts +120 -0
  108. package/src/room/track/defaults.ts +23 -0
  109. package/src/room/track/options.ts +229 -0
  110. package/src/room/track/types.ts +8 -0
  111. package/src/room/track/utils.test.ts +93 -0
  112. package/src/room/track/utils.ts +76 -0
  113. package/src/room/utils.ts +74 -0
  114. package/src/version.ts +2 -0
  115. package/.github/workflows/publish.yaml +0 -55
  116. package/.github/workflows/test.yaml +0 -36
  117. package/example/index.html +0 -248
  118. package/example/sample.ts +0 -621
  119. package/example/styles.css +0 -144
  120. 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
+ }