Browse Source

chore: code style + remove HTTP JSON responses

bdestombes 3 years ago
parent
commit
6e672bda84
4 changed files with 296 additions and 292 deletions
  1. 2 2
      emitter/backend/server.js
  2. 173 173
      emitter/frontend/index.html
  3. 5 3
      receiver/backend/server.js
  4. 116 114
      receiver/frontend/index.html

+ 2 - 2
emitter/backend/server.js

@@ -127,7 +127,7 @@ app.post('/json', function (req, res) {
 					[ '/tuio/2Dcur', 'fseq', fseq ]
 				);
 				oscClient.send(oscBundle, () => {
-					res.status(200).json(JSON.stringify(req.body));
+					res.status(200).send();
 					fseq = 0;
 				});
 			} else {
@@ -360,7 +360,7 @@ app.post('/json', function (req, res) {
 				}
 				oscBundle.append([ '/tuio/2Dobj', 'fseq', fseq ]);
 				oscClient.send(oscBundle, () => {
-					res.status(200).json(JSON.stringify(req.body));
+					res.status(200).send();
 				});
 			} else {
 				res.status(400).send();

+ 173 - 173
emitter/frontend/index.html

@@ -1,189 +1,189 @@
 <!DOCTYPE html>
 <html style="height: 100%;">
-<head>
-	<meta charset="utf-8">
-	<meta name="viewport" content="width=device-width">
-	<title>Touch detect and send to Node server</title>
-</head>
+	<head>
+		<meta charset="utf-8">
+		<meta name="viewport" content="width=device-width">
+		<title>Touch detect and send to Node server</title>
+	</head>
 
-<body style="height: 100%;">
-	<div id="box" style="width: 100%; height: 100%; background-color: #EEEEEE;"></div>
-	<script src="/jquery-1.7.2.js"></script>
-	<script>
-		/* simulation de touch events */
-		/*
-		function sendTouchEvent(x, y, element, eventType) {
-			const touchObj = new Touch({
-				identifier: Date.now(),
-				target: element,
-				clientX: x,
-				clientY: y,
-				radiusX: 2.5,
-				radiusY: 2.5,
-				rotationAngle: 10,
-				force: 0.5,
-			});
+	<body style="height: 100%;">
+		<div id="box" style="width: 100%; height: 100%; background-color: #EEEEEE;"></div>
+		<script src="/jquery-1.7.2.js"></script>
+		<script>
+			/* simulation de touch events */
+			/*
+			function sendTouchEvent(x, y, element, eventType) {
+				const touchObj = new Touch({
+					identifier: Date.now(),
+					target: element,
+					clientX: x,
+					clientY: y,
+					radiusX: 2.5,
+					radiusY: 2.5,
+					rotationAngle: 10,
+					force: 0.5,
+				});
 
-			const touchEvent = new TouchEvent(eventType, {
-				cancelable: true,
-				bubbles: true,
-				touches: [touchObj],
-				targetTouches: [],
-				changedTouches: [touchObj],
-				shiftKey: true,
-			});
+				const touchEvent = new TouchEvent(eventType, {
+					cancelable: true,
+					bubbles: true,
+					touches: [touchObj],
+					targetTouches: [],
+					changedTouches: [touchObj],
+					shiftKey: true,
+				});
 
-			element.dispatchEvent(touchEvent);
-		}
+				element.dispatchEvent(touchEvent);
+			}
 
-		sendTouchEvent(150, 150, box, 'touchstart');
-		sendTouchEvent(220, 200, box, 'touchmove');
-		sendTouchEvent(220, 200, box, 'touchend');
-		*/
+			sendTouchEvent(150, 150, box, 'touchstart');
+			sendTouchEvent(220, 200, box, 'touchmove');
+			sendTouchEvent(220, 200, box, 'touchend');
+			*/
 
-		const box = document.getElementById('box');
+			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()}`);
-		}
+			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()}`);
+			}
 
-		box.addEventListener('touchstart', function(evt) {
-				if (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.addEventListener('touchstart', function(evt) {
+					if (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:5001/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: 'touchstart',
-						debug,
-						section,
-						screenW: $(document).width(),
-						screenH: $(document).height(),
-						changedTouches: touches
-					})
-				});
-				evt.preventDefault();
-		});
-		box.addEventListener('touchmove', function(evt) {
-				if (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:5001/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: 'touchstart',
+							debug,
+							section,
+							screenW: $(document).width(),
+							screenH: $(document).height(),
+							changedTouches: touches
+						})
+					});
+					evt.preventDefault();
+			});
+			box.addEventListener('touchmove', function(evt) {
+					if (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:5001/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: 'touchmove',
-						debug,
-						section,
-						screenW: $(document).width(),
-						screenH: $(document).height(),
-						changedTouches: touches
-					})
-				});
-				evt.preventDefault();
-		});
+					box.innerHTML = evt.touches.length;
+					fetch('http://localhost:5001/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: 'touchmove',
+							debug,
+							section,
+							screenW: $(document).width(),
+							screenH: $(document).height(),
+							changedTouches: touches
+						})
+					});
+					evt.preventDefault();
+			});
 
-		box.addEventListener('touchend', function(evt) {
-				if (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.addEventListener('touchend', function(evt) {
+					if (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:5001/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: 'touchend',
-						debug,
-						section,
-						screenW: $(document).width(),
-						screenH: $(document).height(),
-						changedTouches: touches
-					})
-				});
-				evt.preventDefault();
-		});
+					box.innerHTML = evt.touches.length;
+					fetch('http://localhost:5001/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: 'touchend',
+							debug,
+							section,
+							screenW: $(document).width(),
+							screenH: $(document).height(),
+							changedTouches: touches
+						})
+					});
+					evt.preventDefault();
+			});
 
-		if (!(typeof box.ontouchstart != 'undefined')) {
-				box.style.border = '1px solid red';
-		}
+			if (!(typeof box.ontouchstart != 'undefined')) {
+					box.style.border = '1px solid red';
+			}
 		</script>
-</body>
+	</body>
 </html>

+ 5 - 3
receiver/backend/server.js

@@ -30,17 +30,19 @@ app.use(bodyParser.urlencoded({extended:true}));
 app.use(express.static('./frontend/assets'));
 
 app.get('/', function (req, res) {
-	res.sendFile('./frontend/index.html', { root: path.resolve(__dirname + '/..') });
+	res.sendFile('./frontend/index.html', {
+		root: path.resolve(__dirname + '/..')
+	});
 });
 
 app.get('/json', function (req, res) {
-	res.status(200).json({'message': 'ok'})
+	res.status(200).send();
 });
 
 io.sockets.on('connection', (socket) =>{
 	console.log(`Connecté au client ${socket.id}`);
 	const dgramCallback = function (buf) {
-		console.log(oscParser.decode(buf));
+		// console.log(oscParser.decode(buf));
 		socket.emit('osc', oscParser.decode(buf));
 	};
 

+ 116 - 114
receiver/frontend/index.html

@@ -1,131 +1,133 @@
 <!DOCTYPE html>
 <html>
-<head>
-	<meta charset="utf-8">
-	<meta name="viewport" content="width=device-width">
-	<title>Proof of concept - Objets tangibles</title>
-</head>
+	<head>
+		<meta charset="utf-8">
+		<meta name="viewport" content="width=device-width">
+		<title>Proof of concept - Objets tangibles</title>
 
-<body>
-	<script src="/jquery-1.7.2.js"></script>
-	<script src="/lodash.js"></script>
-	<script src="/socket.io/socket.io.js"></script>
-	<script src="/tuio.js"></script>
-	<style>
-		body {
-			background: #000;
-			margin: 0;
-		}
-		.tuioCursor {
-			background: #fff;
-			height: 8px;
-			left: 0;
-			position: absolute;
-			top: 0;
-			width: 8px;
-		}
-		.tuioObj {
-			background: #f00;
-			height: 15px;
-			left: 0;
-			position: absolute;
-			top: 0;
-			width: 8px;
-			rotate: 0deg;
-		}
-	</style>
+		<style>
+			body {
+				background: #000;
+				margin: 0;
+			}
+			.tuioCursor {
+				background: #fff;
+				height: 8px;
+				left: 0;
+				position: absolute;
+				top: 0;
+				width: 8px;
+			}
+			.tuioObj {
+				background: #f00;
+				height: 15px;
+				left: 0;
+				position: absolute;
+				top: 0;
+				width: 8px;
+				rotate: 0deg;
+			}
+		</style>
+	</head>
 
-	<script>
-				$(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'
-						}),
-						screenW = $(document).width(),
-						screenH = $(document).height()
+	<body>
+		<script src="/jquery-1.7.2.js"></script>
+		<script src="/lodash.js"></script>
+		<script src="/socket.io/socket.io.js"></script>
+		<script src="/tuio.js"></script>
 
-						cursors = {},
-						objects = {},
+		<script>
+		$(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'
+				}),
+				screenW = $(document).width(),
+				screenH = $(document).height()
 
-						onConnect = function() {
-							if (debug) {
-								console.log('connected');
-							}
-						},
+				cursors = {},
+				objects = {},
 
-						onAddTuioCursor = function(addCursor) {
-							var $addCursor = $('<div class="tuioCursor"></div>');
-							$('body').append($addCursor);
-							cursors[addCursor.getCursorId()] = $addCursor;
-							onUpdateTuioCursor(addCursor);
-						},
+				onConnect = function() {
+					if (debug) {
+						console.log('connected');
+					}
+				},
 
-						onUpdateTuioCursor = function(updateCursor) {
-							var $updateCursor = cursors[updateCursor.getCursorId()];
-							$updateCursor.css({
-								left: updateCursor.getScreenX(screenW),
-								top: updateCursor.getScreenY(screenH)
-							});
-						},
+				onAddTuioCursor = function(addCursor) {
+					var $addCursor = $('<div class="tuioCursor"></div>');
+					$('body').append($addCursor);
+					cursors[addCursor.getCursorId()] = $addCursor;
+					onUpdateTuioCursor(addCursor);
+				},
 
-						onRemoveTuioCursor = function(removeCursor) {
-							var $removeCursor = cursors[removeCursor.getCursorId()];
-							$removeCursor.remove();
-							delete[removeCursor.getCursorId()];
-						},
+				onUpdateTuioCursor = function(updateCursor) {
+					var $updateCursor = cursors[updateCursor.getCursorId()];
+					$updateCursor.css({
+						left: updateCursor.getScreenX(screenW),
+						top: updateCursor.getScreenY(screenH)
+					});
+				},
 
-						onAddTuioObject = function(addObject) {
-							var $addObject = $('<div class="tuioObj"></div>');
-							$('body').append($addObject);
-							objects[addObject.symbolID] = $addObject;
-							onUpdateTuioObject(addObject);
-							if (debug) {
-								console.log('addTuioObject', addObject);
-								console.log(objects);
-							}
-						},
+				onRemoveTuioCursor = function(removeCursor) {
+					var $removeCursor = cursors[removeCursor.getCursorId()];
+					$removeCursor.remove();
+					delete[removeCursor.getCursorId()];
+				},
 
-						onUpdateTuioObject = function(updateObject) {
-							var $updateObject = objects[updateObject.symbolID];
-							$updateObject.css({
-								left: updateObject.getScreenX(screenW),
-								top: updateObject.getScreenY(screenH),
-								rotate : updateObject.getAngleDegrees()
-							});
-							if (debug) {
-								console.log('updateTuioObject', updateObject);
-							}
-						},
+				onAddTuioObject = function(addObject) {
+					var $addObject = $('<div class="tuioObj"></div>');
+					$('body').append($addObject);
+					objects[addObject.symbolID] = $addObject;
+					onUpdateTuioObject(addObject);
+					if (debug) {
+						console.log('addTuioObject', addObject);
+					}
+				},
 
-						onRemoveTuioObject = function(removeObject) {
-							var $removeObject = objects[removeObject.symbolID];
-							$removeObject.remove();
-							delete[removeObject.symbolID];
-							if (debug) {
-								console.log('removeTuioObject', removeObject);
-							}
-						},
+				onUpdateTuioObject = function(updateObject) {
+					var $updateObject = objects[updateObject.symbolID];
+					$updateObject.css({
+						left: updateObject.getScreenX(screenW),
+						top: updateObject.getScreenY(screenH),
+						rotate : updateObject.getAngleDegrees()
+					});
+					if (debug) {
+						console.log('updateTuioObject', updateObject);
+					}
+				},
 
-						onRefresh = function(time) {
+				onRemoveTuioObject = function(removeObject) {
+					var $removeObject = objects[removeObject.symbolID];
+					$removeObject.remove();
+					delete[removeObject.symbolID];
+					if (debug) {
+						console.log('removeTuioObject', removeObject);
+					}
+				},
 
-						};
+				onRefresh = function(time) {
+					if (debug) {
+						console.log('refresh', time);
+					}
+				};
 
-						client.on("connect", onConnect);
-						client.on("addTuioCursor", onAddTuioCursor);
-						client.on("updateTuioCursor", onUpdateTuioCursor);
-						client.on("removeTuioCursor", onRemoveTuioCursor);
-						client.on("addTuioObject", onAddTuioObject);
-						client.on("updateTuioObject", onUpdateTuioObject);
-						client.on("removeTuioObject", onRemoveTuioObject);
-						client.on("refresh", onRefresh);
-						client.connect();
-					});
+				client.on('connect', onConnect);
+				client.on('addTuioCursor', onAddTuioCursor);
+				client.on('updateTuioCursor', onUpdateTuioCursor);
+				client.on('removeTuioCursor', onRemoveTuioCursor);
+				client.on('addTuioObject', onAddTuioObject);
+				client.on('updateTuioObject', onUpdateTuioObject);
+				client.on('removeTuioObject', onRemoveTuioObject);
+				client.on('refresh', onRefresh);
+				client.connect();
+			});
 		</script>
-</body>
+	</body>
 </html>