livekit-client 1.7.1 → 1.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. package/README.md +20 -1
  2. package/dist/livekit-client.esm.mjs +2178 -1060
  3. package/dist/livekit-client.esm.mjs.map +1 -1
  4. package/dist/livekit-client.umd.js +1 -1
  5. package/dist/livekit-client.umd.js.map +1 -1
  6. package/dist/src/index.d.ts +3 -1
  7. package/dist/src/index.d.ts.map +1 -1
  8. package/dist/src/proto/google/protobuf/timestamp.d.ts.map +1 -1
  9. package/dist/src/proto/livekit_models.d.ts +32 -0
  10. package/dist/src/proto/livekit_models.d.ts.map +1 -1
  11. package/dist/src/proto/livekit_rtc.d.ts +315 -75
  12. package/dist/src/proto/livekit_rtc.d.ts.map +1 -1
  13. package/dist/src/room/RTCEngine.d.ts +8 -1
  14. package/dist/src/room/RTCEngine.d.ts.map +1 -1
  15. package/dist/src/room/ReconnectPolicy.d.ts +1 -0
  16. package/dist/src/room/ReconnectPolicy.d.ts.map +1 -1
  17. package/dist/src/room/RegionUrlProvider.d.ts +14 -0
  18. package/dist/src/room/RegionUrlProvider.d.ts.map +1 -0
  19. package/dist/src/room/Room.d.ts +4 -0
  20. package/dist/src/room/Room.d.ts.map +1 -1
  21. package/dist/src/room/errors.d.ts +2 -1
  22. package/dist/src/room/errors.d.ts.map +1 -1
  23. package/dist/src/room/events.d.ts +8 -2
  24. package/dist/src/room/events.d.ts.map +1 -1
  25. package/dist/src/room/track/LocalAudioTrack.d.ts.map +1 -1
  26. package/dist/src/room/track/LocalTrack.d.ts +3 -2
  27. package/dist/src/room/track/LocalTrack.d.ts.map +1 -1
  28. package/dist/src/room/track/LocalVideoTrack.d.ts.map +1 -1
  29. package/dist/src/room/track/RemoteTrackPublication.d.ts +1 -1
  30. package/dist/src/room/track/RemoteTrackPublication.d.ts.map +1 -1
  31. package/dist/src/room/track/RemoteVideoTrack.d.ts +1 -1
  32. package/dist/src/room/track/RemoteVideoTrack.d.ts.map +1 -1
  33. package/dist/src/room/track/Track.d.ts +3 -1
  34. package/dist/src/room/track/Track.d.ts.map +1 -1
  35. package/dist/src/room/types.d.ts +4 -0
  36. package/dist/src/room/types.d.ts.map +1 -1
  37. package/dist/src/room/utils.d.ts +4 -0
  38. package/dist/src/room/utils.d.ts.map +1 -1
  39. package/dist/ts4.2/src/index.d.ts +3 -1
  40. package/dist/ts4.2/src/proto/livekit_models.d.ts +32 -0
  41. package/dist/ts4.2/src/proto/livekit_rtc.d.ts +348 -84
  42. package/dist/ts4.2/src/room/RTCEngine.d.ts +8 -1
  43. package/dist/ts4.2/src/room/ReconnectPolicy.d.ts +1 -0
  44. package/dist/ts4.2/src/room/RegionUrlProvider.d.ts +14 -0
  45. package/dist/ts4.2/src/room/Room.d.ts +4 -0
  46. package/dist/ts4.2/src/room/errors.d.ts +2 -1
  47. package/dist/ts4.2/src/room/events.d.ts +8 -2
  48. package/dist/ts4.2/src/room/track/LocalTrack.d.ts +3 -2
  49. package/dist/ts4.2/src/room/track/RemoteTrackPublication.d.ts +1 -1
  50. package/dist/ts4.2/src/room/track/RemoteVideoTrack.d.ts +1 -1
  51. package/dist/ts4.2/src/room/track/Track.d.ts +3 -1
  52. package/dist/ts4.2/src/room/types.d.ts +4 -0
  53. package/dist/ts4.2/src/room/utils.d.ts +4 -0
  54. package/package.json +19 -19
  55. package/src/api/SignalClient.ts +4 -4
  56. package/src/index.ts +3 -0
  57. package/src/proto/google/protobuf/timestamp.ts +15 -6
  58. package/src/proto/livekit_models.ts +903 -222
  59. package/src/proto/livekit_rtc.ts +1053 -279
  60. package/src/room/RTCEngine.ts +143 -40
  61. package/src/room/ReconnectPolicy.ts +2 -0
  62. package/src/room/RegionUrlProvider.ts +73 -0
  63. package/src/room/Room.ts +201 -132
  64. package/src/room/errors.ts +1 -0
  65. package/src/room/events.ts +7 -0
  66. package/src/room/track/LocalAudioTrack.ts +13 -6
  67. package/src/room/track/LocalTrack.ts +22 -8
  68. package/src/room/track/LocalVideoTrack.ts +12 -6
  69. package/src/room/track/RemoteTrackPublication.ts +4 -3
  70. package/src/room/track/RemoteVideoTrack.ts +5 -4
  71. package/src/room/track/Track.ts +46 -31
  72. package/src/room/types.ts +6 -0
  73. package/src/room/utils.ts +53 -0
@@ -21,6 +21,7 @@ export default class RTCEngine extends RTCEngine_base {
21
21
  private lossyDC?;
22
22
  private lossyDCSub?;
23
23
  private reliableDC?;
24
+ private dcBufferStatus;
24
25
  private reliableDCSub?;
25
26
  private subscriberPrimary;
26
27
  private primaryPC?;
@@ -46,6 +47,7 @@ export default class RTCEngine extends RTCEngine_base {
46
47
  private closingLock;
47
48
  private dataProcessLock;
48
49
  private shouldFailNext;
50
+ private regionUrlProvider?;
49
51
  constructor(options: InternalRoomOptions);
50
52
  join(url: string, token: string, opts: SignalOptions, abortSignal?: AbortSignal): Promise<JoinResponse>;
51
53
  close(): Promise<void>;
@@ -66,6 +68,7 @@ export default class RTCEngine extends RTCEngine_base {
66
68
  private handleDataChannel;
67
69
  private handleDataMessage;
68
70
  private handleDataError;
71
+ private handleBufferedAmountLow;
69
72
  private setPreferredCodec;
70
73
  createSender(track: LocalTrack, opts: TrackPublishOptions, encodings?: RTCRtpEncodingParameters[]): Promise<RTCRtpSender>;
71
74
  createSimulcastSender(track: LocalVideoTrack, simulcastTrack: SimulcastTrackInfo, opts: TrackPublishOptions, encodings?: RTCRtpEncodingParameters[]): Promise<RTCRtpSender | undefined>;
@@ -77,8 +80,11 @@ export default class RTCEngine extends RTCEngine_base {
77
80
  private getNextRetryDelay;
78
81
  private restartConnection;
79
82
  private resumeConnection;
80
- waitForPCConnected(): Promise<void>;
83
+ waitForPCInitialConnection(timeout?: number, abortController?: AbortController): Promise<void>;
84
+ waitForPCReconnected(): Promise<void>;
81
85
  sendDataPacket(packet: DataPacket, kind: DataPacket_Kind): Promise<void>;
86
+ private updateAndEmitDCBufferStatus;
87
+ private isBufferStatusLow;
82
88
  /**
83
89
  * @internal
84
90
  */
@@ -107,6 +113,7 @@ export type EngineEventCallbacks = {
107
113
  activeSpeakersUpdate: (speakers: Array<SpeakerInfo>) => void;
108
114
  dataPacketReceived: (userPacket: UserPacket, kind: DataPacket_Kind) => void;
109
115
  transportsCreated: (publisher: PCTransport, subscriber: PCTransport) => void;
116
+ dcBufferStatusChanged: (isLow: boolean, kind: DataPacket_Kind) => void;
110
117
  };
111
118
  export {};
112
119
  //# sourceMappingURL=RTCEngine.d.ts.map
@@ -19,5 +19,6 @@ export interface ReconnectContext {
19
19
  * Reason for retrying
20
20
  */
21
21
  readonly retryReason?: Error;
22
+ readonly serverUrl?: string;
22
23
  }
23
24
  //# sourceMappingURL=ReconnectPolicy.d.ts.map
@@ -0,0 +1,14 @@
1
+ export declare class RegionUrlProvider {
2
+ private serverUrl;
3
+ private token;
4
+ private regionSettings;
5
+ private lastUpdateAt;
6
+ private settingsCacheTime;
7
+ private attemptedRegions;
8
+ constructor(url: string, token: string);
9
+ isCloud(): boolean;
10
+ getNextBestRegionUrl(abortSignal?: AbortSignal): Promise<string | null>;
11
+ resetAttempts(): void;
12
+ private fetchRegionSettings;
13
+ }
14
+ //# sourceMappingURL=RegionUrlProvider.d.ts.map
@@ -86,6 +86,9 @@ declare class Room extends Room_base {
86
86
  */
87
87
  prepareConnection(url: string): Promise<void>;
88
88
  connect: (url: string, token: string, opts?: RoomConnectOptions) => Promise<void>;
89
+ private connectSignal;
90
+ private applyJoinResponse;
91
+ private attemptConnection;
89
92
  /**
90
93
  * disconnects the room, emits [[RoomEvent.Disconnected]]
91
94
  */
@@ -217,5 +220,6 @@ export type RoomEventCallbacks = {
217
220
  audioPlaybackChanged: (playing: boolean) => void;
218
221
  signalConnected: () => void;
219
222
  recordingStatusChanged: (recording: boolean) => void;
223
+ dcBufferStatusChanged: (isLow: boolean, kind: DataPacket_Kind) => void;
220
224
  };
221
225
  //# sourceMappingURL=Room.d.ts.map
@@ -5,7 +5,8 @@ export declare class LivekitError extends Error {
5
5
  export declare const enum ConnectionErrorReason {
6
6
  NotAllowed = 0,
7
7
  ServerUnreachable = 1,
8
- InternalError = 2
8
+ InternalError = 2,
9
+ Cancelled = 3
9
10
  }
10
11
  export declare class ConnectionError extends LivekitError {
11
12
  status?: number;
@@ -231,7 +231,12 @@ export declare enum RoomEvent {
231
231
  * Recording of a room has started/stopped. Room.isRecording will be updated too.
232
232
  * args: (isRecording: boolean)
233
233
  */
234
- RecordingStatusChanged = "recordingStatusChanged"
234
+ RecordingStatusChanged = "recordingStatusChanged",
235
+ /**
236
+ * Emits whenever the current buffer status of a data channel changes
237
+ * args: (isLow: boolean, kind: [[DataPacket_Kind]])
238
+ */
239
+ DCBufferStatusChanged = "dcBufferStatusChanged"
235
240
  }
236
241
  export declare enum ParticipantEvent {
237
242
  /**
@@ -378,7 +383,8 @@ export declare enum EngineEvent {
378
383
  Closing = "closing",
379
384
  MediaTrackAdded = "mediaTrackAdded",
380
385
  ActiveSpeakersUpdate = "activeSpeakersUpdate",
381
- DataPacketReceived = "dataPacketReceived"
386
+ DataPacketReceived = "dataPacketReceived",
387
+ DCBufferStatusChanged = "dcBufferStatusChanged"
382
388
  }
383
389
  export declare enum TrackEvent {
384
390
  Message = "message",
@@ -1,4 +1,4 @@
1
- import Queue from 'async-await-queue';
1
+ import { Mutex } from '../utils';
2
2
  import type { VideoCodec } from './options';
3
3
  import { Track } from './Track';
4
4
  export default abstract class LocalTrack extends Track {
@@ -9,7 +9,8 @@ export default abstract class LocalTrack extends Track {
9
9
  protected constraints: MediaTrackConstraints;
10
10
  protected reacquireTrack: boolean;
11
11
  protected providedByUser: boolean;
12
- protected muteQueue: Queue;
12
+ protected muteLock: Mutex;
13
+ protected pauseUpstreamLock: Mutex;
13
14
  /**
14
15
  *
15
16
  * @param mediaTrack
@@ -1,6 +1,6 @@
1
1
  import { TrackInfo, VideoQuality } from '../../proto/livekit_models';
2
2
  import type RemoteTrack from './RemoteTrack';
3
- import type { Track } from './Track';
3
+ import { Track } from './Track';
4
4
  import { TrackPublication } from './TrackPublication';
5
5
  export default class RemoteTrackPublication extends TrackPublication {
6
6
  track?: RemoteTrack;
@@ -6,7 +6,7 @@ export default class RemoteVideoTrack extends RemoteTrack {
6
6
  private adaptiveStreamSettings?;
7
7
  private lastVisible?;
8
8
  private lastDimensions?;
9
- private hasUsedAttach;
9
+ private isObserved;
10
10
  constructor(mediaTrack: MediaStreamTrack, sid: string, receiver?: RTCRtpReceiver, adaptiveStreamSettings?: AdaptiveStreamSettings);
11
11
  get isAdaptiveStream(): boolean;
12
12
  get mediaStreamTrack(): MediaStreamTrack;
@@ -58,10 +58,12 @@ export declare abstract class Track extends Track_base {
58
58
  protected enable(): void;
59
59
  protected disable(): void;
60
60
  abstract startMonitor(signalClient?: SignalClient): void;
61
- protected stopMonitor(): void;
61
+ stopMonitor(): void;
62
62
  private recycleElement;
63
63
  protected appVisibilityChangedListener: () => void;
64
64
  protected handleAppVisibilityChanged(): Promise<void>;
65
+ protected addAppVisibilityListener(): void;
66
+ protected removeAppVisibilityListener(): void;
65
67
  }
66
68
  /** @internal */
67
69
  export declare function attachToElement(track: MediaStreamTrack, element: HTMLMediaElement): void;
@@ -18,4 +18,8 @@ export type DataPublishOptions = {
18
18
  /** the topic under which the message gets published */
19
19
  topic?: string;
20
20
  };
21
+ export type LiveKitReactNativeInfo = {
22
+ platform: 'ios' | 'android' | 'windows' | 'macos' | 'web' | 'native';
23
+ devicePixelRatio: number;
24
+ };
21
25
  //# sourceMappingURL=types.d.ts.map
@@ -17,6 +17,10 @@ export declare function isFireFox(): boolean;
17
17
  export declare function isSafari(): boolean;
18
18
  export declare function isMobile(): boolean;
19
19
  export declare function isWeb(): boolean;
20
+ export declare function isReactNative(): boolean;
21
+ export declare function isCloud(serverUrl: URL): boolean;
22
+ export declare function getReactNativeOs(): string | undefined;
23
+ export declare function getDevicePixelRatio(): number;
20
24
  export declare function compareVersions(v1: string, v2: string): number;
21
25
  export declare const getResizeObserver: () => ResizeObserver;
22
26
  export declare const getIntersectionObserver: () => IntersectionObserver;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "livekit-client",
3
- "version": "1.7.1",
3
+ "version": "1.8.0",
4
4
  "description": "JavaScript/TypeScript client SDK for LiveKit",
5
5
  "main": "./dist/livekit-client.umd.js",
6
6
  "unpkg": "./dist/livekit-client.umd.js",
@@ -51,40 +51,40 @@
51
51
  "webrtc-adapter": "^8.1.1"
52
52
  },
53
53
  "devDependencies": {
54
- "@babel/core": "7.21.0",
55
- "@babel/preset-env": "7.20.2",
54
+ "@babel/core": "7.21.4",
55
+ "@babel/preset-env": "7.21.4",
56
56
  "@changesets/changelog-github": "0.4.8",
57
- "@changesets/cli": "2.26.0",
57
+ "@changesets/cli": "2.26.1",
58
58
  "@rollup/plugin-babel": "6.0.3",
59
- "@rollup/plugin-commonjs": "24.0.1",
59
+ "@rollup/plugin-commonjs": "24.1.0",
60
60
  "@rollup/plugin-json": "6.0.0",
61
- "@rollup/plugin-node-resolve": "15.0.1",
61
+ "@rollup/plugin-node-resolve": "15.0.2",
62
62
  "@rollup/plugin-terser": "^0.4.0",
63
- "@types/jest": "29.4.0",
64
- "@types/sdp-transform": "2.4.5",
63
+ "@types/jest": "29.5.0",
64
+ "@types/sdp-transform": "2.4.6",
65
65
  "@types/ua-parser-js": "0.7.36",
66
66
  "@types/ws": "8.5.4",
67
- "@typescript-eslint/eslint-plugin": "5.54.0",
68
- "@typescript-eslint/parser": "5.54.0",
67
+ "@typescript-eslint/eslint-plugin": "5.58.0",
68
+ "@typescript-eslint/parser": "5.58.0",
69
69
  "downlevel-dts": "^0.11.0",
70
- "eslint": "8.35.0",
70
+ "eslint": "8.38.0",
71
71
  "eslint-config-airbnb-typescript": "17.0.0",
72
- "eslint-config-prettier": "8.6.0",
72
+ "eslint-config-prettier": "8.8.0",
73
73
  "eslint-plugin-import": "2.27.5",
74
74
  "gh-pages": "5.0.0",
75
- "jest": "29.4.3",
76
- "prettier": "2.8.4",
77
- "rollup": "3.18.0",
75
+ "jest": "29.5.0",
76
+ "prettier": "2.8.7",
77
+ "rollup": "3.20.2",
78
78
  "rollup-plugin-delete": "^2.0.0",
79
79
  "rollup-plugin-filesize": "10.0.0",
80
80
  "rollup-plugin-re": "1.0.7",
81
81
  "rollup-plugin-typescript2": "0.34.1",
82
- "ts-jest": "29.0.5",
83
- "ts-proto": "1.140.0",
84
- "typedoc": "0.23.26",
82
+ "ts-jest": "29.1.0",
83
+ "ts-proto": "1.146.0",
84
+ "typedoc": "0.24.1",
85
85
  "typedoc-plugin-no-inherit": "1.4.0",
86
86
  "typescript": "4.9.5",
87
- "vite": "4.1.4"
87
+ "vite": "4.2.1"
88
88
  },
89
89
  "browserslist": [
90
90
  "safari >= 11",
@@ -33,7 +33,7 @@ import {
33
33
  } from '../proto/livekit_rtc';
34
34
  import { ConnectionError, ConnectionErrorReason } from '../room/errors';
35
35
  import CriticalTimers from '../room/timers';
36
- import { getClientInfo, Mutex, sleep } from '../room/utils';
36
+ import { getClientInfo, isReactNative, Mutex, sleep } from '../room/utils';
37
37
 
38
38
  // internal options
39
39
  interface ConnectOpts {
@@ -216,7 +216,7 @@ export class SignalClient {
216
216
  return new Promise<JoinResponse | ReconnectResponse | void>(async (resolve, reject) => {
217
217
  const abortHandler = async () => {
218
218
  await this.close();
219
- reject(new ConnectionError('room connection has been cancelled'));
219
+ reject(new ConnectionError('room connection has been cancelled (signal)'));
220
220
  };
221
221
 
222
222
  if (abortSignal?.aborted) {
@@ -234,7 +234,7 @@ export class SignalClient {
234
234
  if (!this.isConnected) {
235
235
  try {
236
236
  const resp = await fetch(`http${url.substring(2)}/validate${params}`);
237
- if (!resp.ok) {
237
+ if (resp.status.toFixed(0).startsWith('4')) {
238
238
  const msg = await resp.text();
239
239
  reject(new ConnectionError(msg, ConnectionErrorReason.NotAllowed, resp.status));
240
240
  } else {
@@ -706,7 +706,7 @@ function createConnectionParams(token: string, info: ClientInfo, opts: ConnectOp
706
706
  params.set('auto_subscribe', opts.autoSubscribe ? '1' : '0');
707
707
 
708
708
  // ClientInfo
709
- params.set('sdk', 'js');
709
+ params.set('sdk', isReactNative() ? 'reactnative' : 'js');
710
710
  params.set('version', info.version!);
711
711
  params.set('protocol', info.protocol!.toString());
712
712
  if (info.deviceModel) {
package/src/index.ts CHANGED
@@ -28,10 +28,12 @@ import {
28
28
  } from './room/utils';
29
29
 
30
30
  import type { AudioAnalyserOptions } from './room/utils';
31
+ import type { LiveKitReactNativeInfo } from './room/types';
31
32
 
32
33
  export * from './options';
33
34
  export * from './room/errors';
34
35
  export * from './room/events';
36
+ export type { DataPublishOptions } from './room/types';
35
37
  export * from './room/track/create';
36
38
  export * from './room/track/options';
37
39
  export * from './room/track/Track';
@@ -73,4 +75,5 @@ export {
73
75
  ElementInfo,
74
76
  DefaultReconnectPolicy,
75
77
  CriticalTimers,
78
+ LiveKitReactNativeInfo,
76
79
  };
@@ -127,22 +127,31 @@ export const Timestamp = {
127
127
  },
128
128
 
129
129
  decode(input: _m0.Reader | Uint8Array, length?: number): Timestamp {
130
- const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
130
+ const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
131
131
  let end = length === undefined ? reader.len : reader.pos + length;
132
132
  const message = createBaseTimestamp();
133
133
  while (reader.pos < end) {
134
134
  const tag = reader.uint32();
135
135
  switch (tag >>> 3) {
136
136
  case 1:
137
+ if (tag != 8) {
138
+ break;
139
+ }
140
+
137
141
  message.seconds = longToNumber(reader.int64() as Long);
138
- break;
142
+ continue;
139
143
  case 2:
144
+ if (tag != 16) {
145
+ break;
146
+ }
147
+
140
148
  message.nanos = reader.int32();
141
- break;
142
- default:
143
- reader.skipType(tag & 7);
144
- break;
149
+ continue;
150
+ }
151
+ if ((tag & 7) == 4 || tag == 0) {
152
+ break;
145
153
  }
154
+ reader.skipType(tag & 7);
146
155
  }
147
156
  return message;
148
157
  },