Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -130,7 +130,7 @@ public void sendUpdateToClients()
sendUpdateToUser(userX);
sendUpdateToUser(userO);
}
//[END send_updates]
// [END send_updates]

public void checkWin() {
final Pattern[] wins;
Expand All @@ -152,7 +152,6 @@ public void checkWin() {
}
}

//[START make_move]
public boolean makeMove(int position, String userId) {
String currentMovePlayer;
char value;
Expand Down Expand Up @@ -181,5 +180,4 @@ public boolean makeMove(int position, String userId) {

return false;
}
//[END make_move]
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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]
}
}
4 changes: 4 additions & 0 deletions appengine/firebase-tictactoe/src/main/webapp/static/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down