Skip to content

armgit / Piik

Public Imported from GitHub
0

Free, open-source screen sharing for private live streams with friends. Watch together in a browser or self-host Piik. 免费开源的私密屏幕共享,支持游戏直播、一起看电影与自部署。

fix(sfu): isolate Browser ICE servers

AAAb68f7551f549
diff --git a/src/client/sfu/connection-options.ts b/src/client/sfu/connection-options.ts
new file mode 100644
index 00000000..697e9786
--- /dev/null
+++ b/src/client/sfu/connection-options.ts
@@ -0,0 +1,8 @@
+import type { RoomConnectOptions } from "livekit-client";
+
+export function sfuRoomConnectOptions(): RoomConnectOptions {
+ return {
+ autoSubscribe: false,
+ rtcConfig: { iceServers: [] },
+ };
+}
diff --git a/src/client/sfu/publisher.ts b/src/client/sfu/publisher.ts
index 328d1764..2f6766de 100644
--- a/src/client/sfu/publisher.ts
+++ b/src/client/sfu/publisher.ts
@@ -29,6 +29,7 @@ import {
createStatsAccumulator,
type StatsAccumulator,
} from "../webrtc/stats";
+import { sfuRoomConnectOptions } from "./connection-options";
export interface SfuConnectionConfig {
url: string;
@@ -141,9 +142,7 @@ export class SfuPublisher {
}
});
- await room.connect(config.url, config.token, {
- autoSubscribe: false,
- });
+ await room.connect(config.url, config.token, sfuRoomConnectOptions());
if (!this.owns(room, generation)) {
await safeDisconnect(room);
return false;
diff --git a/src/client/sfu/subscriber.ts b/src/client/sfu/subscriber.ts
index 7ef6b9db..430c4dc9 100644
--- a/src/client/sfu/subscriber.ts
+++ b/src/client/sfu/subscriber.ts
@@ -16,6 +16,7 @@ import {
type StatsAccumulator,
} from "../webrtc/stats";
import { observeDecodedFrameProof } from "../media/decoded-frame-proof";
+import { sfuRoomConnectOptions } from "./connection-options";
interface SubscriberEvents {
onStream: (stream: MediaStream | null) => void;
@@ -92,7 +93,7 @@ export class SfuSubscriber {
this.sdk = sdk;
this.bindRoomEvents(room, sdk, generation);
- await room.connect(config.url, config.token, { autoSubscribe: false });
+ await room.connect(config.url, config.token, sfuRoomConnectOptions());
if (!this.owns(room, generation)) {
await safeDisconnect(room);
return false;
diff --git a/tests/sfu-client.test.ts b/tests/sfu-client.test.ts
index e7386ff3..6f1b34f8 100644
--- a/tests/sfu-client.test.ts
+++ b/tests/sfu-client.test.ts
@@ -569,6 +569,7 @@ describe("SfuPublisher", () => {
expect(room.options).toEqual({ dynacast: false });
expect(room.connect).toHaveBeenCalledWith(connection.url, connection.token, {
autoSubscribe: false,
+ rtcConfig: { iceServers: [] },
});
expect(room.localParticipant.publishTrack).not.toHaveBeenCalled();
@@ -1478,6 +1479,7 @@ describe("SfuSubscriber", () => {
await expect(connecting).resolves.toBe(true);
expect(room.connect).toHaveBeenCalledWith(connection.url, connection.token, {
autoSubscribe: false,
+ rtcConfig: { iceServers: [] },
});
expect(hostVideo.setSubscribed).not.toHaveBeenCalled();
expect(streams).toEqual([]);