From 8fb5c57949076c6f68d41e10916f8d6c1faabdbd Mon Sep 17 00:00:00 2001 From: Jerjou Cheng Date: Tue, 25 Oct 2016 13:39:38 -0700 Subject: [PATCH] Add region tags to firebase sample. --- .../main/java/com/example/appengine/firetactoe/Game.java | 6 ++---- .../com/example/appengine/firetactoe/TicTacToeServlet.java | 2 ++ appengine/firebase-tictactoe/src/main/webapp/static/main.js | 4 ++++ 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/appengine/firebase-tictactoe/src/main/java/com/example/appengine/firetactoe/Game.java b/appengine/firebase-tictactoe/src/main/java/com/example/appengine/firetactoe/Game.java index e990a8b1fe8..a68aa5c5be6 100644 --- a/appengine/firebase-tictactoe/src/main/java/com/example/appengine/firetactoe/Game.java +++ b/appengine/firebase-tictactoe/src/main/java/com/example/appengine/firetactoe/Game.java @@ -104,7 +104,7 @@ public void setMoveX(boolean moveX) { this.moveX = moveX; } - //[START send_updates] + // [START send_updates] public String getChannelKey(String userId) { return userId + id; } @@ -130,7 +130,7 @@ public void sendUpdateToClients() sendUpdateToUser(userX); sendUpdateToUser(userO); } - //[END send_updates] + // [END send_updates] public void checkWin() { final Pattern[] wins; @@ -152,7 +152,6 @@ public void checkWin() { } } - //[START make_move] public boolean makeMove(int position, String userId) { String currentMovePlayer; char value; @@ -181,5 +180,4 @@ public boolean makeMove(int position, String userId) { return false; } - //[END make_move] } diff --git a/appengine/firebase-tictactoe/src/main/java/com/example/appengine/firetactoe/TicTacToeServlet.java b/appengine/firebase-tictactoe/src/main/java/com/example/appengine/firetactoe/TicTacToeServlet.java index 07e040b5244..9bba63d862d 100644 --- a/appengine/firebase-tictactoe/src/main/java/com/example/appengine/firetactoe/TicTacToeServlet.java +++ b/appengine/firebase-tictactoe/src/main/java/com/example/appengine/firetactoe/TicTacToeServlet.java @@ -88,6 +88,7 @@ public void doGet(HttpServletRequest request, HttpServletResponse response) // 3. Inject a secure token into the client, so it can get game updates + // [START pass_token] // The 'Game' object exposes a method which creates a unique string based on the game's key // and the user's id. String token = FirebaseChannel.getInstance().createFirebaseToken(game, userId); @@ -100,5 +101,6 @@ public void doGet(HttpServletRequest request, HttpServletResponse response) request.setAttribute("initial_message", new Gson().toJson(game)); request.setAttribute("game_link", getGameUriWithGameParam(request, gameKey)); request.getRequestDispatcher("/WEB-INF/view/index.jsp").forward(request, response); + // [END pass_token] } } diff --git a/appengine/firebase-tictactoe/src/main/webapp/static/main.js b/appengine/firebase-tictactoe/src/main/webapp/static/main.js index 804b74f86be..4633fbe26c7 100644 --- a/appengine/firebase-tictactoe/src/main/webapp/static/main.js +++ b/appengine/firebase-tictactoe/src/main/webapp/static/main.js @@ -132,18 +132,22 @@ function initGame(gameKey, me, token, channelId, initialMessage) { * finally, it calls onOpened() to let the server know it is ready to receive messages */ function openChannel() { + // [START auth_login] // sign into Firebase with the token passed from the server firebase.auth().signInWithCustomToken(token).catch(function(error) { console.log('Login Failed!', error.code); console.log('Error message: ', error.message); }); + // [END auth_login] + // [START add_listener] // setup a database reference at path /channels/channelId channel = firebase.database().ref('channels/' + channelId); // add a listener to the path that fires any time the value of the data changes channel.on('value', function(data) { onMessage(data.val()); }); + // [END add_listener] onOpened(); // let the server know that the channel is open }