Replit Commit
This commit is contained in:
commit
f49f965a42
41 changed files with 32720 additions and 0 deletions
27
lib/sockets/clients/Viewer.js
Normal file
27
lib/sockets/clients/Viewer.js
Normal file
|
@ -0,0 +1,27 @@
|
|||
import { Manager } 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) {
|
||||
const mgr = new Manager(this.url, {
|
||||
query: { mode: this.mode, jobId },
|
||||
});
|
||||
onLog = onLog ?? this.onLog.bind(this);
|
||||
onClose = onClose ?? this.onClose.bind(this);
|
||||
const sk = mgr.socket("/");
|
||||
sk.on(events.JOB_LOG, onLog);
|
||||
sk.on(events.JOB_CLS, onClose);
|
||||
return sk;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue