mirror of
https://github.com/nbd-wtf/nostr-tools.git
synced 2025-12-15 03:18:51 +00:00
implement some pong-reply logic.
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "nostr-tools",
|
"name": "nostr-tools",
|
||||||
"version": "0.1.2",
|
"version": "0.1.3",
|
||||||
"description": "Tools for making a Nostr client.",
|
"description": "Tools for making a Nostr client.",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"repository": {
|
"repository": {
|
||||||
|
|||||||
19
relay.js
19
relay.js
@@ -32,12 +32,26 @@ export function relayConnect(url, onEvent, onNotice) {
|
|||||||
ws.onclose = () => console.log('relay connection closed', url)
|
ws.onclose = () => console.log('relay connection closed', url)
|
||||||
|
|
||||||
ws.onmessage = async e => {
|
ws.onmessage = async e => {
|
||||||
let data = JSON.parse(e.data)
|
var data
|
||||||
|
try {
|
||||||
|
data = JSON.parse(e.data)
|
||||||
|
} catch (err) {
|
||||||
|
data = e.data
|
||||||
|
}
|
||||||
|
|
||||||
if (data.length > 1) {
|
if (data.length > 1) {
|
||||||
|
if (data === 'PING') {
|
||||||
|
ws.send('PONG')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if (data[0] === 'notice') {
|
if (data[0] === 'notice') {
|
||||||
console.log('message from relay ' + url + ': ' + data[1])
|
console.log('message from relay ' + url + ': ' + data[1])
|
||||||
onNotice(data[1])
|
onNotice(data[1])
|
||||||
} else if (typeof data[0] === 'object') {
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof data[0] === 'object') {
|
||||||
let event = data[0]
|
let event = data[0]
|
||||||
let context = data[1]
|
let context = data[1]
|
||||||
|
|
||||||
@@ -50,6 +64,7 @@ export function relayConnect(url, onEvent, onNotice) {
|
|||||||
context
|
context
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user