Consolidated the server into the project

Added npm scripts to build and launch the whole project
This commit is contained in:
2021-08-26 21:28:10 +02:00
parent 8555e3f9e2
commit 78877f1211
11 changed files with 273 additions and 5 deletions

View File

@@ -1,8 +1,8 @@
import CanvasUtil from './canvas-util/canvasUtil.js';
import Coordinates from './canvas-util/coordinates.js';
import { getWebsocketUrl } from "./websocket/websocket.js";
class CanvasReceiverController {
private canvas!: HTMLCanvasElement;
private canvasDiv: HTMLDivElement;
private canvasUtil: CanvasUtil;
private ws: WebSocket;
@@ -23,7 +23,7 @@ class CanvasReceiverController {
alert('Canvas API unavailable, drawing will not work!');
}
this.ws = new WebSocket('ws://localhost:8081', 'json');
this.ws = new WebSocket(getWebsocketUrl(), 'json');
this.ws.onmessage = message => this.processMessage(message);
this.ws.onopen = () => this.ws.send('RECEIVER');

View File

@@ -1,5 +1,6 @@
import CanvasUtil from "./canvas-util/canvasUtil.js";
import Coordinates from "./canvas-util/coordinates.js";
import { getWebsocketUrl } from "./websocket/websocket.js";
class CanvasSenderController {
private canvasUtil: CanvasUtil;
@@ -28,7 +29,7 @@ class CanvasSenderController {
canvas.addEventListener('touchmove', e => this.onMouseMove(e.touches[0]));
}
this.ws = new WebSocket('ws://localhost:8081', 'json');
this.ws = new WebSocket(getWebsocketUrl(), 'json');
this.ws.onopen = () => this.ws.send('SENDER');
}

View File

@@ -0,0 +1,9 @@
export function getWebsocketUrl(): string {
let scheme = 'ws';
if (document.location.protocol === 'https:') {
scheme += 's';
}
return scheme + '://' + document.location.hostname + ':8081';
}