livekit-client 2.13.3 → 2.13.5

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 (35) hide show
  1. package/dist/livekit-client.esm.mjs +285 -7
  2. package/dist/livekit-client.esm.mjs.map +1 -1
  3. package/dist/livekit-client.umd.js +1 -1
  4. package/dist/livekit-client.umd.js.map +1 -1
  5. package/dist/src/api/SignalClient.d.ts.map +1 -1
  6. package/dist/src/index.d.ts +4 -1
  7. package/dist/src/index.d.ts.map +1 -1
  8. package/dist/src/room/RTCEngine.d.ts +4 -0
  9. package/dist/src/room/RTCEngine.d.ts.map +1 -1
  10. package/dist/src/room/Room.d.ts +1 -1
  11. package/dist/src/room/Room.d.ts.map +1 -1
  12. package/dist/src/room/attribute-typings.d.ts +35 -0
  13. package/dist/src/room/attribute-typings.d.ts.map +1 -0
  14. package/dist/src/room/participant/LocalParticipant.d.ts.map +1 -1
  15. package/dist/src/utils/cloneDeep.d.ts.map +1 -1
  16. package/dist/src/utils/dataPacketBuffer.d.ts +15 -0
  17. package/dist/src/utils/dataPacketBuffer.d.ts.map +1 -0
  18. package/dist/src/utils/ttlmap.d.ts +20 -0
  19. package/dist/src/utils/ttlmap.d.ts.map +1 -0
  20. package/dist/ts4.2/src/index.d.ts +4 -1
  21. package/dist/ts4.2/src/room/RTCEngine.d.ts +4 -0
  22. package/dist/ts4.2/src/room/Room.d.ts +1 -1
  23. package/dist/ts4.2/src/room/attribute-typings.d.ts +35 -0
  24. package/dist/ts4.2/src/utils/dataPacketBuffer.d.ts +15 -0
  25. package/dist/ts4.2/src/utils/ttlmap.d.ts +20 -0
  26. package/package.json +2 -2
  27. package/src/api/SignalClient.ts +4 -1
  28. package/src/index.ts +3 -0
  29. package/src/room/RTCEngine.ts +63 -2
  30. package/src/room/Room.ts +2 -2
  31. package/src/room/attribute-typings.ts +61 -0
  32. package/src/room/participant/LocalParticipant.ts +2 -0
  33. package/src/utils/cloneDeep.ts +4 -0
  34. package/src/utils/dataPacketBuffer.ts +52 -0
  35. package/src/utils/ttlmap.ts +96 -0
@@ -0,0 +1,61 @@
1
+ // This file was generated from JSON Schema using quicktype, do not modify it directly.
2
+ // The code generation lives at https://github.com/livekit/attribute-definitions
3
+ //
4
+ // To parse this data:
5
+ //
6
+ // import { Convert, AgentAttributes, TranscriptionAttributes } from "./file";
7
+ //
8
+ // const agentAttributes = Convert.toAgentAttributes(json);
9
+ // const transcriptionAttributes = Convert.toTranscriptionAttributes(json);
10
+
11
+ export interface AgentAttributes {
12
+ 'lk.agent.inputs'?: AgentInput[];
13
+ 'lk.agent.outputs'?: AgentOutput[];
14
+ 'lk.agent.state'?: AgentState;
15
+ 'lk.publish_on_behalf'?: string;
16
+ [property: string]: any;
17
+ }
18
+
19
+ export type AgentInput = 'audio' | 'video' | 'text';
20
+
21
+ export type AgentOutput = 'transcription' | 'audio';
22
+
23
+ export type AgentState = 'idle' | 'initializing' | 'listening' | 'thinking' | 'speaking';
24
+
25
+ /**
26
+ * Schema for transcription-related attributes
27
+ */
28
+ export interface TranscriptionAttributes {
29
+ /**
30
+ * The segment id of the transcription
31
+ */
32
+ 'lk.segment_id'?: string;
33
+ /**
34
+ * The associated track id of the transcription
35
+ */
36
+ 'lk.transcribed_track_id'?: string;
37
+ /**
38
+ * Whether the transcription is final
39
+ */
40
+ 'lk.transcription_final'?: boolean;
41
+ [property: string]: any;
42
+ }
43
+
44
+ // Converts JSON strings to/from your types
45
+ export class Convert {
46
+ public static toAgentAttributes(json: string): AgentAttributes {
47
+ return JSON.parse(json);
48
+ }
49
+
50
+ public static agentAttributesToJson(value: AgentAttributes): string {
51
+ return JSON.stringify(value);
52
+ }
53
+
54
+ public static toTranscriptionAttributes(json: string): TranscriptionAttributes {
55
+ return JSON.parse(json);
56
+ }
57
+
58
+ public static transcriptionAttributesToJson(value: TranscriptionAttributes): string {
59
+ return JSON.stringify(value);
60
+ }
61
+ }
@@ -260,6 +260,8 @@ export default class LocalParticipant extends Participant {
260
260
  .on(EngineEvent.Disconnected, this.handleDisconnected)
261
261
  .on(EngineEvent.SignalRequestResponse, this.handleSignalRequestResponse)
262
262
  .on(EngineEvent.DataPacketReceived, this.handleDataPacket);
263
+
264
+ this.signalConnectedFuture = undefined;
263
265
  }
264
266
 
265
267
  private handleReconnecting = () => {
@@ -4,6 +4,10 @@ export function cloneDeep<T>(value: T): T {
4
4
  }
5
5
 
6
6
  if (typeof structuredClone === 'function') {
7
+ if (typeof value === 'object' && value !== null) {
8
+ // ensure that the value is not a proxy by spreading it
9
+ return structuredClone({ ...value });
10
+ }
7
11
  return structuredClone(value);
8
12
  } else {
9
13
  return JSON.parse(JSON.stringify(value)) as T;
@@ -0,0 +1,52 @@
1
+ export interface DataPacketItem {
2
+ data: Uint8Array;
3
+ sequence: number;
4
+ }
5
+
6
+ export class DataPacketBuffer {
7
+ private buffer: DataPacketItem[] = [];
8
+
9
+ private _totalSize = 0;
10
+
11
+ push(item: DataPacketItem) {
12
+ this.buffer.push(item);
13
+ this._totalSize += item.data.byteLength;
14
+ }
15
+
16
+ pop(): DataPacketItem | undefined {
17
+ const item = this.buffer.shift();
18
+ if (item) {
19
+ this._totalSize -= item.data.byteLength;
20
+ }
21
+ return item;
22
+ }
23
+
24
+ getAll(): DataPacketItem[] {
25
+ return this.buffer.slice();
26
+ }
27
+
28
+ popToSequence(sequence: number) {
29
+ while (this.buffer.length > 0) {
30
+ const first = this.buffer[0];
31
+ if (first.sequence <= sequence) {
32
+ this.pop();
33
+ } else {
34
+ break;
35
+ }
36
+ }
37
+ }
38
+
39
+ alignBufferedAmount(bufferedAmount: number) {
40
+ while (this.buffer.length > 0) {
41
+ const first = this.buffer[0];
42
+ if (this._totalSize - first.data.byteLength <= bufferedAmount) {
43
+ break;
44
+ }
45
+ this.pop();
46
+ }
47
+ }
48
+
49
+ get length(): number {
50
+ return this.buffer.length;
51
+ }
52
+ }
@@ -0,0 +1,96 @@
1
+ export class TTLMap<K, V> {
2
+ private _map = new Map<K, { value: V; expiresAt: number }>();
3
+
4
+ private ttl: number;
5
+
6
+ private _lastCleanup = 0;
7
+
8
+ /**
9
+ * @param ttl ttl of the key (ms)
10
+ */
11
+ constructor(ttl: number) {
12
+ this.ttl = ttl;
13
+ }
14
+
15
+ set(key: K, value: V) {
16
+ const now = Date.now();
17
+ if (now - this._lastCleanup > this.ttl / 2) {
18
+ this.cleanup();
19
+ }
20
+ const expiresAt = now + this.ttl;
21
+ this._map.set(key, { value, expiresAt });
22
+ return this;
23
+ }
24
+
25
+ get(key: K): V | undefined {
26
+ const entry = this._map.get(key);
27
+ if (!entry) return undefined;
28
+ if (entry.expiresAt < Date.now()) {
29
+ this._map.delete(key);
30
+ return undefined;
31
+ }
32
+ return entry.value;
33
+ }
34
+
35
+ has(key: K): boolean {
36
+ const entry = this._map.get(key);
37
+ if (!entry) return false;
38
+ if (entry.expiresAt < Date.now()) {
39
+ this._map.delete(key);
40
+ return false;
41
+ }
42
+ return true;
43
+ }
44
+
45
+ delete(key: K): boolean {
46
+ return this._map.delete(key);
47
+ }
48
+
49
+ clear() {
50
+ this._map.clear();
51
+ }
52
+
53
+ cleanup() {
54
+ const now = Date.now();
55
+ for (const [key, entry] of this._map.entries()) {
56
+ if (entry.expiresAt < now) {
57
+ this._map.delete(key);
58
+ }
59
+ }
60
+ this._lastCleanup = now;
61
+ }
62
+
63
+ get size() {
64
+ this.cleanup();
65
+ return this._map.size;
66
+ }
67
+
68
+ forEach(callback: (value: V, key: K, map: Map<K, V>) => void) {
69
+ this.cleanup();
70
+ for (const [key, entry] of this._map.entries()) {
71
+ if (entry.expiresAt >= Date.now()) {
72
+ callback(entry.value, key, this.asValueMap());
73
+ }
74
+ }
75
+ }
76
+
77
+ map<U>(callback: (value: V, key: K, map: Map<K, V>) => U): U[] {
78
+ this.cleanup();
79
+ const result: U[] = [];
80
+ const valueMap = this.asValueMap();
81
+ for (const [key, value] of valueMap.entries()) {
82
+ result.push(callback(value, key, valueMap));
83
+ }
84
+ return result;
85
+ }
86
+
87
+ private asValueMap(): Map<K, V> {
88
+ const result = new Map<K, V>();
89
+ for (const [key, entry] of this._map.entries()) {
90
+ if (entry.expiresAt >= Date.now()) {
91
+ result.set(key, entry.value);
92
+ }
93
+ }
94
+ return result;
95
+ }
96
+ }