|
@@ -36,98 +36,97 @@
|
|
|
<script src="/socket.io/socket.io.js"></script>
|
|
|
<script src="/tuio.js"></script>
|
|
|
<script>
|
|
|
- /* -------
|
|
|
- * EMITTER
|
|
|
- * -------
|
|
|
- */
|
|
|
- const box = document.getElementById('box');
|
|
|
-
|
|
|
- const urlParams = new URLSearchParams(window.location.search);
|
|
|
- const sectionParam = urlParams.get('section');
|
|
|
- const section = sectionParam ? parseInt(sectionParam, 10) : 100;
|
|
|
- const debugParams = urlParams.get('debug');
|
|
|
- const debug = debugParams ? true : false;
|
|
|
- if (debug) {
|
|
|
- console.log('--- Debug activated ---');
|
|
|
- console.log(`Section: ${section.toString()}`);
|
|
|
- }
|
|
|
+ let config = {};
|
|
|
+ const getConfig = () => {
|
|
|
+ return fetch('/config.json');
|
|
|
+ };
|
|
|
|
|
|
- const eventHandler = (evt, type) => {
|
|
|
- if (debug) {
|
|
|
- console.log(evt);
|
|
|
+ getConfig().then(response => {
|
|
|
+ return response.json();
|
|
|
+ }).then(data => {
|
|
|
+ config = data;
|
|
|
+
|
|
|
+ const urlParams = new URLSearchParams(window.location.search);
|
|
|
+ const sectionParam = urlParams.get('section');
|
|
|
+ const section = sectionParam ? parseInt(sectionParam, 10) : 100;
|
|
|
+
|
|
|
+ if (config.app.debug) {
|
|
|
+ console.log('--- Frontend debug activated ---');
|
|
|
}
|
|
|
|
|
|
- const touches = [];
|
|
|
- for (var i = 0; i < evt.changedTouches.length; i++) {
|
|
|
- touches[i] = {
|
|
|
- clientX: evt.changedTouches[i].clientX,
|
|
|
- clientY: evt.changedTouches[i].clientY,
|
|
|
- force: evt.changedTouches[i].force,
|
|
|
- identifier: ((evt.changedTouches[i].identifier + 1) % 100) + section,
|
|
|
- pageX: evt.changedTouches[i].pageX,
|
|
|
- pageY: evt.changedTouches[i].pageY,
|
|
|
- radiusX: evt.changedTouches[i].radiusX,
|
|
|
- radiusY: evt.changedTouches[i].radiusY,
|
|
|
- rotationAngle: evt.changedTouches[i].rotationAngle,
|
|
|
- screenX: evt.changedTouches[i].screenX,
|
|
|
- screenY: evt.changedTouches[i].screenY
|
|
|
+ /* -------
|
|
|
+ * EMITTER
|
|
|
+ * -------
|
|
|
+ */
|
|
|
+ const box = document.getElementById('box');
|
|
|
+
|
|
|
+ const eventHandler = (evt, type) => {
|
|
|
+ if (config.app.debug) {
|
|
|
+ console.log(evt);
|
|
|
+ }
|
|
|
+
|
|
|
+ const touches = [];
|
|
|
+ for (var i = 0; i < evt.changedTouches.length; i++) {
|
|
|
+ touches[i] = {
|
|
|
+ clientX: evt.changedTouches[i].clientX,
|
|
|
+ clientY: evt.changedTouches[i].clientY,
|
|
|
+ force: evt.changedTouches[i].force,
|
|
|
+ identifier: ((evt.changedTouches[i].identifier + 1) % 100) + section,
|
|
|
+ pageX: evt.changedTouches[i].pageX,
|
|
|
+ pageY: evt.changedTouches[i].pageY,
|
|
|
+ radiusX: evt.changedTouches[i].radiusX,
|
|
|
+ radiusY: evt.changedTouches[i].radiusY,
|
|
|
+ rotationAngle: evt.changedTouches[i].rotationAngle,
|
|
|
+ screenX: evt.changedTouches[i].screenX,
|
|
|
+ screenY: evt.changedTouches[i].screenY
|
|
|
+ };
|
|
|
};
|
|
|
- };
|
|
|
- box.innerHTML = evt.touches.length;
|
|
|
- fetch('http://localhost:5000/emitter/json', {
|
|
|
- method: 'POST',
|
|
|
- mode: 'cors',
|
|
|
- cache: 'no-cache',
|
|
|
- credentials: 'same-origin',
|
|
|
- headers: {
|
|
|
- 'Content-Type': 'application/json'
|
|
|
- },
|
|
|
- redirect: 'follow',
|
|
|
- referrerPolicy: 'no-referrer',
|
|
|
- body: JSON.stringify({
|
|
|
- event: type,
|
|
|
- debug,
|
|
|
- section,
|
|
|
- screenW: $(document).width(),
|
|
|
- screenH: $(document).height(),
|
|
|
- changedTouches: touches
|
|
|
- })
|
|
|
- });
|
|
|
- evt.preventDefault();
|
|
|
- };
|
|
|
|
|
|
- box.addEventListener('touchstart', (evt) => {
|
|
|
- return eventHandler(evt, 'touchstart');
|
|
|
- });
|
|
|
+ if (config.app.debug) {
|
|
|
+ box.innerHTML = evt.touches.length;
|
|
|
+ }
|
|
|
|
|
|
- box.addEventListener('touchmove', (evt) => {
|
|
|
- return eventHandler(evt, 'touchmove');
|
|
|
- });
|
|
|
+ fetch(`http://localhost:${config.app.httpPort}/emitter/json`, {
|
|
|
+ method: 'POST',
|
|
|
+ mode: 'cors',
|
|
|
+ cache: 'no-cache',
|
|
|
+ credentials: 'same-origin',
|
|
|
+ headers: {
|
|
|
+ 'Content-Type': 'application/json'
|
|
|
+ },
|
|
|
+ redirect: 'follow',
|
|
|
+ referrerPolicy: 'no-referrer',
|
|
|
+ body: JSON.stringify({
|
|
|
+ event: type,
|
|
|
+ section,
|
|
|
+ screenW: $(document).width(),
|
|
|
+ screenH: $(document).height(),
|
|
|
+ changedTouches: touches
|
|
|
+ })
|
|
|
+ });
|
|
|
+ evt.preventDefault();
|
|
|
+ };
|
|
|
|
|
|
- box.addEventListener('touchend', (evt) => {
|
|
|
- return eventHandler(evt, 'touchend');
|
|
|
- });
|
|
|
+ box.addEventListener('touchstart', (evt) => {
|
|
|
+ return eventHandler(evt, 'touchstart');
|
|
|
+ });
|
|
|
|
|
|
- if (!(typeof box.ontouchstart != 'undefined')) {
|
|
|
- box.style.border = '1px solid red';
|
|
|
- }
|
|
|
+ box.addEventListener('touchmove', (evt) => {
|
|
|
+ return eventHandler(evt, 'touchmove');
|
|
|
+ });
|
|
|
|
|
|
+ box.addEventListener('touchend', (evt) => {
|
|
|
+ return eventHandler(evt, 'touchend');
|
|
|
+ });
|
|
|
|
|
|
- /* --------
|
|
|
- * RECEIVER
|
|
|
- * --------
|
|
|
- */
|
|
|
+ /* --------
|
|
|
+ * RECEIVER
|
|
|
+ * --------
|
|
|
+ */
|
|
|
|
|
|
- $(function() {
|
|
|
- const urlParams = new URLSearchParams(window.location.search);
|
|
|
- const debugParams = urlParams.get('debug');
|
|
|
- const debug = debugParams ? true : false;
|
|
|
- if (debug) {
|
|
|
- console.log('--- Debug activated ---');
|
|
|
- }
|
|
|
var dotGroups = [];
|
|
|
var client = new Tuio.Client({
|
|
|
- host: 'http://localhost:5000'
|
|
|
+ host: `http://localhost:${config.app.httpPort}`
|
|
|
}),
|
|
|
screenW = $(document).width(),
|
|
|
screenH = $(document).height()
|
|
@@ -136,8 +135,8 @@
|
|
|
objects = {},
|
|
|
|
|
|
onConnect = function() {
|
|
|
- if (debug) {
|
|
|
- console.log('connected');
|
|
|
+ if (config.app.debug) {
|
|
|
+ console.log('connected to web-socket');
|
|
|
}
|
|
|
},
|
|
|
|
|
@@ -146,6 +145,9 @@
|
|
|
$('body').append($addCursor);
|
|
|
cursors[addCursor.getCursorId()] = $addCursor;
|
|
|
onUpdateTuioCursor(addCursor);
|
|
|
+ if (config.app.debug && config.app.debugLog.frontend.receiver.onAddTuioCursor) {
|
|
|
+ console.log('addTuioCursor', addCursor);
|
|
|
+ }
|
|
|
},
|
|
|
|
|
|
onUpdateTuioCursor = function(updateCursor) {
|
|
@@ -154,12 +156,18 @@
|
|
|
left: updateCursor.getScreenX(screenW),
|
|
|
top: updateCursor.getScreenY(screenH)
|
|
|
});
|
|
|
+ if (config.app.debug && config.app.debugLog.frontend.receiver.onUpdateTuioCursor) {
|
|
|
+ console.log('updateTuioCursor', updateCursor);
|
|
|
+ }
|
|
|
},
|
|
|
|
|
|
onRemoveTuioCursor = function(removeCursor) {
|
|
|
var $removeCursor = cursors[removeCursor.getCursorId()];
|
|
|
$removeCursor.remove();
|
|
|
delete[removeCursor.getCursorId()];
|
|
|
+ if (config.app.debug && config.app.debugLog.frontend.receiver.onRemoveTuioCursor) {
|
|
|
+ console.log('removeTuioCursor', removeCursor);
|
|
|
+ }
|
|
|
},
|
|
|
|
|
|
onAddTuioObject = function(addObject) {
|
|
@@ -167,7 +175,7 @@
|
|
|
$('body').append($addObject);
|
|
|
objects[addObject.symbolID] = $addObject;
|
|
|
onUpdateTuioObject(addObject);
|
|
|
- if (debug) {
|
|
|
+ if (config.app.debug && config.app.debugLog.frontend.receiver.onAddTuioObject) {
|
|
|
console.log('addTuioObject', addObject);
|
|
|
}
|
|
|
},
|
|
@@ -179,7 +187,7 @@
|
|
|
top: updateObject.getScreenY(screenH),
|
|
|
rotate : updateObject.getAngleDegrees()
|
|
|
});
|
|
|
- if (debug) {
|
|
|
+ if (config.app.debug && config.app.debugLog.frontend.receiver.onUpdateTuioObject) {
|
|
|
console.log('updateTuioObject', updateObject);
|
|
|
}
|
|
|
},
|
|
@@ -188,13 +196,13 @@
|
|
|
var $removeObject = objects[removeObject.symbolID];
|
|
|
$removeObject.remove();
|
|
|
delete[removeObject.symbolID];
|
|
|
- if (debug) {
|
|
|
+ if (config.app.debug && config.app.debugLog.frontend.receiver.onRemoveTuioObject) {
|
|
|
console.log('removeTuioObject', removeObject);
|
|
|
}
|
|
|
},
|
|
|
|
|
|
onRefresh = function(time) {
|
|
|
- if (debug) {
|
|
|
+ if (config.app.debug && config.app.debugLog.frontend.receiver.onRefresh) {
|
|
|
console.log('refresh', time);
|
|
|
}
|
|
|
};
|