Created
December 1, 2025 11:16
-
-
Save kuuote/c726a13ecd3d11c47b2a04947297ccc5 to your computer and use it in GitHub Desktop.
nostr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const socket = new WebSocket("wss://yabu.me"); | |
| socket.onopen = () => { | |
| socket.send(JSON.stringify(["REQ", "hoge", {kinds: [1], limit: 20}])); | |
| } | |
| const users = new Map(); | |
| let eventpool = []; | |
| let id = 0; | |
| socket.onmessage = (msg) => { | |
| const data = JSON.parse(msg.data); | |
| if (data[0] == "EOSE" && data[1] != "hoge") { | |
| socket.send(JSON.stringify(["CLOSE", data[1]])); | |
| } | |
| if (data[0] == "EVENT") { | |
| const event = data[2]; | |
| if (event.kind == 0) { | |
| users.set(event.pubkey, JSON.parse(event.content)); | |
| eventpool = eventpool.filter((e) => { | |
| if (users.has(e.pubkey)) { | |
| console.log(`${users.get(e.pubkey).display_name}: ${e.content}`); | |
| return false; | |
| } | |
| return true; | |
| }); | |
| } | |
| if (event.kind == 1) { | |
| let user; | |
| if (users.has(event.pubkey)) { | |
| user = users.get(event.pubkey); | |
| console.log(`${user.display_name}: ${event.content}`); | |
| } else { | |
| socket.send(JSON.stringify(["REQ", `user${id++}`, {kinds: [0], authors: [event.pubkey]}])); | |
| eventpool.push(event); | |
| } | |
| } | |
| } | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment