34 lines
957 B
TypeScript
34 lines
957 B
TypeScript
import { PrivateKey } from "@xo-cash/primitives";
|
|
|
|
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);
|
|
|
|
client.on('message', (message) => {
|
|
console.log(message);
|
|
});
|
|
|
|
// 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();
|