Merge pull request #3560 from urbit/m/webdojo-slogs

webdojo: slogs
This commit is contained in:
matildepark 2020-10-15 18:13:01 -04:00 committed by GitHub
commit 3241377155
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 1 deletions

View File

@ -15,7 +15,7 @@ export class History extends Component {
{this.props.commandLog.map((text, index) => {
return (
<p className="mono" key={index}
style={{ overflowWrap: 'break-word' }}
style={{ overflowWrap: 'break-word', whiteSpace: 'pre' }}
>
{text}
</p>

View File

@ -14,6 +14,32 @@ export default class Subscription {
} else {
console.error('~~~ ERROR: Must set api.ship before operation ~~~');
}
this.setupSlog();
}
setupSlog() {
let available = false;
const slog = new EventSource('/~_~/slog', { withCredentials: true });
slog.onopen = e => {
console.log('slog: opened stream');
available = true;
}
slog.onmessage = e => {
this.handleEvent({ txt: e.data });
}
slog.onerror = e => {
console.error('slog: eventsource error:', e);
if (available) {
window.setTimeout(() => {
if (slog.readyState !== EventSource.CLOSED) return;
console.log('slog: reconnecting...');
this.setupSlog();
}, 10000);
}
}
}
delete() {