if (!isConnected())
return;
- tunnel.sendMessage("key:" + keysym + "," + pressed + ";");
+ tunnel.sendMessage("key", keysym, pressed);
};
guac_client.sendMouseState = function(mouseState) {
if (mouseState.down) buttonMask |= 16;
// Send message
- tunnel.sendMessage("mouse:" + mouseState.x + "," + mouseState.y + "," + buttonMask + ";");
+ tunnel.sendMessage("mouse", mouseState.x, mouseState.y, buttonMask);
};
guac_client.setClipboard = function(data) {
if (!isConnected())
return;
- tunnel.sendMessage("clipboard:" + escapeGuacamoleString(data) + ";");
+ tunnel.sendMessage("clipboard", data);
};
// Handlers
// Send sync response when layers are finished
if (layersToSync == 0)
- tunnel.sendMessage("sync:" + timestamp + ";");
+ tunnel.sendMessage("sync", timestamp);
}
// If all layers are ready, then we didn't install any hooks.
// Send sync message now,
if (layersToSync == 0)
- tunnel.sendMessage("sync:" + timestamp + ";");
+ tunnel.sendMessage("sync", timestamp);
}
&& currentState != STATE_DISCONNECTING) {
setState(STATE_DISCONNECTING);
- tunnel.sendMessage("disconnect;");
+ tunnel.sendMessage("disconnect");
tunnel.disconnect();
setState(STATE_DISCONNECTED);
}
}
- function escapeGuacamoleString(str) {
-
- var escapedString = "";
-
- for (var i=0; i<str.length; i++) {
-
- var c = str.charAt(i);
- if (c == ",")
- escapedString += "\\c";
- else if (c == ";")
- escapedString += "\\s";
- else if (c == "\\")
- escapedString += "\\\\";
- else
- escapedString += c;
-
- }
-
- return escapedString;
-
- }
-
guac_client.disconnect = disconnect;
guac_client.connect = function(data) {
* Send the given message through the tunnel to the service on the other
* side. All messages are guaranteed to be received in the order sent.
*
- * @param {String} message The message to send to the service on the other
- * side of the tunnel.
+ * @param {...} elements The elements of the message to send to the
+ * service on the other side of the tunnel.
*/
- this.sendMessage = function(message) {};
+ this.sendMessage = function(elements) {};
/**
* Fired whenever an error is encountered by the tunnel.
var sendingMessages = false;
var outputMessageBuffer = "";
- this.sendMessage = function(message) {
+ this.sendMessage = function() {
// Do not attempt to send messages if not connected
if (currentState != STATE_CONNECTED)
return;
- // Add event to queue, restart send loop if finished.
+ // Do not attempt to send empty messages
+ if (arguments.length == 0)
+ return;
+
+ function getElement(value) {
+ var string = new String(value);
+ return string.length + "." + string;
+ }
+
+ // Initialized message with first element
+ var message = getElement(arguments[0]);
+
+ // Append remaining elements
+ for (var i=1; i<arguments.length; i++)
+ message += "," + getElement(arguments[i]);
+
+ // Final terminator
+ message += ";";
+
+ // Add message to buffer, restart send loop if finished.
outputMessageBuffer += message;
if (!sendingMessages)
sendPendingMessages();