livekit-client 0.16.6 → 0.17.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 (88) hide show
  1. package/dist/api/RequestQueue.js +6 -6
  2. package/dist/api/RequestQueue.js.map +1 -1
  3. package/dist/api/SignalClient.d.ts +3 -0
  4. package/dist/api/SignalClient.js +23 -3
  5. package/dist/api/SignalClient.js.map +1 -1
  6. package/dist/connect.js +1 -1
  7. package/dist/connect.js.map +1 -1
  8. package/dist/options.d.ts +7 -2
  9. package/dist/proto/livekit_models.d.ts +33 -0
  10. package/dist/proto/livekit_models.js +213 -3
  11. package/dist/proto/livekit_models.js.map +1 -1
  12. package/dist/proto/livekit_rtc.d.ts +15 -1
  13. package/dist/proto/livekit_rtc.js +128 -2
  14. package/dist/proto/livekit_rtc.js.map +1 -1
  15. package/dist/room/RTCEngine.d.ts +3 -2
  16. package/dist/room/RTCEngine.js +12 -8
  17. package/dist/room/RTCEngine.js.map +1 -1
  18. package/dist/room/Room.js +19 -8
  19. package/dist/room/Room.js.map +1 -1
  20. package/dist/room/events.d.ts +6 -1
  21. package/dist/room/events.js +6 -1
  22. package/dist/room/events.js.map +1 -1
  23. package/dist/room/participant/LocalParticipant.d.ts +3 -1
  24. package/dist/room/participant/LocalParticipant.js +17 -1
  25. package/dist/room/participant/LocalParticipant.js.map +1 -1
  26. package/dist/room/participant/RemoteParticipant.d.ts +2 -1
  27. package/dist/room/participant/RemoteParticipant.js +3 -3
  28. package/dist/room/participant/RemoteParticipant.js.map +1 -1
  29. package/dist/room/participant/publishUtils.d.ts +6 -0
  30. package/dist/room/participant/publishUtils.js +65 -24
  31. package/dist/room/participant/publishUtils.js.map +1 -1
  32. package/dist/room/participant/publishUtils.test.js +35 -5
  33. package/dist/room/participant/publishUtils.test.js.map +1 -1
  34. package/dist/room/track/LocalAudioTrack.d.ts +2 -0
  35. package/dist/room/track/LocalAudioTrack.js +23 -0
  36. package/dist/room/track/LocalAudioTrack.js.map +1 -1
  37. package/dist/room/track/LocalTrack.d.ts +4 -0
  38. package/dist/room/track/LocalTrack.js +34 -0
  39. package/dist/room/track/LocalTrack.js.map +1 -1
  40. package/dist/room/track/LocalVideoTrack.d.ts +1 -0
  41. package/dist/room/track/LocalVideoTrack.js +13 -0
  42. package/dist/room/track/LocalVideoTrack.js.map +1 -1
  43. package/dist/room/track/RemoteTrack.d.ts +1 -0
  44. package/dist/room/track/RemoteTrack.js +1 -0
  45. package/dist/room/track/RemoteTrack.js.map +1 -1
  46. package/dist/room/track/RemoteVideoTrack.d.ts +4 -2
  47. package/dist/room/track/RemoteVideoTrack.js +25 -11
  48. package/dist/room/track/RemoteVideoTrack.js.map +1 -1
  49. package/dist/room/track/Track.d.ts +4 -1
  50. package/dist/room/track/Track.js +20 -1
  51. package/dist/room/track/Track.js.map +1 -1
  52. package/dist/room/track/defaults.js +2 -2
  53. package/dist/room/track/defaults.js.map +1 -1
  54. package/dist/room/track/options.d.ts +65 -15
  55. package/dist/room/track/options.js +38 -0
  56. package/dist/room/track/options.js.map +1 -1
  57. package/dist/room/track/types.d.ts +11 -0
  58. package/dist/room/track/utils.d.ts +10 -0
  59. package/dist/room/track/utils.js +46 -1
  60. package/dist/room/track/utils.js.map +1 -1
  61. package/dist/room/utils.d.ts +1 -0
  62. package/dist/room/utils.js +5 -1
  63. package/dist/room/utils.js.map +1 -1
  64. package/package.json +1 -1
  65. package/src/api/RequestQueue.ts +7 -7
  66. package/src/api/SignalClient.ts +31 -4
  67. package/src/connect.ts +1 -1
  68. package/src/options.ts +12 -3
  69. package/src/proto/livekit_models.ts +249 -0
  70. package/src/proto/livekit_rtc.ts +155 -0
  71. package/src/room/RTCEngine.ts +16 -9
  72. package/src/room/Room.ts +17 -7
  73. package/src/room/events.ts +6 -1
  74. package/src/room/participant/LocalParticipant.ts +23 -4
  75. package/src/room/participant/RemoteParticipant.ts +4 -4
  76. package/src/room/participant/publishUtils.test.ts +46 -6
  77. package/src/room/participant/publishUtils.ts +72 -27
  78. package/src/room/track/LocalAudioTrack.ts +19 -1
  79. package/src/room/track/LocalTrack.ts +36 -0
  80. package/src/room/track/LocalVideoTrack.ts +9 -1
  81. package/src/room/track/RemoteTrack.ts +2 -0
  82. package/src/room/track/RemoteVideoTrack.ts +20 -9
  83. package/src/room/track/Track.ts +14 -2
  84. package/src/room/track/defaults.ts +2 -2
  85. package/src/room/track/options.ts +55 -3
  86. package/src/room/track/types.ts +12 -0
  87. package/src/room/track/utils.ts +39 -0
  88. package/src/room/utils.ts +4 -0
@@ -28,11 +28,29 @@ interface ConnectOpts {
28
28
  autoSubscribe?: boolean;
29
29
  /** internal */
30
30
  reconnect?: boolean;
31
+
32
+ publishOnly?: string;
31
33
  }
32
34
 
33
35
  // public options
34
36
  export interface SignalOptions {
35
37
  autoSubscribe?: boolean;
38
+ publishOnly?: string;
39
+ }
40
+
41
+ const passThroughQueueSignals: Array<keyof SignalRequest> = [
42
+ 'syncState',
43
+ 'trickle',
44
+ 'offer',
45
+ 'answer',
46
+ 'simulate',
47
+ ];
48
+
49
+ function canPassThroughQueue(req: SignalRequest): boolean {
50
+ const canPass = Object.keys(req)
51
+ .find((key) => passThroughQueueSignals.includes(key as keyof SignalRequest)) !== undefined;
52
+ log.trace('request allowed to bypass queue:', canPass, req);
53
+ return canPass;
36
54
  }
37
55
 
38
56
  /** @internal */
@@ -100,6 +118,7 @@ export class SignalClient {
100
118
  this.isConnected = false;
101
119
  const res = await this.connect(url, token, {
102
120
  autoSubscribe: opts?.autoSubscribe,
121
+ publishOnly: opts?.publishOnly,
103
122
  });
104
123
  return res as JoinResponse;
105
124
  }
@@ -109,8 +128,6 @@ export class SignalClient {
109
128
  await this.connect(url, token, {
110
129
  reconnect: true,
111
130
  });
112
- this.isReconnecting = false;
113
- this.requestQueue.run();
114
131
  }
115
132
 
116
133
  connect(
@@ -300,8 +317,9 @@ export class SignalClient {
300
317
  // capture all requests while reconnecting and put them in a queue.
301
318
  // keep order by queueing up new events as long as the queue is not empty
302
319
  // unless the request originates from the queue, then don't enqueue again
303
-
304
- if ((this.isReconnecting && !req.simulate) || (!this.requestQueue.isEmpty() && !fromQueue)) {
320
+ if (
321
+ (this.isReconnecting && !canPassThroughQueue(req))
322
+ || (!this.requestQueue.isEmpty() && !fromQueue)) {
305
323
  this.requestQueue.enqueue(() => this.sendRequest(req, true));
306
324
  return;
307
325
  }
@@ -391,6 +409,11 @@ export class SignalClient {
391
409
  }
392
410
  }
393
411
 
412
+ setReconnected() {
413
+ this.isReconnecting = false;
414
+ this.requestQueue.run();
415
+ }
416
+
394
417
  private handleWSError(ev: Event) {
395
418
  log.error('websocket error', ev);
396
419
  }
@@ -458,5 +481,9 @@ function createConnectionParams(token: string, info: ClientInfo, opts?: ConnectO
458
481
  params.set('browser_version', info.browserVersion);
459
482
  }
460
483
 
484
+ if (opts?.publishOnly !== undefined) {
485
+ params.set('publish', opts.publishOnly);
486
+ }
487
+
461
488
  return `?${params.toString()}`;
462
489
  }
package/src/connect.ts CHANGED
@@ -32,7 +32,7 @@ export async function connect(
32
32
  ): Promise<Room> {
33
33
  options ??= {};
34
34
  if (options.adaptiveStream === undefined) {
35
- options.adaptiveStream = options.autoManageVideo;
35
+ options.adaptiveStream = options.autoManageVideo === true ? {} : undefined;
36
36
  }
37
37
  setLogLevel(options.logLevel ?? LogLevel.warn);
38
38
 
package/src/options.ts CHANGED
@@ -1,7 +1,11 @@
1
1
  import { LogLevel, LogLevelDesc } from './logger';
2
2
  import {
3
- AudioCaptureOptions, CreateLocalTracksOptions, TrackPublishDefaults, VideoCaptureOptions,
3
+ AudioCaptureOptions,
4
+ CreateLocalTracksOptions,
5
+ TrackPublishDefaults,
6
+ VideoCaptureOptions,
4
7
  } from './room/track/options';
8
+ import { AdaptiveStreamSettings } from './room/track/types';
5
9
 
6
10
  /**
7
11
  * Options for when creating a new room
@@ -16,7 +20,7 @@ export interface RoomOptions {
16
20
  * When none of the video elements are visible, it'll temporarily pause
17
21
  * the data flow until they are visible again.
18
22
  */
19
- adaptiveStream?: boolean;
23
+ adaptiveStream?: AdaptiveStreamSettings | boolean;
20
24
 
21
25
  /**
22
26
  * enable Dynacast, off by default. With Dynacast dynamically pauses
@@ -64,6 +68,11 @@ export interface RoomConnectOptions {
64
68
  * use to override any RTCConfiguration options.
65
69
  */
66
70
  rtcConfig?: RTCConfiguration;
71
+
72
+ /**
73
+ * publish only mode
74
+ */
75
+ publishOnly?: string;
67
76
  }
68
77
 
69
78
  /**
@@ -77,7 +86,7 @@ export interface ConnectOptions extends CreateLocalTracksOptions {
77
86
  /**
78
87
  * see [[RoomOptions.adaptiveStream]]
79
88
  */
80
- adaptiveStream?: boolean;
89
+ adaptiveStream?: AdaptiveStreamSettings | boolean;
81
90
 
82
91
  /**
83
92
  * alias for adaptiveStream
@@ -174,6 +174,44 @@ export function connectionQualityToJSON(object: ConnectionQuality): string {
174
174
  }
175
175
  }
176
176
 
177
+ export enum ClientConfigSetting {
178
+ UNSET = 0,
179
+ DISABLED = 1,
180
+ ENABLED = 2,
181
+ UNRECOGNIZED = -1,
182
+ }
183
+
184
+ export function clientConfigSettingFromJSON(object: any): ClientConfigSetting {
185
+ switch (object) {
186
+ case 0:
187
+ case "UNSET":
188
+ return ClientConfigSetting.UNSET;
189
+ case 1:
190
+ case "DISABLED":
191
+ return ClientConfigSetting.DISABLED;
192
+ case 2:
193
+ case "ENABLED":
194
+ return ClientConfigSetting.ENABLED;
195
+ case -1:
196
+ case "UNRECOGNIZED":
197
+ default:
198
+ return ClientConfigSetting.UNRECOGNIZED;
199
+ }
200
+ }
201
+
202
+ export function clientConfigSettingToJSON(object: ClientConfigSetting): string {
203
+ switch (object) {
204
+ case ClientConfigSetting.UNSET:
205
+ return "UNSET";
206
+ case ClientConfigSetting.DISABLED:
207
+ return "DISABLED";
208
+ case ClientConfigSetting.ENABLED:
209
+ return "ENABLED";
210
+ default:
211
+ return "UNKNOWN";
212
+ }
213
+ }
214
+
177
215
  export interface Room {
178
216
  sid: string;
179
217
  name: string;
@@ -203,6 +241,7 @@ export interface ParticipantInfo {
203
241
  hidden: boolean;
204
242
  recorder: boolean;
205
243
  name: string;
244
+ version: number;
206
245
  }
207
246
 
208
247
  export enum ParticipantInfo_State {
@@ -368,6 +407,7 @@ export interface ClientInfo {
368
407
  deviceModel: string;
369
408
  browser: string;
370
409
  browserVersion: string;
410
+ address: string;
371
411
  }
372
412
 
373
413
  export enum ClientInfo_SDK {
@@ -432,6 +472,17 @@ export function clientInfo_SDKToJSON(object: ClientInfo_SDK): string {
432
472
  }
433
473
  }
434
474
 
475
+ /** server provided client configuration */
476
+ export interface ClientConfiguration {
477
+ video?: VideoConfiguration;
478
+ screen?: VideoConfiguration;
479
+ resumeConnection: ClientConfigSetting;
480
+ }
481
+
482
+ export interface VideoConfiguration {
483
+ hardwareEncoder: ClientConfigSetting;
484
+ }
485
+
435
486
  const baseRoom: object = {
436
487
  sid: "",
437
488
  name: "",
@@ -711,6 +762,7 @@ const baseParticipantInfo: object = {
711
762
  hidden: false,
712
763
  recorder: false,
713
764
  name: "",
765
+ version: 0,
714
766
  };
715
767
 
716
768
  export const ParticipantInfo = {
@@ -745,6 +797,9 @@ export const ParticipantInfo = {
745
797
  if (message.name !== "") {
746
798
  writer.uint32(74).string(message.name);
747
799
  }
800
+ if (message.version !== 0) {
801
+ writer.uint32(80).uint32(message.version);
802
+ }
748
803
  return writer;
749
804
  },
750
805
 
@@ -783,6 +838,9 @@ export const ParticipantInfo = {
783
838
  case 9:
784
839
  message.name = reader.string();
785
840
  break;
841
+ case 10:
842
+ message.version = reader.uint32();
843
+ break;
786
844
  default:
787
845
  reader.skipType(tag & 7);
788
846
  break;
@@ -839,6 +897,11 @@ export const ParticipantInfo = {
839
897
  } else {
840
898
  message.name = "";
841
899
  }
900
+ if (object.version !== undefined && object.version !== null) {
901
+ message.version = Number(object.version);
902
+ } else {
903
+ message.version = 0;
904
+ }
842
905
  return message;
843
906
  },
844
907
 
@@ -860,6 +923,7 @@ export const ParticipantInfo = {
860
923
  message.hidden !== undefined && (obj.hidden = message.hidden);
861
924
  message.recorder !== undefined && (obj.recorder = message.recorder);
862
925
  message.name !== undefined && (obj.name = message.name);
926
+ message.version !== undefined && (obj.version = message.version);
863
927
  return obj;
864
928
  },
865
929
 
@@ -879,6 +943,7 @@ export const ParticipantInfo = {
879
943
  message.hidden = object.hidden ?? false;
880
944
  message.recorder = object.recorder ?? false;
881
945
  message.name = object.name ?? "";
946
+ message.version = object.version ?? 0;
882
947
  return message;
883
948
  },
884
949
  };
@@ -1651,6 +1716,7 @@ const baseClientInfo: object = {
1651
1716
  deviceModel: "",
1652
1717
  browser: "",
1653
1718
  browserVersion: "",
1719
+ address: "",
1654
1720
  };
1655
1721
 
1656
1722
  export const ClientInfo = {
@@ -1682,6 +1748,9 @@ export const ClientInfo = {
1682
1748
  if (message.browserVersion !== "") {
1683
1749
  writer.uint32(66).string(message.browserVersion);
1684
1750
  }
1751
+ if (message.address !== "") {
1752
+ writer.uint32(74).string(message.address);
1753
+ }
1685
1754
  return writer;
1686
1755
  },
1687
1756
 
@@ -1716,6 +1785,9 @@ export const ClientInfo = {
1716
1785
  case 8:
1717
1786
  message.browserVersion = reader.string();
1718
1787
  break;
1788
+ case 9:
1789
+ message.address = reader.string();
1790
+ break;
1719
1791
  default:
1720
1792
  reader.skipType(tag & 7);
1721
1793
  break;
@@ -1766,6 +1838,11 @@ export const ClientInfo = {
1766
1838
  } else {
1767
1839
  message.browserVersion = "";
1768
1840
  }
1841
+ if (object.address !== undefined && object.address !== null) {
1842
+ message.address = String(object.address);
1843
+ } else {
1844
+ message.address = "";
1845
+ }
1769
1846
  return message;
1770
1847
  },
1771
1848
 
@@ -1781,6 +1858,7 @@ export const ClientInfo = {
1781
1858
  message.browser !== undefined && (obj.browser = message.browser);
1782
1859
  message.browserVersion !== undefined &&
1783
1860
  (obj.browserVersion = message.browserVersion);
1861
+ message.address !== undefined && (obj.address = message.address);
1784
1862
  return obj;
1785
1863
  },
1786
1864
 
@@ -1794,6 +1872,177 @@ export const ClientInfo = {
1794
1872
  message.deviceModel = object.deviceModel ?? "";
1795
1873
  message.browser = object.browser ?? "";
1796
1874
  message.browserVersion = object.browserVersion ?? "";
1875
+ message.address = object.address ?? "";
1876
+ return message;
1877
+ },
1878
+ };
1879
+
1880
+ const baseClientConfiguration: object = { resumeConnection: 0 };
1881
+
1882
+ export const ClientConfiguration = {
1883
+ encode(
1884
+ message: ClientConfiguration,
1885
+ writer: _m0.Writer = _m0.Writer.create()
1886
+ ): _m0.Writer {
1887
+ if (message.video !== undefined) {
1888
+ VideoConfiguration.encode(
1889
+ message.video,
1890
+ writer.uint32(10).fork()
1891
+ ).ldelim();
1892
+ }
1893
+ if (message.screen !== undefined) {
1894
+ VideoConfiguration.encode(
1895
+ message.screen,
1896
+ writer.uint32(18).fork()
1897
+ ).ldelim();
1898
+ }
1899
+ if (message.resumeConnection !== 0) {
1900
+ writer.uint32(24).int32(message.resumeConnection);
1901
+ }
1902
+ return writer;
1903
+ },
1904
+
1905
+ decode(input: _m0.Reader | Uint8Array, length?: number): ClientConfiguration {
1906
+ const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
1907
+ let end = length === undefined ? reader.len : reader.pos + length;
1908
+ const message = { ...baseClientConfiguration } as ClientConfiguration;
1909
+ while (reader.pos < end) {
1910
+ const tag = reader.uint32();
1911
+ switch (tag >>> 3) {
1912
+ case 1:
1913
+ message.video = VideoConfiguration.decode(reader, reader.uint32());
1914
+ break;
1915
+ case 2:
1916
+ message.screen = VideoConfiguration.decode(reader, reader.uint32());
1917
+ break;
1918
+ case 3:
1919
+ message.resumeConnection = reader.int32() as any;
1920
+ break;
1921
+ default:
1922
+ reader.skipType(tag & 7);
1923
+ break;
1924
+ }
1925
+ }
1926
+ return message;
1927
+ },
1928
+
1929
+ fromJSON(object: any): ClientConfiguration {
1930
+ const message = { ...baseClientConfiguration } as ClientConfiguration;
1931
+ if (object.video !== undefined && object.video !== null) {
1932
+ message.video = VideoConfiguration.fromJSON(object.video);
1933
+ } else {
1934
+ message.video = undefined;
1935
+ }
1936
+ if (object.screen !== undefined && object.screen !== null) {
1937
+ message.screen = VideoConfiguration.fromJSON(object.screen);
1938
+ } else {
1939
+ message.screen = undefined;
1940
+ }
1941
+ if (
1942
+ object.resumeConnection !== undefined &&
1943
+ object.resumeConnection !== null
1944
+ ) {
1945
+ message.resumeConnection = clientConfigSettingFromJSON(
1946
+ object.resumeConnection
1947
+ );
1948
+ } else {
1949
+ message.resumeConnection = 0;
1950
+ }
1951
+ return message;
1952
+ },
1953
+
1954
+ toJSON(message: ClientConfiguration): unknown {
1955
+ const obj: any = {};
1956
+ message.video !== undefined &&
1957
+ (obj.video = message.video
1958
+ ? VideoConfiguration.toJSON(message.video)
1959
+ : undefined);
1960
+ message.screen !== undefined &&
1961
+ (obj.screen = message.screen
1962
+ ? VideoConfiguration.toJSON(message.screen)
1963
+ : undefined);
1964
+ message.resumeConnection !== undefined &&
1965
+ (obj.resumeConnection = clientConfigSettingToJSON(
1966
+ message.resumeConnection
1967
+ ));
1968
+ return obj;
1969
+ },
1970
+
1971
+ fromPartial(object: DeepPartial<ClientConfiguration>): ClientConfiguration {
1972
+ const message = { ...baseClientConfiguration } as ClientConfiguration;
1973
+ if (object.video !== undefined && object.video !== null) {
1974
+ message.video = VideoConfiguration.fromPartial(object.video);
1975
+ } else {
1976
+ message.video = undefined;
1977
+ }
1978
+ if (object.screen !== undefined && object.screen !== null) {
1979
+ message.screen = VideoConfiguration.fromPartial(object.screen);
1980
+ } else {
1981
+ message.screen = undefined;
1982
+ }
1983
+ message.resumeConnection = object.resumeConnection ?? 0;
1984
+ return message;
1985
+ },
1986
+ };
1987
+
1988
+ const baseVideoConfiguration: object = { hardwareEncoder: 0 };
1989
+
1990
+ export const VideoConfiguration = {
1991
+ encode(
1992
+ message: VideoConfiguration,
1993
+ writer: _m0.Writer = _m0.Writer.create()
1994
+ ): _m0.Writer {
1995
+ if (message.hardwareEncoder !== 0) {
1996
+ writer.uint32(8).int32(message.hardwareEncoder);
1997
+ }
1998
+ return writer;
1999
+ },
2000
+
2001
+ decode(input: _m0.Reader | Uint8Array, length?: number): VideoConfiguration {
2002
+ const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
2003
+ let end = length === undefined ? reader.len : reader.pos + length;
2004
+ const message = { ...baseVideoConfiguration } as VideoConfiguration;
2005
+ while (reader.pos < end) {
2006
+ const tag = reader.uint32();
2007
+ switch (tag >>> 3) {
2008
+ case 1:
2009
+ message.hardwareEncoder = reader.int32() as any;
2010
+ break;
2011
+ default:
2012
+ reader.skipType(tag & 7);
2013
+ break;
2014
+ }
2015
+ }
2016
+ return message;
2017
+ },
2018
+
2019
+ fromJSON(object: any): VideoConfiguration {
2020
+ const message = { ...baseVideoConfiguration } as VideoConfiguration;
2021
+ if (
2022
+ object.hardwareEncoder !== undefined &&
2023
+ object.hardwareEncoder !== null
2024
+ ) {
2025
+ message.hardwareEncoder = clientConfigSettingFromJSON(
2026
+ object.hardwareEncoder
2027
+ );
2028
+ } else {
2029
+ message.hardwareEncoder = 0;
2030
+ }
2031
+ return message;
2032
+ },
2033
+
2034
+ toJSON(message: VideoConfiguration): unknown {
2035
+ const obj: any = {};
2036
+ message.hardwareEncoder !== undefined &&
2037
+ (obj.hardwareEncoder = clientConfigSettingToJSON(
2038
+ message.hardwareEncoder
2039
+ ));
2040
+ return obj;
2041
+ },
2042
+
2043
+ fromPartial(object: DeepPartial<VideoConfiguration>): VideoConfiguration {
2044
+ const message = { ...baseVideoConfiguration } as VideoConfiguration;
2045
+ message.hardwareEncoder = object.hardwareEncoder ?? 0;
1797
2046
  return message;
1798
2047
  },
1799
2048
  };