Skip to content

Commit 1056e98

Browse files
authored
Merge pull request #386 from GoogleCloudPlatform/firebase-regiontags
Add region tags to firebase sample.
2 parents 310153e + c37b85e commit 1056e98

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

appengine/firebase-tictactoe/src/main/java/com/example/appengine/firetactoe/Game.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public void setMoveX(boolean moveX) {
104104
this.moveX = moveX;
105105
}
106106

107-
//[START send_updates]
107+
// [START send_updates]
108108
public String getChannelKey(String userId) {
109109
return userId + id;
110110
}
@@ -130,7 +130,7 @@ public void sendUpdateToClients()
130130
sendUpdateToUser(userX);
131131
sendUpdateToUser(userO);
132132
}
133-
//[END send_updates]
133+
// [END send_updates]
134134

135135
public void checkWin() {
136136
final Pattern[] wins;
@@ -152,7 +152,6 @@ public void checkWin() {
152152
}
153153
}
154154

155-
//[START make_move]
156155
public boolean makeMove(int position, String userId) {
157156
String currentMovePlayer;
158157
char value;
@@ -181,5 +180,4 @@ public boolean makeMove(int position, String userId) {
181180

182181
return false;
183182
}
184-
//[END make_move]
185183
}

appengine/firebase-tictactoe/src/main/java/com/example/appengine/firetactoe/TicTacToeServlet.java

+2
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ public void doGet(HttpServletRequest request, HttpServletResponse response)
8888

8989
// 3. Inject a secure token into the client, so it can get game updates
9090

91+
// [START pass_token]
9192
// The 'Game' object exposes a method which creates a unique string based on the game's key
9293
// and the user's id.
9394
String token = FirebaseChannel.getInstance().createFirebaseToken(game, userId);
@@ -100,5 +101,6 @@ public void doGet(HttpServletRequest request, HttpServletResponse response)
100101
request.setAttribute("initial_message", new Gson().toJson(game));
101102
request.setAttribute("game_link", getGameUriWithGameParam(request, gameKey));
102103
request.getRequestDispatcher("/WEB-INF/view/index.jsp").forward(request, response);
104+
// [END pass_token]
103105
}
104106
}

appengine/firebase-tictactoe/src/main/webapp/static/main.js

+4
Original file line numberDiff line numberDiff line change
@@ -132,18 +132,22 @@ function initGame(gameKey, me, token, channelId, initialMessage) {
132132
* finally, it calls onOpened() to let the server know it is ready to receive messages
133133
*/
134134
function openChannel() {
135+
// [START auth_login]
135136
// sign into Firebase with the token passed from the server
136137
firebase.auth().signInWithCustomToken(token).catch(function(error) {
137138
console.log('Login Failed!', error.code);
138139
console.log('Error message: ', error.message);
139140
});
141+
// [END auth_login]
140142

143+
// [START add_listener]
141144
// setup a database reference at path /channels/channelId
142145
channel = firebase.database().ref('channels/' + channelId);
143146
// add a listener to the path that fires any time the value of the data changes
144147
channel.on('value', function(data) {
145148
onMessage(data.val());
146149
});
150+
// [END add_listener]
147151
onOpened();
148152
// let the server know that the channel is open
149153
}

0 commit comments

Comments
 (0)