HTML and CSS Reference
In-Depth Information
dest = "/queue/" + $("#opponentName").val();
src = "/queue/" + $("#myName").val();
connect();
};
// Establishing the connection
var connect = function() {
client = Stomp.client(url);
client.connect(un, pw, onconnect, onerror);
};
// Function invoked when connection is established
var onconnect = function() {
console.log("connected to " + url);
client.subscribe(src, function(message) {
console.log("message received: " + message.body);
// The incoming message indicates that the
// opponent had his/her turn (picked).
// Therefore, we draw the buttons for the opponent.
// If this user hasn't had his/her move yet,
// we hide the div containing the buttons, and only display
// them when this user has had his/her move too.
hasOpponentPicked = true;
if (!hasUserPicked) {
$("#opponentsButtons").css("visibility", "hidden");
$("#instructions").html("<p>Your opponent is waiting for you. Make
your move!</p>");
} else {
$("#instructions").html("<p>Results:</p>");
client.disconnect( function() {
console.log("Disconnected...");
});
}
$("#opponentsButtons").html(opponentsBtns);
switch (message.body) {
case "rock" :
opponentsPick = "#opponentRockBtn";
break;
case "paper" :
opponentsPick = "#opponentPaperBtn";
break;
case "scissors" :
opponentsPick = "#opponentScissorsBtn";
break;
}
$(opponentsPick).css("background-color", "yellow");
});
 
Search WWH ::




Custom Search