Javascript Argument Not Passed Across Handler
I am using Google Cloud Channels in Android's WebView, but the same problem probably occurs as well when using any socket in a similar way. Problem: The argument is not passed on b
Solution 1:
The problem was not a JavaScript issue, as I assumed. The assumption that the same issue would occur with any socket type was also incorrect.
The problem had to do with how Google Cloud Channels hands over the message in onMessage().
As I could see from code that Google posted for their Tic Tac Toe example here http://code.google.com/p/channel-tac-toe/source/browse/trunk/index.html, line 175ff, they hand over the string as an event with the variable "data", but called the argument "m" (as in message).
onOpened = function() {
sendMessage('/opened');
};
onMessage = function(m) {
newState = JSON.parse(m.data);
state.board = newState.board || state.board;
state.userX = newState.userX || state.userX;
state.userO = newState.userO || state.userO;
state.moveX = newState.moveX;
state.winner = newState.winner || "";
state.winningBoard = newState.winningBoard || "";
updateGame();
}
openChannel = function() {
var token = '{{ token }}';
var channel = new goog.appengine.Channel(token);
var handler = {
'onopen': onOpened,
'onmessage': onMessage,
'onerror': function() {},
'onclose': function() {}
};
var socket = channel.open(handler);
socket.onopen = onOpened;
socket.onmessage = onMessage;
}
Kind of confusing and undocumented here https://cloud.google.com/appengine/docs/java/channel/?csw=1 and here https://cloud.google.com/appengine/docs/java/channel/javascript, but when I changed the message signature to
onMessage = function(message) {
ChannelListener.onMessage(message.data); // message
};
it worked perfectly fine.
Post a Comment for "Javascript Argument Not Passed Across Handler"