@relaymessenger/livekit 0.1.0-staging.1 → 0.1.0-staging.11
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/README.md +71 -12
- package/dist/engine-werift.d.ts +31 -0
- package/dist/engine-werift.d.ts.map +1 -1
- package/dist/engine-werift.js +247 -24
- package/dist/engine-werift.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/livekit.d.ts +43 -6
- package/dist/livekit.d.ts.map +1 -1
- package/dist/livekit.js +96 -27
- package/dist/livekit.js.map +1 -1
- package/dist/transport.d.ts +182 -10
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +707 -112
- package/dist/transport.js.map +1 -1
- package/package.json +2 -2
package/dist/livekit.d.ts
CHANGED
|
@@ -2,7 +2,18 @@ import { AudioInput, AudioOutput, type AgentSession } from "@livekit/agents";
|
|
|
2
2
|
import { AudioFrame } from "@livekit/rtc-node";
|
|
3
3
|
import type Relay from "@relaymessenger/sdk";
|
|
4
4
|
import type { CallRoomOptions } from "@relaymessenger/sdk";
|
|
5
|
-
import { RelayCallTransport, type RelayCallIceDiagnostics, type RelayIceServer, type RelayIceTransportPolicy } from "./transport.js";
|
|
5
|
+
import { RelayCallTransport, type RelayCallIceDiagnostics, type RelayIceServer, type RelayIceServersProvider, type RelayInboundAudioFormat, type RelayIceTransportPolicy } from "./transport.js";
|
|
6
|
+
/**
|
|
7
|
+
* The format LiveKit's own room input hands an AgentSession:
|
|
8
|
+
* `@livekit/agents` dist/voice/room_io/room_io.js:46-48
|
|
9
|
+
* `DEFAULT_ROOM_INPUT_OPTIONS = { audioSampleRate: 24e3, audioNumChannels: 1 }`,
|
|
10
|
+
* passed to the participant `AudioStream` (room_io.js:373-374). Plugins
|
|
11
|
+
* resample assuming the channel count they construct with
|
|
12
|
+
* (`@livekit/agents-plugin-google` 1.9.0 realtime_api.js:1307-1329
|
|
13
|
+
* `new AudioResampler(frame.sampleRate, 16000, 1)`; rtc-node's resampler reads
|
|
14
|
+
* raw bytes and ignores `frame.channels`), so the session must receive mono.
|
|
15
|
+
*/
|
|
16
|
+
export declare const LIVEKIT_ROOM_INPUT_AUDIO: Readonly<RelayInboundAudioFormat>;
|
|
6
17
|
/** LiveKit Agents input backed by the remote Relay participant's WebRTC audio. */
|
|
7
18
|
export declare class RelayAudioInput extends AudioInput {
|
|
8
19
|
#private;
|
|
@@ -10,11 +21,21 @@ export declare class RelayAudioInput extends AudioInput {
|
|
|
10
21
|
setAttached(attached: boolean): void;
|
|
11
22
|
close(): Promise<void>;
|
|
12
23
|
}
|
|
13
|
-
/**
|
|
24
|
+
/**
|
|
25
|
+
* LiveKit Agents output that publishes TTS PCM to the Relay participant.
|
|
26
|
+
*
|
|
27
|
+
* Shape copied from `@livekit/agents` `ParticipantAudioOutput`
|
|
28
|
+
* (dist/voice/room_io/_output.js): `captureFrame` hands the frame to the
|
|
29
|
+
* transport and returns without waiting for playout, `flush()` starts a playout
|
|
30
|
+
* task that reports `onPlaybackFinished` only once the transport has drained,
|
|
31
|
+
* and `clearBuffer()` resolves the interruption future so that task reports
|
|
32
|
+
* `interrupted: true` with the position actually played.
|
|
33
|
+
*/
|
|
14
34
|
export declare class RelayAudioOutput extends AudioOutput {
|
|
15
35
|
#private;
|
|
16
36
|
constructor(transport: RelayCallTransport, sampleRate?: number);
|
|
17
37
|
captureFrame(frame: AudioFrame): Promise<void>;
|
|
38
|
+
/** Mark the segment complete; `onPlaybackFinished` fires once the transport has drained. */
|
|
18
39
|
flush(): void;
|
|
19
40
|
clearBuffer(): void;
|
|
20
41
|
close(): void;
|
|
@@ -32,14 +53,24 @@ export interface RelayLiveKitConnectOptions extends RelayLiveKitAudioOptions {
|
|
|
32
53
|
relay: Relay;
|
|
33
54
|
callId: string;
|
|
34
55
|
room?: CallRoomOptions;
|
|
35
|
-
/**
|
|
36
|
-
|
|
56
|
+
/**
|
|
57
|
+
* STUN and TURN servers for the agent's WebRTC peer. Defaults to none. A
|
|
58
|
+
* function is called again before every restart, to mint fresh TURN credentials.
|
|
59
|
+
*/
|
|
60
|
+
iceServers?: RelayIceServer[] | RelayIceServersProvider;
|
|
37
61
|
/** `"relay"` forces TURN. Defaults to `"all"`. */
|
|
38
62
|
iceTransportPolicy?: RelayIceTransportPolicy;
|
|
39
|
-
/**
|
|
63
|
+
/**
|
|
64
|
+
* How long one SFU session has to connect before the transport restarts onto
|
|
65
|
+
* a new one. Defaults to 5 seconds. `connect()` has no overall deadline.
|
|
66
|
+
*/
|
|
67
|
+
sessionConnectTimeoutMs?: number;
|
|
68
|
+
/** @deprecated Use `sessionConnectTimeoutMs`; now the per-session wait, not a `connect()` deadline. */
|
|
40
69
|
mediaConnectTimeoutMs?: number;
|
|
41
|
-
/** @deprecated Use `
|
|
70
|
+
/** @deprecated Use `sessionConnectTimeoutMs`. */
|
|
42
71
|
connectionTimeoutMs?: number;
|
|
72
|
+
/** Aborting stops `connect()` and closes the transport; the Call itself is not ended. */
|
|
73
|
+
signal?: AbortSignal;
|
|
43
74
|
}
|
|
44
75
|
type AgentSessionAudioTarget = Pick<AgentSession, "input" | "output">;
|
|
45
76
|
/**
|
|
@@ -56,6 +87,12 @@ export declare class RelayLiveKitCall {
|
|
|
56
87
|
static connect(options: RelayLiveKitConnectOptions): Promise<RelayLiveKitCall>;
|
|
57
88
|
attach(session: AgentSessionAudioTarget): void;
|
|
58
89
|
detach(): void;
|
|
90
|
+
/**
|
|
91
|
+
* Resolves once the person's audio has arrived and the room shows them
|
|
92
|
+
* connected (the transport's `peerAudio`). Await it before starting the
|
|
93
|
+
* AgentSession so the greeting is heard.
|
|
94
|
+
*/
|
|
95
|
+
waitForPeerAudio(timeoutMs: number): Promise<void>;
|
|
59
96
|
/** ICE candidates and state transitions for this call, with a one-line summary for logs. */
|
|
60
97
|
diagnostics(): RelayCallIceDiagnostics;
|
|
61
98
|
setMuted(muted: boolean): void;
|
package/dist/livekit.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"livekit.d.ts","sourceRoot":"","sources":["../src/livekit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,
|
|
1
|
+
{"version":3,"file":"livekit.d.ts","sourceRoot":"","sources":["../src/livekit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAU,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACrF,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE/C,OAAO,KAAK,KAAK,MAAM,qBAAqB,CAAC;AAC7C,OAAO,KAAK,EAAY,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACrE,OAAO,EACL,kBAAkB,EAElB,KAAK,uBAAuB,EAE5B,KAAK,cAAc,EACnB,KAAK,uBAAuB,EAC5B,KAAK,uBAAuB,EAC5B,KAAK,uBAAuB,EAE7B,MAAM,gBAAgB,CAAC;AAExB;;;;;;;;;GASG;AACH,eAAO,MAAM,wBAAwB,EAAE,QAAQ,CAAC,uBAAuB,CAGrE,CAAC;AAEH,kFAAkF;AAClF,qBAAa,eAAgB,SAAQ,UAAU;;gBASjC,SAAS,EAAE,kBAAkB;IA4BhC,WAAW,CAAC,QAAQ,EAAE,OAAO,GAAG,IAAI;IAI9B,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAQtC;AAED;;;;;;;;;GASG;AACH,qBAAa,gBAAiB,SAAQ,WAAW;;gBAWnC,SAAS,EAAE,kBAAkB,EAAE,UAAU,SAAS;IAK/C,YAAY,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAoB7D,4FAA4F;IACnF,KAAK,IAAI,IAAI;IAWb,WAAW,IAAI,IAAI;IAS5B,KAAK,IAAI,IAAI;CAmBd;AAED,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,eAAe,CAAC;IACvB,MA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ItC,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI;IAI9B,GAAG,IAAI,IAAI;IAIL,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAQ7B"}
|
package/dist/livekit.js
CHANGED
|
@@ -1,12 +1,28 @@
|
|
|
1
|
-
import { AudioInput, AudioOutput } from "@livekit/agents";
|
|
1
|
+
import { AudioInput, AudioOutput, Future } from "@livekit/agents";
|
|
2
2
|
import { AudioFrame } from "@livekit/rtc-node";
|
|
3
3
|
import { TransformStream } from "node:stream/web";
|
|
4
4
|
import { RelayCallTransport, } from "./transport.js";
|
|
5
|
+
/**
|
|
6
|
+
* The format LiveKit's own room input hands an AgentSession:
|
|
7
|
+
* `@livekit/agents` dist/voice/room_io/room_io.js:46-48
|
|
8
|
+
* `DEFAULT_ROOM_INPUT_OPTIONS = { audioSampleRate: 24e3, audioNumChannels: 1 }`,
|
|
9
|
+
* passed to the participant `AudioStream` (room_io.js:373-374). Plugins
|
|
10
|
+
* resample assuming the channel count they construct with
|
|
11
|
+
* (`@livekit/agents-plugin-google` 1.9.0 realtime_api.js:1307-1329
|
|
12
|
+
* `new AudioResampler(frame.sampleRate, 16000, 1)`; rtc-node's resampler reads
|
|
13
|
+
* raw bytes and ignores `frame.channels`), so the session must receive mono.
|
|
14
|
+
*/
|
|
15
|
+
export const LIVEKIT_ROOM_INPUT_AUDIO = Object.freeze({
|
|
16
|
+
sampleRate: 24_000,
|
|
17
|
+
channelCount: 1,
|
|
18
|
+
});
|
|
5
19
|
/** LiveKit Agents input backed by the remote Relay participant's WebRTC audio. */
|
|
6
20
|
export class RelayAudioInput extends AudioInput {
|
|
7
21
|
#transport;
|
|
8
22
|
#writer;
|
|
9
23
|
#onAudio;
|
|
24
|
+
/** Serial write chain: each frame waits for the writer, as `pipeTo` does in LiveKit's input. */
|
|
25
|
+
#writes = Promise.resolve();
|
|
10
26
|
#attached = false;
|
|
11
27
|
#closed = false;
|
|
12
28
|
constructor(transport) {
|
|
@@ -19,7 +35,16 @@ export class RelayAudioInput extends AudioInput {
|
|
|
19
35
|
if (this.#closed || !this.#attached)
|
|
20
36
|
return;
|
|
21
37
|
const audio = new AudioFrame(frame.samples, frame.sampleRate, frame.channelCount, frame.samples.length / frame.channelCount);
|
|
22
|
-
|
|
38
|
+
// LiveKit's ParticipantAudioInputStream pipes its AudioStream into the
|
|
39
|
+
// session with `pipeTo(output.writable)` (room_io/_input.js:161-162),
|
|
40
|
+
// which awaits the writer before each chunk. The transport pushes and
|
|
41
|
+
// cannot be paused, so the frames wait here in order instead.
|
|
42
|
+
this.#writes = this.#writes
|
|
43
|
+
.then(async () => {
|
|
44
|
+
await this.#writer.ready;
|
|
45
|
+
await this.#writer.write(audio);
|
|
46
|
+
})
|
|
47
|
+
.catch(() => undefined);
|
|
23
48
|
};
|
|
24
49
|
this.#transport.on("audio", this.#onAudio);
|
|
25
50
|
}
|
|
@@ -31,16 +56,30 @@ export class RelayAudioInput extends AudioInput {
|
|
|
31
56
|
return;
|
|
32
57
|
this.#closed = true;
|
|
33
58
|
this.#transport.off("audio", this.#onAudio);
|
|
59
|
+
await this.#writes;
|
|
34
60
|
await this.#writer.close().catch(() => undefined);
|
|
35
61
|
await super.close();
|
|
36
62
|
}
|
|
37
63
|
}
|
|
38
|
-
/**
|
|
64
|
+
/**
|
|
65
|
+
* LiveKit Agents output that publishes TTS PCM to the Relay participant.
|
|
66
|
+
*
|
|
67
|
+
* Shape copied from `@livekit/agents` `ParticipantAudioOutput`
|
|
68
|
+
* (dist/voice/room_io/_output.js): `captureFrame` hands the frame to the
|
|
69
|
+
* transport and returns without waiting for playout, `flush()` starts a playout
|
|
70
|
+
* task that reports `onPlaybackFinished` only once the transport has drained,
|
|
71
|
+
* and `clearBuffer()` resolves the interruption future so that task reports
|
|
72
|
+
* `interrupted: true` with the position actually played.
|
|
73
|
+
*/
|
|
39
74
|
export class RelayAudioOutput extends AudioOutput {
|
|
40
75
|
#transport;
|
|
41
|
-
|
|
42
|
-
#
|
|
43
|
-
#
|
|
76
|
+
/** Seconds pushed to the transport in the open segment. */
|
|
77
|
+
#pushedDuration = 0;
|
|
78
|
+
#firstFrameEmitted = false;
|
|
79
|
+
#flushTask;
|
|
80
|
+
#flushDone = true;
|
|
81
|
+
/** Resolved by `clearBuffer()` with the milliseconds still queued at that moment. */
|
|
82
|
+
#interruptedFuture = new Future();
|
|
44
83
|
#closed = false;
|
|
45
84
|
constructor(transport, sampleRate = 48_000) {
|
|
46
85
|
super(sampleRate, undefined, { pause: false });
|
|
@@ -49,38 +88,47 @@ export class RelayAudioOutput extends AudioOutput {
|
|
|
49
88
|
async captureFrame(frame) {
|
|
50
89
|
if (this.#closed)
|
|
51
90
|
throw new Error("Relay LiveKit audio output is closed.");
|
|
91
|
+
if (this.#flushTask && !this.#flushDone) {
|
|
92
|
+
this.logger.error("captureFrame called while flush is in progress");
|
|
93
|
+
await this.#flushTask;
|
|
94
|
+
}
|
|
52
95
|
await super.captureFrame(frame);
|
|
53
|
-
if (!this.#
|
|
54
|
-
this.#
|
|
55
|
-
this
|
|
56
|
-
this.onPlaybackStarted(this.#segmentStartedAt);
|
|
96
|
+
if (!this.#firstFrameEmitted) {
|
|
97
|
+
this.#firstFrameEmitted = true;
|
|
98
|
+
this.onPlaybackStarted(Date.now());
|
|
57
99
|
}
|
|
58
|
-
this.#
|
|
100
|
+
this.#pushedDuration += frame.samplesPerChannel / frame.sampleRate;
|
|
101
|
+
// Resolves once the slices are queued; the engine's pump paces the wire.
|
|
59
102
|
await this.#transport.writeAudio({
|
|
60
103
|
samples: frame.data,
|
|
61
104
|
sampleRate: frame.sampleRate,
|
|
62
105
|
channelCount: frame.channels,
|
|
63
106
|
});
|
|
64
107
|
}
|
|
108
|
+
/** Mark the segment complete; `onPlaybackFinished` fires once the transport has drained. */
|
|
65
109
|
flush() {
|
|
66
110
|
super.flush();
|
|
67
|
-
if (!this.#
|
|
111
|
+
if (!this.#pushedDuration)
|
|
68
112
|
return;
|
|
69
|
-
this
|
|
70
|
-
|
|
71
|
-
|
|
113
|
+
if (this.#flushTask && !this.#flushDone)
|
|
114
|
+
return;
|
|
115
|
+
this.#flushDone = false;
|
|
116
|
+
this.#flushTask = this.#waitForPlayoutTask().finally(() => {
|
|
117
|
+
this.#flushDone = true;
|
|
72
118
|
});
|
|
73
|
-
this.#
|
|
119
|
+
void this.#flushTask.catch(() => undefined);
|
|
74
120
|
}
|
|
75
121
|
clearBuffer() {
|
|
122
|
+
const queuedMs = this.#transport.queuedAudioMs();
|
|
76
123
|
this.#transport.clearAudio();
|
|
77
|
-
if (
|
|
124
|
+
if (this.#interruptedFuture.done)
|
|
78
125
|
return;
|
|
79
|
-
this.
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
this.#
|
|
126
|
+
if (this.#pushedDuration === 0 && this.pendingPlayoutSegments === 0)
|
|
127
|
+
return;
|
|
128
|
+
if (!this.#flushTask || this.#flushDone)
|
|
129
|
+
this.flush();
|
|
130
|
+
if (!this.#interruptedFuture.done)
|
|
131
|
+
this.#interruptedFuture.resolve(queuedMs);
|
|
84
132
|
}
|
|
85
133
|
close() {
|
|
86
134
|
if (this.#closed)
|
|
@@ -88,10 +136,19 @@ export class RelayAudioOutput extends AudioOutput {
|
|
|
88
136
|
this.#closed = true;
|
|
89
137
|
this.clearBuffer();
|
|
90
138
|
}
|
|
91
|
-
#
|
|
92
|
-
|
|
93
|
-
this.#
|
|
94
|
-
|
|
139
|
+
async #waitForPlayoutTask() {
|
|
140
|
+
const interruptedFuture = this.#interruptedFuture;
|
|
141
|
+
await Promise.race([this.#transport.waitForPlayout(), interruptedFuture.await]);
|
|
142
|
+
const interrupted = interruptedFuture.done;
|
|
143
|
+
let playbackPosition = this.#pushedDuration;
|
|
144
|
+
if (interrupted) {
|
|
145
|
+
playbackPosition = Math.max(0, playbackPosition - interruptedFuture.result / 1_000);
|
|
146
|
+
}
|
|
147
|
+
this.#pushedDuration = 0;
|
|
148
|
+
this.#firstFrameEmitted = false;
|
|
149
|
+
if (this.#interruptedFuture === interruptedFuture)
|
|
150
|
+
this.#interruptedFuture = new Future();
|
|
151
|
+
this.onPlaybackFinished({ playbackPosition, interrupted });
|
|
95
152
|
}
|
|
96
153
|
}
|
|
97
154
|
/** Build LiveKit Agents audio IO around an already-connected Relay transport. */
|
|
@@ -119,6 +176,7 @@ export class RelayLiveKitCall {
|
|
|
119
176
|
const transportOptions = {
|
|
120
177
|
relay: options.relay,
|
|
121
178
|
callId: options.callId,
|
|
179
|
+
inboundAudio: LIVEKIT_ROOM_INPUT_AUDIO,
|
|
122
180
|
...(options.room ? { room: options.room } : {}),
|
|
123
181
|
...(options.roomClient ? { roomClient: options.roomClient } : {}),
|
|
124
182
|
...(options.webRTC ? { webRTC: options.webRTC } : {}),
|
|
@@ -127,6 +185,9 @@ export class RelayLiveKitCall {
|
|
|
127
185
|
...(options.iceGatheringTimeoutMs === undefined
|
|
128
186
|
? {}
|
|
129
187
|
: { iceGatheringTimeoutMs: options.iceGatheringTimeoutMs }),
|
|
188
|
+
...(options.sessionConnectTimeoutMs === undefined
|
|
189
|
+
? {}
|
|
190
|
+
: { sessionConnectTimeoutMs: options.sessionConnectTimeoutMs }),
|
|
130
191
|
...(options.mediaConnectTimeoutMs === undefined
|
|
131
192
|
? {}
|
|
132
193
|
: { mediaConnectTimeoutMs: options.mediaConnectTimeoutMs }),
|
|
@@ -135,7 +196,7 @@ export class RelayLiveKitCall {
|
|
|
135
196
|
: { connectionTimeoutMs: options.connectionTimeoutMs }),
|
|
136
197
|
};
|
|
137
198
|
const transport = new RelayCallTransport(transportOptions);
|
|
138
|
-
await transport.connect();
|
|
199
|
+
await transport.connect(options.signal ? { signal: options.signal } : {});
|
|
139
200
|
return new RelayLiveKitCall(transport, createRelayLiveKitAudio(transport, options));
|
|
140
201
|
}
|
|
141
202
|
attach(session) {
|
|
@@ -156,6 +217,14 @@ export class RelayLiveKitCall {
|
|
|
156
217
|
this.#session.output.audio = null;
|
|
157
218
|
this.#session = undefined;
|
|
158
219
|
}
|
|
220
|
+
/**
|
|
221
|
+
* Resolves once the person's audio has arrived and the room shows them
|
|
222
|
+
* connected (the transport's `peerAudio`). Await it before starting the
|
|
223
|
+
* AgentSession so the greeting is heard.
|
|
224
|
+
*/
|
|
225
|
+
waitForPeerAudio(timeoutMs) {
|
|
226
|
+
return this.transport.waitForPeerAudio(timeoutMs);
|
|
227
|
+
}
|
|
159
228
|
/** ICE candidates and state transitions for this call, with a one-line summary for logs. */
|
|
160
229
|
diagnostics() {
|
|
161
230
|
return this.transport.diagnostics();
|
package/dist/livekit.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"livekit.js","sourceRoot":"","sources":["../src/livekit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAqB,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"livekit.js","sourceRoot":"","sources":["../src/livekit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,EAAqB,MAAM,iBAAiB,CAAC;AACrF,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAoC,MAAM,iBAAiB,CAAC;AAGpF,OAAO,EACL,kBAAkB,GASnB,MAAM,gBAAgB,CAAC;AAExB;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAsC,MAAM,CAAC,MAAM,CAAC;IACvF,UAAU,EAAE,MAAM;IAClB,YAAY,EAAE,CAAC;CAChB,CAAC,CAAC;AAEH,kFAAkF;AAClF,MAAM,OAAO,eAAgB,SAAQ,UAAU;IACpC,UAAU,CAAqB;IAC/B,OAAO,CAA0C;IACjD,QAAQ,CAAmC;IACpD,gGAAgG;IAChG,OAAO,GAAkB,OAAO,CAAC,OAAO,EAAE,CAAC;IAC3C,SAAS,GAAG,KAAK,CAAC;IAClB,OAAO,GAAG,KAAK,CAAC;IAEhB,Y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
13
13
|
}
|
|
14
14
|
export type RelayIceTransportPolicy = "all" | "relay";
|
|
15
|
+
/**
|
|
16
|
+
* Returns the ICE servers for one peer connection. Called before the first
|
|
17
|
+
* peer and again before every restart, so short-lived TURN credentials can be
|
|
18
|
+
* minted per attempt (PartyTracks: a reconnect "will trigger new sessionId,
|
|
19
|
+
* new ice server credentials and a new peerConnection").
|
|
20
|
+
*/
|
|
21
|
+
export type RelayIceServersProvider = (attempt: {
|
|
22
|
+
/** 0 for the first peer, then 1, 2, ... for each restart. */
|
|
23
|
+
restarts: number;
|
|
24
|
+
}) => RelayIceServer[] | Promise<RelayIceServer[]>;
|
|
25
|
+
/** Why the transport replaced its peer connection with a new SFU session. */
|
|
26
|
+
export type RelayCallRestartReason = "timeout" | "failed" | "disconnected" | "error";
|
|
27
|
+
export interface RelayCallRestartEvent {
|
|
28
|
+
reason: RelayCallRestartReason;
|
|
29
|
+
/** `diagnostics().summary` of the session being replaced, taken as it was given up. */
|
|
30
|
+
summary: string;
|
|
31
|
+
/** Restarts since `connect()`, this one included. */
|
|
32
|
+
restarts: number;
|
|
33
|
+
/** Backoff waited before the new peer was built. */
|
|
34
|
+
delayMs: number;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* PCM format the engine decodes the remote participant's Opus into. The values
|
|
38
|
+
* are the ones libopus decodes to (`@evan/opus` lib.d.ts: `channels?: 1 | 2`,
|
|
39
|
+
* `sample_rate?: 8000 | 12000 | 16000 | 24000 | 48000`); the decoder itself
|
|
40
|
+
* resamples and downmixes, so no PCM is converted by hand.
|
|
41
|
+
*/
|
|
42
|
+
export interface RelayInboundAudioFormat {
|
|
43
|
+
sampleRate: 8000 | 12000 | 16000 | 24000 | 48000;
|
|
44
|
+
channelCount: 1 | 2;
|
|
45
|
+
}
|
|
46
|
+
/** Opus's native rate and Relay's wire channel count. */
|
|
47
|
+
export declare const DEFAULT_INBOUND_AUDIO: Readonly<RelayInboundAudioFormat>;
|
|
15
48
|
export type RelayCallEngine = "werift" | "wrtc";
|
|
16
49
|
export interface RelayCallTransportOptions {
|
|
17
50
|
relay: Relay;
|
|
@@ -24,16 +57,79 @@ export interface RelayCallTransportOptions {
|
|
|
24
57
|
engine?: RelayCallEngine;
|
|
25
58
|
/**
|
|
26
59
|
* STUN and TURN servers handed to the engine's `RTCPeerConnection`. Defaults
|
|
27
|
-
* to
|
|
28
|
-
* servers when the agent runs behind a NAT or firewall
|
|
60
|
+
* to Cloudflare's STUN server, the configuration of Cloudflare's own Realtime
|
|
61
|
+
* echo example. Set TURN servers when the agent runs behind a NAT or firewall
|
|
62
|
+
* that blocks UDP. A function is called before every peer connection,
|
|
63
|
+
* restarts included, so it can mint fresh TURN credentials each time.
|
|
29
64
|
*/
|
|
30
|
-
iceServers?: RelayIceServer[];
|
|
65
|
+
iceServers?: RelayIceServer[] | RelayIceServersProvider;
|
|
31
66
|
/** `"relay"` forces every candidate through TURN. Defaults to `"all"`. */
|
|
32
67
|
iceTransportPolicy?: RelayIceTransportPolicy;
|
|
33
|
-
/**
|
|
68
|
+
/**
|
|
69
|
+
* How long one SFU session has, after its answer is applied, to reach
|
|
70
|
+
* `connected` before the transport restarts onto a new session. Defaults to
|
|
71
|
+
* 5 seconds. `connect()` itself has no deadline: it waits through restarts
|
|
72
|
+
* until media connects, the Call ends, `close()` is called, or its signal aborts.
|
|
73
|
+
*/
|
|
74
|
+
sessionConnectTimeoutMs?: number;
|
|
75
|
+
/** @deprecated Use `sessionConnectTimeoutMs`; now the per-session wait, not a `connect()` deadline. */
|
|
34
76
|
mediaConnectTimeoutMs?: number;
|
|
35
|
-
/** @deprecated Use `
|
|
77
|
+
/** @deprecated Use `sessionConnectTimeoutMs`. */
|
|
36
78
|
connectionTimeoutMs?: number;
|
|
79
|
+
/**
|
|
80
|
+
* PCM format of the `audio` events: the Opus decoder decodes the remote
|
|
81
|
+
* track straight to this rate and channel count. Defaults to 48 kHz stereo.
|
|
82
|
+
* The `"wrtc"` engine delivers libwebrtc's own format and accepts only the default.
|
|
83
|
+
*/
|
|
84
|
+
inboundAudio?: RelayInboundAudioFormat;
|
|
85
|
+
/**
|
|
86
|
+
* Called once per call when outbound audio is queued but no RTP packet has
|
|
87
|
+
* been written for 2 s while media is connected. Receives the diagnostics
|
|
88
|
+
* summary. Defaults to a no-op; nothing is restarted.
|
|
89
|
+
*/
|
|
90
|
+
onWarning?: (message: string) => void;
|
|
91
|
+
}
|
|
92
|
+
/** Packet counts for the other participant's track, as seen by this participant. */
|
|
93
|
+
export interface RelayCallInboundDiagnostics {
|
|
94
|
+
/** RTP packets received on the subscribed track. */
|
|
95
|
+
rtpPackets: number;
|
|
96
|
+
/** Opus packets the decoder rejected. */
|
|
97
|
+
decodeFailures: number;
|
|
98
|
+
/** PCM frames handed to the `audio` listeners. */
|
|
99
|
+
frames: number;
|
|
100
|
+
/** ms since `connect()` for the first and last RTP packet; undefined until one arrives. */
|
|
101
|
+
firstPacketAtMs: number | undefined;
|
|
102
|
+
lastPacketAtMs: number | undefined;
|
|
103
|
+
/** RTP packets received in the 5 s before `diagnostics()` was called. */
|
|
104
|
+
recentRtpPackets: number;
|
|
105
|
+
}
|
|
106
|
+
/** Packet counts for this participant's published track. */
|
|
107
|
+
export interface RelayCallOutboundDiagnostics {
|
|
108
|
+
/** PCM slices accepted from the caller and handed to the engine source. */
|
|
109
|
+
frames: number;
|
|
110
|
+
opusPackets: number;
|
|
111
|
+
/** RTP packets carrying the caller's audio. */
|
|
112
|
+
rtpPackets: number;
|
|
113
|
+
/** RTP packets carrying Opus silence, written while nothing was queued. */
|
|
114
|
+
silencePackets: number;
|
|
115
|
+
/** ms since `connect()` for the first and last RTP packet of either kind. */
|
|
116
|
+
firstPacketAtMs: number | undefined;
|
|
117
|
+
lastPacketAtMs: number | undefined;
|
|
118
|
+
/** RTP packets of either kind written in the 5 s before `diagnostics()` was called. */
|
|
119
|
+
recentRtpPackets: number;
|
|
120
|
+
/** Encoded packets waiting for the 20 ms pacer. */
|
|
121
|
+
queued: number;
|
|
122
|
+
/** `undefined` when the engine does not expose its pacer (`wrtc`). */
|
|
123
|
+
pacerAlive: boolean | undefined;
|
|
124
|
+
}
|
|
125
|
+
/** Room signaling frames counted since `connect()`. */
|
|
126
|
+
export interface RelayCallRoomDiagnostics {
|
|
127
|
+
roomStates: number;
|
|
128
|
+
/** Subscription (pull) offers received from the room. */
|
|
129
|
+
offers: number;
|
|
130
|
+
endedReason: string | undefined;
|
|
131
|
+
/** `error` frame messages, in order. */
|
|
132
|
+
errors: string[];
|
|
37
133
|
}
|
|
38
134
|
/** ICE facts recorded for one call, for logs and for the connect timeout error. */
|
|
39
135
|
export interface RelayCallIceDiagnostics {
|
|
@@ -55,7 +151,18 @@ export interface RelayCallIceDiagnostics {
|
|
|
55
151
|
state: string;
|
|
56
152
|
atMs: number;
|
|
57
153
|
}>;
|
|
154
|
+
/**
|
|
155
|
+
* The local side of the candidate pair media flows on, as `"<type> <protocol>"`
|
|
156
|
+
* (for example `"relay udp"`), read from the W3C stats once the peer connects;
|
|
157
|
+
* undefined until then or when the engine has no `getStats()`.
|
|
158
|
+
*/
|
|
159
|
+
selectedPair: string | undefined;
|
|
58
160
|
connected: boolean;
|
|
161
|
+
inbound: RelayCallInboundDiagnostics;
|
|
162
|
+
outbound: RelayCallOutboundDiagnostics;
|
|
163
|
+
room: RelayCallRoomDiagnostics;
|
|
164
|
+
/** Peer connections replaced by a new SFU session since `connect()`. */
|
|
165
|
+
restarts: number;
|
|
59
166
|
/** One-line rendering of the fields above. */
|
|
60
167
|
summary: string;
|
|
61
168
|
}
|
|
@@ -67,13 +174,47 @@ export interface RelayCallTransportCloseEvent {
|
|
|
67
174
|
type TransportEventMap = {
|
|
68
175
|
audio: [RelayAudioFrame];
|
|
69
176
|
connected: [];
|
|
177
|
+
/** A new peer connection published on a new SFU session; audio continues on it. */
|
|
178
|
+
restarted: [RelayCallRestartEvent];
|
|
70
179
|
roomState: [CallRoomStateFrame];
|
|
180
|
+
/** The person's camera started (`true`) or stopped (`false`) sending, from `roomState`. */
|
|
181
|
+
remoteVideo: [boolean];
|
|
182
|
+
/**
|
|
183
|
+
* Once per call: the person's audio has reached this peer (first inbound
|
|
184
|
+
* frame on the pulled track) and `roomState` shows the person connected. The
|
|
185
|
+
* room pulls both directions together, so from here the person hears what is
|
|
186
|
+
* written; start speaking after this, as LiveKit Agents start a session once
|
|
187
|
+
* the participant is in the room.
|
|
188
|
+
*/
|
|
189
|
+
peerAudio: [];
|
|
71
190
|
ended: [CallRoomEndedFrame];
|
|
72
191
|
error: [Error];
|
|
73
192
|
close: [RelayCallTransportCloseEvent];
|
|
74
193
|
};
|
|
75
194
|
type TransportEvent = keyof TransportEventMap;
|
|
76
195
|
type TransportListener<K extends TransportEvent> = (...args: TransportEventMap[K]) => void;
|
|
196
|
+
/**
|
|
197
|
+
* Restart rule, copied from PartyTracks and Cloudflare (PROTOCOL.md section 4):
|
|
198
|
+
* not `connected` 5 s after the SFU answer (Cloudflare's echo example waits
|
|
199
|
+
* 5000 ms; SFU operations block up to 5 s awaiting `connected`), `failed`, or
|
|
200
|
+
* `disconnected` for 7 s (PartyTracks.ts `timeoutSeconds = 7`). Backoff 250 ms
|
|
201
|
+
* x1.1 per attempt, capped at 10 s (PartyTracks `retryWithBackoff`
|
|
202
|
+
* `backoffFactor: 1.1`, rxjs-helpers.ts defaults). werift never reports
|
|
203
|
+
* `failed` on a session whose checks go unanswered (ice.js:983-986), so the
|
|
204
|
+
* 5 s timer is the trigger that fires in practice.
|
|
205
|
+
*/
|
|
206
|
+
export declare const RESTART_CONNECT_TIMEOUT_MS = 5000;
|
|
207
|
+
export declare const RESTART_DISCONNECTED_MS = 7000;
|
|
208
|
+
export declare const RESTART_INITIAL_DELAY_MS = 250;
|
|
209
|
+
export declare const RESTART_BACKOFF_FACTOR = 1.1;
|
|
210
|
+
export declare const RESTART_MAX_DELAY_MS = 10000;
|
|
211
|
+
/**
|
|
212
|
+
* Backoff before restart number `attempt` (1-based) counted since the last
|
|
213
|
+
* session that connected. PartyTracks passes `resetOnSuccess: true` to rxjs
|
|
214
|
+
* `retry` (rxjs-helpers.ts:18, :39); this transport reads "success" as a
|
|
215
|
+
* session reaching `connected`.
|
|
216
|
+
*/
|
|
217
|
+
export declare const restartDelayMs: (attempt: number) => number;
|
|
77
218
|
export declare class RelayCallTransportError extends Error {
|
|
78
219
|
readonly code?: string;
|
|
79
220
|
constructor(message: string, code?: string);
|
|
@@ -82,25 +223,56 @@ export declare class RelayCallTransportError extends Error {
|
|
|
82
223
|
* Provider-neutral Node WebRTC bridge for Relay Call rooms.
|
|
83
224
|
*
|
|
84
225
|
* The class owns Relay media negotiation internally. Higher-level adapters only
|
|
85
|
-
* exchange PCM16 frames and call lifecycle events.
|
|
226
|
+
* exchange PCM16 frames and call lifecycle events. When an SFU session never
|
|
227
|
+
* connects or dies, the transport builds a new peer connection on a new
|
|
228
|
+
* session (PROTOCOL.md section 4); the audio source and the `audio` events
|
|
229
|
+
* carry on across the swap, so adapters only hear silence.
|
|
86
230
|
*/
|
|
87
231
|
export declare class RelayCallTransport {
|
|
88
232
|
#private;
|
|
89
233
|
constructor(options: RelayCallTransportOptions);
|
|
90
234
|
on<K extends TransportEvent>(event: K, listener: TransportListener<K>): this;
|
|
91
235
|
off<K extends TransportEvent>(event: K, listener: TransportListener<K>): this;
|
|
92
|
-
|
|
236
|
+
/**
|
|
237
|
+
* Join the room, publish, and resolve on the first `connected`. Dead SFU
|
|
238
|
+
* sessions are replaced as they are found (PROTOCOL.md section 4), with no
|
|
239
|
+
* overall deadline: this rejects only when the Call ends, the room or
|
|
240
|
+
* transport closes, the room reports an error, or `signal` aborts (which
|
|
241
|
+
* also closes the transport).
|
|
242
|
+
*/
|
|
243
|
+
connect(options?: {
|
|
244
|
+
signal?: AbortSignal;
|
|
245
|
+
}): Promise<void>;
|
|
93
246
|
/** Replace only the room signaling socket and replay the identical publication. */
|
|
94
247
|
reconnect(): Promise<void>;
|
|
95
|
-
/**
|
|
248
|
+
/**
|
|
249
|
+
* ICE candidates, state transitions, packet counts in both directions,
|
|
250
|
+
* room frame counts and restarts recorded for this call, with a one-line summary.
|
|
251
|
+
*/
|
|
96
252
|
diagnostics(): RelayCallIceDiagnostics;
|
|
97
253
|
/**
|
|
98
254
|
* Feed interleaved PCM16 audio into Relay. Frames are split into 10 ms WebRTC
|
|
99
|
-
* source slices and
|
|
255
|
+
* source slices and handed to the engine at once; the engine's 20 ms pump
|
|
256
|
+
* paces the wire, so adapters may push faster than real time (LiveKit's
|
|
257
|
+
* `AudioSource.captureFrame` shape). Resolves once the slices are queued;
|
|
258
|
+
* `waitForPlayout()` tells when they have left.
|
|
100
259
|
*/
|
|
101
260
|
writeAudio(frame: RelayAudioFrame): Promise<void>;
|
|
102
|
-
/**
|
|
261
|
+
/** Milliseconds of audio accepted by `writeAudio` but not yet written to RTP. */
|
|
262
|
+
queuedAudioMs(): number;
|
|
263
|
+
/**
|
|
264
|
+
* Resolves when every accepted slice has been written to RTP and the engine's
|
|
265
|
+
* pump is idle; immediately when nothing is queued; early on `clearAudio()`
|
|
266
|
+
* or `close()` (the caller reads `queuedAudioMs()` to learn what was dropped).
|
|
267
|
+
*/
|
|
268
|
+
waitForPlayout(): Promise<void>;
|
|
269
|
+
/** Drop outgoing PCM that has not reached RTP and release `waitForPlayout()` callers. */
|
|
103
270
|
clearAudio(): void;
|
|
271
|
+
/**
|
|
272
|
+
* Resolves once `peerAudio` has fired (at once if it already has). Rejects
|
|
273
|
+
* after `timeoutMs`, or when the Call ends or the transport closes first.
|
|
274
|
+
*/
|
|
275
|
+
waitForPeerAudio(timeoutMs: number): Promise<void>;
|
|
104
276
|
setMuted(muted: boolean): void;
|
|
105
277
|
end(): void;
|
|
106
278
|
close(): void;
|
package/dist/transport.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../src/transport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,kBAAkB,EAElB,eA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