server-modules
Advanced tools
Comparing version 0.1.4 to 0.1.5
export { EHttpState } from './modules/express/httpState'; | ||
export { WebsocketConnection } from './modules/websocket/connection'; | ||
export { websocketConnectorMongoDbWatch } from './modules/websocket/connectionMongoDbWatch'; | ||
export { WebsocketConnectorBase } from './modules/websocket/connection'; | ||
export * from './serverEnvironment'; | ||
export { ApiSegment } from './modules/api/apiSegment'; |
@@ -8,4 +8,6 @@ "use strict"; | ||
exports.EHttpState = httpState_1.EHttpState; | ||
var connectionMongoDbWatch_1 = require("./modules/websocket/connectionMongoDbWatch"); | ||
exports.websocketConnectorMongoDbWatch = connectionMongoDbWatch_1.websocketConnectorMongoDbWatch; | ||
var connection_1 = require("./modules/websocket/connection"); | ||
exports.WebsocketConnection = connection_1.WebsocketConnection; | ||
exports.WebsocketConnectorBase = connection_1.WebsocketConnectorBase; | ||
__export(require("./serverEnvironment")); | ||
@@ -12,0 +14,0 @@ var apiSegment_1 = require("./modules/api/apiSegment"); |
/// <reference types="socket.io" /> | ||
export declare abstract class WebsocketConnection { | ||
protected _socket: SocketIO.Socket; | ||
export declare abstract class WebsocketConnectorBase { | ||
private _socket; | ||
constructor(_socket: SocketIO.Socket); | ||
abstract init(): void; | ||
destroy(): void; | ||
protected on(event: string | symbol, listener: (...args: any[]) => void): this; | ||
protected emit(event: string | symbol, ...args: any[]): boolean; | ||
} | ||
export declare type WebsocketConnectorCTOR = new (socket: SocketIO.Socket) => WebsocketConnectorBase; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var WebsocketConnection = /** @class */ (function () { | ||
function WebsocketConnection(_socket) { | ||
var WebsocketConnectorBase = /** @class */ (function () { | ||
function WebsocketConnectorBase(_socket) { | ||
this._socket = _socket; | ||
this.init(); | ||
} | ||
WebsocketConnection.prototype.destroy = function () { | ||
WebsocketConnectorBase.prototype.destroy = function () { | ||
return; | ||
}; | ||
return WebsocketConnection; | ||
WebsocketConnectorBase.prototype.on = function (event, listener) { | ||
this._socket.on(event, listener); | ||
return this; | ||
}; | ||
WebsocketConnectorBase.prototype.emit = function (event) { | ||
var args = []; | ||
for (var _i = 1; _i < arguments.length; _i++) { | ||
args[_i - 1] = arguments[_i]; | ||
} | ||
return (_a = this._socket).emit.apply(_a, [event].concat(args)); | ||
var _a; | ||
}; | ||
return WebsocketConnectorBase; | ||
}()); | ||
exports.WebsocketConnection = WebsocketConnection; | ||
exports.WebsocketConnectorBase = WebsocketConnectorBase; | ||
//# sourceMappingURL=connection.js.map |
@@ -1,7 +0,6 @@ | ||
/// <reference types="socket.io" /> | ||
import { FactoryElement } from '../factory'; | ||
import { WebsocketConnection } from './connection'; | ||
import { WebsocketConnectorCTOR } from './connection'; | ||
export interface WebsocketCfg { | ||
port: number; | ||
connection: new (socket: SocketIO.Socket) => WebsocketConnection; | ||
connection: WebsocketConnectorCTOR | WebsocketConnectorCTOR[]; | ||
} | ||
@@ -8,0 +7,0 @@ export declare class Websocket extends FactoryElement<WebsocketCfg> { |
@@ -16,2 +16,7 @@ "use strict"; | ||
var factory_1 = require("../factory"); | ||
function makeArray(val) { | ||
return Array.isArray(val) | ||
? val | ||
: [val]; | ||
} | ||
var Websocket = /** @class */ (function (_super) { | ||
@@ -32,11 +37,12 @@ __extends(Websocket, _super); | ||
this._io.on('connection', function (socket) { | ||
var connection = new _this._cfg.connection(socket); | ||
_this._connections.push(connection); | ||
var connectionArr = makeArray(_this._cfg.connection).map(function (ctor) { return new ctor(socket); }); | ||
(_a = _this._connections).push.apply(_a, connectionArr); | ||
_this._logger.debug("+ on " + socket.id + " (" + _this._connections.length + " connections)"); | ||
socket.on('disconnect', function () { | ||
connection.destroy(); | ||
connectionArr.forEach(function (connection) { return connection.destroy(); }); | ||
_this._connections = _this._connections | ||
.filter(function (connectionEl) { return connectionEl !== connection; }); | ||
.filter(function (connectionEl) { return connectionArr.indexOf(connectionEl) === -1; }); | ||
_this._logger.debug("- off " + socket.id + " (" + _this._connections.length + " connections)"); | ||
}); | ||
var _a; | ||
}); | ||
@@ -43,0 +49,0 @@ }; |
{ | ||
"name": "server-modules", | ||
"version": "0.1.4", | ||
"version": "0.1.5", | ||
"description": "Easy configurable server modules (logging, express, api, websocket, mongodb)", | ||
@@ -5,0 +5,0 @@ "repository": "https://github.com/JohannesLamberts/easy-server-modules", |
<h1 align="center">server-modules</h1> | ||
<div align="center"> | ||
[![CircleCI](https://img.shields.io/circleci/project/github/JohannesLamberts/server-modules/master.svg)](https://circleci.com/gh/JohannesLamberts/server-modules) | ||
</div> | ||
[![CircleCI](https://img.shields.io/circleci/project/github/JohannesLamberts/server-modules/master.svg)](https://circleci.com/gh/JohannesLamberts/server-modules/tree/master) | ||
@@ -137,2 +135,2 @@ # Features | ||
} | ||
``` | ||
``` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
75397
51
1090
136