Fix Web Sockets. Form into library. Move demo to demo folder. Split demo between sse and websocket.

This commit is contained in:
2026-09-17 11:49:21 +00:00
parent 55d09d048e
commit 711ecba117
10 changed files with 134 additions and 96 deletions
+37
View File
@@ -0,0 +1,37 @@
import { PrivateKey } from "@xo-cash/primitives";
import { toExtendedJson } from "@xo-cash/utils";
import { SSEClient } from '../src/sse/client.js';
const testSSE = async () => {
const privateKey = PrivateKey.fromString('c440ce6ac5b63ae7bc4af9891b80b7a88ccdeebba5e43246885e9ec56f912ac2');
const client = new SSEClient('https://v2.sync.xo.harvmaster.com', privateKey, {
onMessage: (message) => {
console.log(toExtendedJson(message));
},
onError: (error) => {
console.error(error);
},
});
// Connect to the sync server
await client.connect();
// Subscribe to the resource
await client.subscribe('test');
// Write a new value to the resource
await client.write('test', {'message': 'Hello, world! this is the minimal sync client using SSE'});
// Read the current value of the resource
const data = await client.read('test');
console.log(data);
// If the user presses Ctrl+C, disconnect the client and exit the program
process.on('SIGINT', async () => {
await client.disconnect();
process.exit(0);
});
}
testSSE();