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();