qualiteer/libold/common/sockets/clients/Viewer.js

27 lines
717 B
JavaScript
Raw Normal View History

2023-03-19 13:53:37 -04:00
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;
}
}