UNPKG

1.5 kBTypeScriptView Raw
1/// <reference types="node" />
2import * as express from 'express';
3import { Server as HttpServer } from 'http';
4import * as WebSocket from 'ws';
5import { Handle } from '@theintern/common';
6import Node from './executors/Node';
7import { Message } from './channels/Base';
8export interface Context {
9 readonly stopped: boolean;
10 readonly basePath: string;
11 readonly executor: Node;
12 handleMessage(message: Message): Promise<any>;
13}
14export default class Server implements ServerProperties {
15 readonly executor: Node;
16 basePath: string;
17 port: number;
18 runInSync: boolean;
19 socketPort: number;
20 readonly stopped: boolean;
21 protected _app: express.Express | undefined;
22 protected _httpServer: HttpServer | undefined;
23 protected _sessions: {
24 [id: string]: {
25 listeners: ServerListener[];
26 };
27 } | undefined;
28 protected _wsServer: WebSocket.Server | undefined;
29 constructor(options: ServerOptions);
30 start(): Promise<void>;
31 stop(): Promise<any[]>;
32 subscribe(sessionId: string, listener: ServerListener): Handle;
33 private _getSession;
34 private _handleMessage;
35 private _handleWebSocket;
36 private _publish;
37}
38export interface ServerProperties {
39 basePath: string;
40 executor: Node;
41 port: number;
42 runInSync: boolean;
43 socketPort: number;
44}
45export interface ServerListener {
46 (name: string, data?: any): void;
47}
48export declare type ServerOptions = Partial<ServerProperties> & {
49 executor: Node;
50};