Connecting to a server
Importing the library
- ES Module
- CommonJS
import { connectTo } from "zilaws-client";
if you need them, you can import types too:
import {connectTo, ZilaConnection, WSStatus } from "zilaws-client";
const { connectTo } = require("zilaws-client");
if you need them, you can import types too:
const { ZilaConnection, 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 = await connectTo("wss://yourhost.com:6589", (reason?: string) => {
console.error("ZilaConnection error happened:\n" + reason);
});