HTML and CSS Reference
In-Depth Information
$("#instructions").html("<p>Your opponent is waiting for you.
Make your move!</p>");
} else {
client.disconnect( function() {
switch (message.body) {
case "rock" :
opponentsPick = "#opponentRockBtn";
case "paper" :
opponentsPick = "#opponentPaperBtn";
case "scissors" :
opponentsPick = "#opponentScissorsBtn";
$(opponentsPick).css("background-color", "yellow");
console.log("subscribed to " + src);
In case of an error, we can easily handle it using the onerror() callback function,
shown in Listing 5-12. An easy way to test the execution of this function is by creating a
connection first, and then stopping ActiveMQ. By doing so, you'll see an error message on
the console indicating that the connection has been lost.
Listing 5-12. Capturing Errors with the onerror Callback Function
var onerror = function(error) {
The last function of our code is invoked when the user selects one of the three
options: rock, paper, or scissors. The send() function of the client object takes three
parameters: the destination, the headers (which is null in our case), and the message
(the name of our button DOM object). We switch the hasUserPicked flag to true , indicating
that the user has already picked. Then, we disable the form fields. Depending whether the
opponent has moved, we either display the opponent's move, or change the instruction
message, letting this player know that we're waiting for the opponent (Listing 5-13).
Search WWH ::

Custom Search