GUACAMOLE-1293: Allow "onmsg" to determine whether "onjoin" and "onleave" fire.

This commit is contained in:
Mike Jumper
2023-01-31 14:50:54 -08:00
parent b7e3f73ffa
commit bd91327415

View File

@@ -690,7 +690,10 @@ Guacamole.Client = function(tunnel) {
/** /**
* Fired when an arbitrary message is received from the tunnel that should * Fired when an arbitrary message is received from the tunnel that should
* be processed by the client. * be processed by the client. By default, additional message-specific
* events such as "onjoin" and "onleave" will fire for the received message
* after this event has been processed. An event handler for "onmsg" need
* not be supplied if "onjoin" and/or "onleave" will be used.
* *
* @event * @event
* @param {!number} msgcode * @param {!number} msgcode
@@ -700,6 +703,12 @@ Guacamole.Client = function(tunnel) {
* @param {string[]} args * @param {string[]} args
* An array of arguments to be processed with the message sent to the * An array of arguments to be processed with the message sent to the
* client. * client.
*
* @return {boolean}
* true if message-specific events such as "onjoin" and
* "onleave" should be fired for this message, false otherwise. If
* no value is returned, message-specific events will be allowed to
* fire.
*/ */
this.onmsg = null; this.onmsg = null;
@@ -1454,26 +1463,35 @@ Guacamole.Client = function(tunnel) {
var userID; var userID;
var username; var username;
// Fire general message handling event first
var allowDefault = true;
var msgid = parseInt(parameters[0]); var msgid = parseInt(parameters[0]);
if (guac_client.onmsg) if (guac_client.onmsg) {
guac_client.onmsg(msgid, parameters.slice(1)); allowDefault = guac_client.onmsg(msgid, parameters.slice(1));
if (allowDefault === undefined)
allowDefault = true;
}
switch (msgid) { // Fire message-specific convenience events if not prevented by the
// "onmsg" handler
if (allowDefault) {
switch (msgid) {
case Guacamole.Client.Message.USER_JOINED: case Guacamole.Client.Message.USER_JOINED:
userID = parameters[1]; userID = parameters[1];
username = parameters[2]; username = parameters[2];
if (guac_client.onjoin) if (guac_client.onjoin)
guac_client.onjoin(userID, username); guac_client.onjoin(userID, username);
break; break;
case Guacamole.Client.Message.USER_LEFT: case Guacamole.Client.Message.USER_LEFT:
userID = parameters[1]; userID = parameters[1];
username = parameters[2]; username = parameters[2];
if (guac_client.onleave) if (guac_client.onleave)
guac_client.onleave(userID, username); guac_client.onleave(userID, username);
break; break;
}
} }
}, },