mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-03 12:02:50 +08:00
fix: consolidate audited dev updates
This commit is contained in:
1 parent
568b8fd8be
commit
0a552f7ee8
58 files changed
+1930
-132
No files matched your search
@@ -1,5 +1,6 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
import { DatabaseSync } from "node:sqlite";
|
||||
import { mkdtempSync, rmSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { dirname, join, resolve } from "node:path";
|
||||
@@ -14,6 +15,27 @@ import { adminResponses } from "../../src/shared/admin-responses.js";
|
||||
|
||||
const logger: Logger = { debug() {}, info() {}, warn() {}, error() {}, child() { return this; } };
|
||||
|
||||
test("schema 7 upgrades preserve the previously unused public host and initialize ICE defaults", t => {
|
||||
const directory = mkdtempSync(join(tmpdir(), "webspeak-ice-migration-"));
|
||||
const filename = join(directory, "test.db");
|
||||
const original = new WebSpeakDatabase(filename);
|
||||
original.close();
|
||||
const legacy = new DatabaseSync(filename);
|
||||
legacy.exec("ALTER TABLE settings DROP COLUMN webrtc_ipv6_enabled; ALTER TABLE settings DROP COLUMN webrtc_stun_server; PRAGMA user_version = 7;");
|
||||
legacy.prepare("UPDATE settings SET webrtc_public_host = ?").run("media.example.com");
|
||||
legacy.close();
|
||||
const migrated = new WebSpeakDatabase(filename);
|
||||
t.after(() => {
|
||||
migrated.close();
|
||||
assert.equal(dirname(resolve(directory)), resolve(tmpdir()));
|
||||
assert.ok(directory.includes("webspeak-ice-migration-"));
|
||||
rmSync(directory, { recursive: true, force: true });
|
||||
});
|
||||
assert.equal(migrated.getSettings().webRtcPublicHost, "media.example.com");
|
||||
assert.equal(migrated.getSettings().webRtcIpv6Enabled, false);
|
||||
assert.equal(migrated.getSettings().webRtcStunServer, "");
|
||||
});
|
||||
|
||||
test("browser admin API consumes the actual HTTP router and preserves keep/replace/remove secrets", async t => {
|
||||
const directory = mkdtempSync(join(tmpdir(), "webspeak-admin-api-"));
|
||||
const database = new WebSpeakDatabase(join(directory, "test.db"));
|
||||
@@ -51,6 +73,27 @@ test("browser admin API consumes the actual HTTP router and preserves keep/repla
|
||||
assert.equal((await api.session()).authenticated, true);
|
||||
assert.equal((await api.overview()).gateway.version, "test-version");
|
||||
const original = await api.settings();
|
||||
assert.equal(original.webRtcPublicHost, "");
|
||||
assert.equal(original.webRtcIpv6Enabled, false);
|
||||
assert.equal(original.webRtcStunServer, "");
|
||||
const network = { webRtcPublicHost: " MEDIA.example.com ", webRtcIpv6Enabled: true, webRtcStunServer: "stun:stun.example.com" };
|
||||
const updated = await api.saveSettings({ ...original, ...network });
|
||||
assert.equal(updated.settings.webRtcPublicHost, "media.example.com");
|
||||
assert.equal(updated.settings.webRtcStunServer, "stun:stun.example.com:3478");
|
||||
assert.deepEqual(service.getWebRtcAudioOptions(), { enabled: false, publicHost: "media.example.com", ipv6Enabled: true, stunServer: "stun:stun.example.com:3478", udpPortRange: [40000, 40099] });
|
||||
const { webRtcPublicHost, webRtcIpv6Enabled, webRtcStunServer, ...legacyInput } = original;
|
||||
await api.saveSettings(legacyInput);
|
||||
assert.equal((await api.settings()).webRtcPublicHost, "media.example.com", "older clients must preserve the new settings");
|
||||
for (const [key, value, code] of [
|
||||
["webRtcPublicHost", "https://media.example.com", "INVALID_WEBRTC_PUBLIC_HOST"],
|
||||
["webRtcPublicHost", null, "INVALID_WEBRTC_PUBLIC_HOST"],
|
||||
["webRtcStunServer", "turn:user:password@example.com", "INVALID_WEBRTC_STUN_SERVER"],
|
||||
["webRtcStunServer", [], "INVALID_WEBRTC_STUN_SERVER"],
|
||||
["webRtcIpv6Enabled", "true", "INVALID_WEBRTC_IPV6"],
|
||||
] as const) {
|
||||
await assert.rejects(api.saveSettings({ ...original, [key]: value } as never), (error: any) => error.code === code);
|
||||
assert.equal(database.getSettings().webRtcIpv6Enabled, true, "rejected updates must not change stored settings");
|
||||
}
|
||||
for (const passwordAction of ["replace", "keep", "remove"] as const) {
|
||||
const body = {
|
||||
...original, passwordAction, ...(passwordAction === "replace" ? { serverPassword: "test-server-password" } : {}),
|
||||
|
||||
@@ -176,6 +176,30 @@ test("a successful settings save clears submitted secrets and updates their stor
|
||||
assert.equal(state.errorMessage, "");
|
||||
});
|
||||
|
||||
test("ICE settings load, submit and preserve edits made during a pending save", async () => {
|
||||
await mount();
|
||||
const network = { webRtcPublicHost: "media.example.com", webRtcIpv6Enabled: true, webRtcStunServer: "stun:stun.example.com:3478" };
|
||||
handler = path => Promise.resolve(json(path === "/server" ? settings(network) : defaults(path)));
|
||||
await serverModel.loadServerSettings();
|
||||
for (const [key, value] of Object.entries(network)) assert.equal(serverModel.serverForm[key], value);
|
||||
const save = deferred();
|
||||
handler = (path, init) => {
|
||||
if (path !== "/server" || init.method !== "PUT") return Promise.resolve(json(defaults(path)));
|
||||
const submitted = JSON.parse(init.body);
|
||||
for (const [key, value] of Object.entries(network)) assert.equal(submitted[key], value);
|
||||
return save.promise;
|
||||
};
|
||||
const pending = serverModel.saveServerSettings();
|
||||
serverModel.serverForm.webRtcPublicHost = "new-media.example.com";
|
||||
serverModel.serverForm.webRtcIpv6Enabled = false;
|
||||
serverModel.serverForm.webRtcStunServer = "";
|
||||
save.resolve(json({ ok: true, settings: settings(network) }));
|
||||
await pending;
|
||||
assert.equal(serverModel.serverForm.webRtcPublicHost, "new-media.example.com");
|
||||
assert.equal(serverModel.serverForm.webRtcIpv6Enabled, false);
|
||||
assert.equal(serverModel.serverForm.webRtcStunServer, "");
|
||||
});
|
||||
|
||||
test("settings saves preserve relay edits, removals and additions made while awaiting the server", async () => {
|
||||
await mount();
|
||||
serverModel.addRelayNode(); serverModel.addRelayNode();
|
||||
|
||||
@@ -192,10 +192,12 @@ test("normal initialization uses the instance default and cached custom content"
|
||||
const item = { ...skin("sample.a"), author: "test", license: "MIT", contentData: { title: "custom" } };
|
||||
installed.set(item.id, item);
|
||||
handler = async () => json({ skins: [item], defaultSkinId: item.id });
|
||||
const view = page({ timeoutMs: 1_000 }); await view.initialize();
|
||||
const themeMode = ref("system");
|
||||
const view = page({ timeoutMs: 1_000, themeMode }); await view.initialize();
|
||||
assert.equal(view.skinReady.value, true);
|
||||
assert.equal(view.activeSkinId.value, item.id);
|
||||
assert.deepEqual(view.activeSkin.value.contentData, item.contentData);
|
||||
assert.equal(themeMode.value, "system", "initializing a default custom skin must not override the saved system theme");
|
||||
assert.equal(storage.has("webspeak:skin-choice"), false);
|
||||
assert.equal(root.dataset.wsSkin, item.id);
|
||||
});
|
||||
|
||||
@@ -129,7 +129,7 @@ class TestPeer extends EventTarget {
|
||||
localDescription = null;
|
||||
remoteDescription = null;
|
||||
sender = { track: null, replaceTrack: async track => { this.sender.track = track; } };
|
||||
constructor() { super(); TestPeer.instances.push(this); }
|
||||
constructor(config) { super(); this.config = config; TestPeer.instances.push(this); }
|
||||
addTrack(track) { this.sender.track = track; }
|
||||
getSenders() { return [this.sender]; }
|
||||
async createOffer() { return { type: "offer", sdp: "test-offer" }; }
|
||||
@@ -355,7 +355,7 @@ function chatView(t, overrides = {}) {
|
||||
messages: voice.chatMessages, members: voice.members,
|
||||
currentChannel: ref({ id: "1", parentID: "0", name: "Lobby" }), currentChannelName: ref("Lobby"),
|
||||
selectedChannelId: ref("1"), clientId: computed(() => voice.state.tsClientId),
|
||||
connected: computed(() => voice.state.connected), sessionEpoch: voice.sessionEpoch,
|
||||
connected: computed(() => voice.state.connected), sessionEpoch: voice.sessionEpoch, serverKey: ref("example.test:9987"),
|
||||
memberConversationKey: id => voice.memberConversationKey(id),
|
||||
isMobileViewport: ref(false), mobileSection: ref("chat"), closeMemberMenu() {}, notifyPrivateMessage() {},
|
||||
sendTextMessage: voice.sendTextMessage, sendServerMessage: voice.sendServerMessage, sendPrivateMessage: voice.sendPrivateMessage,
|
||||
@@ -363,6 +363,74 @@ function chatView(t, overrides = {}) {
|
||||
}));
|
||||
}
|
||||
|
||||
function chatScroller(chat) {
|
||||
const calls = [];
|
||||
chat.listElement.value = {
|
||||
scrollHeight: 1200, clientHeight: 400, scrollTop: 800,
|
||||
scrollTo(options) { calls.push(options); this.scrollTop = this.scrollHeight - this.clientHeight; },
|
||||
};
|
||||
return calls;
|
||||
}
|
||||
|
||||
test("incoming chat preserves history reading and follows again when the reader returns to the bottom", async t => {
|
||||
const chat = chatView(t);
|
||||
const calls = chatScroller(chat);
|
||||
chat.listElement.value.scrollTop = 100;
|
||||
chat.onScroll();
|
||||
voice.chatMessages.push({ id: "incoming-1", scope: "channel", message: "Hello", timestamp: 1 });
|
||||
await nextTick();
|
||||
await nextTick();
|
||||
assert.equal(calls.length, 0);
|
||||
chat.scrollIfFollowing(); // Keyboard resizing must also preserve the reading position.
|
||||
await nextTick();
|
||||
assert.equal(calls.length, 0);
|
||||
chat.listElement.value.scrollTop = 800;
|
||||
chat.onScroll();
|
||||
voice.chatMessages.push({ id: "incoming-2", scope: "channel", message: "Latest", timestamp: 2 });
|
||||
await nextTick();
|
||||
await nextTick();
|
||||
assert.deepEqual(calls, [{ top: 1200, behavior: "auto" }]);
|
||||
});
|
||||
|
||||
test("own messages and conversation switches reveal the latest message, unrelated chat does not move the list", async t => {
|
||||
const chat = chatView(t);
|
||||
const calls = chatScroller(chat);
|
||||
chat.listElement.value.scrollTop = 100;
|
||||
chat.onScroll();
|
||||
voice.chatMessages.push({ id: "elsewhere", scope: "server", message: "Other conversation", timestamp: 1 });
|
||||
await nextTick();
|
||||
await nextTick();
|
||||
assert.equal(calls.length, 0);
|
||||
voice.chatMessages.push({ id: "own", scope: "channel", message: "Sent", timestamp: 2, isSelf: true });
|
||||
await nextTick();
|
||||
await nextTick();
|
||||
assert.equal(calls.length, 1);
|
||||
chat.listElement.value.scrollTop = 100;
|
||||
chat.onScroll();
|
||||
chat.tab.value = "server";
|
||||
await nextTick();
|
||||
await nextTick();
|
||||
assert.ok(calls.length > 1);
|
||||
assert.equal(chat.listElement.value.scrollTop, 800);
|
||||
});
|
||||
|
||||
test("hidden mobile chat defers scrolling until shown and ignores zero-height scroll events", async t => {
|
||||
const section = ref("voice");
|
||||
const chat = chatView(t, { isMobileViewport: ref(true), mobileSection: section });
|
||||
const calls = chatScroller(chat);
|
||||
chat.listElement.value.clientHeight = 0;
|
||||
chat.onScroll();
|
||||
voice.chatMessages.push({ id: "mobile", scope: "channel", message: "Hello", timestamp: 1 });
|
||||
await nextTick();
|
||||
await nextTick();
|
||||
assert.equal(calls.length, 0);
|
||||
chat.listElement.value.clientHeight = 400;
|
||||
section.value = "chat";
|
||||
await nextTick();
|
||||
await nextTick();
|
||||
assert.equal(calls.length, 1);
|
||||
});
|
||||
|
||||
test("chat cannot create a local success while disconnected or recovering", async () => {
|
||||
await assert.rejects(async () => voice.sendServerMessage("Offline"));
|
||||
assert.equal(voice.chatMessages.length, 0);
|
||||
@@ -2361,3 +2429,16 @@ test("disconnect while initial device labels load still cancels microphone readi
|
||||
await assert.rejects(readiness, error => error.name === "AbortError");
|
||||
assert.equal(voice.state.microphoneErrorCode, "");
|
||||
});
|
||||
|
||||
|
||||
test("voice STUN configuration reaches the browser peer and resets on a legacy connection", async () => {
|
||||
let socket = await connect();
|
||||
socket.receive({ type: "connected", tsClientId: 1, webrtcAvailable: true, webRtcStunServer: "stun:stun.example.com:3478" });
|
||||
await nextTurn();
|
||||
assert.deepEqual(TestPeer.instances.at(-1).config.iceServers, [{ urls: "stun:stun.example.com:3478" }]);
|
||||
voice.disconnect();
|
||||
socket = await connect();
|
||||
socket.receive({ type: "connected", tsClientId: 2, webrtcAvailable: true });
|
||||
await nextTurn();
|
||||
assert.deepEqual(TestPeer.instances.at(-1).config.iceServers, []);
|
||||
});
|
||||
Reference in new issue
Block a user