2017-12-15 21:39:18 +00:00
|
|
|
import EmberObject from '@ember/object';
|
2017-11-14 18:54:36 +00:00
|
|
|
import { task, timeout } from 'ember-concurrency';
|
2017-11-21 01:09:28 +00:00
|
|
|
import AbstractLogger from './abstract-logger';
|
2018-02-26 20:23:01 +00:00
|
|
|
import { fetchFailure } from './log';
|
2017-11-14 18:54:36 +00:00
|
|
|
|
2017-11-21 01:09:28 +00:00
|
|
|
export default EmberObject.extend(AbstractLogger, {
|
2017-11-14 18:54:36 +00:00
|
|
|
interval: 1000,
|
|
|
|
|
|
|
|
start() {
|
2019-03-26 07:46:44 +00:00
|
|
|
return this.poll
|
2017-12-12 00:20:38 +00:00
|
|
|
.linked()
|
|
|
|
.perform();
|
2017-11-14 18:54:36 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
stop() {
|
2019-03-26 07:46:44 +00:00
|
|
|
return this.poll.cancelAll();
|
2017-11-14 18:54:36 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
poll: task(function*() {
|
2019-03-26 07:46:44 +00:00
|
|
|
const { interval, logFetch } = this;
|
2017-11-14 18:54:36 +00:00
|
|
|
while (true) {
|
2019-03-26 07:46:44 +00:00
|
|
|
const url = this.fullUrl;
|
2018-02-26 20:23:01 +00:00
|
|
|
let response = yield logFetch(url).then(res => res, fetchFailure(url));
|
|
|
|
|
|
|
|
if (!response) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let text = yield response.text();
|
2017-11-14 18:54:36 +00:00
|
|
|
|
2017-11-18 04:06:37 +00:00
|
|
|
if (text) {
|
|
|
|
const lines = text.replace(/\}\{/g, '}\n{').split('\n');
|
2018-05-24 22:46:55 +00:00
|
|
|
const frames = lines
|
|
|
|
.map(line => JSON.parse(line))
|
|
|
|
.filter(frame => frame.Data != null && frame.Offset != null);
|
|
|
|
|
|
|
|
if (frames.length) {
|
|
|
|
frames.forEach(frame => (frame.Data = window.atob(frame.Data)));
|
|
|
|
this.set('endOffset', frames[frames.length - 1].Offset);
|
2019-03-26 07:46:44 +00:00
|
|
|
this.write(frames.mapBy('Data').join(''));
|
2018-05-24 22:46:55 +00:00
|
|
|
}
|
2017-11-18 04:06:37 +00:00
|
|
|
}
|
2017-11-17 00:31:18 +00:00
|
|
|
|
|
|
|
yield timeout(interval);
|
2017-11-14 18:54:36 +00:00
|
|
|
}
|
|
|
|
}),
|
|
|
|
});
|