Consolidated the server into the project
Added npm scripts to build and launch the whole project
This commit is contained in:
@@ -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');
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
|
||||
|
||||
9
ts/websocket/websocket.ts
Normal file
9
ts/websocket/websocket.ts
Normal 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';
|
||||
}
|
||||
Reference in New Issue
Block a user