@full-self-browsing/phantom-stream 0.1.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/LICENSE +21 -0
- package/README.md +263 -0
- package/bin/phantom-stream.js +193 -0
- package/dist/types/adapters/bookmarklet.d.ts +22 -0
- package/dist/types/adapters/bookmarklet.d.ts.map +1 -0
- package/dist/types/adapters/browser-inject.d.ts +7 -0
- package/dist/types/adapters/browser-inject.d.ts.map +1 -0
- package/dist/types/adapters/extension.d.ts +43 -0
- package/dist/types/adapters/extension.d.ts.map +1 -0
- package/dist/types/adapters/playwright-inject.d.ts +2 -0
- package/dist/types/adapters/playwright-inject.d.ts.map +1 -0
- package/dist/types/adapters/playwright.d.ts +14 -0
- package/dist/types/adapters/playwright.d.ts.map +1 -0
- package/dist/types/capture/index.d.ts +241 -0
- package/dist/types/capture/index.d.ts.map +1 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/protocol/constants.d.ts +35 -0
- package/dist/types/protocol/constants.d.ts.map +1 -0
- package/dist/types/protocol/envelope.d.ts +41 -0
- package/dist/types/protocol/envelope.d.ts.map +1 -0
- package/dist/types/protocol/index.d.ts +5 -0
- package/dist/types/protocol/index.d.ts.map +1 -0
- package/dist/types/protocol/messages.d.ts +520 -0
- package/dist/types/protocol/messages.d.ts.map +1 -0
- package/dist/types/protocol/remote-control.d.ts +70 -0
- package/dist/types/protocol/remote-control.d.ts.map +1 -0
- package/dist/types/relay/backends/ws.d.ts +39 -0
- package/dist/types/relay/backends/ws.d.ts.map +1 -0
- package/dist/types/relay/index.d.ts +4 -0
- package/dist/types/relay/index.d.ts.map +1 -0
- package/dist/types/relay/limits.d.ts +54 -0
- package/dist/types/relay/limits.d.ts.map +1 -0
- package/dist/types/relay/relay.d.ts +73 -0
- package/dist/types/relay/relay.d.ts.map +1 -0
- package/dist/types/renderer/diff.d.ts +62 -0
- package/dist/types/renderer/diff.d.ts.map +1 -0
- package/dist/types/renderer/index.d.ts +211 -0
- package/dist/types/renderer/index.d.ts.map +1 -0
- package/dist/types/renderer/overlays.d.ts +166 -0
- package/dist/types/renderer/overlays.d.ts.map +1 -0
- package/dist/types/renderer/sanitize.d.ts +73 -0
- package/dist/types/renderer/sanitize.d.ts.map +1 -0
- package/dist/types/renderer/snapshot.d.ts +41 -0
- package/dist/types/renderer/snapshot.d.ts.map +1 -0
- package/dist/types/transport/websocket.d.ts +44 -0
- package/dist/types/transport/websocket.d.ts.map +1 -0
- package/docs/ARCHITECTURE.md +273 -0
- package/docs/DESIGN-HISTORY.md +120 -0
- package/docs/QUICKSTARTS.md +289 -0
- package/docs/RELEASE.md +60 -0
- package/docs/SECURITY.md +156 -0
- package/docs/paper/OUTLINE.md +100 -0
- package/examples/bookmarklet-demo/demo.css +102 -0
- package/examples/bookmarklet-demo/server.js +297 -0
- package/examples/bookmarklet-demo/source.html +52 -0
- package/examples/bookmarklet-demo/viewer.html +48 -0
- package/examples/extension-mv3/demo.css +102 -0
- package/examples/extension-mv3/server.js +350 -0
- package/examples/extension-mv3/source.html +48 -0
- package/examples/extension-mv3/viewer.html +48 -0
- package/examples/loopback-mirror.html +369 -0
- package/examples/loopback-transport.js +65 -0
- package/examples/playwright-demo/demo.css +462 -0
- package/examples/playwright-demo/fixture.html +56 -0
- package/examples/playwright-demo/fixture.js +57 -0
- package/examples/playwright-demo/server.js +517 -0
- package/examples/playwright-demo/viewer.html +112 -0
- package/examples/playwright-demo/viewer.js +414 -0
- package/examples/serve.js +97 -0
- package/examples/two-tab-demo/demo.css +266 -0
- package/examples/two-tab-demo/server.js +233 -0
- package/examples/two-tab-demo/source.html +70 -0
- package/examples/two-tab-demo/source.js +213 -0
- package/examples/two-tab-demo/viewer.html +72 -0
- package/examples/two-tab-demo/viewer.js +121 -0
- package/package.json +107 -0
- package/src/adapters/bookmarklet.js +98 -0
- package/src/adapters/browser-inject.js +17 -0
- package/src/adapters/extension.js +322 -0
- package/src/adapters/playwright-inject.js +4401 -0
- package/src/adapters/playwright.js +540 -0
- package/src/capture/README.md +302 -0
- package/src/capture/index.js +4361 -0
- package/src/index.js +5 -0
- package/src/protocol/constants.js +49 -0
- package/src/protocol/envelope.js +75 -0
- package/src/protocol/index.js +4 -0
- package/src/protocol/messages.js +268 -0
- package/src/protocol/remote-control.js +300 -0
- package/src/relay/README.md +22 -0
- package/src/relay/backends/ws.js +186 -0
- package/src/relay/index.js +3 -0
- package/src/relay/limits.js +105 -0
- package/src/relay/relay.js +397 -0
- package/src/renderer/README.md +443 -0
- package/src/renderer/diff.js +389 -0
- package/src/renderer/index.js +1401 -0
- package/src/renderer/overlays.js +528 -0
- package/src/renderer/sanitize.js +366 -0
- package/src/renderer/snapshot.js +202 -0
- package/src/transport/websocket.js +553 -0
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
* { box-sizing: border-box; }
|
|
2
|
+
|
|
3
|
+
body {
|
|
4
|
+
background: #0f1117;
|
|
5
|
+
color: #e0e0e0;
|
|
6
|
+
font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
|
|
7
|
+
font-size: 15px;
|
|
8
|
+
line-height: 1.5;
|
|
9
|
+
padding: 24px;
|
|
10
|
+
max-width: 1200px;
|
|
11
|
+
margin: 0 auto;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
header { margin-bottom: 24px; }
|
|
15
|
+
|
|
16
|
+
.header-row {
|
|
17
|
+
display: flex;
|
|
18
|
+
align-items: center;
|
|
19
|
+
justify-content: space-between;
|
|
20
|
+
gap: 16px;
|
|
21
|
+
flex-wrap: wrap;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
h1 {
|
|
25
|
+
font-size: 28px;
|
|
26
|
+
font-weight: 600;
|
|
27
|
+
line-height: 1.2;
|
|
28
|
+
margin: 0;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.subtitle {
|
|
32
|
+
color: #888888;
|
|
33
|
+
font-size: 15px;
|
|
34
|
+
font-weight: 400;
|
|
35
|
+
line-height: 1.5;
|
|
36
|
+
margin: 8px 0 0;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
.badge {
|
|
40
|
+
display: inline-flex;
|
|
41
|
+
align-items: center;
|
|
42
|
+
gap: 8px;
|
|
43
|
+
color: #e0e0e0;
|
|
44
|
+
font-size: 13px;
|
|
45
|
+
font-weight: 600;
|
|
46
|
+
line-height: 1.2;
|
|
47
|
+
text-transform: uppercase;
|
|
48
|
+
letter-spacing: 1px;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
.badge-dot {
|
|
52
|
+
width: 8px;
|
|
53
|
+
height: 8px;
|
|
54
|
+
border-radius: 50%;
|
|
55
|
+
background: #22c55e;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
.badge.paused .badge-dot,
|
|
59
|
+
.state-disconnected .badge-dot {
|
|
60
|
+
background: #ef4444;
|
|
61
|
+
animation: none;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
.state-connecting .badge-dot,
|
|
65
|
+
.state-stale .badge-dot {
|
|
66
|
+
background: #eab308;
|
|
67
|
+
animation: none;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.state-live .badge-dot,
|
|
71
|
+
.badge:not(.paused) .badge-dot {
|
|
72
|
+
background: #22c55e;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
@media (prefers-reduced-motion: no-preference) {
|
|
76
|
+
.state-live .badge-dot,
|
|
77
|
+
.badge:not(.paused) .badge-dot {
|
|
78
|
+
animation: pulse 2000ms ease-in-out infinite;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
@keyframes pulse {
|
|
82
|
+
0%, 100% { opacity: 1; }
|
|
83
|
+
50% { opacity: .6; }
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
.status-strip,
|
|
88
|
+
.health-row {
|
|
89
|
+
display: flex;
|
|
90
|
+
flex-wrap: wrap;
|
|
91
|
+
gap: 8px;
|
|
92
|
+
background: #1e1e2e;
|
|
93
|
+
border: 1px solid #333333;
|
|
94
|
+
border-radius: 8px;
|
|
95
|
+
padding: 16px;
|
|
96
|
+
margin-bottom: 16px;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
.metric {
|
|
100
|
+
display: inline-flex;
|
|
101
|
+
align-items: baseline;
|
|
102
|
+
gap: 4px;
|
|
103
|
+
min-width: 120px;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
.metric-label,
|
|
107
|
+
.pane-header {
|
|
108
|
+
color: #888888;
|
|
109
|
+
font-size: 13px;
|
|
110
|
+
font-weight: 600;
|
|
111
|
+
line-height: 1.2;
|
|
112
|
+
text-transform: uppercase;
|
|
113
|
+
letter-spacing: 1px;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
.metric-value {
|
|
117
|
+
color: #e0e0e0;
|
|
118
|
+
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
|
|
119
|
+
font-size: 15px;
|
|
120
|
+
line-height: 1.5;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
.selectable { user-select: text; }
|
|
124
|
+
|
|
125
|
+
.pane {
|
|
126
|
+
background: #1e1e2e;
|
|
127
|
+
border: 1px solid #333333;
|
|
128
|
+
border-radius: 12px;
|
|
129
|
+
padding: 16px;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
.pane-header { margin-bottom: 8px; }
|
|
133
|
+
|
|
134
|
+
.controls {
|
|
135
|
+
display: flex;
|
|
136
|
+
flex-wrap: wrap;
|
|
137
|
+
gap: 8px;
|
|
138
|
+
margin-bottom: 16px;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
button {
|
|
142
|
+
min-height: 36px;
|
|
143
|
+
padding: 8px 16px;
|
|
144
|
+
border-radius: 6px;
|
|
145
|
+
font: 600 13px/1.2 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
|
|
146
|
+
cursor: pointer;
|
|
147
|
+
transition: background 150ms ease, filter 150ms ease;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
button:focus-visible {
|
|
151
|
+
outline: 2px solid #f59e0b;
|
|
152
|
+
outline-offset: 2px;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
.btn-primary {
|
|
156
|
+
background: #f59e0b;
|
|
157
|
+
color: #0f1117;
|
|
158
|
+
border: 1px solid transparent;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
.btn-primary:hover { filter: brightness(1.1); }
|
|
162
|
+
|
|
163
|
+
.btn-secondary {
|
|
164
|
+
background: transparent;
|
|
165
|
+
border: 1px solid #333333;
|
|
166
|
+
color: #e0e0e0;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
.btn-secondary:hover { background: rgba(255, 255, 255, 0.06); }
|
|
170
|
+
|
|
171
|
+
.source-surface {
|
|
172
|
+
position: relative;
|
|
173
|
+
min-height: 240px;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
.rows {
|
|
177
|
+
list-style: none;
|
|
178
|
+
display: flex;
|
|
179
|
+
flex-direction: column;
|
|
180
|
+
gap: 8px;
|
|
181
|
+
margin: 0;
|
|
182
|
+
padding: 0;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
.rows li {
|
|
186
|
+
background: #0f1117;
|
|
187
|
+
border: 1px solid #333333;
|
|
188
|
+
border-radius: 6px;
|
|
189
|
+
padding: 8px 16px;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
.source-empty {
|
|
193
|
+
display: none;
|
|
194
|
+
color: #888888;
|
|
195
|
+
text-align: center;
|
|
196
|
+
padding: 24px;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
.rows:empty + .source-empty {
|
|
200
|
+
display: block;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
.stage {
|
|
204
|
+
position: relative;
|
|
205
|
+
aspect-ratio: 16 / 10;
|
|
206
|
+
min-height: 280px;
|
|
207
|
+
height: min(72vh, 720px);
|
|
208
|
+
background: #0f1117;
|
|
209
|
+
border: 1px solid #333333;
|
|
210
|
+
border-radius: 12px;
|
|
211
|
+
overflow: hidden;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
.empty-state {
|
|
215
|
+
position: absolute;
|
|
216
|
+
inset: 0;
|
|
217
|
+
display: flex;
|
|
218
|
+
flex-direction: column;
|
|
219
|
+
align-items: center;
|
|
220
|
+
justify-content: center;
|
|
221
|
+
gap: 8px;
|
|
222
|
+
color: #888888;
|
|
223
|
+
text-align: center;
|
|
224
|
+
padding: 16px;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
.stage.has-frame .empty-state {
|
|
228
|
+
display: none;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
.empty-state h2,
|
|
232
|
+
.source-empty h2 {
|
|
233
|
+
color: #e0e0e0;
|
|
234
|
+
font-size: 13px;
|
|
235
|
+
font-weight: 600;
|
|
236
|
+
line-height: 1.2;
|
|
237
|
+
margin: 0;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
.empty-state p,
|
|
241
|
+
.source-empty p {
|
|
242
|
+
font-size: 13px;
|
|
243
|
+
margin: 0;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
footer {
|
|
247
|
+
margin-top: 24px;
|
|
248
|
+
color: #888888;
|
|
249
|
+
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
|
|
250
|
+
font-size: 13px;
|
|
251
|
+
line-height: 1.5;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
.log {
|
|
255
|
+
margin-top: 8px;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
.log div {
|
|
259
|
+
white-space: pre-wrap;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
@media (max-width: 720px) {
|
|
263
|
+
body { padding: 16px; }
|
|
264
|
+
.stage { min-height: 220px; }
|
|
265
|
+
.metric { min-width: 100%; }
|
|
266
|
+
}
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
// Local-only PhantomStream two-tab demo server.
|
|
2
|
+
//
|
|
3
|
+
// The server owns three things for the demo: strict static file serving from
|
|
4
|
+
// the repo root, a bundled WebSocket relay at /ws, and generated source/viewer
|
|
5
|
+
// URLs that carry the same unguessable room key.
|
|
6
|
+
|
|
7
|
+
import { createServer } from 'node:http';
|
|
8
|
+
import { createReadStream } from 'node:fs';
|
|
9
|
+
import { stat } from 'node:fs/promises';
|
|
10
|
+
import { randomBytes } from 'node:crypto';
|
|
11
|
+
import { extname, resolve, sep } from 'node:path';
|
|
12
|
+
import { fileURLToPath } from 'node:url';
|
|
13
|
+
|
|
14
|
+
import { createRelay, createWebSocketRelayBackend } from '../../src/relay/index.js';
|
|
15
|
+
|
|
16
|
+
const ROOT = resolve(fileURLToPath(new URL('../../', import.meta.url)));
|
|
17
|
+
const HOST = '127.0.0.1';
|
|
18
|
+
const DEFAULT_PORT = 8643;
|
|
19
|
+
const DEFAULT_PORT_ATTEMPTS = 20;
|
|
20
|
+
|
|
21
|
+
const MIME = {
|
|
22
|
+
'.html': 'text/html; charset=utf-8',
|
|
23
|
+
'.js': 'text/javascript; charset=utf-8',
|
|
24
|
+
'.mjs': 'text/javascript; charset=utf-8',
|
|
25
|
+
'.css': 'text/css; charset=utf-8',
|
|
26
|
+
'.json': 'application/json',
|
|
27
|
+
'.svg': 'image/svg+xml',
|
|
28
|
+
'.png': 'image/png',
|
|
29
|
+
'.ico': 'image/x-icon',
|
|
30
|
+
'.map': 'application/json'
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Start the local two-tab demo server.
|
|
35
|
+
*
|
|
36
|
+
* @param {{host?: string, port?: number, roomKey?: string, logger?: Object}} [options]
|
|
37
|
+
* @returns {Promise<{
|
|
38
|
+
* host: string,
|
|
39
|
+
* port: number,
|
|
40
|
+
* sourceUrl: string,
|
|
41
|
+
* viewerUrl: string,
|
|
42
|
+
* roomKey: string,
|
|
43
|
+
* roomKeyPrefix: string,
|
|
44
|
+
* server: import('node:http').Server,
|
|
45
|
+
* relay: ReturnType<typeof createRelay>,
|
|
46
|
+
* backend: ReturnType<typeof createWebSocketRelayBackend>,
|
|
47
|
+
* close: () => Promise<void>
|
|
48
|
+
* }>}
|
|
49
|
+
*/
|
|
50
|
+
export async function startDemoServer(options = {}) {
|
|
51
|
+
var host = options.host || HOST;
|
|
52
|
+
if (host !== HOST) throw new Error('demo-host-local-only');
|
|
53
|
+
|
|
54
|
+
var requestedPort = options.port == null ? DEFAULT_PORT : Number(options.port);
|
|
55
|
+
if (!Number.isInteger(requestedPort) || requestedPort < 0 || requestedPort > 65535) {
|
|
56
|
+
throw new Error('demo-port-invalid');
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
var roomKey = typeof options.roomKey === 'string' && options.roomKey
|
|
60
|
+
? options.roomKey
|
|
61
|
+
: randomBytes(16).toString('hex');
|
|
62
|
+
var attempts = requestedPort === 0 ? 1 : DEFAULT_PORT_ATTEMPTS;
|
|
63
|
+
var lastError = null;
|
|
64
|
+
|
|
65
|
+
for (var i = 0; i < attempts; i++) {
|
|
66
|
+
var port = requestedPort === 0 ? 0 : requestedPort + i;
|
|
67
|
+
var handle = createDemoServerHandle({ logger: options.logger });
|
|
68
|
+
try {
|
|
69
|
+
await listen(handle.server, host, port);
|
|
70
|
+
var address = handle.server.address();
|
|
71
|
+
var actualPort = typeof address === 'object' && address ? address.port : port;
|
|
72
|
+
var urls = buildDemoUrls({ host, port: actualPort, roomKey });
|
|
73
|
+
return Object.assign({
|
|
74
|
+
host,
|
|
75
|
+
port: actualPort,
|
|
76
|
+
roomKey,
|
|
77
|
+
roomKeyPrefix: roomKey.slice(0, 8),
|
|
78
|
+
sourceUrl: urls.sourceUrl,
|
|
79
|
+
viewerUrl: urls.viewerUrl,
|
|
80
|
+
}, handle);
|
|
81
|
+
} catch (err) {
|
|
82
|
+
lastError = err;
|
|
83
|
+
await closeHandle(handle);
|
|
84
|
+
if (!err || err.code !== 'EADDRINUSE' || requestedPort === 0) break;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
throw lastError || new Error('demo-server-start-failed');
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function createDemoServerHandle(options) {
|
|
92
|
+
var logger = options.logger || {};
|
|
93
|
+
var relay = createRelay({ logger });
|
|
94
|
+
var server = createServer(handleStaticRequest);
|
|
95
|
+
var backend = createWebSocketRelayBackend({
|
|
96
|
+
server,
|
|
97
|
+
relay,
|
|
98
|
+
path: '/ws',
|
|
99
|
+
logger
|
|
100
|
+
});
|
|
101
|
+
var closed = false;
|
|
102
|
+
|
|
103
|
+
async function close() {
|
|
104
|
+
if (closed) return;
|
|
105
|
+
closed = true;
|
|
106
|
+
await closeHandle({ server, backend, relay });
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return { server, relay, backend, close };
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
async function handleStaticRequest(req, res) {
|
|
113
|
+
if (req.method !== 'GET' && req.method !== 'HEAD') {
|
|
114
|
+
sendText(res, 405, 'method not allowed');
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
var pathname;
|
|
119
|
+
try {
|
|
120
|
+
pathname = decodeURIComponent(String(req.url || '/').split('?')[0]);
|
|
121
|
+
} catch {
|
|
122
|
+
sendText(res, 400, 'bad request');
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
var filePath = resolve(ROOT, '.' + pathname);
|
|
127
|
+
if (filePath !== ROOT && !filePath.startsWith(ROOT + sep)) {
|
|
128
|
+
sendText(res, 403, 'forbidden');
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
try {
|
|
133
|
+
var stats = await stat(filePath);
|
|
134
|
+
if (!stats.isFile()) {
|
|
135
|
+
sendText(res, 404, 'not found');
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
res.writeHead(200, {
|
|
140
|
+
'content-type': MIME[extname(filePath)] || 'application/octet-stream',
|
|
141
|
+
'cache-control': 'no-store',
|
|
142
|
+
'x-content-type-options': 'nosniff'
|
|
143
|
+
});
|
|
144
|
+
if (req.method === 'HEAD') {
|
|
145
|
+
res.end();
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
var stream = createReadStream(filePath);
|
|
149
|
+
stream.on('error', function () { res.destroy(); });
|
|
150
|
+
stream.pipe(res);
|
|
151
|
+
} catch {
|
|
152
|
+
sendText(res, 404, 'not found');
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function sendText(res, statusCode, text) {
|
|
157
|
+
res.writeHead(statusCode, {
|
|
158
|
+
'content-type': 'text/plain; charset=utf-8',
|
|
159
|
+
'cache-control': 'no-store',
|
|
160
|
+
'x-content-type-options': 'nosniff'
|
|
161
|
+
});
|
|
162
|
+
res.end(text);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function buildDemoUrls(options) {
|
|
166
|
+
var base = 'http://' + options.host + ':' + options.port;
|
|
167
|
+
var sourceWsUrl = buildWsUrl(options, 'source');
|
|
168
|
+
var viewerWsUrl = buildWsUrl(options, 'viewer');
|
|
169
|
+
return {
|
|
170
|
+
sourceUrl: buildPageUrl(base, '/examples/two-tab-demo/source.html', options.roomKey, sourceWsUrl),
|
|
171
|
+
viewerUrl: buildPageUrl(base, '/examples/two-tab-demo/viewer.html', options.roomKey, viewerWsUrl)
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function buildWsUrl(options, role) {
|
|
176
|
+
var url = new URL('ws://' + options.host + ':' + options.port + '/ws');
|
|
177
|
+
url.searchParams.set('room', options.roomKey);
|
|
178
|
+
url.searchParams.set('role', role);
|
|
179
|
+
return url.toString();
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function buildPageUrl(base, pathname, roomKey, wsUrl) {
|
|
183
|
+
var url = new URL(pathname, base);
|
|
184
|
+
url.searchParams.set('room', roomKey);
|
|
185
|
+
url.searchParams.set('ws', wsUrl);
|
|
186
|
+
return url.toString();
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function listen(server, host, port) {
|
|
190
|
+
return new Promise(function (resolveListen, rejectListen) {
|
|
191
|
+
function cleanup() {
|
|
192
|
+
server.off('error', onError);
|
|
193
|
+
server.off('listening', onListening);
|
|
194
|
+
}
|
|
195
|
+
function onError(err) {
|
|
196
|
+
cleanup();
|
|
197
|
+
rejectListen(err);
|
|
198
|
+
}
|
|
199
|
+
function onListening() {
|
|
200
|
+
cleanup();
|
|
201
|
+
resolveListen();
|
|
202
|
+
}
|
|
203
|
+
server.once('error', onError);
|
|
204
|
+
server.once('listening', onListening);
|
|
205
|
+
server.listen(port, host);
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
async function closeHandle(handle) {
|
|
210
|
+
if (handle.backend && typeof handle.backend.close === 'function') {
|
|
211
|
+
try {
|
|
212
|
+
await handle.backend.close();
|
|
213
|
+
} catch (err) {
|
|
214
|
+
if (!isExpectedCloseError(err)) throw err;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
if (handle.server && handle.server.listening) {
|
|
218
|
+
await new Promise(function (resolveClose, rejectClose) {
|
|
219
|
+
handle.server.close(function (err) {
|
|
220
|
+
if (err) rejectClose(err);
|
|
221
|
+
else resolveClose();
|
|
222
|
+
});
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
if (handle.relay && typeof handle.relay.clear === 'function') {
|
|
226
|
+
handle.relay.clear();
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function isExpectedCloseError(err) {
|
|
231
|
+
var message = err && err.message ? err.message : '';
|
|
232
|
+
return /not running|closed/i.test(message);
|
|
233
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
6
|
+
<title>PhantomStream — Source Tab</title>
|
|
7
|
+
<link rel="stylesheet" href="./demo.css">
|
|
8
|
+
</head>
|
|
9
|
+
<body>
|
|
10
|
+
|
|
11
|
+
<header data-phantomstream-ui="source-header">
|
|
12
|
+
<div class="header-row">
|
|
13
|
+
<div>
|
|
14
|
+
<h1>PhantomStream — Source Tab</h1>
|
|
15
|
+
<p class="subtitle">Mutate this page; the viewer tab mirrors it through the local relay.</p>
|
|
16
|
+
</div>
|
|
17
|
+
<span class="badge" id="capture-badge" role="status" aria-live="polite">
|
|
18
|
+
<span class="badge-dot" aria-hidden="true"></span>
|
|
19
|
+
<span id="capture-label">CAPTURING</span>
|
|
20
|
+
</span>
|
|
21
|
+
</div>
|
|
22
|
+
</header>
|
|
23
|
+
|
|
24
|
+
<section class="status-strip" data-phantomstream-ui="source-status" aria-label="Source stream status">
|
|
25
|
+
<div class="metric">
|
|
26
|
+
<span class="metric-label">Room</span>
|
|
27
|
+
<span class="metric-value selectable" id="source-room">unknown</span>
|
|
28
|
+
</div>
|
|
29
|
+
<div class="metric">
|
|
30
|
+
<span class="metric-label">Relay</span>
|
|
31
|
+
<span class="metric-value" id="source-relay">connecting</span>
|
|
32
|
+
</div>
|
|
33
|
+
<div class="metric">
|
|
34
|
+
<span class="metric-label">Sent</span>
|
|
35
|
+
<span class="metric-value" id="source-sent">0</span>
|
|
36
|
+
</div>
|
|
37
|
+
<div class="metric">
|
|
38
|
+
<span class="metric-label">Last send</span>
|
|
39
|
+
<span class="metric-value" id="source-last-send">never</span>
|
|
40
|
+
</div>
|
|
41
|
+
</section>
|
|
42
|
+
|
|
43
|
+
<main>
|
|
44
|
+
<section class="pane">
|
|
45
|
+
<div class="pane-header">SOURCE</div>
|
|
46
|
+
<div class="controls" data-phantomstream-ui="source-controls">
|
|
47
|
+
<button type="button" class="btn-primary" id="btn-add">Add row</button>
|
|
48
|
+
<button type="button" class="btn-secondary" id="btn-remove">Remove row</button>
|
|
49
|
+
<button type="button" class="btn-secondary" id="btn-edit">Edit text</button>
|
|
50
|
+
<button type="button" class="btn-secondary" id="btn-dialog">Show dialog</button>
|
|
51
|
+
<button type="button" class="btn-secondary" id="btn-auto" aria-pressed="true">Auto-mutate</button>
|
|
52
|
+
</div>
|
|
53
|
+
<div class="source-surface" id="capture-surface">
|
|
54
|
+
<ul class="rows" id="rows"></ul>
|
|
55
|
+
<div class="source-empty" id="source-empty">
|
|
56
|
+
<h2>No rows yet</h2>
|
|
57
|
+
<p>Add a row to send a visible mutation.</p>
|
|
58
|
+
</div>
|
|
59
|
+
</div>
|
|
60
|
+
</section>
|
|
61
|
+
</main>
|
|
62
|
+
|
|
63
|
+
<footer data-phantomstream-ui="source-log">
|
|
64
|
+
<div>Source tab transport log</div>
|
|
65
|
+
<div class="log" id="source-log"></div>
|
|
66
|
+
</footer>
|
|
67
|
+
|
|
68
|
+
<script type="module" src="./source.js?v=04-demo"></script>
|
|
69
|
+
</body>
|
|
70
|
+
</html>
|