Skip to content

Commit

Permalink
Merge pull request #4335 from hashicorp/b-ui-safari-log-streaming
Browse files Browse the repository at this point in the history
UI: Use polling instead of streaming for following logs in Safari
  • Loading branch information
DingoEatingFuzz committed May 30, 2018
2 parents 5febedd + 65adc38 commit d5cbcc6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
14 changes: 9 additions & 5 deletions ui/app/utils/classes/poll-logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,15 @@ export default EmberObject.extend(AbstractLogger, {

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)));

this.set('endOffset', frames[frames.length - 1].Offset);
this.get('write')(frames.mapBy('Data').join(''));
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);
this.get('write')(frames.mapBy('Data').join(''));
}
}

yield timeout(interval);
Expand Down
13 changes: 12 additions & 1 deletion ui/app/utils/classes/stream-logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,16 @@ export default EmberObject.extend(AbstractLogger, {
}
}),
}).reopenClass({
isSupported: !!window.ReadableStream,
isSupported: !!window.ReadableStream && !isSafari(),
});

// Fetch streaming doesn't work in Safari yet despite all the primitives being in place.
// Bug: https://bugs.webkit.org/show_bug.cgi?id=185924
// Until this is fixed, Safari needs to be explicitly targeted for poll-based logging.
function isSafari() {
const oldSafariTest = /constructor/i.test(window.HTMLElement);
const newSafariTest = (function(p) {
return p.toString() === '[object SafariRemoteNotification]';
})(!window['safari'] || (typeof window.safari !== 'undefined' && window.safari.pushNotification));
return oldSafariTest || newSafariTest;
}
2 changes: 1 addition & 1 deletion ui/tests/integration/task-log-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { logEncode } from '../../mirage/data/logs';
const HOST = '1.1.1.1:1111';
const allowedConnectionTime = 100;
const commonProps = {
interval: 50,
interval: 200,
allocation: {
id: 'alloc-1',
node: {
Expand Down

0 comments on commit d5cbcc6

Please sign in to comment.