-
Notifications
You must be signed in to change notification settings - Fork 1
/
relay.js
31 lines (31 loc) · 1.4 KB
/
relay.js
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
class Relay {
constructor(relay_url) {
this.relay_url = relay_url;
this.relay = new WebSocket(relay_url);
this.relay.onopen = () => {
// log(`[+] Connected to ${this.relay_url}`);
this.relay.send(JSON.stringify(["REQ","TEST",{"kinds":[0],"limit": 4}]));
}
this.relay.onmessage = event => {
let data = JSON.parse(event.data);
if ( data[0] === "EOSE" ) {
this.relay.send( JSON.stringify( ["CLOSE", data[1]] ) )
} /* else if ( data[2].kind === 4 ) {
let payload = data[2];
let k = payload.tags[0][1];
nostr.nip04.decrypt(k, payload.content).then( txt => {
data[2].content = txt;
document.querySelector('.log').innerText += JSON.stringify(data) + "\n";
})
} */
// document.querySelector('.log').innerText += event.data + "\n";
log(event.data);
}
}
send(payload) {
this.relay.send(payload);
}
close() {
this.relay.close();
}
}