2024-10-19 02:13:52 +00:00
|
|
|
let client : Client;
|
|
|
|
|
2024-08-16 04:52:46 +00:00
|
|
|
enum SequenceStatus {
|
|
|
|
IDLE,
|
|
|
|
RUNNING,
|
|
|
|
PAUSED
|
|
|
|
}
|
|
|
|
|
|
|
|
class Display {
|
|
|
|
private parentElement : HTMLUListElement;
|
|
|
|
private canvas : HTMLCanvasElement;
|
|
|
|
private ctx : CanvasRenderingContext2D;
|
2024-10-22 20:31:04 +00:00
|
|
|
private img : HTMLImageElement;
|
2024-08-16 04:52:46 +00:00
|
|
|
private screen : any;
|
2024-08-18 01:22:17 +00:00
|
|
|
private sequence : boolean = false;
|
2024-10-24 15:01:03 +00:00
|
|
|
private focus : boolean = false;
|
2024-10-24 15:23:33 +00:00
|
|
|
private framing : boolean = false;
|
2024-08-18 01:22:17 +00:00
|
|
|
|
|
|
|
private offsetX : number = 0;
|
|
|
|
private offsetY : number = 0;
|
|
|
|
private width : number = 0;
|
|
|
|
private height : number = 0;
|
|
|
|
|
|
|
|
private canvasScale : number = 0;
|
|
|
|
private canvasWidth : number = 0;
|
|
|
|
private canvasHeight : number = 0;
|
|
|
|
private canvasOffsetX : number = 0;
|
|
|
|
private canvasOffsetY : number = 0;
|
|
|
|
|
|
|
|
private screenWidth : number = 0;
|
|
|
|
private screenHeight : number = 0;
|
|
|
|
private screenOffsetX : number = 0;
|
|
|
|
private screenOffsetY : number = 0;
|
|
|
|
|
|
|
|
private displayWidth : number = 0;
|
|
|
|
private displayHeight : number = 0;
|
|
|
|
private displayOffsetX : number = 0;
|
|
|
|
private displayOffsetY : number = 0;
|
|
|
|
|
2024-08-16 04:52:46 +00:00
|
|
|
constructor () {
|
|
|
|
this.parentElement = document.getElementById('display') as HTMLUListElement;
|
|
|
|
this.create();
|
2024-08-18 01:22:17 +00:00
|
|
|
window.onresize = this.onResize.bind(this);
|
2024-08-16 04:52:46 +00:00
|
|
|
}
|
2024-10-22 03:51:38 +00:00
|
|
|
|
2024-08-16 04:52:46 +00:00
|
|
|
private create () {
|
|
|
|
this.canvas = this.parentElement.getElementsByTagName('canvas')[0];
|
|
|
|
this.ctx = this.canvas.getContext('2d');
|
|
|
|
this.screen = {
|
|
|
|
width : parseInt((document.getElementById('width') as HTMLInputElement).value),
|
|
|
|
height : parseInt((document.getElementById('height') as HTMLInputElement).value)
|
|
|
|
}
|
|
|
|
this.updateSize();
|
2024-08-18 01:22:17 +00:00
|
|
|
this.clear();
|
|
|
|
this.updateScreen();
|
|
|
|
this.updateDisplay();
|
2024-08-16 04:52:46 +00:00
|
|
|
}
|
2024-08-18 01:22:17 +00:00
|
|
|
|
2024-08-16 04:52:46 +00:00
|
|
|
private updateSize () {
|
2024-08-18 01:22:17 +00:00
|
|
|
this.canvasScale = window.devicePixelRatio;
|
|
|
|
this.canvasWidth = this.parentElement.clientWidth - 12;
|
|
|
|
this.canvasHeight = this.parentElement.clientHeight - 12;
|
2024-10-22 19:04:25 +00:00
|
|
|
//console.log(`${this.canvasWidth},${this.canvasHeight}`);
|
2024-08-18 01:22:17 +00:00
|
|
|
this.canvas.width = this.canvasWidth;
|
|
|
|
this.canvas.height = this.canvasHeight;
|
|
|
|
}
|
|
|
|
|
2024-10-22 19:04:25 +00:00
|
|
|
public clear () {
|
2024-08-18 01:22:17 +00:00
|
|
|
this.ctx.fillStyle = 'rgb(0, 0, 0)';
|
|
|
|
this.ctx.fillRect(0, 0, this.canvasWidth, this.canvasHeight);
|
|
|
|
}
|
|
|
|
|
2024-10-22 19:04:25 +00:00
|
|
|
public updateScreen () {
|
2024-08-18 01:22:17 +00:00
|
|
|
const clientRatio : number = this.canvasWidth / this.canvasHeight;
|
2024-08-16 04:52:46 +00:00
|
|
|
const screenRatio : number = this.screen.width / this.screen.height;
|
2024-08-18 01:22:17 +00:00
|
|
|
|
2024-08-16 04:52:46 +00:00
|
|
|
if (screenRatio > clientRatio) {
|
2024-08-18 01:22:17 +00:00
|
|
|
this.screenWidth = this.canvasWidth - 2;
|
|
|
|
this.screenHeight = Math.floor(this.canvasWidth / screenRatio);
|
|
|
|
this.screenOffsetX = 1;
|
|
|
|
this.screenOffsetY = Math.round((this.canvasHeight - this.screenHeight) / 2);
|
2024-08-16 04:52:46 +00:00
|
|
|
} else {
|
2024-08-18 01:22:17 +00:00
|
|
|
this.screenWidth = Math.round(this.canvasHeight * screenRatio);
|
|
|
|
this.screenHeight = this.canvasHeight - 2;
|
|
|
|
this.screenOffsetY = 1;
|
|
|
|
this.screenOffsetX = Math.round((this.canvasWidth - this.screenWidth) / 2);
|
2024-08-16 04:52:46 +00:00
|
|
|
}
|
2024-08-18 01:22:17 +00:00
|
|
|
this.ctx.strokeStyle = 'rgb(0, 0, 255)';
|
|
|
|
this.ctx.rect(this.screenOffsetX, this.screenOffsetY, this.screenWidth, this.screenHeight);
|
2024-08-16 04:52:46 +00:00
|
|
|
this.ctx.stroke();
|
|
|
|
}
|
2024-08-18 01:22:17 +00:00
|
|
|
|
2024-08-24 14:23:15 +00:00
|
|
|
public updateDisplay () {
|
2024-10-24 15:23:33 +00:00
|
|
|
if (!this.sequence && !this.focus && !this.framing) {
|
2024-08-18 01:22:17 +00:00
|
|
|
return;
|
|
|
|
}
|
2024-10-22 19:04:25 +00:00
|
|
|
//console.log(this.sequence);
|
2024-08-18 01:22:17 +00:00
|
|
|
const screenScaleX : number = this.screenWidth / this.screen.width;
|
|
|
|
const screenScaleY : number = this.screenHeight / this.screen.height;
|
|
|
|
this.displayWidth = Math.round(this.width * screenScaleX);
|
|
|
|
this.displayHeight = Math.round(this.height * screenScaleY);
|
|
|
|
this.displayOffsetX = this.screenOffsetX + Math.round(this.offsetX * screenScaleX);
|
|
|
|
this.displayOffsetY = this.screenOffsetY + Math.round(this.offsetY * screenScaleY);
|
|
|
|
|
2024-08-24 14:23:15 +00:00
|
|
|
this.ctx.fillStyle = 'rgb(0, 0, 0)';
|
2024-08-18 01:22:17 +00:00
|
|
|
this.ctx.fillRect(this.displayOffsetX, this.displayOffsetY, this.displayWidth, this.displayHeight);
|
2024-10-22 19:04:25 +00:00
|
|
|
//console.log(`${this.displayOffsetX}, ${this.displayOffsetY}, ${this.displayWidth}, ${this.displayHeight}`);
|
2024-08-18 01:22:17 +00:00
|
|
|
this.updateImage();
|
|
|
|
}
|
|
|
|
|
2024-08-24 14:23:15 +00:00
|
|
|
public updateImage() {
|
2024-10-22 20:31:04 +00:00
|
|
|
this.img = new Image;
|
|
|
|
this.img.onload = function () {
|
|
|
|
this.ctx.drawImage(this.img, this.displayOffsetX, this.displayOffsetY, this.displayWidth, this.displayHeight);
|
2024-08-18 01:22:17 +00:00
|
|
|
}.bind(this);
|
2024-10-22 20:31:04 +00:00
|
|
|
this.img.src = `/${this.displayWidth}/${this.displayHeight}/image.jpg?cacheBreaker=${+new Date()}`;
|
2024-08-18 01:22:17 +00:00
|
|
|
}
|
|
|
|
|
2024-08-16 04:52:46 +00:00
|
|
|
public update (msg : Message) {
|
|
|
|
|
|
|
|
}
|
2024-08-18 01:22:17 +00:00
|
|
|
|
|
|
|
public set (state : State) {
|
|
|
|
this.sequence = true;
|
2024-10-24 15:01:03 +00:00
|
|
|
this.focus = false;
|
2024-08-18 01:22:17 +00:00
|
|
|
this.offsetX = state.offset.x;
|
|
|
|
this.offsetY = state.offset.y;
|
|
|
|
this.width = state.display.width;
|
|
|
|
this.height = state.display.height;
|
|
|
|
this.updateDisplay();
|
|
|
|
}
|
|
|
|
|
2024-10-24 15:01:03 +00:00
|
|
|
public setFocus () {
|
|
|
|
this.focus = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public unsetFocus () {
|
|
|
|
this.focus = false;
|
|
|
|
}
|
|
|
|
|
2024-10-24 15:23:33 +00:00
|
|
|
public setFraming () {
|
|
|
|
this.framing= true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public unsetFraming () {
|
|
|
|
this.framing = false;
|
|
|
|
}
|
|
|
|
|
2024-08-18 01:22:17 +00:00
|
|
|
private onResize (event : any) {
|
|
|
|
this.updateSize();
|
|
|
|
this.clear();
|
|
|
|
this.updateScreen();
|
|
|
|
this.updateDisplay();
|
|
|
|
}
|
2024-08-16 04:52:46 +00:00
|
|
|
}
|
|
|
|
|
2024-05-15 21:29:59 +00:00
|
|
|
class Client {
|
2024-08-16 04:52:46 +00:00
|
|
|
private display : Display;
|
2024-05-15 21:29:59 +00:00
|
|
|
private client : WebSocket;
|
|
|
|
private connected : boolean = false;
|
2024-07-12 13:51:39 +00:00
|
|
|
private progress : HTMLProgressElement;
|
2024-08-24 14:23:15 +00:00
|
|
|
private progressText : HTMLElement;
|
2024-08-30 17:49:16 +00:00
|
|
|
private frames : number = 0;
|
2024-07-12 13:51:39 +00:00
|
|
|
|
2024-05-15 21:29:59 +00:00
|
|
|
constructor () {
|
2024-08-24 20:26:49 +00:00
|
|
|
let uri : string = this.getWebsocketUri();
|
2024-07-12 13:51:39 +00:00
|
|
|
this.progress = document.getElementById('progress') as HTMLProgressElement;
|
2024-08-24 14:23:15 +00:00
|
|
|
this.progressText = document.getElementById('progressText');
|
2024-05-15 21:29:59 +00:00
|
|
|
this.client = new WebSocket(uri);
|
2024-08-16 04:52:46 +00:00
|
|
|
this.display = new Display();
|
2024-05-15 21:29:59 +00:00
|
|
|
this.client.onopen = this.onOpen.bind(this);
|
2024-08-15 02:43:02 +00:00
|
|
|
this.client.onclose = this.onClose.bind(this);
|
2024-05-15 21:29:59 +00:00
|
|
|
this.client.onmessage = this.onMessage.bind(this);
|
2024-10-20 01:15:52 +00:00
|
|
|
|
|
|
|
this.resetForm('sequenceSelectForm');
|
|
|
|
this.resetForm('sequenceCtrlForm');
|
|
|
|
this.resetForm('manualCtrlForm');
|
|
|
|
this.resetForm('exposureCtrlForm');
|
|
|
|
this.resetForm('statisticsForm');
|
|
|
|
|
2024-08-16 04:52:46 +00:00
|
|
|
this.disableClass('sequenceCtrl');
|
|
|
|
this.disableClass('manualCtrl');
|
2024-10-18 03:06:37 +00:00
|
|
|
this.disableClass('exposureCtrl');
|
2024-08-24 20:26:49 +00:00
|
|
|
this.setProgress({ hash: null, progress: 0 });
|
|
|
|
}
|
|
|
|
|
|
|
|
private getWebsocketUri () : string {
|
|
|
|
const host : string = (window.location.host + '').split(':')[0];
|
|
|
|
//WEBSOCKET_PORT defined on page via template
|
|
|
|
//@ts-ignore
|
|
|
|
return `ws://${host}:${WEBSOCKET_PORT}`
|
2024-05-15 21:29:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private onMessage (event : any) {
|
2024-07-13 13:23:58 +00:00
|
|
|
const msg : Message = JSON.parse(event.data) as Message;
|
2024-08-16 04:52:46 +00:00
|
|
|
if (typeof msg.cmd !== 'undefined' && msg.cmd !== null) {
|
2024-08-02 14:29:12 +00:00
|
|
|
this.cmd(msg);
|
2024-07-12 13:51:39 +00:00
|
|
|
}
|
2024-05-15 21:29:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private onOpen (event : any) {
|
|
|
|
console.log('Connected');
|
|
|
|
this.connected = true;
|
2024-08-15 02:43:02 +00:00
|
|
|
this.active();
|
2024-08-16 04:52:46 +00:00
|
|
|
this.enableClass('manualCtrl');
|
2024-08-15 02:43:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private onClose (event : any) {
|
|
|
|
console.log('Disconnected');
|
|
|
|
this.connected = false;
|
|
|
|
this.inactive();
|
2024-05-15 21:29:59 +00:00
|
|
|
}
|
2024-07-12 13:51:39 +00:00
|
|
|
|
2024-08-16 04:52:46 +00:00
|
|
|
private setSequence(state : State) {
|
|
|
|
this.setProgress(state.sequence);
|
2024-08-24 14:23:15 +00:00
|
|
|
this.setFrame(state.sequence);
|
2024-08-16 04:52:46 +00:00
|
|
|
this.setStatus(state.sequence);
|
2024-10-18 03:06:37 +00:00
|
|
|
this.setExposure(state);
|
2024-08-16 04:52:46 +00:00
|
|
|
this.setDisplay(state);
|
2024-10-19 02:13:52 +00:00
|
|
|
this.set('sequence', state.sequence.hash);
|
|
|
|
this.removeClass('sequence', 'edited');
|
2024-08-16 04:52:46 +00:00
|
|
|
}
|
|
|
|
|
2024-08-24 14:23:15 +00:00
|
|
|
private setUpdate(state : State) {
|
|
|
|
this.setProgress(state.sequence);
|
|
|
|
this.setFrame(state.sequence);
|
|
|
|
this.setStatus(state.sequence);
|
2024-10-18 03:06:37 +00:00
|
|
|
this.setExposure(state);
|
2024-10-19 02:13:52 +00:00
|
|
|
this.setStatistics(state.statistics);
|
2024-08-24 14:23:15 +00:00
|
|
|
this.display.updateImage();
|
|
|
|
}
|
|
|
|
|
2024-08-16 04:52:46 +00:00
|
|
|
private setStatus (sequence : SequenceState) {
|
|
|
|
let status : string;
|
|
|
|
switch (sequence.status) {
|
|
|
|
case SequenceStatus.IDLE :
|
|
|
|
status = 'Idle';
|
|
|
|
break;
|
|
|
|
case SequenceStatus.RUNNING :
|
|
|
|
status = 'Running';
|
|
|
|
break;
|
|
|
|
case SequenceStatus.PAUSED :
|
|
|
|
status = 'Paused';
|
|
|
|
break;
|
|
|
|
default :
|
|
|
|
status = 'Unknown State';
|
|
|
|
}
|
2024-08-30 17:49:16 +00:00
|
|
|
this.frames = sequence.frames;
|
2024-08-16 04:52:46 +00:00
|
|
|
document.getElementById('sequenceStatus').innerText = status;
|
|
|
|
document.getElementById('sequenceName').innerText = sequence.name;
|
|
|
|
document.getElementById('sequenceLength').innerText = `Sequence Length: ${sequence.frames}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
private setProgress (sequence : SequenceState) {
|
2024-07-12 13:51:39 +00:00
|
|
|
const percent : number = sequence.progress * 100.0;
|
2024-08-24 14:23:15 +00:00
|
|
|
this.progress.value = sequence.progress;
|
|
|
|
this.progressText.innerText = `Progress: ${Math.floor(percent)}%`;
|
|
|
|
}
|
|
|
|
|
|
|
|
private setFrame (sequence : SequenceState) {
|
|
|
|
if (typeof sequence.current !== 'undefined') {
|
2024-10-19 02:13:52 +00:00
|
|
|
this.set('frame', `${sequence.current}`.padStart(5, '0'));
|
|
|
|
this.removeClass('frame', 'edited');
|
2024-08-16 04:52:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-18 03:06:37 +00:00
|
|
|
private setExposure (state : State) {
|
|
|
|
if (typeof state.exposure !== 'undefined') {
|
2024-10-19 02:13:52 +00:00
|
|
|
const el : HTMLInputElement = document.getElementById('exposure') as HTMLInputElement;
|
2024-10-18 03:06:37 +00:00
|
|
|
this.enableClass('exposureCtrl');
|
2024-10-19 02:13:52 +00:00
|
|
|
this.set('exposure', `${state.exposure}`);
|
|
|
|
this.removeClass('exposure', 'edited');
|
2024-10-18 03:06:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-08-16 04:52:46 +00:00
|
|
|
private setDisplay (state : State) {
|
2024-08-24 14:23:15 +00:00
|
|
|
if (typeof state.display !== 'undefined') {
|
2024-10-19 02:13:52 +00:00
|
|
|
this.set('displayWidth', state.display.width.toString());
|
|
|
|
this.set('displayHeight', state.display.height.toString());
|
2024-10-22 19:04:25 +00:00
|
|
|
this.set('offsetLeft', state.offset.x.toString());
|
|
|
|
this.set('offsetTop', state.offset.y.toString());
|
2024-10-19 02:13:52 +00:00
|
|
|
this.set('sourceWidth', state.source.width.toString());
|
|
|
|
this.set('sourceHeight', state.source.height.toString());
|
2024-08-18 13:10:37 +00:00
|
|
|
|
2024-10-19 02:13:52 +00:00
|
|
|
//widthEl.readOnly = false;
|
|
|
|
//heightEl.readOnly = false;
|
2024-08-24 14:23:15 +00:00
|
|
|
//console.dir(state);
|
|
|
|
this.display.set(state);
|
|
|
|
}
|
2024-07-12 13:51:39 +00:00
|
|
|
}
|
2024-07-13 02:00:24 +00:00
|
|
|
|
2024-10-19 02:13:52 +00:00
|
|
|
public edited (el : HTMLElement) {
|
|
|
|
el.classList.add('edited');
|
|
|
|
}
|
|
|
|
|
|
|
|
private setStatistics (stats : SequenceStatistics) {
|
|
|
|
if (stats !== null) {
|
2024-10-20 12:53:25 +00:00
|
|
|
this.set('statsFrameTotalLast', this.roundDigits(stats.totalFrameLast, 0));
|
|
|
|
this.set('statsFrameTotalAvg', this.roundDigits(stats.totalFrameAvg, 2));
|
|
|
|
this.set('statsFrameTotalMargin', this.roundDigits(stats.totalFrameMargin, 1));
|
2024-10-19 02:13:52 +00:00
|
|
|
|
2024-10-20 12:53:25 +00:00
|
|
|
this.set('statsFPS', this.roundDigits(stats.fps, 2));
|
2024-10-19 02:13:52 +00:00
|
|
|
|
2024-10-20 12:53:25 +00:00
|
|
|
this.set('statsFrameLoadAvg', this.roundDigits(stats.loadAvg, 2));
|
|
|
|
this.set('statsFrameLoadMargin', this.roundDigits(stats.loadMargin, 1));
|
2024-10-19 02:13:52 +00:00
|
|
|
|
2024-10-20 12:53:25 +00:00
|
|
|
this.set('statsFrameOpenLast', this.roundDigits(stats.openLast, 0));
|
|
|
|
this.set('statsFrameOpenAvg', this.roundDigits(stats.openAvg, 2));
|
|
|
|
this.set('statsFrameOpenMargin', this.roundDigits(stats.openMargin, 1));
|
2024-10-19 02:13:52 +00:00
|
|
|
|
2024-10-20 12:53:25 +00:00
|
|
|
this.set('statsFrameCloseLast', this.roundDigits(stats.closeLast, 0));
|
|
|
|
this.set('statsFrameCloseAvg', this.roundDigits(stats.closeAvg, 2));
|
|
|
|
this.set('statsFrameCloseMargin', this.roundDigits(stats.closeMargin, 1));
|
2024-10-19 02:13:52 +00:00
|
|
|
|
2024-10-20 12:53:25 +00:00
|
|
|
this.set('statsExposureLast', this.roundDigits(stats.exposureLast, 0));
|
|
|
|
this.set('statsExposureAvg', this.roundDigits(stats.exposureAvg, 2));
|
|
|
|
this.set('statsExposureMargin', this.roundDigits(stats.exposureMargin, 1));
|
2024-10-19 02:13:52 +00:00
|
|
|
|
2024-10-20 12:53:25 +00:00
|
|
|
this.set('statsElapsed', this.roundDigits(stats.elapsed, 0));
|
|
|
|
this.set('statsEstimate', this.roundDigits(stats.estimate, 0));
|
2024-10-20 01:15:52 +00:00
|
|
|
|
|
|
|
this.set('statsElapsedHuman', this.shortenHumanize(Math.round(stats.elapsed)));
|
|
|
|
this.set('statsEstimateHuman', this.shortenHumanize(Math.round(stats.estimate)));
|
2024-10-19 02:13:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-08-02 14:29:12 +00:00
|
|
|
private cmd (msg : Message) {
|
|
|
|
switch (msg.cmd) {
|
2024-08-24 20:26:49 +00:00
|
|
|
case 'ping' :
|
|
|
|
this.receivePing();
|
|
|
|
break;
|
2024-07-13 13:23:58 +00:00
|
|
|
case 'open' :
|
|
|
|
this.receiveCameraOpen();
|
|
|
|
break;
|
2024-08-01 15:57:49 +00:00
|
|
|
case 'close' :
|
|
|
|
this.receiveCameraClose();
|
|
|
|
break;
|
2024-08-02 14:29:12 +00:00
|
|
|
case 'select' :
|
|
|
|
this.receiveSelect(msg);
|
2024-08-09 20:20:07 +00:00
|
|
|
break;
|
2024-08-24 14:23:15 +00:00
|
|
|
case 'update' :
|
|
|
|
this.receiveUpdate(msg);
|
|
|
|
break;
|
2024-10-22 03:51:38 +00:00
|
|
|
case 'focus' :
|
|
|
|
this.receiveFocus(msg);
|
|
|
|
break;
|
2024-10-24 15:01:03 +00:00
|
|
|
case 'unfocus' :
|
|
|
|
this.receiveUnfocus(msg);
|
2024-10-24 15:23:33 +00:00
|
|
|
break;
|
|
|
|
case 'framing' :
|
|
|
|
this.receiveFraming(msg);
|
|
|
|
break;
|
|
|
|
case 'unframing' :
|
|
|
|
this.receiveUnframing(msg);
|
|
|
|
break;
|
2024-10-22 19:04:25 +00:00
|
|
|
case 'display' :
|
|
|
|
this.receiveDisplay(msg);
|
|
|
|
break;
|
2024-07-13 13:23:58 +00:00
|
|
|
default:
|
2024-08-09 20:20:07 +00:00
|
|
|
console.warn(`No command "${msg.cmd}"`);
|
2024-07-13 13:23:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-08-09 20:20:07 +00:00
|
|
|
public disableClass (className : string) {
|
2024-08-15 22:55:37 +00:00
|
|
|
console.log(`Disabling class: ${className}`);
|
2024-08-09 20:20:07 +00:00
|
|
|
document.querySelectorAll(`.${className}`).forEach((el : HTMLButtonElement) => {
|
|
|
|
el.disabled = true;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public enableClass (className : string) {
|
2024-08-15 22:55:37 +00:00
|
|
|
console.log(`Enabling class: ${className}`);
|
2024-08-09 20:20:07 +00:00
|
|
|
document.querySelectorAll(`.${className}`).forEach((el : HTMLButtonElement) => {
|
|
|
|
el.disabled = false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-07-13 13:23:58 +00:00
|
|
|
public sendCameraOpen () {
|
|
|
|
console.log('send camera open');
|
2024-08-09 20:20:07 +00:00
|
|
|
this.disableClass('manualCtrl');
|
2024-07-13 02:00:24 +00:00
|
|
|
this.client.send(JSON.stringify({ cmd : 'open' }));
|
|
|
|
}
|
2024-07-13 13:23:58 +00:00
|
|
|
|
2024-08-24 20:26:49 +00:00
|
|
|
private receivePing() {
|
|
|
|
this.sendPong();
|
|
|
|
}
|
|
|
|
|
2024-07-13 13:23:58 +00:00
|
|
|
private receiveCameraOpen () {
|
|
|
|
console.log('got camera open');
|
2024-08-09 20:20:07 +00:00
|
|
|
this.enableClass('manualCtrl');
|
2024-07-13 13:23:58 +00:00
|
|
|
}
|
2024-08-01 15:57:49 +00:00
|
|
|
|
|
|
|
public sendCameraClose () {
|
|
|
|
console.log('send camera close');
|
2024-08-09 20:20:07 +00:00
|
|
|
this.disableClass('manualCtrl');
|
2024-08-01 15:57:49 +00:00
|
|
|
this.client.send(JSON.stringify({ cmd : 'close' }));
|
|
|
|
}
|
|
|
|
|
|
|
|
private receiveCameraClose () {
|
|
|
|
console.log('got camera close');
|
2024-08-09 20:20:07 +00:00
|
|
|
this.enableClass('manualCtrl');
|
2024-08-01 15:57:49 +00:00
|
|
|
}
|
|
|
|
|
2024-08-24 20:26:49 +00:00
|
|
|
private sendPong () {
|
|
|
|
this.client.send(JSON.stringify({ cmd : 'pong' }));
|
|
|
|
}
|
|
|
|
|
2024-08-24 14:23:15 +00:00
|
|
|
public sendAdvance () {
|
|
|
|
this.client.send(JSON.stringify({ cmd : 'advance' }));
|
|
|
|
}
|
|
|
|
|
|
|
|
public sendRewind () {
|
|
|
|
this.client.send(JSON.stringify({ cmd : 'rewind' }));
|
|
|
|
}
|
|
|
|
|
2024-08-30 17:49:16 +00:00
|
|
|
public sendFrameSet () {
|
|
|
|
const frameStr : string = (document.getElementById('frame') as HTMLInputElement).value;
|
|
|
|
let frameNum : number = null;
|
|
|
|
try {
|
|
|
|
frameNum = parseInt(frameStr);
|
|
|
|
} catch (err) {
|
|
|
|
console.error(`Error parsing ${frameStr}`);
|
|
|
|
}
|
|
|
|
if (frameNum === null) {
|
|
|
|
frameNum = 0;
|
|
|
|
}
|
|
|
|
if (frameNum < 0) {
|
|
|
|
frameNum = 0;
|
|
|
|
}
|
|
|
|
if (frameNum > this.frames - 1) {
|
|
|
|
frameNum = this.frames - 1;
|
|
|
|
}
|
|
|
|
this.client.send(JSON.stringify({ cmd : 'set', state : { sequence : { current : frameNum } } }));
|
|
|
|
}
|
|
|
|
|
|
|
|
public sendToEnd () {
|
|
|
|
this.client.send(JSON.stringify({ cmd : 'set', state : { sequence : { current : this.frames - 1 } } }));
|
|
|
|
}
|
|
|
|
|
|
|
|
public sendToStart () {
|
|
|
|
this.client.send(JSON.stringify({ cmd : 'set', state : { sequence : { current : 0 } } }));
|
|
|
|
}
|
|
|
|
|
2024-08-01 15:57:49 +00:00
|
|
|
public sendSelect () {
|
2024-08-16 04:52:46 +00:00
|
|
|
const hash : string = (document.getElementById('sequence') as HTMLSelectElement ).value;
|
2024-08-01 15:57:49 +00:00
|
|
|
let msg : Message;
|
2024-08-16 04:52:46 +00:00
|
|
|
if (hash === '- Select Image Sequence -') {
|
2024-08-01 15:57:49 +00:00
|
|
|
return;
|
|
|
|
}
|
2024-08-16 04:52:46 +00:00
|
|
|
msg = { cmd : 'select', state : { sequence : { hash } } };
|
2024-10-19 02:13:52 +00:00
|
|
|
console.log(`send select ${hash}`);
|
2024-08-01 15:57:49 +00:00
|
|
|
this.client.send(JSON.stringify(msg));
|
|
|
|
}
|
|
|
|
|
2024-08-02 14:29:12 +00:00
|
|
|
private receiveSelect (msg : Message) {
|
2024-08-16 04:52:46 +00:00
|
|
|
this.enableClass('sequenceCtrl');
|
|
|
|
this.setSequence(msg.state);
|
|
|
|
}
|
|
|
|
|
2024-08-24 14:23:15 +00:00
|
|
|
public sendStart () {
|
|
|
|
this.client.send(JSON.stringify({ cmd : 'start' }));
|
|
|
|
}
|
2024-08-16 04:52:46 +00:00
|
|
|
|
2024-08-24 14:23:15 +00:00
|
|
|
public sendStop () {
|
|
|
|
this.client.send(JSON.stringify({ cmd : 'stop' }));
|
|
|
|
}
|
|
|
|
|
2024-10-18 03:06:37 +00:00
|
|
|
public sendExposure () {
|
2024-10-19 02:13:52 +00:00
|
|
|
const exposure : number = parseInt(this.get('exposure'));
|
2024-10-18 03:06:37 +00:00
|
|
|
this.client.send(JSON.stringify({ cmd : 'exposure', state : { exposure }}));
|
|
|
|
}
|
|
|
|
|
2024-08-24 14:23:15 +00:00
|
|
|
private receiveUpdate (msg : Message) {
|
|
|
|
this.setUpdate(msg.state);
|
2024-08-02 14:29:12 +00:00
|
|
|
}
|
|
|
|
|
2024-10-22 19:04:25 +00:00
|
|
|
private receiveDisplay (msg: Message) {
|
|
|
|
this.display.clear();
|
|
|
|
this.display.updateScreen();
|
|
|
|
this.setDisplay(msg.state);
|
|
|
|
}
|
|
|
|
|
2024-10-22 03:51:38 +00:00
|
|
|
public sendFocus () {
|
|
|
|
console.log('send focus');
|
|
|
|
//this.disableClass('manualCtrl');
|
|
|
|
this.client.send(JSON.stringify({ cmd : 'focus' }));
|
|
|
|
}
|
|
|
|
|
|
|
|
private receiveFocus (msg : Message) {
|
2024-10-24 15:01:03 +00:00
|
|
|
this.display.setFocus();
|
|
|
|
this.display.updateImage();
|
|
|
|
}
|
|
|
|
|
|
|
|
private receiveUnfocus (msg : Message) {
|
|
|
|
this.display.unsetFocus();
|
2024-10-22 03:51:38 +00:00
|
|
|
this.display.updateImage();
|
|
|
|
}
|
|
|
|
|
2024-10-24 15:23:33 +00:00
|
|
|
public sendFraming () {
|
|
|
|
console.log('send framing');
|
|
|
|
//this.disableClass('manualCtrl');
|
|
|
|
this.client.send(JSON.stringify({ cmd : 'framing' }));
|
|
|
|
}
|
|
|
|
|
|
|
|
private receiveFraming (msg : Message) {
|
|
|
|
this.display.setFraming();
|
|
|
|
this.display.updateImage();
|
|
|
|
}
|
|
|
|
|
|
|
|
private receiveUnframing (msg : Message) {
|
|
|
|
this.display.unsetFraming();
|
|
|
|
this.display.updateImage();
|
|
|
|
}
|
|
|
|
|
2024-10-22 19:04:25 +00:00
|
|
|
public sendOffset (x : number, y : number) {
|
|
|
|
this.client.send(JSON.stringify({ cmd : 'offset', x, y }));
|
|
|
|
}
|
|
|
|
|
|
|
|
public sendSize (width : number, height : number) {
|
|
|
|
this.client.send(JSON.stringify({ cmd : 'size', width, height }));
|
|
|
|
}
|
|
|
|
|
|
|
|
public sendScale (scale : number) {
|
|
|
|
this.client.send(JSON.stringify({ cmd : 'scale', scale }));
|
|
|
|
}
|
|
|
|
|
2024-10-22 03:51:38 +00:00
|
|
|
/**
|
|
|
|
* HELPERS
|
|
|
|
**/
|
|
|
|
|
2024-08-01 15:57:49 +00:00
|
|
|
public fullscreen () {
|
|
|
|
if (!document.fullscreenElement) {
|
|
|
|
document.documentElement.requestFullscreen();
|
|
|
|
} else {
|
|
|
|
this.exitFullscreen();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public exitFullscreen () {
|
|
|
|
if (document.fullscreenElement) {
|
|
|
|
document.exitFullscreen()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-08-15 02:43:02 +00:00
|
|
|
private active () {
|
2024-10-19 02:13:52 +00:00
|
|
|
this.addClass('overlay', 'active');
|
2024-08-15 02:43:02 +00:00
|
|
|
}
|
|
|
|
private inactive () {
|
2024-10-19 02:13:52 +00:00
|
|
|
this.removeClass('overlay', 'active');
|
|
|
|
}
|
|
|
|
|
|
|
|
public addClass (id : string, className : string) {
|
|
|
|
document.getElementById(id).classList.add(className);
|
|
|
|
}
|
|
|
|
public removeClass (id : string, className : string) {
|
|
|
|
document.getElementById(id).classList.remove(className);
|
|
|
|
}
|
|
|
|
|
|
|
|
public set (id : string, value : string) {
|
|
|
|
try {
|
|
|
|
(document.getElementById(id) as HTMLInputElement).value = value;
|
|
|
|
} catch (err) {
|
|
|
|
console.warn(`Element ${id} does not exist or cannot be set`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public get (id : string) {
|
|
|
|
return (document.getElementById(id) as HTMLInputElement).value;
|
2024-08-15 02:43:02 +00:00
|
|
|
}
|
2024-10-20 01:15:52 +00:00
|
|
|
|
|
|
|
private resetForm (id : string) {
|
|
|
|
(document.getElementById(id) as HTMLFormElement ).reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
private shortenHumanize (val : number) : string {
|
|
|
|
const str : string = humanizeDuration(val, { round : true });
|
|
|
|
return str.replace('years', 'y').replace('year', 'y')
|
|
|
|
.replace('months', 'mo').replace('month', 'mo')
|
|
|
|
.replace('weeks', 'w').replace('week', 'w')
|
|
|
|
.replace('days', 'd').replace('day', 'd')
|
|
|
|
.replace('hours', 'h').replace('hour', 'h')
|
|
|
|
.replace('minutes', 'm').replace('minute', 'm')
|
|
|
|
.replace('seconds', 's').replace('second', 's');
|
|
|
|
}
|
2024-10-20 01:22:15 +00:00
|
|
|
|
2024-10-20 12:53:25 +00:00
|
|
|
private roundDigits (val : number, digits : number) : string {
|
2024-10-20 01:22:15 +00:00
|
|
|
const mult : number = Math.pow(10.0, digits);
|
2024-10-20 12:53:25 +00:00
|
|
|
const rounded : number = Math.round(val * mult) / mult;
|
|
|
|
return rounded.toString();
|
2024-10-20 01:22:15 +00:00
|
|
|
}
|
2024-05-15 21:29:59 +00:00
|
|
|
}
|
|
|
|
|
2024-10-19 02:13:52 +00:00
|
|
|
client = new Client();
|