From 4bdc52bd391d8afc73887811d3e4cd9e78dab026 Mon Sep 17 00:00:00 2001 From: Jeffery R Date: Sun, 28 Jan 2018 05:54:04 -0500 Subject: [PATCH] fixed async fnc call of google api --- README.md | 11 ++++++++- googletrendsgame/server/index.html | 9 +++++++ googletrendsgame/server/server.js | 37 ++++++++++++++++++---------- googletrendsgame/server/trendsAPI.js | 2 ++ 4 files changed, 45 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index c0cdc3f..d2ed4ff 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,8 @@ npm install promise ```` ##Database Construction + +```` create database googleTrends; use googleTrends; @@ -37,4 +39,11 @@ create table data( ); -grant all on googleTrends.* to trendingUser@localhost identified by "password"; \ No newline at end of file +grant all on googleTrends.* to trendingUser@localhost identified by "password"; +```` + +## Socket IO events for server + +```` + +```` \ No newline at end of file diff --git a/googletrendsgame/server/index.html b/googletrendsgame/server/index.html index ae024c1..d2cf6a2 100644 --- a/googletrendsgame/server/index.html +++ b/googletrendsgame/server/index.html @@ -9,6 +9,14 @@ var socket = io(); socket.emit('register', 'jeff'); + var join = function(name) + { + var obj = new Object(); + obj.roomName = name; + obj.password = ''; + socket.emit('joinRoom', obj); + } + socket.on('sendRooms', function(data) { console.log("got rooms"); @@ -17,6 +25,7 @@ data.rooms.forEach(function(r) { + document.write(""); document.write(r.name) document.write("
"); }); diff --git a/googletrendsgame/server/server.js b/googletrendsgame/server/server.js index 4990547..9fb988b 100644 --- a/googletrendsgame/server/server.js +++ b/googletrendsgame/server/server.js @@ -124,7 +124,7 @@ var room = function(capacityP, pass, owner) { console.log("room update called"); u.socket.emit('roomUpdate', message); - console.log(message); + //console.log(message); }); } @@ -145,8 +145,8 @@ var room = function(capacityP, pass, owner) this.state = 2; } - console.log("rooms users"); - console.log(this.users); + console.log("user added to room " + player.name); + //console.log(this.users); this.update(); } @@ -211,6 +211,7 @@ var room = function(capacityP, pass, owner) */ this.newRound = function() { + console.log("new round started"); if(this.words.length == 0) { this.state == 4; @@ -231,6 +232,7 @@ var room = function(capacityP, pass, owner) //updates room variables this.update = function() { + console.log("update methed called"); switch(this.state) { case 1: //waiting for users to join @@ -276,6 +278,7 @@ var room = function(capacityP, pass, owner) console.log("You don goof up") } } + console.log(this.state + "uuuuuuuuuuuuuuuuu"); this.sendRoomUpdate(); } this.addUser(owner); @@ -326,20 +329,26 @@ var player = function(s) */ this.selectWord = function(data) { - this.sumbission = data; var w = data + " " + this.room.currentWord; + this.sumbission = data; + + console.log(w); + trendingAPI.getPopularity(w).then(function(result) { - var obj = new Object(); - obj.word = w; - obj.score = result; - this.log.push(obj); - + // var obj = new Object(); + // obj.word = w; + // obj.score = result; + // this.log.push(obj); + console.log("api result for " + result); this.roundScore = result; this.score += result; - console.log("api result for " + result); + + console.print(this.room); this.room.update(); + }) + } } @@ -433,7 +442,7 @@ io.on('connection', function(socket) socket.emit('sendRooms', generateSendRoomsJSON()); console.log("send rooms called"); - console.log(generateSendRoomsJSON()); + //console.log(generateSendRoomsJSON()); } else { @@ -441,7 +450,7 @@ io.on('connection', function(socket) console.log("registration failed sent"); } - console.log(player); + //console.log(player); }); /** @@ -489,14 +498,16 @@ io.on('connection', function(socket) if(rooms[data.roomName] != null && rooms[data.roomName].canJoin(data.password)) { + p.room = rooms[data.roomName]; rooms[data.roomName].addUser(p); + console.log("user joined room"); } else { socket.emit('joinFailed', 'Failed connecting to room'); } - console.log(rooms); + //console.log(rooms); }); /** diff --git a/googletrendsgame/server/trendsAPI.js b/googletrendsgame/server/trendsAPI.js index d359614..617c68e 100644 --- a/googletrendsgame/server/trendsAPI.js +++ b/googletrendsgame/server/trendsAPI.js @@ -59,6 +59,8 @@ module.exports= }) //tell function to return + console.log("********************" + total); + //pl.selectWord2(total); resolve(total); }).catch(function(err){ reject("Google Trends Query Failed");