-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-browser-streaming.html
More file actions
217 lines (188 loc) · 7.97 KB
/
test-browser-streaming.html
File metadata and controls
217 lines (188 loc) · 7.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
<!DOCTYPE html>
<html>
<head>
<title>Browser Streaming Test - Session Isolation Verification</title>
<style>
body { font-family: Arial, sans-serif; padding: 20px; }
button { margin: 5px; padding: 10px 15px; }
#status { margin: 10px 0; font-weight: bold; }
#canvas { border: 2px solid #333; margin: 10px 0; display: block; }
.connected { color: green; }
.disconnected { color: red; }
.connecting { color: orange; }
#metadata {
margin: 10px 0;
padding: 15px;
background: #f5f5f5;
border-radius: 5px;
font-family: monospace;
font-size: 14px;
}
#metadata h3 {
margin: 0 0 10px 0;
font-size: 16px;
color: #333;
}
#metadata .field {
margin: 5px 0;
}
#metadata .label {
font-weight: bold;
color: #666;
}
#metadata .value {
color: #0066cc;
}
</style>
</head>
<body>
<h1>Browser Streaming Session Isolation Test</h1>
<p>Testing session-to-target mapping on <code>ws://localhost:8933</code></p>
<div>
<button onclick="connect()">Connect</button>
<button onclick="startStreaming()">Start Streaming (New Session)</button>
<button onclick="stopStreaming()">Stop Streaming</button>
<button onclick="disconnect()">Disconnect</button>
</div>
<div id="status" class="disconnected">Not connected</div>
<!-- Session/Target Metadata Display -->
<div id="metadata">
<h3>Session Metadata</h3>
<div class="field"><span class="label">Session ID:</span> <span id="sessionId" class="value">-</span></div>
<div class="field"><span class="label">Target ID:</span> <span id="targetId" class="value">-</span></div>
<div class="field"><span class="label">CDP Endpoint:</span> <span id="cdpEndpoint" class="value">-</span></div>
<div class="field"><span class="label">Frames Received:</span> <span id="frameCount" class="value">0</span></div>
<div class="field"><span class="label">Last Frame Time:</span> <span id="lastFrameTime" class="value">-</span></div>
</div>
<canvas id="canvas" width="960" height="540"></canvas>
<div id="messages" style="margin-top: 20px; max-height: 200px; overflow-y: auto; border: 1px solid #ccc; padding: 10px; font-family: monospace; font-size: 12px;"></div>
<script>
let ws = null;
let canvas = document.getElementById('canvas');
let ctx = canvas.getContext('2d');
let statusEl = document.getElementById('status');
let messagesEl = document.getElementById('messages');
let currentSessionId = null;
let frameCount = 0;
function log(message) {
const timestamp = new Date().toLocaleTimeString();
messagesEl.innerHTML += `[${timestamp}] ${message}<br>`;
messagesEl.scrollTop = messagesEl.scrollHeight;
console.log(message);
}
function updateMetadata(field, value) {
const element = document.getElementById(field);
if (element) {
element.textContent = value || '-';
}
}
function connect() {
if (ws) {
log('Already connected or connecting');
return;
}
statusEl.textContent = 'Connecting...';
statusEl.className = 'connecting';
ws = new WebSocket('ws://localhost:8933');
ws.onopen = () => {
statusEl.textContent = 'Connected to WebSocket';
statusEl.className = 'connected';
log('WebSocket connection opened');
};
ws.onmessage = (event) => {
try {
const message = JSON.parse(event.data);
if (message.type === 'frame') {
// Update frame counter (don't log - too spammy)
frameCount++;
updateMetadata('frameCount', frameCount);
updateMetadata('lastFrameTime', new Date().toLocaleTimeString());
// Draw the frame to canvas
const img = new Image();
img.onload = () => {
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
};
img.src = `data:image/jpeg;base64,${message.data}`;
} else if (message.type === 'streaming-started') {
log(`✓ Streaming started for session: ${message.sessionId}`);
log(` Target ID: ${message.targetId}`);
log(` CDP Endpoint: ${message.cdpEndpoint}`);
// Update metadata display
updateMetadata('sessionId', message.sessionId);
updateMetadata('targetId', message.targetId);
updateMetadata('cdpEndpoint', message.cdpEndpoint);
} else if (message.type === 'streaming-stopped') {
log(`✓ Streaming stopped for session: ${message.sessionId}`);
} else if (message.type === 'error') {
log(`✗ ERROR: ${message.error}`);
} else {
// Log unknown message types
log(`Received: ${message.type}`);
}
} catch (err) {
log(`Error parsing message: ${err.message}`);
}
};
ws.onclose = () => {
statusEl.textContent = 'Disconnected';
statusEl.className = 'disconnected';
log('WebSocket connection closed');
ws = null;
};
ws.onerror = (error) => {
statusEl.textContent = 'Connection error';
statusEl.className = 'disconnected';
log(`WebSocket error: ${error}`);
};
}
function startStreaming() {
if (!ws || ws.readyState !== WebSocket.OPEN) {
log('Not connected to WebSocket');
return;
}
// Generate unique session ID for each start
currentSessionId = 'test-session-' + Date.now();
frameCount = 0; // Reset frame counter
const message = {
type: 'start-streaming',
sessionId: currentSessionId
};
ws.send(JSON.stringify(message));
log(`→ Sent: ${message.type} for session ${currentSessionId}`);
// Reset metadata
updateMetadata('sessionId', currentSessionId);
updateMetadata('targetId', 'waiting...');
updateMetadata('cdpEndpoint', 'waiting...');
updateMetadata('frameCount', '0');
updateMetadata('lastFrameTime', '-');
}
function stopStreaming() {
if (!ws || ws.readyState !== WebSocket.OPEN) {
log('Not connected to WebSocket');
return;
}
if (!currentSessionId) {
log('No active session to stop');
return;
}
const message = {
type: 'stop-streaming',
sessionId: currentSessionId
};
ws.send(JSON.stringify(message));
log(`→ Sent: ${message.type} for session ${currentSessionId}`);
}
function disconnect() {
if (ws) {
ws.close();
ws = null;
}
}
// Auto-connect on page load
window.onload = () => {
log('Page loaded. Click Connect to start.');
};
</script>
</body>
</html>