badman-websocket-starter
TypeScript icon, indicating that this package has built-in type declarations

0.1.17 • Public • Published

The Configurable And Extensible WebsocketServer.

There are 2 important Classes, AbstractWebSocketServerConnection and AbstractWebSocketServer. The core.

Demo APIs :

async main(){
	let logging:Logging = await SingletonObjectFactory2.init<Logging>(Logging);
	let logger:Logger = logging.logger(BadmanWebSocket.name);
	let properties:WebSocketServerProperties={
			port: 1000,
			context: 'custom',
			heartBeatInterval : 10000
	};
	new DefaultWebSocketServer(properties,logger).afterInitialized();
}

export default class DefaultWebSocketServer extends AbstractWebSocketServer<RequestBodyEntity,DefaultClientConnection>{

    constructor (serverProperties:WebSocketServerProperties,logger:Logger) {
        super(serverProperties,logger);
    }
    protected canDeleteConnection (connection: DefaultClientConnection) :boolean{
        return true;
    }

    protected newConnection (requestBody: RequestBodyEntity, ws: WebSocket): DefaultClientConnection {
        return new DefaultClientConnection(this.serverProperties,ws,requestBody);
    }

}

export default class DefaultClientConnection extends AbstractWebSocketServerConnection<RequestBodyEntity>{

    private logger:Logger;

    constructor (serverProperties:WebSocketServerProperties,ws: WebSocket, requestBody: RequestBodyEntity) {
        super(serverProperties,ws, requestBody);
        this.logger = SingletonObjectFactory2.Instance<Logging>(Logging.name).logger(DefaultClientConnection.name);
    }


    notifyClientCustomized () {
        this.sendMessage("DefaultClientConnectionDefaultClientConnectionDefaultClientConnectionDefaultClientConnection");
    }

    onMessage (msg:Buffer) {

        console.info('-------------------------------------',msg.toString());
        this.logger.info(msg.toString());
    }

}

Package Sidebar

Install

npm i badman-websocket-starter

Weekly Downloads

4

Version

0.1.17

License

MIT

Unpacked Size

222 kB

Total Files

129

Last publish

Collaborators

  • badmanmaster