Preserve accumulated client implementation since v0.1.4, including local identities, multi-server state, chat, administration, audio and streaming controls. Refine official-source layout, original artwork, responsive composer overflow, settings navigation and chat scroll anchoring. Current verification: Node suite passes; isolated packaged chat and responsive control smokes pass without device capture. Native core is reused, not rebuilt in this pass. Strict whole-screen visual parity remains incomplete; no 1:1 or cross-platform acceptance claim. Local checkpoint only; no release or push.
72 lines
4.4 KiB
JavaScript
72 lines
4.4 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { StreamDirectory, channelOffers } from '../app/renderer/js/stream/directory.js';
|
|
|
|
test('notifystreaminfo with id registers a stream; return_code-only replies are ignored', () => {
|
|
const d = new StreamDirectory();
|
|
assert.equal(d.handle('notifystreaminfo', [{ return_code: '1' }]), false);
|
|
assert.equal(d.handle('notifystreaminfo', [{ id: 'c4', clid: '16', name: '\u042d\u043a\u0440\u0430\u043d 1', audio: '0', mode: '1', return_code: '2' }]), true);
|
|
assert.equal(d.byClient(16).name, '\u042d\u043a\u0440\u0430\u043d 1');
|
|
assert.equal(d.get('c4').fields.audio, '0');
|
|
});
|
|
|
|
test('updates merge fields, stop removes, prune drops absent clients', () => {
|
|
const d = new StreamDirectory();
|
|
d.handle('notifystreamstarted', [{ id: 'a', clid: '5', name: 'one' }, { id: 'b', clid: '6', name: 'two' }]);
|
|
d.handle('notifystreamupdated', [{ id: 'a', name: 'renamed' }]);
|
|
assert.equal(d.get('a').name, 'renamed');
|
|
assert.equal(d.get('a').clientId, 5);
|
|
assert.equal(d.handle('notifystreamupdated', [{ id: 'zzz', name: 'x' }]), false, 'updates never create');
|
|
d.handle('notifystreamstopped', [{ id: 'a' }]);
|
|
assert.equal(d.get('a'), null);
|
|
assert.equal(d.prune(new Set([1, 2])), true);
|
|
assert.equal(d.streams.size, 0);
|
|
});
|
|
|
|
test('stop by clid only (requeststreaminfo error) removes that client stream', () => {
|
|
const d = new StreamDirectory();
|
|
d.handle('notifystreaminfo', [{ id: 'a', clid: '5' }]);
|
|
assert.equal(d.handle('notifystreamstopped', [{ clid: '5' }]), true);
|
|
assert.equal(d.byClient(5), null);
|
|
});
|
|
|
|
test('duplicate or unknown explicit stream stop never removes sibling shares', () => {
|
|
const d = new StreamDirectory();
|
|
d.handle('notifystreaminfo', [{ id: 'a', clid: '5' }, { id: 'b', clid: '5' }]);
|
|
assert.equal(d.handle('notifystreamstopped', [{ id: 'a', clid: '5' }]), true);
|
|
assert.equal(d.handle('notifystreamstopped', [{ id: 'a', clid: '5' }]), false);
|
|
assert.equal(d.handle('notifystreamstopped', [{ id: 'unknown', clid: '5' }]), false);
|
|
assert.deepEqual(d.allOf(5).map((s) => s.id), ['b']);
|
|
assert.equal(d.handle('notifystreamstopped', [{ clid: '5' }]), true);
|
|
});
|
|
|
|
test('SFU notification is remembered', () => {
|
|
const d = new StreamDirectory();
|
|
assert.equal(d.handle('notifysfuaccessinfo', [{}]), true);
|
|
assert.equal(d.sfuSeen, true);
|
|
});
|
|
|
|
const member = (id, channel, extra = {}) => ({ id, nickname: `n${id}`, channel_id: channel, is_self: false, client_type: 'normal', is_streaming: null, ...extra });
|
|
const kinds = (offers) => offers.map((o) => (o.kind === 'stream' ? `stream:${o.stream.id}` : `${o.kind}:${o.client.id}`));
|
|
|
|
test('channel offers list every stream of the channel, also several of one client, and nothing else', () => {
|
|
const d = new StreamDirectory();
|
|
d.handle('notifystreaminfo', [{ id: 'a2', clid: '5', name: 'two' }, { id: 'a1', clid: '5', name: 'one' }, { id: 'b', clid: '6' }, { id: 'x', clid: '9' }]);
|
|
const clients = [member(5, 1), member(6, 1), member(7, 1, { is_self: true, is_streaming: true }), member(8, 1, { client_type: 'query' }), member(9, 2)];
|
|
const offers = channelOffers({ clients, channelId: 1, directory: d, probes: new Map(), watchingIds: [] });
|
|
assert.deepEqual(kinds(offers), ['stream:a1', 'stream:a2', 'stream:b']);
|
|
const watching = channelOffers({ clients, channelId: 1, directory: d, probes: new Map(), watchingIds: ['a1', 'b'] });
|
|
assert.deepEqual(kinds(watching), ['stream:a2'], 'every watched stream has its own player, not another Watch action');
|
|
});
|
|
|
|
test('a member flagged as streaming without a known stream is shown as checking, unavailable or failed — never watchable', () => {
|
|
const d = new StreamDirectory();
|
|
const clients = [member(5, 1, { is_streaming: true }), member(6, 1, { is_streaming: true }), member(7, 1, { is_streaming: true }), member(8, 1, { is_streaming: true }), member(9, 1, { is_streaming: false })];
|
|
const probes = new Map([[6, { state: 'pending' }], [7, { state: 'done' }], [8, { state: 'done', error: { code: 'not_connected' } }]]);
|
|
const offers = channelOffers({ clients, channelId: 1, directory: d, probes, watchingIds: [] });
|
|
assert.deepEqual(kinds(offers), ['checking:5', 'checking:6', 'unavailable:7', 'error:8']);
|
|
assert.equal(offers[3].error.code, 'not_connected');
|
|
d.handle('notifystreaminfo', [{ id: 's7', clid: '7' }]);
|
|
assert.deepEqual(kinds(channelOffers({ clients, channelId: 1, directory: d, probes, watchingIds: [] })), ['checking:5', 'checking:6', 'stream:s7', 'error:8']);
|
|
});
|