Add player control-plane and dashboard updates
This commit is contained in:
@@ -0,0 +1,134 @@
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
|
||||
require('../src/common');
|
||||
|
||||
const { createPlayerActionService } = require('../src/web/lib/player-actions');
|
||||
|
||||
test('player actions prefer the exact configured player registration over a remote FQDN row', async () => {
|
||||
const fetchCalls = [];
|
||||
const originalFetch = global.fetch;
|
||||
global.fetch = async function (url, init) {
|
||||
fetchCalls.push({ url, init });
|
||||
return {
|
||||
ok: true,
|
||||
status: 200,
|
||||
headers: {
|
||||
get() {
|
||||
return null;
|
||||
}
|
||||
},
|
||||
async json() {
|
||||
return { ok: true };
|
||||
},
|
||||
async text() {
|
||||
return JSON.stringify({ ok: true });
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
const playerActionService = createPlayerActionService({
|
||||
common: {},
|
||||
pool: {
|
||||
async query() {
|
||||
return [[
|
||||
{
|
||||
identifier: 'player-local',
|
||||
internal_base_url: 'http://player:8081'
|
||||
},
|
||||
{
|
||||
identifier: 'player-remote',
|
||||
internal_base_url: 'https://pulse-dev-bridge.lzstealth.com'
|
||||
}
|
||||
]];
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
const originalIdentifier = process.env.PLAYER_IDENTIFIER;
|
||||
process.env.PLAYER_IDENTIFIER = 'player-local';
|
||||
|
||||
try {
|
||||
const response = await playerActionService.forwardPlayerCommand('demo', { command: 'refresh' });
|
||||
|
||||
assert.deepEqual(response, { ok: true });
|
||||
assert.equal(fetchCalls.length, 1);
|
||||
assert.equal(fetchCalls[0].url, 'http://player:8081/api/screens/demo/commands');
|
||||
} finally {
|
||||
process.env.PLAYER_IDENTIFIER = originalIdentifier;
|
||||
global.fetch = originalFetch;
|
||||
}
|
||||
});
|
||||
|
||||
test('player actions merge screen connections from every recent player registration', async () => {
|
||||
const fetchCalls = [];
|
||||
const originalFetch = global.fetch;
|
||||
global.fetch = async function (url, init) {
|
||||
fetchCalls.push({ url, init });
|
||||
if (String(url).includes('player-a.example')) {
|
||||
return {
|
||||
ok: true,
|
||||
status: 200,
|
||||
headers: { get() { return null; } },
|
||||
async json() {
|
||||
return {
|
||||
screenSlug: 'demo',
|
||||
connections: [
|
||||
{ id: 'a-1', playerPublicBaseUrl: 'http://player-a.example' }
|
||||
]
|
||||
};
|
||||
},
|
||||
async text() {
|
||||
return JSON.stringify({ ok: true });
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
ok: true,
|
||||
status: 200,
|
||||
headers: { get() { return null; } },
|
||||
async json() {
|
||||
return {
|
||||
screenSlug: 'demo',
|
||||
connections: [
|
||||
{ id: 'b-1', playerPublicBaseUrl: 'http://player-b.example' }
|
||||
]
|
||||
};
|
||||
},
|
||||
async text() {
|
||||
return JSON.stringify({ ok: true });
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
const playerActionService = createPlayerActionService({
|
||||
common: {},
|
||||
pool: {
|
||||
async query() {
|
||||
return [[
|
||||
{
|
||||
identifier: 'player-a',
|
||||
public_base_url: 'http://player-a.example',
|
||||
last_seen_at: new Date().toISOString()
|
||||
},
|
||||
{
|
||||
identifier: 'player-b',
|
||||
public_base_url: 'http://player-b.example',
|
||||
last_seen_at: new Date().toISOString()
|
||||
}
|
||||
]];
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
try {
|
||||
const response = await playerActionService.getScreenConnections('demo');
|
||||
|
||||
assert.equal(response.count, 2);
|
||||
assert.deepEqual(response.connections.map(function (connection) { return connection.id; }), ['a-1', 'b-1']);
|
||||
assert.equal(fetchCalls.length, 2);
|
||||
} finally {
|
||||
global.fetch = originalFetch;
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user