specrails-desktop 2.63.1 → 2.64.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/client/dist/assets/{ActivityFeedPage-B1bpTy7O.js → ActivityFeedPage-D23wXKgy.js} +1 -1
- package/client/dist/assets/{AgentBrowserCapture-BussBbN3.js → AgentBrowserCapture-DQzS4XcK.js} +1 -1
- package/client/dist/assets/{AgentModeAnalyticsPane-BiT1n3BU.js → AgentModeAnalyticsPane-CFTiSl8T.js} +2 -2
- package/client/dist/assets/{AgentModeCodePane-CUjNfeKa.js → AgentModeCodePane-DAaSzIPA.js} +2 -2
- package/client/dist/assets/{AgentModeJobsPane-RVEwyS59.js → AgentModeJobsPane-C29YpixV.js} +1 -1
- package/client/dist/assets/{AgentsPage-DKE-eMC5.js → AgentsPage-B-sSTP1I.js} +1 -1
- package/client/dist/assets/{AnalyticsPage-Bser2Ly3.js → AnalyticsPage-81fI80nA.js} +1 -1
- package/client/dist/assets/{CodePage-BK0grm6e.js → CodePage-Ct4XEPdx.js} +1 -1
- package/client/dist/assets/{DesktopAnalyticsPage-DEBidZbs.js → DesktopAnalyticsPage-Bt37XOLF.js} +1 -1
- package/client/dist/assets/{DocsDialog-Dhyo57n9.js → DocsDialog-_IEr8umI.js} +1 -1
- package/client/dist/assets/{DocsPage-BcEkPXd6.js → DocsPage-DX9WOqt2.js} +1 -1
- package/client/dist/assets/{ExportDropdown-mRmqdkjr.js → ExportDropdown-Bb1lHx3r.js} +1 -1
- package/client/dist/assets/{InteractiveJobComposer-BlCe3vrU.js → InteractiveJobComposer-DDI6TdsS.js} +1 -1
- package/client/dist/assets/{JobDetailModal-CkAejD1F.js → JobDetailModal-CkD0PBaZ.js} +1 -1
- package/client/dist/assets/{JobDetailPage-P-FS_lKz.js → JobDetailPage-B8Rd4U5J.js} +1 -1
- package/client/dist/assets/{JobsPage-CoUXgYse.js → JobsPage-ChOiSbJn.js} +1 -1
- package/client/dist/assets/{LoopBuilderPage-iFylNk68.js → LoopBuilderPage-6Xwt2G6G.js} +1 -1
- package/client/dist/assets/{LoopPreviewModal-4obS_Ptg.js → LoopPreviewModal-CyDapSvB.js} +1 -1
- package/client/dist/assets/{LoopWindowSurface-CLr5OPqj.js → LoopWindowSurface-gRdx4nmg.js} +1 -1
- package/client/dist/assets/{LoopsPage-eKpWFtCp.js → LoopsPage-BPGVFsH-.js} +1 -1
- package/client/dist/assets/{MinimizedChatsContext-BHIUPVmC.js → MinimizedChatsContext-DHfigjHS.js} +1 -1
- package/client/dist/assets/{PluginsPage-BgTC2CQx.js → PluginsPage-DQRRdCUi.js} +1 -1
- package/client/dist/assets/{ProjectSettingsDialog-B4chTfU8.js → ProjectSettingsDialog-Ce8DSG6H.js} +1 -1
- package/client/dist/assets/{RepositoryDeliveries-DAIxIYsl.js → RepositoryDeliveries-B4ybHOyB.js} +1 -1
- package/client/dist/assets/{RepositoryScopeSelector-DeCoUsRN.js → RepositoryScopeSelector-2eSqR9WK.js} +1 -1
- package/client/dist/assets/{ReviewPacketPage-Cktv0-9b.js → ReviewPacketPage-WVoio8GJ.js} +1 -1
- package/client/dist/assets/{TemplatePreviewModal-BZTV1TM1.js → TemplatePreviewModal-CTBZUXAN.js} +1 -1
- package/client/dist/assets/{TicketDetailModalContext-DiPngt2g.js → TicketDetailModalContext-Dkwo2cDs.js} +1 -1
- package/client/dist/assets/{Trans-ZiXIfj50.js → Trans-BbFxRFtR.js} +1 -1
- package/client/dist/assets/{formatDistanceToNow-CdN5lTyD.js → formatDistanceToNow-NjPHBLfB.js} +1 -1
- package/client/dist/assets/{getTimezoneOffsetInMilliseconds-62h40I4t.js → getTimezoneOffsetInMilliseconds-vJ7qUoqN.js} +1 -1
- package/client/dist/assets/{index-CECj3joE.js → index-IdGpV21X.js} +36 -36
- package/client/dist/assets/{jira-api-C_D_RDhl.js → jira-api-Cabj-H0J.js} +1 -1
- package/client/dist/assets/{project-repositories-Be0CWklo.js → project-repositories-Cnnuj9Ia.js} +1 -1
- package/client/dist/assets/{settings-Hw7av-B1.js → settings-B1NV8Ow9.js} +1 -1
- package/client/dist/assets/settings-BQ8XFZeE.js +1 -0
- package/client/dist/assets/settings-BRkxfBbO.js +1 -0
- package/client/dist/assets/settings-C_CcU1dP.js +1 -0
- package/client/dist/assets/settings-Cto9n0eL.js +1 -0
- package/client/dist/assets/{settings-nryN6wuS.js → settings-Pyw8uYtL.js} +1 -1
- package/client/dist/assets/settings-b3HVCNNd.js +1 -0
- package/client/dist/assets/settings-hdive4u6.js +1 -0
- package/client/dist/assets/{spending-eWiZGhC_.js → spending-CQnrWiR3.js} +1 -1
- package/client/dist/assets/{useDesktop-C0mRIlHT.js → useDesktop-BjLT0_EE.js} +1 -1
- package/client/dist/assets/{useRuntimeRuns-B1a6GChu.js → useRuntimeRuns-C97qEqMg.js} +1 -1
- package/client/dist/assets/{useSharedWebSocket-CcsE5986.js → useSharedWebSocket-Bj4LMp7b.js} +2 -2
- package/client/dist/index.html +15 -15
- package/docs/ci-cd.md +3 -4
- package/docs/getting-started.md +1 -1
- package/docs/internals/api-reference.md +26 -0
- package/docs/internals/core-runtime-updates.md +3 -3
- package/docs/internals/source-map.md +9 -3
- package/docs/platforms/macos.md +4 -4
- package/docs/platforms/windows.md +5 -5
- package/docs/running-pipelines.md +12 -0
- package/package.json +1 -1
- package/server/dist/index.js +14 -1
- package/server/dist/mobile/mobile-admin-router.js +16 -0
- package/server/dist/mobile/mobile-gateway.js +18 -0
- package/server/dist/mobile/mobile-missions.js +6 -4
- package/server/dist/mobile/mobile-preview-channel.js +179 -0
- package/server/dist/mobile/mobile-preview.js +366 -0
- package/server/dist/mobile/mobile-router.js +9 -1
- package/server/dist/mobile/mobile-webrtc-peer.js +54 -4
- package/server/dist/mobile/mobile-ws.js +4 -2
- package/server/dist/modules/browser/domain/preview-origins.js +117 -0
- package/server/dist/modules/browser/runtime/browser-capture-manager.js +141 -18
- package/server/dist/modules/browser/runtime/browser-capture-types.js +10 -1
- package/server/dist/modules/browser/runtime/browser-playwright.js +19 -0
- package/server/dist/modules/browser/runtime/preview-targets.js +80 -0
- package/server/dist/modules/terminals/runtime/background-process-service.js +24 -1
- package/server/dist/project-registry.js +10 -0
- package/client/dist/assets/settings-BO2N-oPf.js +0 -1
- package/client/dist/assets/settings-BQChAs_w.js +0 -1
- package/client/dist/assets/settings-BzmYlcQB.js +0 -1
- package/client/dist/assets/settings-CGjXb6TX.js +0 -1
- package/client/dist/assets/settings-CMxEWY46.js +0 -1
- package/client/dist/assets/settings-C_dRSgI2.js +0 -1
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PreviewInboundLimiter = exports.PreviewChannelClient = exports.PREVIEW_INBOUND_MAX_BYTES = exports.PREVIEW_INBOUND_MAX_PER_MINUTE = exports.PREVIEW_MAX_MESSAGE_BYTES = exports.PREVIEW_CHUNK_HEADER_BYTES = exports.PREVIEW_CHANNEL_PREFIX = void 0;
|
|
4
|
+
exports.encodeFrameChunks = encodeFrameChunks;
|
|
5
|
+
exports.parsePreviewInbound = parsePreviewInbound;
|
|
6
|
+
// Companion app preview: one WebRTC DataChannel per browser session, labelled
|
|
7
|
+
// `preview:<sessionId>`, opened by Desktop on the device's EXISTING peer (a new
|
|
8
|
+
// channel on an established SCTP association needs no SDP renegotiation). It is
|
|
9
|
+
// separate from the `mobile` RPC channel so JPEG frames never queue ahead of RPC.
|
|
10
|
+
//
|
|
11
|
+
// Wire format (Desktop → Companion):
|
|
12
|
+
// - text: JSON control (`ready`, `nav`, `popup`, `closed`) — always small.
|
|
13
|
+
// - binary: screencast frame fragments, each `u32 frameSeq | u16 index |
|
|
14
|
+
// u16 count` (big-endian) + payload. A frame renders only once all
|
|
15
|
+
// of its fragments arrived; a newer `frameSeq` discards an older
|
|
16
|
+
// incomplete one.
|
|
17
|
+
// Wire format (Companion → Desktop): JSON text `{type:'input', event}` and
|
|
18
|
+
// `{type:'navigate', action, url?}`.
|
|
19
|
+
exports.PREVIEW_CHANNEL_PREFIX = 'preview:';
|
|
20
|
+
exports.PREVIEW_CHUNK_HEADER_BYTES = 8;
|
|
21
|
+
/** Same per-message budget the `mobile` channel's text chunking proved safe
|
|
22
|
+
* across werift, libwebrtc (native companion) and browsers (web companion). */
|
|
23
|
+
exports.PREVIEW_MAX_MESSAGE_BYTES = 16000;
|
|
24
|
+
const MAX_CHUNKS = 0xffff;
|
|
25
|
+
const WS_OPEN = 1;
|
|
26
|
+
const WS_CLOSED = 3;
|
|
27
|
+
/** Mirrors the PTY-tuned cap of `/ws/browser/:id` (BUG-MOBILE-07). */
|
|
28
|
+
exports.PREVIEW_INBOUND_MAX_PER_MINUTE = 6000;
|
|
29
|
+
exports.PREVIEW_INBOUND_MAX_BYTES = 64 * 1024;
|
|
30
|
+
/** Split one JPEG frame into header-prefixed binary fragments. */
|
|
31
|
+
function encodeFrameChunks(frameSeq, frame, maxMessageBytes = exports.PREVIEW_MAX_MESSAGE_BYTES) {
|
|
32
|
+
const payload = maxMessageBytes - exports.PREVIEW_CHUNK_HEADER_BYTES;
|
|
33
|
+
if (payload <= 0)
|
|
34
|
+
throw new RangeError('maxMessageBytes too small');
|
|
35
|
+
const count = Math.max(1, Math.ceil(frame.length / payload));
|
|
36
|
+
if (count > MAX_CHUNKS)
|
|
37
|
+
throw new RangeError('frame too large');
|
|
38
|
+
const seq = frameSeq >>> 0;
|
|
39
|
+
const chunks = [];
|
|
40
|
+
for (let index = 0; index < count; index++) {
|
|
41
|
+
const part = frame.subarray(index * payload, (index + 1) * payload);
|
|
42
|
+
const chunk = Buffer.allocUnsafe(exports.PREVIEW_CHUNK_HEADER_BYTES + part.length);
|
|
43
|
+
chunk.writeUInt32BE(seq, 0);
|
|
44
|
+
chunk.writeUInt16BE(index, 4);
|
|
45
|
+
chunk.writeUInt16BE(count, 6);
|
|
46
|
+
part.copy(chunk, exports.PREVIEW_CHUNK_HEADER_BYTES);
|
|
47
|
+
chunks.push(chunk);
|
|
48
|
+
}
|
|
49
|
+
return chunks;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Presents a preview DataChannel to `BrowserCaptureManager` as a
|
|
53
|
+
* `BrowserWsClient`, so attach/detach, popup state and the newest-wins
|
|
54
|
+
* screencast fan-out (which checks `bufferedAmount` BEFORE handing over a
|
|
55
|
+
* frame) are reused unchanged. A frame is always sent whole: conflation runs
|
|
56
|
+
* per frame, never per fragment, so a partial frame never goes out.
|
|
57
|
+
*/
|
|
58
|
+
class PreviewChannelClient {
|
|
59
|
+
channel;
|
|
60
|
+
frameSeq = 0;
|
|
61
|
+
constructor(channel) {
|
|
62
|
+
this.channel = channel;
|
|
63
|
+
}
|
|
64
|
+
get readyState() {
|
|
65
|
+
return this.channel.readyState === 'open' ? WS_OPEN : WS_CLOSED;
|
|
66
|
+
}
|
|
67
|
+
get bufferedAmount() {
|
|
68
|
+
return this.channel.bufferedAmount;
|
|
69
|
+
}
|
|
70
|
+
send(data) {
|
|
71
|
+
if (typeof data === 'string') {
|
|
72
|
+
this.channel.send(data);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
const seq = this.frameSeq;
|
|
76
|
+
this.frameSeq = (this.frameSeq + 1) >>> 0;
|
|
77
|
+
for (const chunk of encodeFrameChunks(seq, data))
|
|
78
|
+
this.channel.send(chunk);
|
|
79
|
+
}
|
|
80
|
+
close(_code, reason) {
|
|
81
|
+
try {
|
|
82
|
+
if (this.channel.readyState === 'open')
|
|
83
|
+
this.channel.send(JSON.stringify({ type: 'closed', reason: reason ?? 'session_closed' }));
|
|
84
|
+
}
|
|
85
|
+
catch { /* the channel is already going away */ }
|
|
86
|
+
try {
|
|
87
|
+
this.channel.close();
|
|
88
|
+
}
|
|
89
|
+
catch { /* ignore */ }
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
exports.PreviewChannelClient = PreviewChannelClient;
|
|
93
|
+
const finite = (value) => typeof value === 'number' && Number.isFinite(value);
|
|
94
|
+
const modifiers = (value) => Number.isInteger(value) && value >= 0 && value <= 15 ? value : undefined;
|
|
95
|
+
const BUTTONS = new Set(['left', 'middle', 'right']);
|
|
96
|
+
function parseEvent(raw) {
|
|
97
|
+
if (!raw || typeof raw !== 'object')
|
|
98
|
+
return null;
|
|
99
|
+
const e = raw;
|
|
100
|
+
switch (e.type) {
|
|
101
|
+
case 'mouse': {
|
|
102
|
+
if (!['move', 'down', 'up'].includes(e.action) || !finite(e.x) || !finite(e.y) || e.x < 0 || e.y < 0)
|
|
103
|
+
return null;
|
|
104
|
+
const button = typeof e.button === 'string' && BUTTONS.has(e.button) ? e.button : undefined;
|
|
105
|
+
const clickCount = Number.isInteger(e.clickCount) && e.clickCount >= 1 && e.clickCount <= 3 ? e.clickCount : undefined;
|
|
106
|
+
return { type: 'mouse', action: e.action, x: e.x, y: e.y, ...(button ? { button } : {}), ...(clickCount ? { clickCount } : {}), ...(modifiers(e.modifiers) !== undefined ? { modifiers: modifiers(e.modifiers) } : {}) };
|
|
107
|
+
}
|
|
108
|
+
case 'wheel': {
|
|
109
|
+
if (!finite(e.x) || !finite(e.y) || !finite(e.deltaX) || !finite(e.deltaY) || e.x < 0 || e.y < 0)
|
|
110
|
+
return null;
|
|
111
|
+
const clamp = (v) => Math.max(-10_000, Math.min(10_000, v));
|
|
112
|
+
return { type: 'wheel', x: e.x, y: e.y, deltaX: clamp(e.deltaX), deltaY: clamp(e.deltaY), ...(modifiers(e.modifiers) !== undefined ? { modifiers: modifiers(e.modifiers) } : {}) };
|
|
113
|
+
}
|
|
114
|
+
case 'key': {
|
|
115
|
+
if (!['down', 'up'].includes(e.action) || typeof e.key !== 'string' || e.key.length === 0 || e.key.length > 32)
|
|
116
|
+
return null;
|
|
117
|
+
const code = typeof e.code === 'string' && e.code.length <= 32 ? e.code : undefined;
|
|
118
|
+
const text = typeof e.text === 'string' && e.text.length <= 8 ? e.text : undefined;
|
|
119
|
+
return { type: 'key', action: e.action, key: e.key, ...(code ? { code } : {}), ...(text !== undefined ? { text } : {}), ...(modifiers(e.modifiers) !== undefined ? { modifiers: modifiers(e.modifiers) } : {}) };
|
|
120
|
+
}
|
|
121
|
+
case 'resize': {
|
|
122
|
+
if (!finite(e.width) || !finite(e.height) || e.width <= 0 || e.height <= 0)
|
|
123
|
+
return null;
|
|
124
|
+
return { type: 'resize', width: e.width, height: e.height, ...(finite(e.deviceScaleFactor) ? { deviceScaleFactor: e.deviceScaleFactor } : {}) };
|
|
125
|
+
}
|
|
126
|
+
default:
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
/** Validate one inbound control message; anything malformed is dropped. */
|
|
131
|
+
function parsePreviewInbound(text) {
|
|
132
|
+
if (text.length > exports.PREVIEW_INBOUND_MAX_BYTES)
|
|
133
|
+
return null;
|
|
134
|
+
let msg;
|
|
135
|
+
try {
|
|
136
|
+
msg = JSON.parse(text);
|
|
137
|
+
}
|
|
138
|
+
catch {
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
141
|
+
if (!msg || typeof msg !== 'object')
|
|
142
|
+
return null;
|
|
143
|
+
if (msg.type === 'input') {
|
|
144
|
+
const event = parseEvent(msg.event);
|
|
145
|
+
return event ? { type: 'input', event } : null;
|
|
146
|
+
}
|
|
147
|
+
if (msg.type === 'navigate') {
|
|
148
|
+
const action = msg.action ?? 'goto';
|
|
149
|
+
if (!['goto', 'back', 'forward', 'reload'].includes(action))
|
|
150
|
+
return null;
|
|
151
|
+
if (action === 'goto' && (typeof msg.url !== 'string' || msg.url.length > 2048))
|
|
152
|
+
return null;
|
|
153
|
+
return { type: 'navigate', action: action, ...(action === 'goto' ? { url: msg.url } : {}) };
|
|
154
|
+
}
|
|
155
|
+
return null;
|
|
156
|
+
}
|
|
157
|
+
/** Sliding one-minute message budget for one channel. */
|
|
158
|
+
class PreviewInboundLimiter {
|
|
159
|
+
now;
|
|
160
|
+
maxPerMinute;
|
|
161
|
+
windowStart = 0;
|
|
162
|
+
count = 0;
|
|
163
|
+
constructor(now = Date.now, maxPerMinute = exports.PREVIEW_INBOUND_MAX_PER_MINUTE) {
|
|
164
|
+
this.now = now;
|
|
165
|
+
this.maxPerMinute = maxPerMinute;
|
|
166
|
+
}
|
|
167
|
+
take() {
|
|
168
|
+
const at = this.now();
|
|
169
|
+
if (at - this.windowStart >= 60_000) {
|
|
170
|
+
this.windowStart = at;
|
|
171
|
+
this.count = 0;
|
|
172
|
+
}
|
|
173
|
+
if (this.count >= this.maxPerMinute)
|
|
174
|
+
return false;
|
|
175
|
+
this.count += 1;
|
|
176
|
+
return true;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
exports.PreviewInboundLimiter = PreviewInboundLimiter;
|
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MobilePreviewService = exports.PreviewError = void 0;
|
|
4
|
+
exports.createMobilePreviewRouter = createMobilePreviewRouter;
|
|
5
|
+
const express_1 = require("express");
|
|
6
|
+
const browser_capture_types_1 = require("../modules/browser/runtime/browser-capture-types");
|
|
7
|
+
const preview_origins_1 = require("../modules/browser/domain/preview-origins");
|
|
8
|
+
const agent_store_1 = require("../modules/agents/runtime/agent-store");
|
|
9
|
+
const mobile_missions_1 = require("./mobile-missions");
|
|
10
|
+
const mobile_preview_channel_1 = require("./mobile-preview-channel");
|
|
11
|
+
class PreviewError extends Error {
|
|
12
|
+
status;
|
|
13
|
+
code;
|
|
14
|
+
constructor(status, code, message) {
|
|
15
|
+
super(message);
|
|
16
|
+
this.status = status;
|
|
17
|
+
this.code = code;
|
|
18
|
+
this.name = 'PreviewError';
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.PreviewError = PreviewError;
|
|
22
|
+
/**
|
|
23
|
+
* Companion app-preview use cases. Owns only the channel bindings; sessions,
|
|
24
|
+
* budgets and the origin policy live in BrowserCaptureManager, targets in the
|
|
25
|
+
* process-log source. A binding is replaced on re-attach (new peer after a
|
|
26
|
+
* Wi-Fi drop) and detached — never killed — when its channel closes, so the
|
|
27
|
+
* idle sweep reclaims abandoned previews.
|
|
28
|
+
*/
|
|
29
|
+
class MobilePreviewService {
|
|
30
|
+
deps;
|
|
31
|
+
bindings = new Map();
|
|
32
|
+
now;
|
|
33
|
+
constructor(deps) {
|
|
34
|
+
this.deps = deps;
|
|
35
|
+
this.now = deps.now ?? Date.now;
|
|
36
|
+
}
|
|
37
|
+
available() {
|
|
38
|
+
return this.deps.enabled();
|
|
39
|
+
}
|
|
40
|
+
/** Targets of a mission's running processes. */
|
|
41
|
+
targetsForMission(projectId, chatId) {
|
|
42
|
+
if (!this.available())
|
|
43
|
+
return [];
|
|
44
|
+
return this.deps.targets.list(projectId).filter((target) => target.chatId === chatId);
|
|
45
|
+
}
|
|
46
|
+
async open(device, projectId, input) {
|
|
47
|
+
const browser = this.requireBrowser(projectId);
|
|
48
|
+
const target = this.deps.targets.forProcess(projectId, input.processId);
|
|
49
|
+
if (!target || target.chatId !== input.chatId)
|
|
50
|
+
throw new PreviewError(404, 'preview_target_gone', 'This process is no longer running or announced no URL.');
|
|
51
|
+
const origin = (0, preview_origins_1.previewOrigin)(input.url);
|
|
52
|
+
if (!origin || !target.urls.some((url) => (0, preview_origins_1.previewOrigin)(url) === origin)) {
|
|
53
|
+
throw new PreviewError(400, 'preview_url_not_announced', 'Only URLs announced by this process can be previewed.');
|
|
54
|
+
}
|
|
55
|
+
let meta;
|
|
56
|
+
try {
|
|
57
|
+
meta = await browser.create({ initialUrl: input.url, owner: { kind: 'device', deviceId: device.id, deviceName: device.name }, viewport: input.viewport });
|
|
58
|
+
}
|
|
59
|
+
catch (err) {
|
|
60
|
+
throw translateBrowserError(err);
|
|
61
|
+
}
|
|
62
|
+
try {
|
|
63
|
+
const opened = { sessionId: meta.id, channel: this.bind(projectId, device.id, browser, meta.id), url: input.url };
|
|
64
|
+
this.changed();
|
|
65
|
+
return opened;
|
|
66
|
+
}
|
|
67
|
+
catch (err) {
|
|
68
|
+
await browser.kill(meta.id);
|
|
69
|
+
throw err;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/** Re-attach a live session after the peer reconnected. */
|
|
73
|
+
attach(device, projectId, sessionId) {
|
|
74
|
+
const browser = this.requireBrowser(projectId);
|
|
75
|
+
this.requireOwner(browser, device.id, sessionId);
|
|
76
|
+
return { sessionId, channel: this.bind(projectId, device.id, browser, sessionId) };
|
|
77
|
+
}
|
|
78
|
+
async navigate(device, projectId, sessionId, action, url) {
|
|
79
|
+
const browser = this.requireBrowser(projectId);
|
|
80
|
+
this.requireOwner(browser, device.id, sessionId);
|
|
81
|
+
try {
|
|
82
|
+
const result = await browser.navigateAsDevice(sessionId, device.id, action, url);
|
|
83
|
+
if (!result)
|
|
84
|
+
throw new PreviewError(404, 'preview_session_closed', 'This preview session has ended.');
|
|
85
|
+
return { url: result.url, title: result.title };
|
|
86
|
+
}
|
|
87
|
+
catch (err) {
|
|
88
|
+
throw translateBrowserError(err);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
async close(device, projectId, sessionId) {
|
|
92
|
+
const browser = this.requireBrowser(projectId);
|
|
93
|
+
this.requireOwner(browser, device.id, sessionId);
|
|
94
|
+
this.unbind(sessionId);
|
|
95
|
+
await browser.kill(sessionId);
|
|
96
|
+
this.changed();
|
|
97
|
+
}
|
|
98
|
+
/** Live device-owned sessions across projects (Desktop indicator). */
|
|
99
|
+
listDeviceSessions() {
|
|
100
|
+
if (!this.available())
|
|
101
|
+
return [];
|
|
102
|
+
const sessions = [];
|
|
103
|
+
for (const browser of this.deps.allBrowsers()) {
|
|
104
|
+
for (const meta of browser.listSessions()) {
|
|
105
|
+
if (meta.owner.kind !== 'device')
|
|
106
|
+
continue;
|
|
107
|
+
sessions.push({ projectId: meta.projectId, sessionId: meta.id, deviceId: meta.owner.deviceId, deviceName: meta.owner.deviceName,
|
|
108
|
+
url: meta.url, title: meta.title, createdAt: meta.createdAt });
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return sessions.sort((a, b) => b.createdAt - a.createdAt);
|
|
112
|
+
}
|
|
113
|
+
/** The Desktop user ends a phone's preview; the viewer shows "session closed". */
|
|
114
|
+
async endFromDesktop(projectId, sessionId) {
|
|
115
|
+
const browser = this.deps.browserFor(projectId);
|
|
116
|
+
if (!browser || browser.sessionOwner(sessionId)?.kind !== 'device')
|
|
117
|
+
return false;
|
|
118
|
+
// Kill first so the attached channel client receives `closed` before the
|
|
119
|
+
// binding is dropped.
|
|
120
|
+
const killed = await browser.kill(sessionId);
|
|
121
|
+
this.unbind(sessionId);
|
|
122
|
+
if (killed)
|
|
123
|
+
this.changed();
|
|
124
|
+
return killed;
|
|
125
|
+
}
|
|
126
|
+
/** Device revoked/unpaired: end every preview it owns, in every project. */
|
|
127
|
+
async closeForDevice(deviceId) {
|
|
128
|
+
for (const [sessionId, binding] of [...this.bindings])
|
|
129
|
+
if (binding.deviceId === deviceId)
|
|
130
|
+
this.unbind(sessionId);
|
|
131
|
+
for (const browser of this.deps.allBrowsers()) {
|
|
132
|
+
try {
|
|
133
|
+
await browser.killDeviceSessions(deviceId);
|
|
134
|
+
}
|
|
135
|
+
catch { /* best-effort per project */ }
|
|
136
|
+
}
|
|
137
|
+
this.changed();
|
|
138
|
+
}
|
|
139
|
+
changed() {
|
|
140
|
+
try {
|
|
141
|
+
this.deps.onChange?.();
|
|
142
|
+
}
|
|
143
|
+
catch { /* a notification failure never fails the use case */ }
|
|
144
|
+
}
|
|
145
|
+
requireBrowser(projectId) {
|
|
146
|
+
if (!this.available())
|
|
147
|
+
throw new PreviewError(404, 'preview_unavailable', 'App preview requires browser capture to be enabled on Desktop.');
|
|
148
|
+
const browser = this.deps.browserFor(projectId);
|
|
149
|
+
if (!browser)
|
|
150
|
+
throw new PreviewError(404, 'unknown_project', 'Unknown project');
|
|
151
|
+
return browser;
|
|
152
|
+
}
|
|
153
|
+
requireOwner(browser, deviceId, sessionId) {
|
|
154
|
+
const owner = browser.sessionOwner(sessionId);
|
|
155
|
+
// A session of another device or of Desktop is indistinguishable from a
|
|
156
|
+
// missing one: never confirm its existence to this device.
|
|
157
|
+
if (!owner || owner.kind !== 'device' || owner.deviceId !== deviceId) {
|
|
158
|
+
throw new PreviewError(404, 'preview_session_closed', 'This preview session has ended.');
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
bind(projectId, deviceId, browser, sessionId) {
|
|
162
|
+
const label = `${mobile_preview_channel_1.PREVIEW_CHANNEL_PREFIX}${sessionId}`;
|
|
163
|
+
const channel = this.deps.openChannel(deviceId, label);
|
|
164
|
+
if (!channel)
|
|
165
|
+
throw new PreviewError(409, 'preview_requires_webrtc', 'Reconnect Companion to Desktop to preview apps.');
|
|
166
|
+
this.unbind(sessionId);
|
|
167
|
+
const client = new mobile_preview_channel_1.PreviewChannelClient(channel);
|
|
168
|
+
const binding = { projectId, deviceId, channel, client };
|
|
169
|
+
this.bindings.set(sessionId, binding);
|
|
170
|
+
const limiter = new mobile_preview_channel_1.PreviewInboundLimiter(this.now);
|
|
171
|
+
const current = () => this.bindings.get(sessionId) === binding;
|
|
172
|
+
channel.onOpen(() => {
|
|
173
|
+
if (!current())
|
|
174
|
+
return;
|
|
175
|
+
void browser.attach(sessionId, client).then((meta) => {
|
|
176
|
+
if (!meta)
|
|
177
|
+
client.close(1000, 'session_closed');
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
channel.onMessage((data) => {
|
|
181
|
+
if (!current() || !limiter.take())
|
|
182
|
+
return;
|
|
183
|
+
const msg = (0, mobile_preview_channel_1.parsePreviewInbound)(typeof data === 'string' ? data : data.toString('utf8'));
|
|
184
|
+
if (!msg)
|
|
185
|
+
return;
|
|
186
|
+
if (msg.type === 'input') {
|
|
187
|
+
void browser.handleInput(sessionId, msg.event).catch(() => { });
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
void browser.navigateAsDevice(sessionId, deviceId, msg.action, msg.url).catch(() => {
|
|
191
|
+
// A rejected or failed navigation keeps the current page; tell the
|
|
192
|
+
// viewer so it can restore its address field.
|
|
193
|
+
try {
|
|
194
|
+
channel.send(JSON.stringify({ type: 'nav_rejected' }));
|
|
195
|
+
}
|
|
196
|
+
catch { /* ignore */ }
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
channel.onClose(() => {
|
|
201
|
+
browser.detach(sessionId, client);
|
|
202
|
+
if (current())
|
|
203
|
+
this.bindings.delete(sessionId);
|
|
204
|
+
});
|
|
205
|
+
return label;
|
|
206
|
+
}
|
|
207
|
+
unbind(sessionId) {
|
|
208
|
+
const binding = this.bindings.get(sessionId);
|
|
209
|
+
if (!binding)
|
|
210
|
+
return;
|
|
211
|
+
this.bindings.delete(sessionId);
|
|
212
|
+
try {
|
|
213
|
+
binding.channel.close();
|
|
214
|
+
}
|
|
215
|
+
catch { /* ignore */ }
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
exports.MobilePreviewService = MobilePreviewService;
|
|
219
|
+
function translateBrowserError(err) {
|
|
220
|
+
if (err instanceof PreviewError)
|
|
221
|
+
return err;
|
|
222
|
+
if (err instanceof browser_capture_types_1.BrowserNavigationRejectedError)
|
|
223
|
+
return new PreviewError(400, 'preview_url_not_announced', 'Only URLs announced by this project can be opened in a preview.');
|
|
224
|
+
if (err instanceof browser_capture_types_1.BrowserLimitExceededError)
|
|
225
|
+
return new PreviewError(429, 'preview_limit', `Up to ${err.limit} phones can preview this project at once. Close another preview and retry.`);
|
|
226
|
+
return new PreviewError(502, 'preview_failed', 'Desktop could not open the preview. Retry in a moment.');
|
|
227
|
+
}
|
|
228
|
+
const ID = /^[A-Za-z0-9_-]{1,160}$/;
|
|
229
|
+
const ACTIONS = new Set(['goto', 'back', 'forward', 'reload']);
|
|
230
|
+
function viewportFrom(raw) {
|
|
231
|
+
if (!raw || typeof raw !== 'object')
|
|
232
|
+
return undefined;
|
|
233
|
+
const v = raw;
|
|
234
|
+
const ok = (n) => typeof n === 'number' && Number.isFinite(n) && n > 0;
|
|
235
|
+
if (!ok(v.width) || !ok(v.height))
|
|
236
|
+
return undefined;
|
|
237
|
+
return { width: v.width, height: v.height, ...(ok(v.deviceScaleFactor) ? { deviceScaleFactor: v.deviceScaleFactor } : {}) };
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Gateway routes. Preview targets come from mission processes, so they follow
|
|
241
|
+
* the mission rule: an all-projects device grant (`mobile-mission-control`).
|
|
242
|
+
*/
|
|
243
|
+
function createMobilePreviewRouter({ db, preview }) {
|
|
244
|
+
const router = (0, express_1.Router)();
|
|
245
|
+
const segment = (value) => typeof value === 'string' ? value : '';
|
|
246
|
+
const device = (req) => {
|
|
247
|
+
const row = req.mobileDevice;
|
|
248
|
+
return { id: row.id, name: row.name };
|
|
249
|
+
};
|
|
250
|
+
const fail = (res, err) => {
|
|
251
|
+
if (err instanceof PreviewError) {
|
|
252
|
+
res.status(err.status).json({ error: err.message, code: err.code });
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
res.status(500).json({ error: 'Preview failed', code: 'preview_failed' });
|
|
256
|
+
};
|
|
257
|
+
const gate = (req, res) => {
|
|
258
|
+
const pid = segment(req.params.pid);
|
|
259
|
+
if (!ID.test(pid)) {
|
|
260
|
+
res.status(400).json({ error: 'Invalid parameter' });
|
|
261
|
+
return null;
|
|
262
|
+
}
|
|
263
|
+
if (!(0, mobile_missions_1.mobileCapabilities)(db, device(req).id).features.missions) {
|
|
264
|
+
res.status(403).json({ error: mobile_missions_1.MISSION_ACCESS_REASON });
|
|
265
|
+
return null;
|
|
266
|
+
}
|
|
267
|
+
if (!preview.available()) {
|
|
268
|
+
res.status(404).json({ error: 'App preview is unavailable on Desktop.', code: 'preview_unavailable' });
|
|
269
|
+
return null;
|
|
270
|
+
}
|
|
271
|
+
return pid;
|
|
272
|
+
};
|
|
273
|
+
const mission = (res, pid, cid) => {
|
|
274
|
+
if (!ID.test(cid)) {
|
|
275
|
+
res.status(400).json({ error: 'Invalid mission identity' });
|
|
276
|
+
return false;
|
|
277
|
+
}
|
|
278
|
+
const conversation = (0, agent_store_1.getAgentConversation)(db, cid);
|
|
279
|
+
if (!conversation || conversation.pinned_project_id !== pid) {
|
|
280
|
+
res.status(404).json({ error: 'Mission not found in this project' });
|
|
281
|
+
return false;
|
|
282
|
+
}
|
|
283
|
+
return true;
|
|
284
|
+
};
|
|
285
|
+
router.get('/projects/:pid/missions/:cid/preview-targets', (req, res) => {
|
|
286
|
+
const pid = gate(req, res);
|
|
287
|
+
if (!pid)
|
|
288
|
+
return;
|
|
289
|
+
const cid = segment(req.params.cid);
|
|
290
|
+
if (!mission(res, pid, cid))
|
|
291
|
+
return;
|
|
292
|
+
res.json({ targets: preview.targetsForMission(pid, cid).map(({ processId, urls }) => ({ processId, urls })) });
|
|
293
|
+
});
|
|
294
|
+
router.post('/projects/:pid/preview-sessions', async (req, res) => {
|
|
295
|
+
const pid = gate(req, res);
|
|
296
|
+
if (!pid)
|
|
297
|
+
return;
|
|
298
|
+
const body = (req.body ?? {});
|
|
299
|
+
const cid = segment(body.missionId), processId = segment(body.processId), url = segment(body.url);
|
|
300
|
+
if (!mission(res, pid, cid))
|
|
301
|
+
return;
|
|
302
|
+
if (!ID.test(processId) || !url || url.length > 2048) {
|
|
303
|
+
res.status(400).json({ error: 'processId and url are required' });
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
try {
|
|
307
|
+
res.status(201).json(await preview.open(device(req), pid, { chatId: cid, processId, url, viewport: viewportFrom(body.viewport) }));
|
|
308
|
+
}
|
|
309
|
+
catch (err) {
|
|
310
|
+
fail(res, err);
|
|
311
|
+
}
|
|
312
|
+
});
|
|
313
|
+
router.post('/projects/:pid/preview-sessions/:sid/attach', (req, res) => {
|
|
314
|
+
const pid = gate(req, res);
|
|
315
|
+
if (!pid)
|
|
316
|
+
return;
|
|
317
|
+
const sid = segment(req.params.sid);
|
|
318
|
+
if (!ID.test(sid)) {
|
|
319
|
+
res.status(400).json({ error: 'Invalid parameter' });
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
try {
|
|
323
|
+
res.json(preview.attach(device(req), pid, sid));
|
|
324
|
+
}
|
|
325
|
+
catch (err) {
|
|
326
|
+
fail(res, err);
|
|
327
|
+
}
|
|
328
|
+
});
|
|
329
|
+
router.post('/projects/:pid/preview-sessions/:sid/navigate', async (req, res) => {
|
|
330
|
+
const pid = gate(req, res);
|
|
331
|
+
if (!pid)
|
|
332
|
+
return;
|
|
333
|
+
const sid = segment(req.params.sid);
|
|
334
|
+
const body = (req.body ?? {});
|
|
335
|
+
const action = segment(body.action) || 'goto';
|
|
336
|
+
const url = typeof body.url === 'string' ? body.url : undefined;
|
|
337
|
+
if (!ID.test(sid) || !ACTIONS.has(action) || (action === 'goto' && (!url || url.length > 2048))) {
|
|
338
|
+
res.status(400).json({ error: 'Invalid navigation' });
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
try {
|
|
342
|
+
res.json(await preview.navigate(device(req), pid, sid, action, url));
|
|
343
|
+
}
|
|
344
|
+
catch (err) {
|
|
345
|
+
fail(res, err);
|
|
346
|
+
}
|
|
347
|
+
});
|
|
348
|
+
router.delete('/projects/:pid/preview-sessions/:sid', async (req, res) => {
|
|
349
|
+
const pid = gate(req, res);
|
|
350
|
+
if (!pid)
|
|
351
|
+
return;
|
|
352
|
+
const sid = segment(req.params.sid);
|
|
353
|
+
if (!ID.test(sid)) {
|
|
354
|
+
res.status(400).json({ error: 'Invalid parameter' });
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
357
|
+
try {
|
|
358
|
+
await preview.close(device(req), pid, sid);
|
|
359
|
+
res.json({ ok: true });
|
|
360
|
+
}
|
|
361
|
+
catch (err) {
|
|
362
|
+
fail(res, err);
|
|
363
|
+
}
|
|
364
|
+
});
|
|
365
|
+
return router;
|
|
366
|
+
}
|
|
@@ -9,6 +9,7 @@ const mobile_auth_1 = require("./mobile-auth");
|
|
|
9
9
|
const mobile_devices_1 = require("./mobile-devices");
|
|
10
10
|
const mobile_missions_1 = require("./mobile-missions");
|
|
11
11
|
const mobile_code_1 = require("./mobile-code");
|
|
12
|
+
const mobile_preview_1 = require("./mobile-preview");
|
|
12
13
|
// The gateway's authenticated REST surface: the `/v1/*` allow-list. Each route
|
|
13
14
|
// forwards, in-process, via a REAL loopback HTTP request to
|
|
14
15
|
// http://127.0.0.1:<desktopPort> with the master token injected server-side as
|
|
@@ -455,7 +456,9 @@ function createMobileRouter(deps) {
|
|
|
455
456
|
...(body !== undefined ? { body: JSON.stringify(body) } : {}) });
|
|
456
457
|
return { status: response.status, json: await response.json() };
|
|
457
458
|
};
|
|
458
|
-
v1.use((0, mobile_missions_1.createMobileMissionsRouter)({ db: deps.db, upstream: mobileUpstream }));
|
|
459
|
+
v1.use((0, mobile_missions_1.createMobileMissionsRouter)({ db: deps.db, upstream: mobileUpstream, appPreview: () => deps.preview?.available() ?? false }));
|
|
460
|
+
if (deps.preview)
|
|
461
|
+
v1.use((0, mobile_preview_1.createMobilePreviewRouter)({ db: deps.db, preview: deps.preview }));
|
|
459
462
|
v1.use((0, mobile_code_1.createMobileCodeRouter)(mobileUpstream));
|
|
460
463
|
router.use('/v1', v1);
|
|
461
464
|
// Any unmatched gateway path → 404 JSON (NEVER falls through to a SPA handler;
|
|
@@ -472,6 +475,11 @@ exports.MOBILE_ALLOWLIST = [
|
|
|
472
475
|
{ method: 'GET', path: '/v1/projects/:pid/repositories/:rid/code/find' },
|
|
473
476
|
{ method: 'GET', path: '/v1/projects/:pid/repositories/:rid/code/file' },
|
|
474
477
|
{ method: 'GET', path: '/v1/capabilities' },
|
|
478
|
+
{ method: 'GET', path: '/v1/projects/:pid/missions/:cid/preview-targets' },
|
|
479
|
+
{ method: 'POST', path: '/v1/projects/:pid/preview-sessions' },
|
|
480
|
+
{ method: 'POST', path: '/v1/projects/:pid/preview-sessions/:sid/attach' },
|
|
481
|
+
{ method: 'POST', path: '/v1/projects/:pid/preview-sessions/:sid/navigate' },
|
|
482
|
+
{ method: 'DELETE', path: '/v1/projects/:pid/preview-sessions/:sid' },
|
|
475
483
|
{ method: 'GET', path: '/v1/mission-models' },
|
|
476
484
|
{ method: 'PATCH', path: '/v1/projects/:pid/missions/:cid/messages/:mid/intent' },
|
|
477
485
|
{ method: 'GET', path: '/v1/projects/:pid/repositories' },
|
|
@@ -14,6 +14,9 @@ class MobileWebrtcGateway {
|
|
|
14
14
|
// answer to whatever happened to be pending. Per-room keying isolates them.
|
|
15
15
|
_pending = new Map();
|
|
16
16
|
_active = new Set();
|
|
17
|
+
/** The live peer of each authenticated device (latest wins), so Desktop can
|
|
18
|
+
* open extra DataChannels (app preview) on the connection it already has. */
|
|
19
|
+
_byDevice = new Map();
|
|
17
20
|
constructor(_deps) {
|
|
18
21
|
this._deps = _deps;
|
|
19
22
|
}
|
|
@@ -48,17 +51,23 @@ class MobileWebrtcGateway {
|
|
|
48
51
|
// require a valid existing device token instead, and never mint.
|
|
49
52
|
new mobile_datachannel_1.DataChannelPeer(toChannelLike(dc), {
|
|
50
53
|
registerDevice: async (input) => {
|
|
54
|
+
let result;
|
|
51
55
|
if (isReconnect) {
|
|
52
|
-
|
|
56
|
+
result = await this._deps.registerDevice({
|
|
53
57
|
deviceName: input.deviceName,
|
|
54
58
|
platform: input.platform,
|
|
55
59
|
token: input.token,
|
|
56
60
|
requireExistingToken: true,
|
|
57
61
|
});
|
|
58
62
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
63
|
+
else {
|
|
64
|
+
result = input.secret && (0, auth_1.safeEqual)(input.secret, secret)
|
|
65
|
+
? await this._deps.registerDevice({ deviceName: input.deviceName, platform: input.platform, token: input.token })
|
|
66
|
+
: { ok: false };
|
|
67
|
+
}
|
|
68
|
+
if (result.ok)
|
|
69
|
+
this._byDevice.set(result.deviceId, pc);
|
|
70
|
+
return result;
|
|
62
71
|
},
|
|
63
72
|
rpcDispatch: this._deps.rpcDispatch,
|
|
64
73
|
bridge: this._deps.bridge,
|
|
@@ -67,6 +76,9 @@ class MobileWebrtcGateway {
|
|
|
67
76
|
console.log('[webrtc] pc connectionState:', s);
|
|
68
77
|
if (s === 'failed' || s === 'closed' || s === 'disconnected') {
|
|
69
78
|
this._active.delete(pc);
|
|
79
|
+
for (const [deviceId, owned] of this._byDevice)
|
|
80
|
+
if (owned === pc)
|
|
81
|
+
this._byDevice.delete(deviceId);
|
|
70
82
|
// Drop this pc from whichever room slot still holds it.
|
|
71
83
|
if (this._pending.get(key)?.pc === pc)
|
|
72
84
|
this._pending.delete(key);
|
|
@@ -101,6 +113,24 @@ class MobileWebrtcGateway {
|
|
|
101
113
|
return { ok: false };
|
|
102
114
|
}
|
|
103
115
|
}
|
|
116
|
+
/** Open an ordered, reliable DataChannel on the device's live peer (no SDP
|
|
117
|
+
* renegotiation: the SCTP association already exists). Null when the
|
|
118
|
+
* device has no connected WebRTC peer. */
|
|
119
|
+
openChannel(deviceId, label) {
|
|
120
|
+
const pc = this._byDevice.get(deviceId);
|
|
121
|
+
if (!pc || pc.connectionState !== 'connected')
|
|
122
|
+
return null;
|
|
123
|
+
try {
|
|
124
|
+
return toPreviewChannel(pc.createDataChannel(label, { ordered: true }));
|
|
125
|
+
}
|
|
126
|
+
catch {
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
/** Forget a device's peer (revoked). Its channels close with the peer. */
|
|
131
|
+
forgetDevice(deviceId) {
|
|
132
|
+
this._byDevice.delete(deviceId);
|
|
133
|
+
}
|
|
104
134
|
/** Tear down every peer (gateway stopping / disabled). */
|
|
105
135
|
stop() {
|
|
106
136
|
for (const key of [...this._pending.keys()])
|
|
@@ -108,6 +138,7 @@ class MobileWebrtcGateway {
|
|
|
108
138
|
for (const pc of this._active)
|
|
109
139
|
this._close(pc);
|
|
110
140
|
this._active.clear();
|
|
141
|
+
this._byDevice.clear();
|
|
111
142
|
}
|
|
112
143
|
_close(pc) {
|
|
113
144
|
try {
|
|
@@ -137,6 +168,25 @@ function toChannelLike(dc) {
|
|
|
137
168
|
},
|
|
138
169
|
};
|
|
139
170
|
}
|
|
171
|
+
function toPreviewChannel(dc) {
|
|
172
|
+
return {
|
|
173
|
+
get label() { return dc.label; },
|
|
174
|
+
get readyState() { return dc.readyState; },
|
|
175
|
+
get bufferedAmount() { return dc.bufferedAmount; },
|
|
176
|
+
send: (data) => dc.send(data),
|
|
177
|
+
close: () => dc.close(),
|
|
178
|
+
onOpen: (cb) => {
|
|
179
|
+
if (dc.readyState === 'open')
|
|
180
|
+
queueMicrotask(cb);
|
|
181
|
+
else
|
|
182
|
+
dc.stateChanged.subscribe((s) => { if (s === 'open')
|
|
183
|
+
cb(); });
|
|
184
|
+
},
|
|
185
|
+
onMessage: (cb) => { dc.onMessage.subscribe((d) => cb(d)); },
|
|
186
|
+
onClose: (cb) => { dc.stateChanged.subscribe((s) => { if (s === 'closed')
|
|
187
|
+
cb(); }); },
|
|
188
|
+
};
|
|
189
|
+
}
|
|
140
190
|
/** Vanilla ICE: resolve once gathering completes so the offer SDP carries all
|
|
141
191
|
* candidates (there's no trickle channel — the SDP travels by QR). */
|
|
142
192
|
function waitIceComplete(pc) {
|