@xenon-device-management/xenon 2.3.0 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/package.json +1 -1
- package/lib/public/assets/{AnnotationOverlay-AxcBYoKp.js → AnnotationOverlay-BeypNvFL.js} +1 -1
- package/lib/public/assets/{ApiKeyGate-CIU02EIx.js → ApiKeyGate-CQg51mzi.js} +1 -1
- package/lib/public/assets/{BugReportButton-_akEEjXm.js → BugReportButton-JVduDicX.js} +1 -1
- package/lib/public/assets/{DeviceMosaicView-Bhk1udmn.js → DeviceMosaicView-BnEKlOi9.js} +1 -1
- package/lib/public/assets/{EmptyState-DRKRm19_.js → EmptyState-CVk_39sG.js} +1 -1
- package/lib/public/assets/{FieldGroup-zQQHPh7x.js → FieldGroup-DC4jWFOr.js} +1 -1
- package/lib/public/assets/{FilterMenu-C9_StnDi.js → FilterMenu-Df4ApWT_.js} +1 -1
- package/lib/public/assets/{Menu-0J7io6pF.js → Menu-BZcyp6Df.js} +1 -1
- package/lib/public/assets/{Modal-C677ljNX.js → Modal-D27eM9ja.js} +1 -1
- package/lib/public/assets/{RecordingPage-BDJFck-L.js → RecordingPage-ScK_NxUR.js} +1 -1
- package/lib/public/assets/{RecordingsPage-DQkimbKK.js → RecordingsPage-DO6KsDwr.js} +1 -1
- package/lib/public/assets/{SegmentedControl-DvGMZBIE.js → SegmentedControl-P0_wzUSa.js} +1 -1
- package/lib/public/assets/{SettingCard-ogyouYBq.js → SettingCard-CnbZajUY.js} +1 -1
- package/lib/public/assets/{Table-BLFCOLlO.js → Table-DCLEpILV.js} +1 -1
- package/lib/public/assets/{activity-BU55TGRG.js → activity-c-lgQI29.js} +1 -1
- package/lib/public/assets/{ai-settings-GpDAiHav.js → ai-settings-S4Qb0zMX.js} +1 -1
- package/lib/public/assets/{api-keys-dOzP0k8_.js → api-keys-B8OZRdWq.js} +1 -1
- package/lib/public/assets/{apps-mAwAQmkn.js → apps-BUdm1f-6.js} +1 -1
- package/lib/public/assets/{arrow-left-Dg9mxe9T.js → arrow-left-DuWnjija.js} +1 -1
- package/lib/public/assets/{arrow-right-BVcmUyq3.js → arrow-right-9qDEU3uD.js} +1 -1
- package/lib/public/assets/{arrow-up-right-ByR5pZrH.js → arrow-up-right-b6Of0lQ3.js} +1 -1
- package/lib/public/assets/{auth-shell-Jpgk8CgY.js → auth-shell-DM7UlvlL.js} +2 -2
- package/lib/public/assets/builds-page-AOQqU3g3.js +16 -0
- package/lib/public/assets/{button-D-X4wjO8.js → button-D2poE4AT.js} +1 -1
- package/lib/public/assets/{calendar-ur_p5ETA.js → calendar-BwZZxp7_.js} +1 -1
- package/lib/public/assets/{check-K33iMeyq.js → check-bpRVp-8m.js} +1 -1
- package/lib/public/assets/{chevron-left-DMVWShd-.js → chevron-left-o5fCPIVE.js} +1 -1
- package/lib/public/assets/{chevron-right-DphLJ2_X.js → chevron-right-Bp0cGaHf.js} +1 -1
- package/lib/public/assets/{circle-check-CNFhu8oE.js → circle-check-C7h_YWkh.js} +1 -1
- package/lib/public/assets/{circle-x-BH_cUbqZ.js → circle-x-BevILQ_g.js} +1 -1
- package/lib/public/assets/{clock-CVMVdVvp.js → clock-BEKymxJ4.js} +1 -1
- package/lib/public/assets/{copy-CZ2XHafL.js → copy-R5Kb2Sya.js} +1 -1
- package/lib/public/assets/{device-explorer-B94BhaqF.js → device-explorer-DuD_PXL0.js} +51 -56
- package/lib/public/assets/{download-UUiyw7kO.js → download-CUlaFpHe.js} +1 -1
- package/lib/public/assets/{forgot-password-CrS14F79.js → forgot-password-CHO8yPDz.js} +1 -1
- package/lib/public/assets/{funnel-BMOE5qJY.js → funnel-uB2CBRiY.js} +1 -1
- package/lib/public/assets/{index-hymrhlEZ.css → index-DSFSk-0t.css} +1 -1
- package/lib/public/assets/{index-D0R9Yic3.js → index-KgmoUqNo.js} +1 -1
- package/lib/public/assets/{index-2XPPbPwy.js → index-yibbsLFD.js} +2 -2
- package/lib/public/assets/{input-C-1b8J7i.js → input-BR-cDtqC.js} +1 -1
- package/lib/public/assets/{keycodes-Cly7dQc9.js → keycodes-dLBaFcVi.js} +1 -1
- package/lib/public/assets/{layers-DFZfqGdX.js → layers-BESinxSO.js} +1 -1
- package/lib/public/assets/list-checks-DpKchgZl.js +6 -0
- package/lib/public/assets/{lock-ylHMJpfP.js → lock--sC5e3s6.js} +1 -1
- package/lib/public/assets/{login-DWsWKqDx.js → login-Cc-IivWH.js} +1 -1
- package/lib/public/assets/{maintenance-settings-9B6_MTqW.js → maintenance-settings-CO1mxmXj.js} +1 -1
- package/lib/public/assets/{monitor-CzX0hBH1.js → monitor-Cf5xQDkm.js} +1 -1
- package/lib/public/assets/{mouse-pointer-2-CZHD7N3z.js → mouse-pointer-2-D0FTHFsu.js} +1 -1
- package/lib/public/assets/{network-Bikc4MyT.js → network-BDR_XEsw.js} +1 -1
- package/lib/public/assets/{overview-DzaA0aMe.js → overview-Bgr23HrL.js} +1 -1
- package/lib/public/assets/{page-header-DqGlDufy.js → page-header-mkEQJJPW.js} +1 -1
- package/lib/public/assets/{plus-Ct6aQTGM.js → plus-BGTOA7GD.js} +1 -1
- package/lib/public/assets/{profile-page-CCnUQ1Qk.js → profile-page-hogPzCrJ.js} +1 -1
- package/lib/public/assets/{reset-password-AmkGGXo5.js → reset-password-BobaiMBQ.js} +1 -1
- package/lib/public/assets/{runbook-page-DQQn9VyE.js → runbook-page-qw6u9fmW.js} +1 -1
- package/lib/public/assets/{select-k5ogtEWW.js → select-skq1Kjsx.js} +1 -1
- package/lib/public/assets/{selector-detail-page-BCcwC5ku.js → selector-detail-page-BJl3YxfV.js} +1 -1
- package/lib/public/assets/{selector-health-BVyX6kIh.js → selector-health-CMmIKYip.js} +1 -1
- package/lib/public/assets/{selector-health-page-CElBB6XT.js → selector-health-page-DR8zYoS9.js} +1 -1
- package/lib/public/assets/session-detail-page-Cpbl4HPh.js +3 -0
- package/lib/public/assets/{settings-DKBj9KyN.js → settings-rZ0cTErR.js} +1 -1
- package/lib/public/assets/{tablet-B6HI5OxV.js → tablet-C08V4-n2.js} +1 -1
- package/lib/public/assets/{teams-owoDHbOU.js → teams-9lNK5Hv4.js} +1 -1
- package/lib/public/assets/{trash-2-D61PoUrZ.js → trash-2-Uko_-EoJ.js} +1 -1
- package/lib/public/assets/{upload-1ZYEVvgD.js → upload-CyTBX5YJ.js} +1 -1
- package/lib/public/assets/use-builds-data-TVBd_s-l.js +1 -0
- package/lib/public/assets/{use-password-reset-mode-Dx0ghiiQ.js → use-password-reset-mode-BQkqB45G.js} +1 -1
- package/lib/public/assets/{users-C5CS5Qez.js → users-CQKCMBqe.js} +1 -1
- package/lib/public/assets/{users-PbGMd5sD.js → users-D7RusV-M.js} +1 -1
- package/lib/public/assets/{video-off-_XusI0HK.js → video-off-CWBbZnqz.js} +1 -1
- package/lib/public/assets/{webhook-settings-Bi_HHQlQ.js → webhook-settings-Q3AJC_pt.js} +1 -1
- package/lib/public/assets/{zap-uzHWFAKI.js → zap-CN2fMC_t.js} +1 -1
- package/lib/public/index.html +2 -2
- package/lib/src/app/routers/dashboard.js +42 -2
- package/lib/src/app/routers/nodePhoneControl.js +29 -6
- package/lib/src/app/routers/sessionInsights.js +221 -0
- package/lib/src/services/recording/RecordingOrchestrator.js +39 -5
- package/lib/src/services/recording/busy-precheck.js +5 -2
- package/lib/src/services/recording/nodeRecordingSource.js +156 -0
- package/lib/test/unit/busy-precheck.spec.js +32 -0
- package/lib/test/unit/node-phone-control.spec.js +26 -0
- package/lib/test/unit/node-recording-relay.spec.js +165 -0
- package/lib/test/unit/recording-orchestrator.spec.js +86 -2
- package/lib/test/unit/session-list-insights.spec.js +329 -0
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/lib/public/assets/builds-page-VnRTrcdl.js +0 -6
- package/lib/public/assets/session-detail-page-6bqo_-ND.js +0 -3
- package/lib/public/assets/status-pill-outline-CZNpvqej.js +0 -1
|
@@ -99,6 +99,38 @@ describe('BusyPrecheck', () => {
|
|
|
99
99
|
const out = yield pc.findBusy(['U1'], 'actor-1');
|
|
100
100
|
(0, chai_1.expect)(out[0]).to.deep.include({ udid: 'U1', reason: 'manual_other', blockId: 'manual_U1' });
|
|
101
101
|
}));
|
|
102
|
+
// On a hub, a node's phone held by a preview has the holder in nodeHold,
|
|
103
|
+
// from the node's report; session_id is the hub's own and stays empty.
|
|
104
|
+
// Read as unknown, the user's own preview kept them from recording it.
|
|
105
|
+
it('reads a node phone’s preview hold from nodeHold: mine to take over, another user’s not', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
106
|
+
const pc = precheck(withDevices({
|
|
107
|
+
MINE: {
|
|
108
|
+
udid: 'MINE',
|
|
109
|
+
busy: true,
|
|
110
|
+
nodeBusy: true,
|
|
111
|
+
session_id: null,
|
|
112
|
+
nodeHold: 'manual_alice_MINE',
|
|
113
|
+
},
|
|
114
|
+
THEIRS: {
|
|
115
|
+
udid: 'THEIRS',
|
|
116
|
+
busy: true,
|
|
117
|
+
nodeBusy: true,
|
|
118
|
+
session_id: null,
|
|
119
|
+
nodeHold: 'manual_bob_THEIRS',
|
|
120
|
+
},
|
|
121
|
+
NODE_SESSION: {
|
|
122
|
+
udid: 'NODE_SESSION',
|
|
123
|
+
busy: true,
|
|
124
|
+
nodeBusy: true,
|
|
125
|
+
session_id: null,
|
|
126
|
+
nodeHold: null,
|
|
127
|
+
},
|
|
128
|
+
}));
|
|
129
|
+
(0, chai_1.expect)(yield pc.findBusy(['MINE', 'THEIRS', 'NODE_SESSION'], 'alice')).to.deep.equal([
|
|
130
|
+
{ udid: 'THEIRS', reason: 'manual_other', blockId: 'manual_bob_THEIRS' },
|
|
131
|
+
{ udid: 'NODE_SESSION', reason: 'unknown' },
|
|
132
|
+
]);
|
|
133
|
+
}));
|
|
102
134
|
it('returns reason=unknown for missing devices', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
103
135
|
const pc = precheck(withDevices({}));
|
|
104
136
|
const out = yield pc.findBusy(['MISSING']);
|
|
@@ -216,6 +216,32 @@ describe('nodePhoneControl', () => {
|
|
|
216
216
|
(0, chai_1.expect)(cloud.body.error, action).to.equal('not_available_for_cloud_phone');
|
|
217
217
|
}
|
|
218
218
|
}));
|
|
219
|
+
// The node doesn't know this server is recording its phone, so it would stop
|
|
220
|
+
// the stream the recording reads; /control refuses a local phone's the same way.
|
|
221
|
+
it('refuses to stop a node phone’s preview while this server records it', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
222
|
+
const node = (0, express_1.default)();
|
|
223
|
+
const hits = [];
|
|
224
|
+
node.use((req, res) => {
|
|
225
|
+
hits.push(req.path);
|
|
226
|
+
res.json({ success: true });
|
|
227
|
+
});
|
|
228
|
+
const origin = `http://127.0.0.1:${(yield loopback.serve(node)).address().port}`;
|
|
229
|
+
findDevice = () => __awaiter(void 0, void 0, void 0, function* () { return ({ udid: 'p', host: origin, nodeId: 'node-1' }); });
|
|
230
|
+
let recording = { groupId: 'g-1' };
|
|
231
|
+
const a = (0, express_1.default)();
|
|
232
|
+
a.use(express_1.default.json());
|
|
233
|
+
a.use('/xenon/api/control', (0, nodePhoneControl_1.nodePhoneControl)({
|
|
234
|
+
findDevice: (udid) => findDevice(udid),
|
|
235
|
+
activeRecordingFor: () => __awaiter(void 0, void 0, void 0, function* () { return recording; }),
|
|
236
|
+
}));
|
|
237
|
+
const refused = yield (0, loopbackRequest_1.default)(a).post('/xenon/api/control/p/stream/stop').send({});
|
|
238
|
+
(0, chai_1.expect)(refused.status).to.equal(409);
|
|
239
|
+
(0, chai_1.expect)(refused.body).to.include({ error: 'device_recording', groupId: 'g-1' });
|
|
240
|
+
(0, chai_1.expect)(hits).to.deep.equal([]);
|
|
241
|
+
recording = null;
|
|
242
|
+
yield (0, loopbackRequest_1.default)(a).post('/xenon/api/control/p/stream/stop').send({}).expect(200);
|
|
243
|
+
(0, chai_1.expect)(hits).to.deep.equal(['/xenon/api/control/p/stream/stop']);
|
|
244
|
+
}));
|
|
219
245
|
it('refuses a host it must never call', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
220
246
|
findDevice = () => __awaiter(void 0, void 0, void 0, function* () { return ({ udid: 'p', host: 'http://169.254.169.254', nodeId: 'node-1' }); });
|
|
221
247
|
const res = yield (0, loopbackRequest_1.default)(app()).get('/xenon/api/control/p/screenshot');
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
require("reflect-metadata");
|
|
16
|
+
const chai_1 = require("chai");
|
|
17
|
+
const http_1 = __importDefault(require("http"));
|
|
18
|
+
const express_1 = __importDefault(require("express"));
|
|
19
|
+
const typedi_1 = require("typedi");
|
|
20
|
+
const loopbackServer_1 = require("../helpers/loopbackServer");
|
|
21
|
+
const PluginContext_1 = require("../../src/PluginContext");
|
|
22
|
+
const IPluginArgs_1 = require("../../src/interfaces/IPluginArgs");
|
|
23
|
+
const nodeRecordingSource_1 = require("../../src/services/recording/nodeRecordingSource");
|
|
24
|
+
/**
|
|
25
|
+
* Recording a node's phone on a hub. The recording's ffmpeg reads a loopback
|
|
26
|
+
* port, as for this server's own phones; for a node's phone that port is a
|
|
27
|
+
* relay to the node's MJPEG stream, signed for the recording's user on every
|
|
28
|
+
* connection. ffmpeg reconnects on any hiccup, and the hub's control token
|
|
29
|
+
* lasts a minute, so a token taken once would end the recording on the first
|
|
30
|
+
* reconnect after that.
|
|
31
|
+
*/
|
|
32
|
+
describe('nodeRecordingSource', () => {
|
|
33
|
+
const loopback = (0, loopbackServer_1.loopbackServers)();
|
|
34
|
+
const closers = [];
|
|
35
|
+
let context;
|
|
36
|
+
let saved;
|
|
37
|
+
beforeEach(() => {
|
|
38
|
+
context = typedi_1.Container.get(PluginContext_1.PluginContext);
|
|
39
|
+
saved = Object.assign({}, context);
|
|
40
|
+
context.setContext(Object.assign(Object.assign({}, IPluginArgs_1.DefaultPluginArgs), { bindHostOrIp: '127.0.0.1' }), 1, 'hub-1', '');
|
|
41
|
+
});
|
|
42
|
+
afterEach(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
43
|
+
Object.assign(context, saved);
|
|
44
|
+
for (const close of closers.splice(0))
|
|
45
|
+
yield close();
|
|
46
|
+
yield loopback.closeAll();
|
|
47
|
+
}));
|
|
48
|
+
/** A node serving GET /control/p/stream, recording each request's token. */
|
|
49
|
+
function fakeNode() {
|
|
50
|
+
return __awaiter(this, arguments, void 0, function* (status = 200, firstFrameAfterMs = 0) {
|
|
51
|
+
const seen = [];
|
|
52
|
+
const app = (0, express_1.default)();
|
|
53
|
+
app.get('/xenon/api/control/p/stream', (req, res) => {
|
|
54
|
+
const call = { token: req.header('x-xenon-hub-token'), closed: false };
|
|
55
|
+
seen.push(call);
|
|
56
|
+
req.on('close', () => (call.closed = true));
|
|
57
|
+
if (status !== 200)
|
|
58
|
+
return res.status(status).json({ error: 'node says no' });
|
|
59
|
+
res.writeHead(200, { 'content-type': 'multipart/x-mixed-replace; boundary=f' });
|
|
60
|
+
let timer;
|
|
61
|
+
const wait = setTimeout(() => {
|
|
62
|
+
timer = setInterval(() => res.write('--f\r\nFRAME\r\n'), 30);
|
|
63
|
+
}, firstFrameAfterMs);
|
|
64
|
+
res.on('close', () => {
|
|
65
|
+
clearTimeout(wait);
|
|
66
|
+
if (timer)
|
|
67
|
+
clearInterval(timer);
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
const origin = `http://127.0.0.1:${(yield loopback.serve(app)).address().port}`;
|
|
71
|
+
return { origin, seen };
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
/** Read from the relay until `n` frames arrived, then hang up. */
|
|
75
|
+
const read = (port, n = 2) => new Promise((resolve, reject) => {
|
|
76
|
+
const req = http_1.default.get({ host: '127.0.0.1', port, path: '/' }, (res) => {
|
|
77
|
+
let body = '';
|
|
78
|
+
res.on('data', (c) => {
|
|
79
|
+
body += c.toString();
|
|
80
|
+
if (body.split('FRAME').length > n) {
|
|
81
|
+
req.destroy();
|
|
82
|
+
resolve({ status: res.statusCode, type: String(res.headers['content-type']), body });
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
res.on('end', () => resolve({ status: res.statusCode, body }));
|
|
86
|
+
});
|
|
87
|
+
req.on('error', (e) => (e.code === 'ECONNRESET' ? undefined : reject(e)));
|
|
88
|
+
});
|
|
89
|
+
it('relays the node’s stream, signed afresh for each connection', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
90
|
+
const node = yield fakeNode();
|
|
91
|
+
let n = 0;
|
|
92
|
+
const relay = yield (0, nodeRecordingSource_1.openNodeMjpegRelay)({ udid: 'p', host: node.origin, actorId: 'alice' }, { controlToken: (grant) => __awaiter(void 0, void 0, void 0, function* () { return `token-${++n}-${grant.userId}-${grant.udid}`; }) });
|
|
93
|
+
closers.push(() => relay.close());
|
|
94
|
+
const first = yield read(relay.port);
|
|
95
|
+
const second = yield read(relay.port);
|
|
96
|
+
(0, chai_1.expect)(first.status).to.equal(200);
|
|
97
|
+
(0, chai_1.expect)(first.type).to.include('multipart/x-mixed-replace');
|
|
98
|
+
(0, chai_1.expect)(second.body).to.include('FRAME');
|
|
99
|
+
// The first is the relay making sure the node is streaming before it
|
|
100
|
+
// hands out the port.
|
|
101
|
+
(0, chai_1.expect)(node.seen.map((s) => s.token)).to.deep.equal([
|
|
102
|
+
'token-1-alice-p',
|
|
103
|
+
'token-2-alice-p',
|
|
104
|
+
'token-3-alice-p',
|
|
105
|
+
]);
|
|
106
|
+
}));
|
|
107
|
+
it('hangs up on the node when the reader goes, and stops listening when closed', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
108
|
+
const node = yield fakeNode();
|
|
109
|
+
const relay = yield (0, nodeRecordingSource_1.openNodeMjpegRelay)({ udid: 'p', host: node.origin, actorId: 'alice' }, { controlToken: () => __awaiter(void 0, void 0, void 0, function* () { return null; }) });
|
|
110
|
+
yield read(relay.port);
|
|
111
|
+
yield new Promise((r) => setTimeout(r, 100));
|
|
112
|
+
(0, chai_1.expect)(node.seen[1].closed, 'the node’s request ends with the reader').to.equal(true);
|
|
113
|
+
yield relay.close();
|
|
114
|
+
const refused = yield new Promise((resolve) => {
|
|
115
|
+
http_1.default
|
|
116
|
+
.get({ host: '127.0.0.1', port: relay.port, path: '/' }, () => resolve('answered'))
|
|
117
|
+
.on('error', (e) => resolve(e.code));
|
|
118
|
+
});
|
|
119
|
+
(0, chai_1.expect)(refused).to.equal('ECONNREFUSED');
|
|
120
|
+
}));
|
|
121
|
+
// Local recording starts the phone's stream before ffmpeg (ensureMjpegForRecording).
|
|
122
|
+
// Handed the port at once, ffmpeg started before the node's stream was up
|
|
123
|
+
// (an iPhone's WebDriverAgent takes seconds): the video began late, and
|
|
124
|
+
// every mark on it, timed from ffmpeg's start, was off by as much.
|
|
125
|
+
it('opens once the node is streaming, not before', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
126
|
+
const node = yield fakeNode(200, 400);
|
|
127
|
+
const t0 = Date.now();
|
|
128
|
+
const relay = yield (0, nodeRecordingSource_1.openNodeMjpegRelay)({ udid: 'p', host: node.origin, actorId: 'alice' }, { controlToken: () => __awaiter(void 0, void 0, void 0, function* () { return null; }) });
|
|
129
|
+
closers.push(() => relay.close());
|
|
130
|
+
(0, chai_1.expect)(Date.now() - t0).to.be.at.least(350);
|
|
131
|
+
}));
|
|
132
|
+
it('fails to open when the node refuses the stream, or never sends a frame', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
133
|
+
const refusing = yield fakeNode(409);
|
|
134
|
+
let error;
|
|
135
|
+
yield (0, nodeRecordingSource_1.openNodeMjpegRelay)({ udid: 'p', host: refusing.origin, actorId: 'alice' }, { controlToken: () => __awaiter(void 0, void 0, void 0, function* () { return null; }) }).catch((e) => (error = e));
|
|
136
|
+
(0, chai_1.expect)(error === null || error === void 0 ? void 0 : error.message).to.include('409');
|
|
137
|
+
const silent = yield fakeNode(200, 60000);
|
|
138
|
+
error = undefined;
|
|
139
|
+
yield (0, nodeRecordingSource_1.openNodeMjpegRelay)({ udid: 'p', host: silent.origin, actorId: 'alice' }, { controlToken: () => __awaiter(void 0, void 0, void 0, function* () { return null; }), readyTimeoutMs: 200 }).catch((e) => (error = e));
|
|
140
|
+
(0, chai_1.expect)(error === null || error === void 0 ? void 0 : error.message).to.match(/first frame/);
|
|
141
|
+
}));
|
|
142
|
+
describe('recordingSourceFor', () => {
|
|
143
|
+
const rows = {};
|
|
144
|
+
const find = (udid) => __awaiter(void 0, void 0, void 0, function* () { var _a; return (_a = rows[udid]) !== null && _a !== void 0 ? _a : null; });
|
|
145
|
+
it('is null for this server’s own phone and an unknown one', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
146
|
+
rows.own = { udid: 'own', host: 'http://10.0.0.9:4723', nodeId: 'hub-1' };
|
|
147
|
+
(0, chai_1.expect)(yield (0, nodeRecordingSource_1.recordingSourceFor)('own', 'alice', { findDevice: find })).to.equal(null);
|
|
148
|
+
(0, chai_1.expect)(yield (0, nodeRecordingSource_1.recordingSourceFor)('ghost', 'alice', { findDevice: find })).to.equal(null);
|
|
149
|
+
}));
|
|
150
|
+
it('opens a relay for a node’s phone, and refuses a cloud provider’s', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
151
|
+
const node = yield fakeNode();
|
|
152
|
+
rows.p = { udid: 'p', host: node.origin, nodeId: 'node-1' };
|
|
153
|
+
const relay = yield (0, nodeRecordingSource_1.recordingSourceFor)('p', 'alice', {
|
|
154
|
+
findDevice: find,
|
|
155
|
+
controlToken: () => __awaiter(void 0, void 0, void 0, function* () { return null; }),
|
|
156
|
+
});
|
|
157
|
+
(0, chai_1.expect)(relay === null || relay === void 0 ? void 0 : relay.port).to.be.a('number');
|
|
158
|
+
closers.push(() => relay.close());
|
|
159
|
+
rows.c = { udid: 'c', host: 'https://hub.cloud.example', cloud: '{"cloudName":"x"}' };
|
|
160
|
+
let error;
|
|
161
|
+
yield (0, nodeRecordingSource_1.recordingSourceFor)('c', 'alice', { findDevice: find }).catch((e) => (error = e));
|
|
162
|
+
(0, chai_1.expect)(error === null || error === void 0 ? void 0 : error.message).to.match(/cloud provider/);
|
|
163
|
+
}));
|
|
164
|
+
});
|
|
165
|
+
});
|
|
@@ -60,7 +60,7 @@ const fs = __importStar(require("fs"));
|
|
|
60
60
|
const os = __importStar(require("os"));
|
|
61
61
|
const path = __importStar(require("path"));
|
|
62
62
|
function makeOrch(overrides = {}) {
|
|
63
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
63
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
64
64
|
const busyPrecheck = (_a = overrides.busyPrecheck) !== null && _a !== void 0 ? _a : { findBusy: sinon_1.default.stub().resolves([]) };
|
|
65
65
|
const store = (_b = overrides.store) !== null && _b !== void 0 ? _b : {
|
|
66
66
|
create: sinon_1.default.stub().callsFake((i) => __awaiter(this, void 0, void 0, function* () { return (Object.assign({ id: `rec-${i.deviceUdid}` }, i)); })),
|
|
@@ -80,7 +80,9 @@ function makeOrch(overrides = {}) {
|
|
|
80
80
|
const blockDeviceFn = (_e = overrides.blockDeviceFn) !== null && _e !== void 0 ? _e : sinon_1.default.stub().resolves();
|
|
81
81
|
const unblockDeviceFn = (_f = overrides.unblockDeviceFn) !== null && _f !== void 0 ? _f : sinon_1.default.stub().resolves();
|
|
82
82
|
const ensureMjpegPortFn = (_g = overrides.ensureMjpegPortFn) !== null && _g !== void 0 ? _g : sinon_1.default.stub().callsFake(() => __awaiter(this, void 0, void 0, function* () { return 9100; }));
|
|
83
|
-
|
|
83
|
+
// This server's own phones, unless a test says otherwise.
|
|
84
|
+
const nodeSourceFn = (_h = overrides.nodeSourceFn) !== null && _h !== void 0 ? _h : sinon_1.default.stub().resolves(null);
|
|
85
|
+
const eventMgr = (_j = overrides.eventMgr) !== null && _j !== void 0 ? _j : {
|
|
84
86
|
emitRecordingStarted: sinon_1.default.stub(),
|
|
85
87
|
emitRecordingStopped: sinon_1.default.stub(),
|
|
86
88
|
emitRecordingFailed: sinon_1.default.stub(),
|
|
@@ -96,6 +98,7 @@ function makeOrch(overrides = {}) {
|
|
|
96
98
|
eventMgr: eventMgr,
|
|
97
99
|
unblockDeviceFn,
|
|
98
100
|
ensureMjpegPortFn,
|
|
101
|
+
nodeSourceFn,
|
|
99
102
|
now: overrides.now,
|
|
100
103
|
});
|
|
101
104
|
return {
|
|
@@ -108,8 +111,89 @@ function makeOrch(overrides = {}) {
|
|
|
108
111
|
unblockDeviceFn,
|
|
109
112
|
eventMgr,
|
|
110
113
|
ensureMjpegPortFn,
|
|
114
|
+
nodeSourceFn,
|
|
111
115
|
};
|
|
112
116
|
}
|
|
117
|
+
// On a hub, a node's phone is recorded from a loopback relay to its node's
|
|
118
|
+
// stream (nodeRecordingSource.ts); this server's own phones as before.
|
|
119
|
+
describe('RecordingOrchestrator: a node’s phone', () => {
|
|
120
|
+
(0, artifact_store_1.useArtifactStore)();
|
|
121
|
+
beforeEach(() => {
|
|
122
|
+
sinon_1.default.stub(deviceStoreModule.DeviceStoreFactory, 'getStore').returns({
|
|
123
|
+
findDevice: sinon_1.default
|
|
124
|
+
.stub()
|
|
125
|
+
.callsFake((_a) => __awaiter(void 0, [_a], void 0, function* ({ udid }) { return ({ udid, host: 'h', busy: false }); })),
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
afterEach(() => sinon_1.default.restore());
|
|
129
|
+
/** A store that keeps what create() was given, as listGroup's rows. */
|
|
130
|
+
function rowStore() {
|
|
131
|
+
const rows = [];
|
|
132
|
+
return {
|
|
133
|
+
rows,
|
|
134
|
+
create: sinon_1.default.stub().callsFake((i) => __awaiter(this, void 0, void 0, function* () {
|
|
135
|
+
rows.push({
|
|
136
|
+
id: i.id,
|
|
137
|
+
group_id: i.groupId,
|
|
138
|
+
device_udid: i.deviceUdid,
|
|
139
|
+
device_host: i.deviceHost,
|
|
140
|
+
file_path: i.filePath,
|
|
141
|
+
started_at: new Date().toISOString(),
|
|
142
|
+
status: 'RECORDING',
|
|
143
|
+
});
|
|
144
|
+
return i;
|
|
145
|
+
})),
|
|
146
|
+
finalize: sinon_1.default.stub().resolves({}),
|
|
147
|
+
listActive: sinon_1.default.stub().resolves([]),
|
|
148
|
+
listGroup: sinon_1.default.stub().callsFake(() => __awaiter(this, void 0, void 0, function* () { return rows; })),
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
const relayFor = (udid, port) => {
|
|
152
|
+
const close = sinon_1.default.stub().resolves();
|
|
153
|
+
const fn = sinon_1.default.stub().callsFake((u) => __awaiter(void 0, void 0, void 0, function* () { return (u === udid ? { port, close } : null); }));
|
|
154
|
+
return { fn, close };
|
|
155
|
+
};
|
|
156
|
+
it('records it from its relay’s port, and this server’s own phone from its own stream', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
157
|
+
const relay = relayFor('N1', 5555);
|
|
158
|
+
const { orch, videoPipeline, ensureMjpegPortFn } = makeOrch({ nodeSourceFn: relay.fn });
|
|
159
|
+
yield orch.start({ udids: ['N1', 'L1'], actorId: 'alice' });
|
|
160
|
+
const ports = videoPipeline.startRecording
|
|
161
|
+
.getCalls()
|
|
162
|
+
.map((c) => [c.args[0].udid, c.args[0].mjpegPort]);
|
|
163
|
+
(0, chai_1.expect)(ports).to.deep.equal([
|
|
164
|
+
['N1', 5555],
|
|
165
|
+
['L1', 9100],
|
|
166
|
+
]);
|
|
167
|
+
(0, chai_1.expect)(ensureMjpegPortFn.getCalls().map((c) => c.args[0])).to.deep.equal(['L1']);
|
|
168
|
+
(0, chai_1.expect)(relay.fn.getCalls().map((c) => c.args)).to.deep.equal([
|
|
169
|
+
['N1', 'alice'],
|
|
170
|
+
['L1', 'alice'],
|
|
171
|
+
]);
|
|
172
|
+
const composite = videoPipeline.startComposite.firstCall.args[0].inputs.map((i) => i.mjpegPort);
|
|
173
|
+
(0, chai_1.expect)(composite).to.deep.equal([5555, 9100]);
|
|
174
|
+
}));
|
|
175
|
+
it('closes the relay once the recording has stopped', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
176
|
+
const relay = relayFor('N1', 5555);
|
|
177
|
+
const store = rowStore();
|
|
178
|
+
const { orch } = makeOrch({ nodeSourceFn: relay.fn, store });
|
|
179
|
+
const { groupId } = yield orch.start({ udids: ['N1'], actorId: 'alice' });
|
|
180
|
+
(0, chai_1.expect)(relay.close.called).to.equal(false);
|
|
181
|
+
yield orch.stop(groupId);
|
|
182
|
+
(0, chai_1.expect)(relay.close.calledOnce).to.equal(true);
|
|
183
|
+
}));
|
|
184
|
+
it('closes the relay when that phone’s recording can’t start', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
185
|
+
const relay = relayFor('N1', 5555);
|
|
186
|
+
const videoPipeline = {
|
|
187
|
+
startRecording: sinon_1.default.stub().rejects(new Error('ffmpeg would not start')),
|
|
188
|
+
stopRecording: sinon_1.default.stub().resolves('/tmp/x.mp4'),
|
|
189
|
+
startComposite: sinon_1.default.stub().resolves(),
|
|
190
|
+
stopComposite: sinon_1.default.stub().resolves(null),
|
|
191
|
+
};
|
|
192
|
+
const { orch } = makeOrch({ nodeSourceFn: relay.fn, videoPipeline });
|
|
193
|
+
yield orch.start({ udids: ['N1'], actorId: 'alice' });
|
|
194
|
+
(0, chai_1.expect)(relay.close.calledOnce).to.equal(true);
|
|
195
|
+
}));
|
|
196
|
+
});
|
|
113
197
|
describe('RecordingOrchestrator.start', () => {
|
|
114
198
|
// compositeOutputPath and per-device paths resolve through ArtifactStore.
|
|
115
199
|
(0, artifact_store_1.useArtifactStore)();
|