279 lines
17 KiB
JavaScript
279 lines
17 KiB
JavaScript
// REFERENCE-ONLY scenario driver for the official TeamSpeak 6 UI (QA harness, never shipped).
|
|
// Navigation uses the official app controller and DOM clicks on official components; synthetic
|
|
// server state enters only through the fixture bridge events the official code subscribes to.
|
|
(() => {
|
|
'use strict';
|
|
const f = window.__tsReferenceFixture;
|
|
const sleep = ms => new Promise(r => setTimeout(r, ms));
|
|
const until = async (fn, what, ms = 15000) => {
|
|
const end = Date.now() + ms;
|
|
for (;;) {
|
|
const v = fn();
|
|
if (v) return v;
|
|
if (Date.now() > end) throw new Error(`Reference scenario timed out waiting for ${what}`);
|
|
await sleep(50);
|
|
}
|
|
};
|
|
const root = () => document.querySelector('.tsv-window')?.__vue__?.$root;
|
|
const controller = () => root()?.appController;
|
|
const handler = () => root()._vm.tsapi.server_connection_handlers[0];
|
|
|
|
const SETTINGS = ['account', 'identities', 'privacy', 'appearance', 'audio', 'video', 'keybinds', 'chats', 'whispers', 'notifications', 'filetransfer', 'os', 'remoteapps', 'about'];
|
|
|
|
// ---- Synthetic reference server (connection handler 1). Names are neutral fixture data. ----
|
|
const SC = 1;
|
|
const OWN = 1;
|
|
const MOVE = { Subscription: 0, Move: 1, Moved: 2, Timeout: 3 };
|
|
const VIS = { Enter: 0, Retain: 1, Leave: 2 };
|
|
const STATUS = { Disconnected: 0, Connecting: 1, Connected: 2, ConnectionEstablishing: 3, ConnectionEstablished: 4 };
|
|
// Channel properties replace the official defaults wholesale, so every field of the official
|
|
// channel property class is present.
|
|
const CHANNEL_DEFAULTS = { name: '', topic: '', description: '', password: '', codec: 4, codecQuality: 6, maxclients: -1, maxfamilyclients: -1, order: '0', flagPermanent: true, flagSemiPermanent: false, flagDefault: false, flagPassword: false, codecLatencyFactor: 1, codecIsUnencrypted: false, deleteDelay: 0, flagMaxclientsUnlimited: true, flagMaxfamilyclientsUnlimited: true, flagMaxfamilyclientsInherited: false, flagAreSubscribed: true, neededTalkPower: 0, forcedSilence: false, namePhonetic: '', iconId: 0, bannerGfxUrl: '', bannerMode: 0, permissionHints: -1, uniqueIdentifier: '', storageQuota: -1 };
|
|
const channel = (id, name, order, extra = {}) => ({ id: String(id), parentId: '0', properties: { ...CHANNEL_DEFAULTS, name, order: String(order), uniqueIdentifier: `reference-channel-${id}`, ...extra } });
|
|
const scenario = {
|
|
server: { name: 'Reference Server', uid: 'cmVmZXJlbmNlLXNlcnZlci0x' },
|
|
channels: [
|
|
channel(1, 'Lobby', 0, { flagDefault: true }),
|
|
channel(2, 'cs', 1),
|
|
channel(3, 'Gaming', 2),
|
|
channel(4, 'Music', 3),
|
|
channel(5, 'AFK', 4),
|
|
],
|
|
clients: [
|
|
{ id: OWN, channel: '2', nickname: 'Reference User' },
|
|
{ id: 2, channel: '2', nickname: 'Alex' },
|
|
{ id: 3, channel: '2', nickname: 'Mira' },
|
|
{ id: 4, channel: '3', nickname: 'Sam' },
|
|
{ id: 5, channel: '5', nickname: 'Robin' },
|
|
],
|
|
};
|
|
const uid = id => btoa(`reference-client-${id}`);
|
|
const clientProps = c => ({ nickname: c.nickname, uniqueIdentifier: uid(c.id), databaseId: String(c.id + 10), channelGroupId: '8', serverGroups: '7', talkPower: 0, platform: 'Windows', version: '6.0.0', inputHardware: true, outputHardware: true });
|
|
// capabilityExtensions: HTTP file transfer + P2P/SFU streaming (TS6 server features the bundle
|
|
// checks); no MATRIXCHAT, so the channel chat is the classic server chat.
|
|
const serverProps = () => ({ name: scenario.server.name, uniqueIdentifier: scenario.server.uid, welcomeMessage: '', platform: 'Linux', version: '6.0.0', maxClients: 32, clientsOnline: scenario.clients.length, channelsOnline: scenario.channels.length, hostMessage: '', hostMessageMode: 0, defaultServerGroup: '7', defaultChannelGroup: '8', id: '1', nickname: scenario.server.name, canonicalName: scenario.server.name, capabilityExtensions: 'HTTPFT,STREAM_P2P,STREAM_SFU' });
|
|
const group = (id, name, sortId) => ({ id: String(id), name, nameMode: 0, iconId: 0, sortId, saveDb: true, type: 1, neededMemberAddPower: 0, neededMemberRemovePower: 0, neededModifyPower: 0 });
|
|
const GROUPS = {
|
|
0: [group(6, 'Server Admin', 10), group(7, 'Normal', 20), group(8, 'Guest', 30)],
|
|
1: [group(5, 'Channel Admin', 10), group(6, 'Operator', 20), group(8, 'Guest', 30)],
|
|
};
|
|
const emit = (event, payload) => f.emit(event, { connectionId: SC, hotReload: false, ...payload });
|
|
|
|
// Classic channel chat history of the own channel (official message_type: 1 text, 3 joined,
|
|
// 4 left; event content is the JSON the official chat stores). Variant via cfg.chat:
|
|
// 'full' (overflows the viewport), 'few' (bottom-aligned short history) or 'empty'.
|
|
const T0 = new Date(2026, 9, 31, 16, 23).getTime();
|
|
const MT = { TextMessage: 1, ChannelJoined: 3, ChannelLeft: 4 };
|
|
const invoker = id => ({ uid: uid(id), nickname: scenario.clients.find(c => c.id === id)?.nickname ?? 'Admin', id });
|
|
const ev = (min, who, type, eventType, channelId, by) => ({ min, sender: who, message_type: type, content: JSON.stringify({ displayName: scenario.clients.find(c => c.id === who).nickname, associated_channel_id: channelId, eventType, invoker: by ? invoker(by) : undefined, reason: '' }) });
|
|
const text = (min, who, content) => ({ min, sender: who, message_type: MT.TextMessage, content });
|
|
const ROUND = [
|
|
ev(0, 2, MT.ChannelJoined, MOVE.Moved, '3', 3), ev(0, 2, MT.ChannelLeft, MOVE.Move, '3'), ev(1, 4, MT.ChannelJoined, MOVE.Moved, '1', 3),
|
|
ev(1, 4, MT.ChannelLeft, MOVE.Moved, '4', 3), ev(2, 5, MT.ChannelLeft, MOVE.Move, '0'), text(4, 3, 'Anyone up for a match tonight?'),
|
|
text(5, 2, 'Sure, after 8'), ev(6, 4, MT.ChannelLeft, MOVE.Move, '0'), ev(15, 5, MT.ChannelJoined, MOVE.Move, '3'),
|
|
ev(15, 3, MT.ChannelJoined, MOVE.Move, '3'), ev(28, 5, MT.ChannelLeft, MOVE.Timeout, '0'), text(29, OWN, 'Back in five'),
|
|
ev(30, 5, MT.ChannelJoined, MOVE.Move, '1'),
|
|
];
|
|
const HISTORY = {
|
|
full: [0, 1, 2].flatMap(round => ROUND.map(m => ({ ...m, min: m.min + round * 45 }))),
|
|
few: [text(2, 4, 'Server restarts at midnight'), ev(3, 2, MT.ChannelJoined, MOVE.Move, '1'), text(4, OWN, 'Thanks!')],
|
|
empty: [],
|
|
};
|
|
f.chatHistory = channelId => (channelId === '2' ? HISTORY[f.cfg.chat || 'full'] : []).map((m, i) => ({
|
|
id: i + 1, content: m.content, sender_uuid: uid(m.sender), sender_name: scenario.clients.find(c => c.id === m.sender).nickname,
|
|
timestamp: T0 + m.min * 60000, message_type: m.message_type,
|
|
}));
|
|
|
|
// Permission catalogue: the names the installed bundle itself knows (permission.all.* locale keys),
|
|
// with synthetic sequential ids. The reference own client is granted all of them (admin view), so
|
|
// every official action/menu entry renders.
|
|
async function permissions() {
|
|
const en = await (await fetch('tsui://default/locales/en.json')).json();
|
|
const names = Object.keys(en).filter(k => k.startsWith('permission.all.')).map(k => k.slice('permission.all.'.length));
|
|
const data = names.map((name, i) => ({ id: i + 1, name, description: en[`permission.all.${name}`] }));
|
|
const needed = {};
|
|
for (const p of data) needed[p.id] = p.name.startsWith('b_') ? 1 : 100;
|
|
return { data, needed };
|
|
}
|
|
|
|
async function connect() {
|
|
if (f.connected) return;
|
|
const perms = await permissions();
|
|
emit('connectStatusChanged', { status: STATUS.Connecting, error: 0, info: {} });
|
|
emit('connectStatusChanged', { status: STATUS.Connected, error: 0, info: { serverUid: scenario.server.uid, legacyUUID: scenario.server.uid, clientId: OWN } });
|
|
emit('connectStatusChanged', { status: STATUS.ConnectionEstablishing, error: 0, info: {} });
|
|
emit('serverPropertiesUpdated', { properties: serverProps() });
|
|
emit('permissionList', { data: perms.data, groupEndIds: [] });
|
|
emit('neededPermissions', { data: perms.needed });
|
|
emit('groupInfo', { type: 0, data: GROUPS[0] });
|
|
emit('groupInfo', { type: 1, data: GROUPS[1] });
|
|
emit('channels', { info: { rootChannels: scenario.channels, subChannels: {} } });
|
|
for (const c of scenario.clients) {
|
|
emit('clientMoved', { clientId: c.id, type: MOVE.Subscription, oldChannelId: '0', newChannelId: c.channel, visibility: VIS.Enter, properties: clientProps(c), invoker: null, message: '', time: 0 });
|
|
}
|
|
emit('connectStatusChanged', { status: STATUS.ConnectionEstablished, error: 0, info: {} });
|
|
f.connected = true;
|
|
await sleep(300);
|
|
}
|
|
f.scenario = scenario;
|
|
f.connect = connect;
|
|
// Canonical synthetic data (server, channels, clients with full properties, groups, own-channel
|
|
// history per chat variant with fixed timestamps) for product captures to reuse verbatim.
|
|
f.fixtureData = () => ({
|
|
referenceOnly: true,
|
|
epochNote: 'timestamps are ms since epoch computed from local 2026-10-31 16:23 (T0) + minute offsets',
|
|
server: { ...scenario.server, properties: serverProps() },
|
|
ownClientId: OWN,
|
|
channels: scenario.channels,
|
|
clients: scenario.clients.map(c => ({ id: c.id, channelId: c.channel, properties: clientProps(c) })),
|
|
groups: { server: GROUPS[0], channel: GROUPS[1] },
|
|
chat: Object.fromEntries(Object.keys(HISTORY).map(variant => [variant, HISTORY[variant].map((m, i) => ({
|
|
id: i + 1, senderId: m.sender, sender_name: scenario.clients.find(c => c.id === m.sender).nickname,
|
|
timestamp: T0 + m.min * 60000, iso: new Date(T0 + m.min * 60000).toISOString(), message_type: m.message_type, content: m.content,
|
|
}))])),
|
|
});
|
|
|
|
const screens = {
|
|
async dashboard() {
|
|
const ac = controller();
|
|
ac.showItem(ac.dashboard ?? ac.home);
|
|
return { route: location.hash };
|
|
},
|
|
// Server activity (tree in the main pane, server info in the detail pane).
|
|
async server() {
|
|
const ac = controller();
|
|
ac.showItem(handler());
|
|
await until(() => document.querySelector('.ts-server-tree-item-leaf'), 'server tree');
|
|
return { route: location.hash };
|
|
},
|
|
// Official classic channel view of the own channel in Chat content mode.
|
|
async main() {
|
|
await screens.server();
|
|
const ac = controller();
|
|
ac.showItem(handler().ownClient.channel, 'Chat');
|
|
await until(() => location.hash.includes('Chat'), 'channel chat route');
|
|
await sleep(800);
|
|
return { route: location.hash, chat: f.cfg.chat || 'full' };
|
|
},
|
|
// Official client context menu (right click on a tree client row).
|
|
async menu(nickname = 'Alex') {
|
|
await screens.main();
|
|
// Dismiss a menu left open by a previous screen the way a user would (Escape, outside click).
|
|
if (document.querySelector('.ts-context-menu')?.children.length) {
|
|
document.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape', code: 'Escape', bubbles: true }));
|
|
document.body.dispatchEvent(new MouseEvent('mousedown', { bubbles: true, clientX: 5, clientY: 990 }));
|
|
document.body.dispatchEvent(new MouseEvent('click', { bubbles: true, clientX: 5, clientY: 990 }));
|
|
await until(() => !document.querySelector('.ts-context-menu')?.children.length, 'previous context menu closed', 3000);
|
|
}
|
|
const row = [...document.querySelectorAll('.ts-server-tree-item-leaf')].find(e => e.textContent.trim() === nickname);
|
|
if (!row) throw new Error(`Tree client ${nickname} not found`);
|
|
const target = row.querySelector('.ts-server-tree-item-node-content') || row;
|
|
const r = target.getBoundingClientRect();
|
|
const at = { bubbles: true, cancelable: true, view: window, button: 2, buttons: 2, clientX: r.x + 40, clientY: r.y + r.height / 2 };
|
|
target.dispatchEvent(new MouseEvent('mousedown', at));
|
|
target.dispatchEvent(new MouseEvent('mouseup', at));
|
|
target.dispatchEvent(new MouseEvent('contextmenu', at));
|
|
await until(() => document.querySelector('.ts-context-menu')?.children.length, 'official context menu', 4000);
|
|
return { route: location.hash, target: nickname };
|
|
},
|
|
// Official broadcast (stream) setup modal, opened from the server status bar "Start Stream"
|
|
// constructive button. Step 'settings': clicks the first synthetic application source (the
|
|
// official selectSource; its native preview request stays unanswered, nothing is captured) and
|
|
// then opens the official settings pane by setting the modal's own `settingsOpen` state, because
|
|
// the official Next button stays disabled without preview frames.
|
|
async broadcast(step = 'source') {
|
|
await screens.main();
|
|
const label = root().$t('video.action.start_stream');
|
|
const button = [...document.querySelectorAll('.ts-server-status-constructive-buttons:not(.ts-hidden) .tsv-tool-button')].find(e => e.textContent.trim() === label);
|
|
if (!button) throw new Error('Official Start Stream button not found');
|
|
button.click();
|
|
await until(() => document.querySelector('.ts-setup-stream.loaded'), 'official setup-stream modal with sources');
|
|
await sleep(400);
|
|
if (step === 'settings') {
|
|
document.querySelector('[data-video-type="windows"]').click();
|
|
await sleep(300);
|
|
let el = document.querySelector('.ts-setup-stream');
|
|
while (el && el.__vue__?.$options.name !== 'ts-setup-stream-modal') el = el.parentElement;
|
|
if (!el) throw new Error('ts-setup-stream-modal instance not found');
|
|
el.__vue__.settingsOpen = true;
|
|
await sleep(600);
|
|
}
|
|
return { route: location.hash, step, driven: step === 'settings' ? 'ts-setup-stream-modal.settingsOpen=true after official selectSource click' : 'official Start Stream click' };
|
|
},
|
|
// Official context-menu action: spec '<tree row text>><i18n key>', e.g. 'cs>universal.edit'
|
|
// opens the official channel edit form; the label is resolved with the bundle's own $t.
|
|
async act(spec = 'cs>universal.edit') {
|
|
const [row, key] = spec.split('>');
|
|
await screens.menu(row);
|
|
const label = root().$t(key);
|
|
const item = [...document.querySelectorAll('.ts-context-menu *')].find(e => e.children.length === 0 && e.textContent.trim() === label);
|
|
if (!item) throw new Error(`Context menu item ${key} (${label}) not found on ${row}`);
|
|
item.click();
|
|
await sleep(1200);
|
|
return { route: location.hash, row, action: key };
|
|
},
|
|
// Official item views through appController.showItem(item, mode), the call the bundle itself
|
|
// uses: spec '<target>.<Mode>', target = server | channel-<id> | client-<nickname>, Mode = Info |
|
|
// Chat | ChannelFiles | Permissions | ClientList | BanList | PrivKeys | TempPws | ServerIcons |
|
|
// ServerSnapshot. Edit forms are reached through the official context menu (act screen).
|
|
async view(spec = 'server.Info') {
|
|
await screens.server();
|
|
const [target, mode = 'Info'] = spec.split('.');
|
|
const h = handler();
|
|
const item = target === 'server' ? h
|
|
: target.startsWith('channel-') ? h.FindChannel(target.slice(8))
|
|
: target.startsWith('client-') ? [...h.clients.values()].find(c => c.properties.nickname === target.slice(7)) : null;
|
|
if (!item) throw new Error(`Unknown view target ${target}`);
|
|
controller().showItem(item, mode);
|
|
await sleep(1200);
|
|
return { route: location.hash, target, mode };
|
|
},
|
|
// spec '<category>[~bottom]': '~bottom' scrolls the official settings page's own scroll
|
|
// container(s) to the end so the lower sections (e.g. Audio Processing) are visible.
|
|
async settings(spec = 'account') {
|
|
const [category, position] = spec.split('~');
|
|
const ac = controller();
|
|
if (!document.querySelector('.tsv-settings-categories')) ac.showItem(ac.settings);
|
|
const items = await until(() => {
|
|
const list = document.querySelectorAll('.tsv-settings-categories .tsv-item');
|
|
return list.length >= SETTINGS.length ? list : null;
|
|
}, 'settings categories');
|
|
const index = SETTINGS.indexOf(category);
|
|
if (index < 0) throw new Error(`Unknown settings category ${category}`);
|
|
items[index].click();
|
|
await until(() => items[index].matches('.selected, .tsv-selected, [aria-selected="true"]') || items[index].className.includes('select'), `settings ${category} selected`, 3000).catch(() => {});
|
|
await sleep(800);
|
|
let scrolled = 0;
|
|
if (position === 'bottom') {
|
|
const listRight = document.querySelector('.tsv-settings-categories').getBoundingClientRect().right;
|
|
for (const el of document.querySelectorAll('*')) {
|
|
const cs = getComputedStyle(el);
|
|
if (el.scrollHeight > el.clientHeight + 10 && /auto|scroll/.test(cs.overflowY) && el.getBoundingClientRect().left >= listRight - 1) {
|
|
el.scrollTop = el.scrollHeight;
|
|
scrolled++;
|
|
}
|
|
}
|
|
await sleep(500);
|
|
}
|
|
return { route: location.hash, category, position: position ?? 'top', scrolledContainers: scrolled, label: items[index].innerText.trim() };
|
|
},
|
|
};
|
|
|
|
f.open = async screen => {
|
|
const [name, arg] = String(screen).split(':');
|
|
const fn = screens[name];
|
|
if (!fn) throw new Error(`Unknown reference screen ${screen}; known: ${Object.keys(screens).join(', ')}`);
|
|
const result = await fn(arg);
|
|
await sleep(300);
|
|
return { screen, ...result };
|
|
};
|
|
f.screens = screens;
|
|
|
|
(async () => {
|
|
await until(() => controller() && document.querySelector('.tsv-sidebar'), 'official shell');
|
|
await sleep(500);
|
|
if (f.cfg.scenario === 'connected') await connect();
|
|
f.ready = true;
|
|
})().catch(e => { f.readyError = String(e); });
|
|
})();
|