/// import * as schema from '@stencila/schema'; import WebSocket from 'isomorphic-ws'; import { Connection } from '../base/Connection'; import { Claims, Executor } from '../base/Executor'; import { Addresses, WebSocketAddressInitializer } from '../base/Transports'; import { TcpServer } from '../tcp/TcpServer'; /** * A WebSocket connection. */ export declare class WebSocketConnection implements Connection { /** * @implements Implements {@link Connection.id} to provide * a unique id for the WebSocket client. */ id: string; /** * Claims made for this connection */ claims: Claims; /** * The WebSocket used by this connection */ socket: WebSocket; constructor(socket: WebSocket, id: string, claims: Claims); /** * @implements Implements {@link Connection.notify} to send the * notification over the WebSocket. * * @description Will log an warning if the send failed for a * WebSocket that is still open (i.e. will ignore failures for * connections that are closing or have closed). */ notify(level: string, message: string, node: schema.Node): Promise; /** * Send a response using the Websocket * * Will wait until the socket is open before * attempting to send the data. */ send(data: string): Promise; /** * @implements Implements {@link Connection.stop} by closing the WebSocket. */ stop(): Promise; } /** * A `Server` using WebSockets as the transport protocol. */ export declare class WebSocketServer extends TcpServer { /** * The WebSocket server. */ wsServer?: WebSocket.Server; /** * The secret used to verify JWT tokens. * * If this is not provided to the constructor * then a random secret will be generated and * logged for use in generating tokens. */ readonly jwtSecret: string; constructor(address?: WebSocketAddressInitializer, jwtSecret?: string); /** * @override Overrides {@link TcpServer.addresses} * to provide a WebSocket entry. */ addresses(): Promise; /** * @override Overrides {@link TcpServer.start} to start * a WebSocket server. */ start(executor: Executor): Promise; /** * @override Overrides {@link TcpServer.stop} to stop the * WebSocket server. * * Calls `super.stop()` to close all connections. */ stop(): Promise; }