resclient-ts
v1.1.16
Published
A RES client written in typescript.
Readme
Javascript client library implementing the RES-Client Protocol. Used to establish WebSocket connections to Resgate, to get your data synchronized in real-time.
Visit Resgate.io for more information.
Installation
npm install resclient-tsThis module supports both ESModules and CommonJS. The primary code is ESModules.
Basic Usage
import WebSocket from "ws";
import { ResClient } from "resclient-ts";
const wsFactory = () => new WebSocket("ws://localhost:8080");
// Create instance with a WebSocket factory function
const client = new ResClient(wsFactory);Example usage
import WebSocket from "ws";
import { ResClient } from "resclient-ts";
const wsFactory = () => new WebSocket("ws://localhost:8080");
const client = new ResClient(wsFactory);
client.get("example.mymodel").then(model => {
console.log(model.message);
const onChange = () => {
console.log("New message: " + model.message);
};
// Listen to changes for 5 seconds, eventually unsubscribing
model.resourceOn("change", onChange);
setTimeout(() => {
model.resourceOff("change", onChange);
}, 5000);
});