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. 免费开源的私密屏幕共享,支持游戏直播、一起看电影与自部署。

feat(admission): support 20-viewer rooms

AAAd4353686a400
diff --git a/native/sender/internal/remote/wire.go b/native/sender/internal/remote/wire.go
index ef6242b2..4b1daaf5 100644
--- a/native/sender/internal/remote/wire.go
+++ b/native/sender/internal/remote/wire.go
@@ -17,7 +17,7 @@ import (
const (
signalingProtocol = "screener-v6"
- maxProtocolViewers = 16
+ maxProtocolViewers = 20
maxEndpointMediaCopyCapacity = 3
maxRouteRevision = int64(1<<53 - 1)
maxSignalSDPBytes = 48 << 10
diff --git a/native/sender/internal/remote/wire_test.go b/native/sender/internal/remote/wire_test.go
index a0c3d2f2..ba828825 100644
--- a/native/sender/internal/remote/wire_test.go
+++ b/native/sender/internal/remote/wire_test.go
@@ -64,6 +64,25 @@ func TestDecodeOrdinaryHostAuthentication(t *testing.T) {
}
}
+func TestDecodeOrdinaryHostAuthenticationAcceptsViewerCeiling(t *testing.T) {
+ var candidate map[string]any
+ if err := json.Unmarshal([]byte(validHostAuthenticated), &candidate); err != nil {
+ t.Fatal(err)
+ }
+ candidate["maxViewers"] = maxProtocolViewers
+ payload, err := json.Marshal(candidate)
+ if err != nil {
+ t.Fatal(err)
+ }
+ message, err := decodeServerMessage(payload)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if message.MaxViewers != maxProtocolViewers {
+ t.Fatalf("max viewers = %d, want %d", message.MaxViewers, maxProtocolViewers)
+ }
+}
+
func TestDecodePeerAssistedHostAuthentication(t *testing.T) {
message, err := decodeServerMessage([]byte(validPeerAssistedHostAuthenticated))
if err != nil {
@@ -142,7 +161,7 @@ func TestDecodeOrdinaryHostAuthenticationRejectsInvalidVariants(t *testing.T) {
"wrong-protocol": func(message map[string]any) { message["protocol"] = "screener-v5" },
"missing-max": func(message map[string]any) { delete(message, "maxViewers") },
"zero-max": func(message map[string]any) { message["maxViewers"] = 0 },
- "too-large-max": func(message map[string]any) { message["maxViewers"] = 17 },
+ "too-large-max": func(message map[string]any) { message["maxViewers"] = maxProtocolViewers + 1 },
"missing-endpoint-cap": func(message map[string]any) { delete(message, "endpointMediaCopyCapacity") },
"zero-endpoint-cap": func(message map[string]any) { message["endpointMediaCopyCapacity"] = 0 },
"too-large-endpoint-cap": func(message map[string]any) { message["endpointMediaCopyCapacity"] = 4 },
diff --git a/src/shared/protocol.ts b/src/shared/protocol.ts
index 4d52b265..fd21e93b 100644
--- a/src/shared/protocol.ts
+++ b/src/shared/protocol.ts
@@ -3,7 +3,7 @@ import { z } from "zod";
import { MAX_ENDPOINT_MEDIA_COPY_CAPACITY } from "./media-copy-accounting.js";
import { isCanonicalVideoCodecEvidence } from "./video-codec-evidence.js";
-export const MAX_VIEWERS_PER_ROOM_LIMIT = 16;
+export const MAX_VIEWERS_PER_ROOM_LIMIT = 20;
export const MAX_PARTICIPANTS_PER_ROOM_LIMIT = MAX_VIEWERS_PER_ROOM_LIMIT + 1;
export const MAX_SIGNAL_BYTES = 64 * 1024;
export const SIGNALING_PROTOCOL = "screener-v6";
diff --git a/tests/peer-assisted-benchmark.test.ts b/tests/peer-assisted-benchmark.test.ts
index f0d64435..4b7e9c1d 100644
--- a/tests/peer-assisted-benchmark.test.ts
+++ b/tests/peer-assisted-benchmark.test.ts
@@ -16,6 +16,7 @@ import {
parseViewerCounts,
summarizeSamples,
} from "../scripts/peer-assisted-benchmark";
+import { MAX_VIEWERS_PER_ROOM_LIMIT } from "../src/shared/protocol";
import type {
MediaRouteUpstream,
ParticipantRouteAssignment,
@@ -234,8 +235,14 @@ describe("peer topology loopback configuration", () => {
});
it("accepts the room viewer ceiling and rejects values above it", () => {
- expect(parseViewerCounts("16")).toEqual([16]);
- expect(() => parseViewerCounts("17")).toThrow(/1 to 16/);
+ expect(parseViewerCounts(String(MAX_VIEWERS_PER_ROOM_LIMIT))).toEqual([
+ MAX_VIEWERS_PER_ROOM_LIMIT,
+ ]);
+ expect(() =>
+ parseViewerCounts(String(MAX_VIEWERS_PER_ROOM_LIMIT + 1)),
+ ).toThrow(
+ new RegExp(`1 to ${MAX_VIEWERS_PER_ROOM_LIMIT}`),
+ );
});
it("requires recovery to target one selected case", () => {
diff --git a/tests/protocol.test.ts b/tests/protocol.test.ts
index 16fa78da..152ac785 100644
--- a/tests/protocol.test.ts
+++ b/tests/protocol.test.ts
@@ -861,6 +861,7 @@ describe("server signaling protocol", () => {
}
it("accepts dynamic viewer limits within the protocol boundary", () => {
+ expect(MAX_VIEWERS_PER_ROOM_LIMIT).toBe(20);
expect(serverMessageSchema.safeParse(authenticatedMessage(1)).success).toBe(
true,
);
diff --git a/tests/room-store.test.ts b/tests/room-store.test.ts
index 0554933b..c0b860c6 100644
--- a/tests/room-store.test.ts
+++ b/tests/room-store.test.ts
@@ -181,6 +181,49 @@ describe("RoomStore", () => {
expect(store.maxViewersPerRoom).toBe(2);
});
+ it("admits one Host plus the 20-Viewer room ceiling", () => {
+ const store = new RoomStore({
+ ttlMs: 10_000,
+ maxRooms: 10,
+ maxViewersPerRoom: MAX_VIEWERS_PER_ROOM_LIMIT,
+ });
+ const room = store.createRoom();
+
+ expect(
+ store.connectParticipant({
+ roomId: room.roomId,
+ role: "host",
+ token: room.hostToken,
+ clientId: "host-client",
+ sessionId: "host-session",
+ }).role,
+ ).toBe("host");
+
+ for (let index = 1; index <= MAX_VIEWERS_PER_ROOM_LIMIT; index += 1) {
+ expect(
+ store.connectParticipant({
+ roomId: room.roomId,
+ role: "viewer",
+ viewerGrant: viewerGrant(room),
+ clientId: `viewer-client-${index}`,
+ sessionId: `viewer-session-${index}`,
+ }).role,
+ ).toBe("viewer");
+ }
+
+ expectRoomError(
+ () =>
+ store.connectParticipant({
+ roomId: room.roomId,
+ role: "viewer",
+ viewerGrant: viewerGrant(room),
+ clientId: `viewer-client-${MAX_VIEWERS_PER_ROOM_LIMIT + 1}`,
+ sessionId: `viewer-session-${MAX_VIEWERS_PER_ROOM_LIMIT + 1}`,
+ }),
+ "ROOM_FULL",
+ );
+ });
+
it("allows only the same host identity to replace an online host", () => {
const store = new RoomStore({
ttlMs: 10_000,
diff --git a/tests/server-config.test.ts b/tests/server-config.test.ts
index 40bf9dff..ad250843 100644
--- a/tests/server-config.test.ts
+++ b/tests/server-config.test.ts
@@ -1,5 +1,6 @@
import { describe, expect, it } from "vitest";
+import { MAX_VIEWERS_PER_ROOM_LIMIT } from "../src/shared/protocol.ts";
import { loadConfig } from "../src/server/config.ts";
const liveKitAdmission = {
@@ -319,20 +320,20 @@ describe("server configuration", () => {
);
});
- it("keeps the peer-assisted room default at 8 and accepts explicit 16", () => {
+ it("keeps the peer-assisted room default at 8 and accepts the room ceiling", () => {
expect(
loadConfig({ PEER_ASSISTED_MEDIA: "true" }).maxViewersPerRoom,
).toBe(8);
expect(
loadConfig({
PEER_ASSISTED_MEDIA: "true",
- MAX_VIEWERS_PER_ROOM: "16",
+ MAX_VIEWERS_PER_ROOM: String(MAX_VIEWERS_PER_ROOM_LIMIT),
}).maxViewersPerRoom,
- ).toBe(16);
+ ).toBe(MAX_VIEWERS_PER_ROOM_LIMIT);
expect(() =>
loadConfig({
PEER_ASSISTED_MEDIA: "true",
- MAX_VIEWERS_PER_ROOM: "17",
+ MAX_VIEWERS_PER_ROOM: String(MAX_VIEWERS_PER_ROOM_LIMIT + 1),
}),
).toThrow("MAX_VIEWERS_PER_ROOM");
});
@@ -427,7 +428,7 @@ describe("server configuration", () => {
expect(config.livekitFallback?.url).toBe("wss://livekit.test");
});
- it.each([1, 16])(
+ it.each([1, MAX_VIEWERS_PER_ROOM_LIMIT])(
"accepts a per-room viewer limit at boundary %i",
(maxViewersPerRoom) => {
expect(
@@ -437,7 +438,7 @@ describe("server configuration", () => {
},
);
- it.each(["0", "17", "1.5"])(
+ it.each(["0", String(MAX_VIEWERS_PER_ROOM_LIMIT + 1), "1.5"])(
"rejects invalid per-room viewer limit %s",
(maxViewersPerRoom) => {
expect(() =>
diff --git a/tests/server-http.test.ts b/tests/server-http.test.ts
index 49f965b2..3f78f50f 100644
--- a/tests/server-http.test.ts
+++ b/tests/server-http.test.ts
@@ -4,7 +4,10 @@ import { join } from "node:path";
import { afterEach, describe, expect, it, vi } from "vitest";
-import { createRoomResponseSchema } from "../src/shared/protocol.ts";
+import {
+ MAX_VIEWERS_PER_ROOM_LIMIT,
+ createRoomResponseSchema,
+} from "../src/shared/protocol.ts";
import {
createScreenerServer,
type CreateServerOptions,
@@ -287,6 +290,20 @@ describe("room HTTP API", () => {
expect("iceConfig" in body).toBe(false);
});
+ it("passes the shared Viewer ceiling to room admission", async () => {
+ const baseUrl = await start(
+ testConfig({
+ siteAccessPassword: undefined,
+ maxViewersPerRoom: MAX_VIEWERS_PER_ROOM_LIMIT,
+ }),
+ );
+
+ expect((await createRoom(baseUrl)).status).toBe(201);
+ expect(runningServer?.roomStore.maxViewersPerRoom).toBe(
+ MAX_VIEWERS_PER_ROOM_LIMIT,
+ );
+ });
+
it("accepts only the admitted fixed provisional Host lease", async () => {
const baseUrl = await start();
expect((await createRoom(baseUrl, undefined, "private-link", 300)).status).toBe(