UNPKG

gamesocket.io

Version:
63 lines (62 loc) 2.11 kB
'use strict' var __importDefault = (this && this.__importDefault) || function (mod) { return mod && mod.__esModule ? mod : { default: mod } } Object.defineProperty(exports, '__esModule', { value: true }) exports.Namespace = void 0 const io_js_1 = require('../io.js') const DestinationConrtoller_js_1 = __importDefault(require('../DestinationConrtoller/DestinationConrtoller.js')) const Logger_js_1 = __importDefault(require('../Logger/Logger.js')) const List_js_1 = require('../SocketList/List.js') class Namespace { _name _events _aliases = new io_js_1.AliasPool() _sockets = new List_js_1.List('undefiend') constructor(_name, _events) { this._name = _name this._events = _events } get name() { return this._name } control(destinations) { if (Logger_js_1.default.flags.debug) Logger_js_1.default.debug(`${this._name}: controlling ${destinations}`) if (destinations instanceof Array) { if (destinations[0] == 'broadcast') Logger_js_1.default.fatal( `{ ${this._name}.control('broadcast') } is reserved. Try to use { ${this._name}.emit(...) } instead`, ) return (0, DestinationConrtoller_js_1.default)(this._name, ...destinations) } else { if (destinations == 'broadcast') Logger_js_1.default.fatal( `{ ${this._name}.control('broadcast') } is reserved. Try to use { ${this._name}.emit(...) } instead`, ) return (0, DestinationConrtoller_js_1.default)(this._name, destinations) } } emit(event, ...data) { if (Logger_js_1.default.flags.debug) Logger_js_1.default.debug(`${this._name}: emitting '${event}'`) this.control('reserved/broadcast').emit(event, data) } on(event, callback) { if (Logger_js_1.default.flags.debug) Logger_js_1.default.debug(`${this._name}: create handler "${event}"`) this._events.spawn(event, callback) } get Aliases() { return this._aliases } get Sockets() { return this._sockets } get EventsKeys() { return this._events.events } get Events() { return this._events } } exports.Namespace = Namespace