initial commit.

This commit is contained in:
fiatjaf
2021-01-04 14:15:27 -03:00
commit b077271d46
7 changed files with 99 additions and 0 deletions

27
relay.js Normal file
View File

@@ -0,0 +1,27 @@
import PersistentWebSocket from 'pws'
export function relayConnect(url, onEventCallback) {
if (url.length && url[url.length - 1] === '/') url = url.slice(0, -1)
const ws = new PersistentWebSocket(url + '/ws?session=' + Math.random(), {
pingTimeout: 30 * 1000
})
ws.onopen = () => console.log('connected to ', url)
ws.onerror = err => console.log('error connecting', url, err)
ws.onmessage = e => {
let event = JSON.parse(e.data)
event.context
}
return {
url,
subscribe() {},
request() {},
publish() {},
close() {
ws.close()
}
}
}