listeners(eventName) { if(this._name == null && WebSocketChannel.NO_WRAP_EVENTS.indexOf(eventName) >= 0) return this._emitter.listeners(eventName); else { return this._emitter.listeners(eventName).map((wrapper) => { return wrapper._original; }); } }
/* The following `emit` and `request` methods will serialize and send the event over the WebSocket using the WebSocketWrapper. */ emit(eventName) { if(this._name == null && WebSocketChannel.NO_WRAP_EVENTS.indexOf(eventName) >= 0) return this._emitter.emit.apply(this._emitter, arguments); else return this._wrapper._sendEvent(this._name, eventName, arguments); }
removeListener(eventName, listener) { if(this._name == null && WebSocketChannel.NO_WRAP_EVENTS.indexOf(eventName) >= 0) this._emitter.removeListener(eventName, listener); else this._emitter.removeListener(eventName, this._wrappedListeners.get(listener) ); return this; }
once(eventName, listener) { if(this._name == null && WebSocketChannel.NO_WRAP_EVENTS.indexOf(eventName) >= 0) this._emitter.once(eventName, listener, this); else this._emitter.once(eventName, this._wrapListener(listener) ); return this; }
/* Expose EventEmitter-like API When `eventName` is one of the `NO_WRAP_EVENTS`, the event handlers are left untouched, and the emitted events are just sent to the EventEmitter; otherwise, event listeners are wrapped to process the incoming request and the emitted events are sent to the WebSocketWrapper to be serialized and sent over the WebSocket. */ on(eventName, listener) { if(this._name == null && WebSocketChannel.NO_WRAP_EVENTS.indexOf(eventName) >= 0) /* Note: The following is equivalent to: `this._emitter.on(eventName, listener.bind(this));` But thanks to eventemitter3, the following is a touch faster. */ this._emitter.on(eventName, listener, this); else this._emitter.on(eventName, this._wrapListener(listener) ); return this; }