@obelisk/client
Advanced tools
Comparing version 2.1.1 to 2.1.2
@@ -5,4 +5,4 @@ "use strict"; | ||
const rxjs_1 = require("rxjs"); | ||
const operators_1 = require("rxjs/operators"); | ||
const util_1 = require("../util"); | ||
const operators_1 = require("rxjs/operators"); | ||
/** | ||
@@ -50,34 +50,25 @@ * Endpoint class represents an IoT-stack API Endpoint. | ||
observablePolyEventSource(options) { | ||
const start = Date.now(); | ||
const url = options ? this.addOptionsToUrl(this._url, options) : this._url; | ||
const h = { | ||
headers: { Authorization: 'Bearer ' + (this.client.tokens.rpt ? this.client.tokens.rpt.getToken() : '<no rpt present>') }, | ||
Transport: XMLHttpRequest | ||
Transport: XMLHttpRequest, | ||
}; | ||
const subject = new rxjs_1.ReplaySubject(1); | ||
const eventsource = new event_source_polyfill_1.EventSourcePolyfill(url, h); | ||
return rxjs_1.Observable.create((observer) => { | ||
if (util_1.Config.debug) { | ||
// console.log(eventsource); | ||
eventsource.onopen = function () { | ||
console.log(Date.now() - start); | ||
}; | ||
eventsource.onmessage = function (event) { | ||
const json = JSON.parse(event.data); | ||
subject.next(json); | ||
}; | ||
eventsource.onerror = function (event) { | ||
eventsource.close(); | ||
if (eventsource.readyState === 0) { // connecting | ||
subject.complete(); | ||
} | ||
eventsource.onmessage = function (event) { | ||
const json = JSON.parse(event.data); | ||
observer.next(json); | ||
}; | ||
eventsource.onerror = function (event) { | ||
eventsource.close(); | ||
if (eventsource.readyState === 0) { | ||
observer.complete(); | ||
} | ||
else { | ||
observer.error(event); | ||
} | ||
}; | ||
return () => { | ||
eventsource.close(); | ||
}; | ||
}).pipe(operators_1.finalize(() => { | ||
else { | ||
subject.error(event); | ||
} | ||
}; | ||
return subject.asObservable().pipe(operators_1.finalize(() => { | ||
eventsource.close(); | ||
eventsource.readyState = 2; | ||
})); | ||
@@ -84,0 +75,0 @@ } |
{ | ||
"name": "@obelisk/client", | ||
"version": "2.1.1", | ||
"version": "2.1.2", | ||
"description": "Typescript client to interact with Obelisk on a higher level than the regular ReST API calls.", | ||
@@ -42,3 +42,3 @@ "keywords": [ | ||
"eventsource": "^1.0.7", | ||
"rxjs": "6.x" | ||
"rxjs": "^6.5.1" | ||
}, | ||
@@ -45,0 +45,0 @@ "peerDependencies": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
97952
2612
Updatedrxjs@^6.5.1