/**
* Utility function for using WebSockets
*/
///
import WebSocket from 'isomorphic-ws';
/**
* Generate the `Sec-Websocket-Protocol` header.
*
* This is the only header that can be set in the WebSocket constructor
* and we use it to pass client id and JWT to the server.
* The generated header follows the recommendations of
* https://tools.ietf.org/html/rfc6455#section-1.9 with `+`
* used as a separator between its parts.
*
* @param id The id of the client
* @param jwt A JWT
*/
export declare function generateProtocol(id: string, jwt?: string): string;
/**
* Parse the `Sec-Websocket-Protocol` header.
*
* @param protocol The protocol header
* @returns The id and jwt in the header
*/
export declare function parseProtocol(protocol: string): {
id: string;
jwt?: string;
};
/**
* Is a WebSocket in the open state?
*
* @param socket The WebSocket to check
*/
export declare function isOpen(socket: WebSocket): boolean;
/**
* Is a WebSocket in the closing or closed state?
*
* @param socket The WebSocket to check
*/
export declare function isClosingOrClosed(socket: WebSocket): boolean;
/**
* Wait until a socket is in the open state.
*
* @param socket The WebSocket to wait for
* @param timeout The number of seconds to wait for the socket
* to be open before throwing a timeout error
*/
export declare function untilOpen(socket: WebSocket, timeout?: number): Promise;
/**
* Send data on a WebSocket connection.
*
* @param socket The WebSocket to send data on
* @param data The data to send
* @param timeout The number of seconds to wait for the socket
* to be open before throwing a timeout error
*/
export declare function send(socket: WebSocket, data: string, timeout?: number): Promise;