diff --git a/localServer.js b/localServer.js deleted file mode 100644 index eb328b1..0000000 --- a/localServer.js +++ /dev/null @@ -1,14 +0,0 @@ - -const port = 880; //Specify a port for our web server -const express = require('express'); //load express with the use of requireJs -var path = require('path'); -const app = express(); //Create an instance of the express library -var public = path.join(__dirname, 'public'); -app.get('/', function(req, res) { - res.sendFile(path.join(public , 'index.html')); -}); - -app.use('/', express.static(public)); -app.listen(port, function() { //Listener for specified port - console.log("Server running at: http://localhost:" + port) -}); \ No newline at end of file diff --git a/package.json b/package.json index 7f856b0..9b12130 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,6 @@ }, "homepage": "https://github.com/CoDaS-Lab/ASIST-Game#readme", "dependencies": { - "express": "^4.17.1", - "phaser": "^3.24.1" + "express": "^4.17.1" } } diff --git a/public/js/config.js b/public/js/config.js index 860e57e..8923fdf 100644 --- a/public/js/config.js +++ b/public/js/config.js @@ -380,6 +380,22 @@ const surveyJSON = {"title":"Instruction Attention Check", "questionsOnPageMode":"singlePage" } -var socketURL = "https://asist-api.herokuapp.com/" -// var socketURL = "http://127.0.0.1:5000" +var socketURL; +$.ajax({ + async: false, + type: "GET", + url: window.location.origin+"/data", + contentType: "application/json; charset=utf-8", + dataType: "json", + crossDomain: true, + success: function(data){ + console.log(data); + socketURL = data["socketURL"] + }, + failure: function(errMsg) { + console.log(errMsg); + } +}); + export {phaserConfig, getMapData, getGameData, socketURL, getRandomConfig, surveyJSON}; + diff --git a/public/js/expNav.js b/public/js/expNav.js index c485404..df7f5f4 100644 --- a/public/js/expNav.js +++ b/public/js/expNav.js @@ -16,8 +16,8 @@ var changeDisplay = function(socketObj, handlerId, hideElement, showElement, key $(showElement).show(); } -var joinQuiz = function(socket, socketId){ - changeDisplay(socket, "game_info", "#mainInfo2", "#surveyContainer", {"event":"start_quiz", "socket_id":socketId}) +var joinQuiz = function(socket, socketId, awsID){ + changeDisplay(socket, "game_info", "#mainInfo2", "#surveyContainer", {"event":"start_quiz", "aws_id": awsID, "socket_id":socketId}) var sendDataToServer = function (survey) { let quizResult = true; var quizData; @@ -28,10 +28,10 @@ var joinQuiz = function(socket, socketId){ } } if (quizResult===true){ - quizData = {"event":"quiz_passed", "quiz_data": survey.data, "socket_id":socketId} + quizData = {"event":"quiz_passed", "quiz_data": survey.data, "aws_id": awsID, "socket_id":socketId} changeDisplay(socket, "game_info", "#surveyContainer", "#quiz-success", quizData) }else{ - quizData = {"event":"quiz_failed", "quiz_data": survey.data, "socket_id":socketId} + quizData = {"event":"quiz_failed", "quiz_data": survey.data, "aws_id": awsID, "socket_id":socketId} changeDisplay(socket, "game_info", "#surveyContainer", "#quiz-fail", quizData) } } @@ -44,11 +44,11 @@ var joinQuiz = function(socket, socketId){ }); } -var endSession = function(gameObj, socketObj, timerObj, playerId, roomIdx, sessionId, socketId, keyMessage, sessionLimit, sessionMessage){ +var endSession = function(gameObj, socketObj, timerObj, playerId, roomIdx, sessionId, awsID, socketId, keyMessage, sessionLimit, sessionMessage){ gameObj.scene.stop("GamePlay"); timerObj.stop(); $("#game-screen").hide(); - socketObj.emit('end_game', {"event": keyMessage, "s_id":sessionId, 'rm_id':roomIdx, "socket_id":socketId, + socketObj.emit('end_game', {"event": keyMessage, "s_id":sessionId, 'rm_id':roomIdx, "aws_id": awsID, "socket_id":socketId, 'p_id': playerId, "time": new Date().toISOString()}) if (sessionId==sessionLimit){ $("#exp-close").show(); diff --git a/public/js/index.js b/public/js/index.js index adab6f9..b37c340 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -21,7 +21,7 @@ var gamePlayState = new Phaser.Class({ gameTimer.addEventListener('targetAchieved', ()=>{ this.input.keyboard.removeAllKeys() - sessionId = endSession(game, socket, gameTimer, playerId, roomIdx, sessionId, socketId, "go_time", sessionLimit, "Game Time Over") + sessionId = endSession(game, socket, gameTimer, playerId, roomIdx, sessionId, window.location.pathname, socketId, "go_time", sessionLimit, "Game Time Over") }); gameTimer.addEventListener('secondTenthsUpdated', function() { @@ -44,7 +44,7 @@ var gamePlayState = new Phaser.Class({ } victimCount = this.mapConfig["victimIndexes"].length; var initializedGameData = {"event":"game_created", "map_config": this.mapConfig, "game_config":this.gameConfig, - globalVariable:{"rm_id":roomIdx, "p_id":playerId, "socket_id": socketId, "session_id":sessionId, "session_limit":sessionLimit}} + globalVariable:{"rm_id":roomIdx, "p_id":playerId, "aws_id": window.location.pathname,"socket_id": socketId, "session_id":sessionId, "session_limit":sessionLimit}} socket.emit("game_config", initializedGameData); if (this.gameConfig["leaderName"]!=null){ @@ -124,14 +124,14 @@ var gamePlayState = new Phaser.Class({ socket.emit("player_move_displayed", message); if (this.gameConfig.roundLimit - this.gameConfig.roundCount <= 0){ this.input.keyboard.removeAllKeys() - sessionId = endSession(game, socket, gameTimer, playerId, roomIdx, sessionId, socketId, "go_round", sessionLimit, "All Rounds Used") + sessionId = endSession(game, socket, gameTimer, playerId, roomIdx, sessionId, window.location.pathname, socketId, "go_round", sessionLimit, "All Rounds Used") } }, _leaderAnimation: function(){ let currentLeaderloc = this.gameConfig.leaderMovementIndexes.length - (this.leaderTimer.getRepeatCount()+1) socket.emit("player_move", {'x': this.gameConfig.leaderMovementIndexes[currentLeaderloc][0], 'y': this.gameConfig.leaderMovementIndexes[currentLeaderloc][1], - "s_id":sessionId, "socket_id":socketId, "event":this.gameConfig.leaderMovementIndexes[currentLeaderloc][2], 'rm_id':roomIdx, + "s_id":sessionId, "socket_id":socketId, "event":this.gameConfig.leaderMovementIndexes[currentLeaderloc][2], "aws_id": window.location.pathname,'rm_id':roomIdx, 'p_id': 1, "input_time":new Date().toISOString() }) if (this.leaderTimer.getRepeatCount()===0){ @@ -141,13 +141,13 @@ var gamePlayState = new Phaser.Class({ _victimSave(){ let rescueIndexes = this.gameState.getVictimRescueIndexes(this.playerList[playerId].y, this.playerList[playerId].x); - socket.emit("rescue_attempt", {'x': this.playerList[playerId].x, 'y': this.playerList[playerId].y,"event":"r", 'rm_id':roomIdx, + socket.emit("rescue_attempt", {'x': this.playerList[playerId].x, 'y': this.playerList[playerId].y,"event":"r", "aws_id": window.location.pathname, 'rm_id':roomIdx, 'p_id': playerId, "socket_id":socketId, "victims_alive": Array.from(this.gameState.set_victims), "time":new Date().toISOString()}) for(const victimIndex of this.gameState.set_victims){ if (rescueIndexes.includes(victimIndex)){ if (this.gameState.set_victims.has(victimIndex)){ socket.emit("rescue_success", {'x': this.playerList[playerId].x, 'y': this.playerList[playerId].y, - "event":"rs", 'rm_id':roomIdx, "socket_id":socketId, 'p_id': playerId, "victims_alive": Array.from(this.gameState.set_victims), + "event":"rs", "aws_id": window.location.pathname, 'rm_id':roomIdx, "socket_id":socketId, 'p_id': playerId, "victims_alive": Array.from(this.gameState.set_victims), "victim":victimIndex, "time":new Date().toISOString()}) this.gameState.victimObj[String(victimIndex)].fillColor = "0xf6fa78"; this.gameState.set_victims.delete(victimIndex); @@ -155,7 +155,7 @@ var gamePlayState = new Phaser.Class({ if (this.gameState.set_victims.size === 0){ console.log("SUCCESS") this.input.keyboard.removeAllKeys() - sessionId = endSession(game, socket, gameTimer, playerId, roomIdx, sessionId, socketId, "go_victim", sessionLimit, "Victim Saved") + sessionId = endSession(game, socket, gameTimer, playerId, roomIdx, sessionId, window.location.pathname, socketId, "go_victim", sessionLimit, "Victim Saved") } } } @@ -167,7 +167,7 @@ var gamePlayState = new Phaser.Class({ let newIdx = (y*this.mapConfig.cols)+ x; if (!(this.gameState.noRoadIndex.has(newIdx)) && !(this.playersCurrentLoc.includes(newIdx)) && (this.gameConfig.roundLimit - this.gameConfig.roundCount >0)){ socket.emit("player_move", {'x': x, 'y': y, "s_id":sessionId, "socket_id":socketId, - "event":direction, 'rm_id':roomIdx, 'p_id': playerId, "input_time":new Date().toISOString(), + "event":direction, "aws_id": window.location.pathname, 'rm_id':roomIdx, 'p_id': playerId, "input_time":new Date().toISOString(), "r": this.gameConfig.roundCount + 1 }); } @@ -264,7 +264,7 @@ var gameInfoState = new Phaser.Class({ this.topRight.setScale(0.3) this.bottomRight.setScale(0.3) this.bottomLeft.setScale(0.3) - socket.emit("game_info", {"socket_id":socketId, 'rm_id':roomIdx, 'p_id': playerId, "input_time":new Date().toISOString(), + socket.emit("game_info", {"socket_id":socketId, "aws_id": window.location.pathname, 'rm_id':roomIdx, 'p_id': playerId, "input_time":new Date().toISOString(), 'top_left': this.tl, 'top_right': this.tr, 'bottom_left': this.bl, 'bottom_right': this.br}); }, }); @@ -287,7 +287,7 @@ gameInformation.scene.add("GameInfo", gameInfoState); // gameInformation.scene.start("GameInfo"); socket.on('connect',()=>{ - socket.emit("game_info", {"event": "start_t&c", "socket_id": socketId, "time": new Date().toISOString()}); + socket.emit("game_info", {"event": "start_t&c", "socket_id": socketId, "aws_id": window.location.pathname, "time": new Date().toISOString()}); }) socket.on('welcome',(message)=>{ @@ -300,30 +300,30 @@ $(document).ready(function() { $("#agree").change(actExpSmryBtn); $("#cte").on("click", function(){ if ($("#agree").prop('checked') == true) { - changeDisplay(socket, "game_info" ,"#tmcn", "#mainInfo", {"event":"start_instructions", "socket_id":socketId}); + changeDisplay(socket, "game_info" ,"#tmcn", "#mainInfo", {"event":"start_instructions", "aws_id": window.location.pathname, "socket_id":socketId}); } else { alert('Please indicate that you have read and agree to the Terms and Conditions and Privacy Policy'); } }); $("#join-room").on("click", function(){ - changeDisplay(socket, "start_wait", "#quiz-success", "#wait-room", {"event":"start_wait", "socket_id":socketId}) + changeDisplay(socket, "start_wait", "#quiz-success", "#wait-room", {"event":"start_wait", "aws_id": window.location.pathname, "socket_id":socketId}) }); $("#join-quiz").on("click", function(){ - joinQuiz(socket, socketId); + joinQuiz(socket, socketId, window.location.pathname); }); $("#continue-instructions").on("click", function(){ - changeDisplay(socket, "game_info", "#mainInfo", "#mainInfo2", {"event":"continue-instructions", "socket_id":socketId}) + changeDisplay(socket, "game_info", "#mainInfo", "#mainInfo2", {"event":"continue-instructions", "aws_id": window.location.pathname, "socket_id":socketId}) }); $("#revise-intructions").on("click", function(){ - changeDisplay(socket, "game_info", "#quiz-fail", "#mainInfo", {"event":"revise_instructions", "socket_id":socketId}) + changeDisplay(socket, "game_info", "#quiz-fail", "#mainInfo", {"event":"revise_instructions", "aws_id": window.location.pathname, "socket_id":socketId}) }); $('#start-session').on("click", function(){ - startSession(game, socket, "#session-over", "#game-screen", "#sessionId", {"event":"start_game", "s_id": sessionId, 'rm_id':roomIdx, + startSession(game, socket, "#session-over", "#game-screen", "#sessionId", {"event":"start_game", "s_id": sessionId, "aws_id": window.location.pathname, 'rm_id':roomIdx, 'p_id': playerId, "socket_id":socketId}); }); @@ -335,7 +335,7 @@ $(document).ready(function() { $("#feedbackSbmt").on("click", function(){ turk.submit({"p_id":playerId, "rm_id":roomIdx}); - socket.emit('feedback', {"event": "feedback", "comment":feedback_str, "socket_id": socketId, "s_id":sessionId, 'rm_id':roomIdx, + socket.emit('feedback', {"event": "feedback", "comment":feedback_str, "socket_id": socketId, "s_id":sessionId, "aws_id": window.location.pathname, 'rm_id':roomIdx, 'p_id': playerId, "time": new Date().toISOString()}) $("#exp-close").hide(); $("#game-over").show(); @@ -354,6 +354,7 @@ socket.on('start_game', (message)=>{ message["event"] = "start_game" message["s_id"] = sessionId message["socket_id"] = socketId + message["aws_id"] = window.location.pathname console.log(message) startSession(game, socket, gameInformation, "#wait-room", "#game-screen", "#sessionId", message); }); \ No newline at end of file diff --git a/server.js b/server.js index 2ea5256..92fea1b 100644 --- a/server.js +++ b/server.js @@ -1,12 +1,18 @@ -const express = require('express'); -const app = express(); +const express = require('express'); const path = require('path'); +const app = express(); var public = path.join(__dirname, '/public'); app.use('/', express.static(public)); app.get('/', function(req, res) { res.sendFile(path.join(public , 'index.html')); }); -app.listen(process.env.PORT, process.env.IP, function(){ - console.log("Server has started"); +app.get('/data', function(req, res){ + console.log('data route called'); + res.json({ "socketURL": process.env.LOCAL_SOCKET_URL }); }); + +console.log("Server Address: "+ process.env.IP+ "/"+process.env.PORT) +app.listen(process.env.PORT, process.env.IP, function() { + console.log("Server has started" ) +}); \ No newline at end of file