How to use event-source-polyfill - 4 common examples

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 latenighttales / alcali / src / components / core / Layout.vue View on Github external
saltStatus() {
        // Various Salt event tag matchers.
        let isJobEvent = helpersMixin.methods.fnmatch("salt/job/*")
        let isJobNew = helpersMixin.methods.fnmatch("salt/job/*/new")
        let isJobReturn = helpersMixin.methods.fnmatch("salt/job/*/ret/*")
        const accessToken = localStorage.getItem("access")
        let es = new EventSourcePolyfill("/api/event_stream/", {
          headers: {
            "Authorization": `Bearer ${accessToken}`,
          },
        })
        es.addEventListener("open", () => {
          this.$store.dispatch("updateWs")

        })
        es.addEventListener("message", event => {
          let data = JSON.parse(event.data)
          // Display only activated notifs.
          if (isJobNew(data.tag) && this.notifs.published === true) {
            if (data.data.fun !== 'saltutil.find_job') {
              data.type = "new"
              data.color = "green"
              data.icon = "keyboard_tab"
github bosch-io / iot-things-examples / octopus-bidirectional / iot-frontend / src / utils / bus.js View on Github external
fire(event, data = null) {

        if (event === "initSSE") {

            // start listening with a little timeout
            let values = Object.values(this.vue.items);
            let thingIds = values.map(element => element.thingId).join(",");
            switch(this.vue.suiteAuthActive){
                case true:
                    this.source = new EventSourcePolyfill(
                        `${
                            this.vue.connection.http_endpoint
                            }/api/2/things?ids=${thingIds}&fields=thingId,policyId,attributes,features,_revision`,
                        {
                            headers: {
                                Authorization: Api.getConfig().headers.Authorization
                            },
                            withCredentials: true
                        }
                    );
                break;
                case false:
                    this.source = new EventSourcePolyfill(
                        `${
                            this.vue.connection.http_endpoint
                            }/api/2/things?ids=${thingIds}&x-cr-api-token=${
github doubleleft / hook-javascript / dist / hook.js View on Github external
}, function (data) {
      that.readyState = EventSource.CLOSED;
      that._trigger.apply(that, ["state:error", data]);
    });
  };
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

62 / 100
Full package analysis