Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/single-peer-connection.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@livekit/agents': patch
---

Expose `singlePeerConnection` in `JobContext.connect` and pass it through to the underlying LiveKit room connection options.
9 changes: 8 additions & 1 deletion agents/src/job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ export enum AutoSubscribe {
AUDIO_ONLY,
}

type RoomConnectOptions = NonNullable<Parameters<Room['connect']>[2]> & {
singlePeerConnection?: boolean;
};

export type JobAcceptArguments = {
name: string;
identity: string;
Expand Down Expand Up @@ -239,21 +243,24 @@ export class JobContext<ProcessUserData = Record<string, unknown>> {
*
* @see {@link https://github.com/livekit/node-sdks/tree/main/packages/livekit-rtc#readme |
* @livekit/rtc-node} for more information about the parameters.
* @param singlePeerConnection - Use a single peer connection for publishing and subscribing.
*/
async connect(
e2ee?: E2EEOptions,
autoSubscribe: AutoSubscribe = AutoSubscribe.SUBSCRIBE_ALL,
rtcConfig?: RtcConfiguration,
singlePeerConnection?: boolean,
) {
if (this.connected) {
return;
}

const opts = {
const opts: RoomConnectOptions = {
e2ee,
autoSubscribe: autoSubscribe == AutoSubscribe.SUBSCRIBE_ALL,
rtcConfig,
dynacast: false,
singlePeerConnection,
};

await this.#room.connect(this.#info.url, this.#info.token, opts);
Expand Down
Loading