|
| 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.0"> |
| 6 | + <title>Bluesky WebSocket Feed Monitor</title> |
| 7 | + <style> |
| 8 | + body { |
| 9 | + font-family: system-ui, -apple-system, sans-serif; |
| 10 | + max-width: 800px; |
| 11 | + margin: 20px auto; |
| 12 | + padding: 0 20px; |
| 13 | + } |
| 14 | + #output { |
| 15 | + width: 100%; |
| 16 | + height: 400px; |
| 17 | + margin-top: 20px; |
| 18 | + padding: 10px; |
| 19 | + font-family: monospace; |
| 20 | + border: 1px solid #ccc; |
| 21 | + border-radius: 4px; |
| 22 | + } |
| 23 | + .controls { |
| 24 | + margin: 20px 0; |
| 25 | + } |
| 26 | + button { |
| 27 | + padding: 8px 16px; |
| 28 | + margin-right: 10px; |
| 29 | + cursor: pointer; |
| 30 | + } |
| 31 | + </style> |
| 32 | +</head> |
| 33 | +<body> |
| 34 | + <h1>Bluesky WebSocket Feed Monitor</h1> |
| 35 | + <div class="controls"> |
| 36 | + <button id="connect">Connect</button> |
| 37 | + <button id="disconnect">Disconnect</button> |
| 38 | + <button id="clear">Clear Log</button> |
| 39 | + </div> |
| 40 | + <textarea id="output" readonly></textarea> |
| 41 | + |
| 42 | + <script> |
| 43 | + let ws = null; |
| 44 | + const output = document.getElementById('output'); |
| 45 | + |
| 46 | + function log(message) { |
| 47 | + const timestamp = new Date().toISOString(); |
| 48 | + output.value += `[${timestamp}] ${message}\n`; |
| 49 | + output.scrollTop = output.scrollHeight; |
| 50 | + } |
| 51 | + |
| 52 | + function connect() { |
| 53 | + if (ws) { |
| 54 | + log('Already connected!'); |
| 55 | + return; |
| 56 | + } |
| 57 | + |
| 58 | + try { |
| 59 | + ws = new WebSocket('wss://jetstream2.us-east.bsky.network/subscribe?wantedCollections=app.bsky.feed.post'); |
| 60 | + |
| 61 | + ws.onopen = () => { |
| 62 | + log('Connected to Bluesky WebSocket'); |
| 63 | + }; |
| 64 | + |
| 65 | + ws.onmessage = (event) => { |
| 66 | + try { |
| 67 | + const data = JSON.parse(event.data); |
| 68 | + log(`Received: ${JSON.stringify(data, null, 2)}`); |
| 69 | + } catch (e) { |
| 70 | + log(`Raw message: ${event.data}`); |
| 71 | + } |
| 72 | + }; |
| 73 | + |
| 74 | + ws.onerror = (error) => { |
| 75 | + log(`WebSocket Error: ${error.message}`); |
| 76 | + }; |
| 77 | + |
| 78 | + ws.onclose = () => { |
| 79 | + log('Disconnected from Bluesky WebSocket'); |
| 80 | + ws = null; |
| 81 | + }; |
| 82 | + |
| 83 | + } catch (error) { |
| 84 | + log(`Connection Error: ${error.message}`); |
| 85 | + ws = null; |
| 86 | + } |
| 87 | + } |
| 88 | + |
| 89 | + function disconnect() { |
| 90 | + if (ws) { |
| 91 | + ws.close(); |
| 92 | + ws = null; |
| 93 | + log('Disconnected by user'); |
| 94 | + } else { |
| 95 | + log('Not connected'); |
| 96 | + } |
| 97 | + } |
| 98 | + |
| 99 | + // Event Listeners |
| 100 | + document.getElementById('connect').addEventListener('click', connect); |
| 101 | + document.getElementById('disconnect').addEventListener('click', disconnect); |
| 102 | + document.getElementById('clear').addEventListener('click', () => { |
| 103 | + output.value = ''; |
| 104 | + }); |
| 105 | + </script> |
| 106 | +</body> |
| 107 | +</html> |
0 commit comments