qnet-websocket-browser
v0.0.0
Published
```ts import { QNetWebSocketBrowser } from "qnet-websocket-browser"; ```
Downloads
2
Readme
qnet-websocket-browser
Usage
Run the QNet Server
Front-End Example
import { QNetWebSocketBrowser } from "qnet-websocket-browser";
/** Create instance */
const qnet = new QNetWebSocketBrowser();
/** Connect to server (server is running in docker) */
qnet.connect().then(async () => {
/** Update connection status */
setConnectionInfo("Connected");
/** Get machine instance */
const machine = MachineSimulator.getInstance();
/** Start the machine and its id */
const id = await machine.start();
/** Subscribe to the `id/your/topic` topic */
qnet
.getSubPub()
.subscribe(`${id}/your/topic`, (message: QNetWebSocketMessage) => {
/** Process the message */
processAnalog(message);
});
/** Publish to the `id/your/topic` topic */
qnet
.getSubPub()
.publish(`${id}/your/topic`, JSON.stringify({your: 'data'}));
});