openvibers/openvibe.live Commits

Agent streams: ending a stream and revoking its ticket stop the desk (#625)

OP OpenVibers committed 7 days ago · f419702830 · 2 files, +24 −1

service.end required ./publish-tickets, which does not exist, so every end (POST /end, DELETE /ticket, and the expiry sweep) answered 500 after marking the stream ended. Require ./tickets, and cover both routes in test/agent-streams.test.js.

Changes

ddiff --git a/server/agent-streams/service.js b/server/agent-streams/service.js
iindex 7f3d8f89..55f7fe46 100644
---- a/server/agent-streams/service.js
++++ b/server/agent-streams/service.js
@@@ -250,7 +250,7 @@ async function end(row, { reason = 'ended' } = {}) {
set: { state: 'ended', ended_at: now, worked_seconds: worked, curtain_up: 0, curtain_since: null, curtain_reason: null },
event: { kind: 'ended', extra: { reason } },
});
-- await require('./publish-tickets').revokeAll(row.managed_stream_id);
++ await require('./tickets').revokeAll(row.managed_stream_id);
if (session) {
try {
const whip = require('../streaming/whip-handler');
ddiff --git a/test/agent-streams.test.js b/test/agent-streams.test.js
iindex 17b3b1e2..a3fc3bfe 100644
---- a/test/agent-streams.test.js
++++ b/test/agent-streams.test.js
@@@ -225,6 +225,29 @@ async function check(name, fn) {
assert.strictEqual(pub.data.encode, true);
});
++ await check('ending the stream and revoking the ticket answer 200 and stop the desk', async () => {
++ const made = await call('POST', '/api/streams/agent', {
++ as: 1,
++ body: { title: 'Ended', task: { source: 'node', ref: 'n1', title: 'End' }, visibility: 'private' },
++ });
++ assert.strictEqual(made.status, 201);
++ const id = made.data.stream.id;
++ const ended = await call('POST', `/api/streams/agent/${id}/end`, { as: 1, body: {} });
++ assert.strictEqual(ended.status, 200);
++ assert.strictEqual(ended.data.stream.state, 'ended');
++ const stale = await call('GET', `/api/streams/agent/${id}/state`, { as: 1, headers: { Authorization: `Bearer ${made.data.publish.ticket}` } });
++ assert.strictEqual(stale.status, 401, 'the publish ticket is gone with the stream');
++
++ const second = await call('POST', '/api/streams/agent', {
++ as: 1,
++ body: { title: 'Revoked', task: { source: 'node', ref: 'n2', title: 'Revoke' }, visibility: 'private' },
++ });
++ assert.strictEqual(second.status, 201);
++ const revoked = await call('DELETE', `/api/streams/agent/${second.data.stream.id}/ticket`, { as: 1 });
++ assert.strictEqual(revoked.status, 200);
++ assert.strictEqual(revoked.data.stream.state, 'ended');
++ });
++
quiet('agent streams: the curtain');
await check('up pauses every viewer consumer, down resumes exactly those', async () => {
const roomId = 'stream-999';