hatch
Version:
Eve events over the wire using HTTP EventSource
37 lines (36 loc) • 1.35 kB
JavaScript
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var events_1 = require("events");
var HatchClient = /** @class */ (function (_super) {
__extends(HatchClient, _super);
function HatchClient(id, source) {
var _this = _super.call(this) || this;
_this.id = id;
_this.source = source;
source.onmessage = function (evt) { return _this.handleMessage(evt); };
return _this;
}
HatchClient.prototype.handleMessage = function (evt) {
try {
var data = JSON.parse(evt.data);
this.emit.apply(this, [data.name].concat(data.args));
}
catch (e) {
}
};
return HatchClient;
}(events_1.EventEmitter));
exports.HatchClient = HatchClient;
;