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() {
|
2017-12-12 00:20:38 +00:00
|
|
|
return this.get('poll')
|
|
|
|
.linked()
|
|
|
|
.perform();
|
2017-11-14 18:54:36 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
stop() {
|
|
|
|
return this.get('poll').cancelAll();
|
|
|
|
},
|
|
|
|
|
|
|
|
poll: task(function*() {
|
2017-11-18 04:06:37 +00:00
|
|
|
const { interval, logFetch } = this.getProperties('interval', 'logFetch');
|
2017-11-14 18:54:36 +00:00
|
|
|
while (true) {
|
2018-02-26 20:23:01 +00:00
|
|
|
const url = this.get('fullUrl');
|
|
|
|
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');
|
|
|
|
const frames = lines.map(line => JSON.parse(line));
|
|
|
|
frames.forEach(frame => (frame.Data = window.atob(frame.Data)));
|
2017-11-14 18:54:36 +00:00
|
|
|
|
2017-11-18 04:06:37 +00:00
|
|
|
this.set('endOffset', frames[frames.length - 1].Offset);
|
|
|
|
this.get('write')(frames.mapBy('Data').join(''));
|
|
|
|
}
|
2017-11-17 00:31:18 +00:00
|
|
|
|
|
|
|
yield timeout(interval);
|
2017-11-14 18:54:36 +00:00
|
|
|
}
|
|
|
|
}),
|
|
|
|
});
|