Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
constructor(id, ws, nick, options) {
this.events = new E3.EventEmitter();
this.id = id;
this.nick = nick;
this.options = Object.assign({}, DefaultOptions, options);
this.lastSeen = new Date().getTime();
this._ws = ws;
this._joined = new Map();
debug('User connected with', this.id, this.nick, this.lastSeen);
this._ws.on('message', message => {
// Message from user
this.events.emit(
'message',
this.options.parser.fromSerialized(message),
this);
});
export default function TransmuxerWorker (self) {
const observer = new EventEmitter() as any;
observer.trigger = (event, data) => {
observer.emit(event, event, ...data);
};
observer.off = (event, ...data) => {
observer.removeListener(event, ...data);
};
const forwardMessage = (ev, data) => {
self.postMessage({ event: ev, data: data });
};
// forward events to main thread
observer.on(Event.FRAG_DECRYPTED, forwardMessage);
observer.on(Event.ERROR, forwardMessage);
public subscribe(request: SubscribeRequest): any {
const events = new EventEmitter();
this.session
.request(SubscribeApi.method, SubscribeApi.url, {
events: ['logs'],
filter: urlEncodeFilter(request.filter!),
})
.then(response => {
if (response.id === undefined || response.id === null) {
throw new Error(`subscription failed: ${response}`);
}
// Store the event -> queueId mapping so that we can unsubscribe later.
this.subscriptions.set(request.event, response.id);
PollingService.instance({
url: this.url,
session: this.session,
queueId: response.id,
}).subscribe(response.id, (event: any) => {
constructor(n) {
super();
if (Streamer[n]) {
throw 'the stream already exists';
}
Streamer[n] = this;
this.name = n;
this.subscriptionName = `stream-${ STREAM_NAMES[this.name] }`;
this.internals = new EventEmitter;
this[prepareSubscription]();
this[prepareMethod]();
this[authorizaton] = {
read: {},
write: {},
};
}
this.sigv4utils = new sig4utils_1.SigV4Utils();
}
this.connectionParams = connectionParams;
this.connectionCallback = connectionCallback;
this.iotEndpoint = iotEndpoint;
this.region = options.region;
this.operations = {};
this.nextOperationId = 0;
this.timeout = timeout;
this.unsentMessagesQueue = [];
this.reconnect = reconnect;
this.reconnecting = false;
this.reconnectionAttempts = reconnectionAttempts;
this.closedByUser = false;
this.backoff = new Backoff({ jitter: 0.5 });
this.eventEmitter = new eventemitter3_1.EventEmitter();
this.middlewares = [];
this.client = null;
this.maxConnectTimeGenerator = this.createMaxConnectTimeGenerator();
this.request = this.request.bind(this);
this.debug = options.debug;
this.connect();
}
SubscriptionClient.prototype.close = function (isForced, closedByUser) {
EE3.call(this);
this.web = createRightProxy('web')(options);
this.ws = createRightProxy('ws')(options);
this.options = options;
this.webPasses = Object.keys(web).map(function(pass) {
return web[pass];
});
this.wsPasses = Object.keys(ws).map(function(pass) {
return ws[pass];
});
}
require('util').inherits(ProxyServer, EE3);
ProxyServer.prototype.listen = function(port) {
var self = this,
closure = function(req, res) { self.web(req, res); };
this._server = this.options.ssl ?
https.createServer(this.options.ssl, closure) :
http.createServer(closure);
if(this.options.ws) {
this._server.on('upgrade', function(req, socket, head) { self.ws(req, socket, head); });
}
this._server.listen(port);
return this;
private constructor(
private session: Http,
private queueId?: number,
responseWindow?: Window,
interval?: number
) {
this.responseWindow = responseWindow ? responseWindow : new Window();
this.interval = interval ? interval : 1000;
this.responses = new EventEmitter();
this.lastResponseTs = Date.now();
}