Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Channel.prototype.subscribe = function (event, callback) {
if (typeof (callback) === "undefined") {
callback = event;
event = "_default";
}
this.callbacks[event] = callback;
var promise = this.connect();
if (this.readyState === EventSource.CONNECTING) {
var that = this;
promise.then(function () {
that.event_source.onopen = function (e) {
that.readyState = e.readyState;
that._trigger.apply(that, ["state:" + e.type, e]);
};
that.event_source.onerror = function (e) {
that.readyState = e.readyState;
that._trigger.apply(that, ["state:" + e.type, e]);
};
that.event_source.onmessage = function (e) {
var data = JSON.parse(e.data), event = data.event;
delete data.event;
that._trigger.apply(that, [event, data]);
};
});