1 |
|
2 | import express from 'express';
|
3 | import { Server as HttpServer } from 'http';
|
4 | import WebSocket from 'ws';
|
5 | import { Handle } from '@theintern/common';
|
6 | import Node from './executors/Node';
|
7 | import { Message } from './channels/Base';
|
8 | export interface Context {
|
9 | readonly stopped: boolean;
|
10 | readonly basePath: string;
|
11 | readonly executor: Node;
|
12 | handleMessage(message: Message): Promise<any>;
|
13 | }
|
14 | export default class Server implements ServerProperties {
|
15 | readonly executor: Node;
|
16 | basePath: string;
|
17 | port: number;
|
18 | runInSync: boolean;
|
19 | socketPort: number;
|
20 | get 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 | protected _wsPingTimers: NodeJS.Timer[];
|
30 | constructor(options: ServerOptions);
|
31 | start(): Promise<void>;
|
32 | stop(): Promise<any[]>;
|
33 | subscribe(sessionId: string, listener: ServerListener): Handle;
|
34 | private _getSession;
|
35 | private _handleMessage;
|
36 | private _handleWebSocket;
|
37 | private _publish;
|
38 | }
|
39 | export interface ServerProperties {
|
40 | basePath: string;
|
41 | executor: Node;
|
42 | port: number;
|
43 | runInSync: boolean;
|
44 | socketPort: number;
|
45 | }
|
46 | export interface ServerListener {
|
47 | (name: string, data?: any): void;
|
48 | }
|
49 | export declare type ServerOptions = Partial<ServerProperties> & {
|
50 | executor: Node;
|
51 | };
|