26 lines
717 B
JavaScript
26 lines
717 B
JavaScript
import io from "socket.io-client";
|
|
import modes from "../modes.js";
|
|
import events from "../events.js";
|
|
|
|
export { default as events } from "../events.js";
|
|
export { default as modes } from "../modes.js";
|
|
|
|
export default class Viewer {
|
|
constructor(url, options = {}) {
|
|
this.url = url;
|
|
this.mode = modes.VIEW;
|
|
this.onLog = options.onLog ?? console.log;
|
|
this.onClose = options.onClose ?? (() => {});
|
|
}
|
|
|
|
viewJob(jobId, onLog, onClose) {
|
|
onLog = onLog ?? this.onLog.bind(this);
|
|
onClose = onClose ?? this.onClose.bind(this);
|
|
const sk = io(this.url, {
|
|
query: { mode: this.mode, jobId },
|
|
});
|
|
sk.on(events.JOB_LOG, onLog);
|
|
sk.on(events.JOB_CLS, onClose);
|
|
return sk;
|
|
}
|
|
}
|