Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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"
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=${
}, function (data) {
that.readyState = EventSource.CLOSED;
that._trigger.apply(that, ["state:error", data]);
});
};
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]);
};
});