Connecting to a server
Importing the library
- ES Module
- CommonJS
import { ZilaConnection } from "zilaws-client";
if you need them, you can import types too:
import { WSStatus } from "zilaws-client";
const { ZilaConnection } = require("zilaws-client");
if you need them, you can import types too:
const { WSStatus } = require("zilaws-client");
Connecting
Connecting to the server is asynchronous. The first parameter is a standard websocket connection URL string. The second parameter of the connectTo function is optional. It is a callback which gets called when a problem or error happens.
const client = new ZilaConnection();
//Register message handlers, event handlers here
await client.connectTo("wss://yourhost.com:6589", (reason?: string) => {
console.error("ZilaConnection error happened:\n" + reason);
});