How to use the event-source-polyfill.CONNECTING function in event-source-polyfill

To help you get started, we’ve selected a few event-source-polyfill examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github doubleleft / hook-javascript / dist / hook.js View on Github external
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]);
        };
      });

event-source-polyfill

A polyfill for http://www.w3.org/TR/eventsource/

MIT
Latest version published 2 years ago

Package Health Score

74 / 100
Full package analysis