import { network } from '@oliveai/ldk';
// Must go to a secure address or specific IP.
const url = 'wss://some.api.com';
// Optional parameter. Headers for the request are given as
// a Record<string, string[]> object.
'some-required-header': ['Foo', 'Bar'],
// Optional parameter. Indicates whether the web socket server
// uses compression or not
const useCompression = false;
// Optional parameter. Describes the subprotocols used by the server
const subprotocols = ['value1', 'value2'];
network.webSocketConnect({
// The return from this promise is an object of the type Socket.
// Sockets have several different functions that allow bidirectional
// communication between it and the server. All functions are also
// promises that can be chained.
socket.setCloseHandler((error, code, text) => {
// Configure how to handle close...
socket.setMessageHandler((error, message) => {
// Configure how to handle different messages received...
socket.setPongHandler((error, msg) => {
// Configure how to handle the message received after pinging
socket.writeMessage(message).then(() => {
// Write a message back to the server...
socket.ping(); // Ping the server, which should respond with a pongD
socket.close(); // Close the socket connection