Use isomorphic-ws
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@snort/system",
|
||||
"version": "1.0.18",
|
||||
"version": "1.0.19",
|
||||
"description": "Snort nostr system package",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
@ -20,10 +20,13 @@
|
||||
"@peculiar/webcrypto": "^1.4.3",
|
||||
"@types/debug": "^4.1.8",
|
||||
"@types/jest": "^29.5.1",
|
||||
"@types/node": "^20.5.9",
|
||||
"@types/uuid": "^9.0.2",
|
||||
"@types/ws": "^8.5.5",
|
||||
"jest": "^29.5.0",
|
||||
"jest-environment-jsdom": "^29.5.0",
|
||||
"ts-jest": "^29.1.0",
|
||||
"ts-node": "^10.9.1",
|
||||
"typescript": "^5.2.2"
|
||||
},
|
||||
"dependencies": {
|
||||
@ -34,6 +37,8 @@
|
||||
"@stablelib/xchacha20": "^1.0.1",
|
||||
"debug": "^4.3.4",
|
||||
"dexie": "^3.2.4",
|
||||
"uuid": "^9.0.0"
|
||||
"isomorphic-ws": "^5.0.0",
|
||||
"uuid": "^9.0.0",
|
||||
"ws": "^8.14.0"
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { v4 as uuid } from "uuid";
|
||||
import debug from "debug";
|
||||
import WebSocket from "isomorphic-ws";
|
||||
import { unwrap, ExternalStore, unixNowMs } from "@snort/shared";
|
||||
|
||||
import { DefaultConnectTimeout } from "./const";
|
||||
@ -138,7 +139,7 @@ export class Connection extends ExternalStore<ConnectionStateSnapshot> {
|
||||
this.#sendPendingRaw();
|
||||
}
|
||||
|
||||
OnClose(e: CloseEvent) {
|
||||
OnClose(e: WebSocket.CloseEvent) {
|
||||
if (this.ReconnectTimer) {
|
||||
clearTimeout(this.ReconnectTimer);
|
||||
this.ReconnectTimer = undefined;
|
||||
@ -171,10 +172,10 @@ export class Connection extends ExternalStore<ConnectionStateSnapshot> {
|
||||
this.notifyChange();
|
||||
}
|
||||
|
||||
OnMessage(e: MessageEvent) {
|
||||
OnMessage(e: WebSocket.MessageEvent) {
|
||||
this.#activity = unixNowMs();
|
||||
if (e.data.length > 0) {
|
||||
const msg = JSON.parse(e.data);
|
||||
if ((e.data as string).length > 0) {
|
||||
const msg = JSON.parse(e.data as string);
|
||||
const tag = msg[0];
|
||||
switch (tag) {
|
||||
case "AUTH": {
|
||||
@ -221,7 +222,7 @@ export class Connection extends ExternalStore<ConnectionStateSnapshot> {
|
||||
}
|
||||
}
|
||||
|
||||
OnError(e: Event) {
|
||||
OnError(e: WebSocket.Event) {
|
||||
this.#log("Error: %O", e);
|
||||
this.notifyChange();
|
||||
}
|
||||
|
14
packages/system/tests/node.ts
Normal file
14
packages/system/tests/node.ts
Normal file
@ -0,0 +1,14 @@
|
||||
import {NostrSystem, SystemInterface} from "..";
|
||||
|
||||
const Relay = "wss://relay.snort.social/";
|
||||
|
||||
const system = new NostrSystem({}) as SystemInterface;
|
||||
|
||||
async function test() {
|
||||
await system.ConnectToRelay(Relay, {read: true, write: true});
|
||||
setTimeout(() => {
|
||||
system.DisconnectRelay(Relay);
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
test().catch(console.error);
|
Reference in New Issue
Block a user