mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 21:27:40 +00:00
GUACAMOLE-1293: Add "onjoin" and "onleave" events as alternative to handling low-level "msg" instructions directly.
This commit is contained in:
@@ -703,6 +703,40 @@ Guacamole.Client = function(tunnel) {
|
|||||||
*/
|
*/
|
||||||
this.onmsg = null;
|
this.onmsg = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fired when a user joins a shared connection.
|
||||||
|
*
|
||||||
|
* @event
|
||||||
|
* @param {!string} userID
|
||||||
|
* A unique value representing this specific user's connection to the
|
||||||
|
* shared connection. This value is generated by the server and is
|
||||||
|
* guaranteed to be unique relative to other users of the connection.
|
||||||
|
*
|
||||||
|
* @param {!string} name
|
||||||
|
* A human-readable name representing the user that joined, such as
|
||||||
|
* their username. This value is provided by the web application during
|
||||||
|
* the connection handshake and is not necessarily unique relative to
|
||||||
|
* other users of the connection.
|
||||||
|
*/
|
||||||
|
this.onjoin = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fired when a user leaves a shared connection.
|
||||||
|
*
|
||||||
|
* @event
|
||||||
|
* @param {!string} userID
|
||||||
|
* A unique value representing this specific user's connection to the
|
||||||
|
* shared connection. This value is generated by the server and is
|
||||||
|
* guaranteed to be unique relative to other users of the connection.
|
||||||
|
*
|
||||||
|
* @param {!string} name
|
||||||
|
* A human-readable name representing the user that left, such as their
|
||||||
|
* username. This value is provided by the web application during the
|
||||||
|
* connection handshake and is not necessarily unique relative to other
|
||||||
|
* users of the connection.
|
||||||
|
*/
|
||||||
|
this.onleave = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fired when a audio stream is created. The stream provided to this event
|
* Fired when a audio stream is created. The stream provided to this event
|
||||||
* handler will contain its own event handlers for received data.
|
* handler will contain its own event handlers for received data.
|
||||||
@@ -1417,7 +1451,23 @@ Guacamole.Client = function(tunnel) {
|
|||||||
|
|
||||||
"msg" : function(parameters) {
|
"msg" : function(parameters) {
|
||||||
|
|
||||||
if (guac_client.onmsg) guac_client.onmsg(parseInt(parameters[0]), parameters.slice(1));
|
var msgid = parseInt(parameters[0]);
|
||||||
|
if (guac_client.onmsg)
|
||||||
|
guac_client.onmsg(msgid, parameters.slice(1));
|
||||||
|
|
||||||
|
switch (msgid) {
|
||||||
|
|
||||||
|
case Guacamole.Client.Message.USER_JOINED:
|
||||||
|
if (guac_client.onjoin)
|
||||||
|
guac_client.onjoin(parameters[1] /* User ID */, parameters[2] /* Name */);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Guacamole.Client.Message.USER_LEFT:
|
||||||
|
if (guac_client.onleave)
|
||||||
|
guac_client.onleave(parameters[1] /* User ID */, parameters[2] /* Name */);
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@@ -508,46 +508,34 @@ angular.module('client').factory('ManagedClient', ['$rootScope', '$injector',
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// Handle messages received from guacd to display to the client.
|
// Update user count when a new user joins
|
||||||
client.onmsg = function clientMessage(msgcode, args) {
|
client.onjoin = function userJoined(id, username) {
|
||||||
switch (msgcode) {
|
$rootScope.$apply(function usersChanged() {
|
||||||
|
|
||||||
// Update current users on connection when a user joins/leaves
|
var connections = managedClient.users[username] || {};
|
||||||
case Guacamole.Client.Message.USER_JOINED:
|
managedClient.users[username] = connections;
|
||||||
case Guacamole.Client.Message.USER_LEFT:
|
|
||||||
|
|
||||||
var userID = args[0];
|
managedClient.userCount++;
|
||||||
var username = args[1];
|
connections[id] = true;
|
||||||
|
|
||||||
var connections = managedClient.users[username] || {};
|
});
|
||||||
managedClient.users[username] = connections;
|
};
|
||||||
|
|
||||||
$rootScope.$apply(function usersChanged() {
|
// Update user count when a user leaves
|
||||||
|
client.onleave = function userLeft(id, username) {
|
||||||
|
$rootScope.$apply(function usersChanged() {
|
||||||
|
|
||||||
// Add/remove user
|
var connections = managedClient.users[username] || {};
|
||||||
if (msgcode === Guacamole.Client.Message.USER_JOINED) {
|
managedClient.users[username] = connections;
|
||||||
managedClient.userCount++;
|
|
||||||
connections[userID] = true;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
managedClient.userCount--;
|
|
||||||
delete connections[userID];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Delete user entry after no connections remain
|
managedClient.userCount--;
|
||||||
if (_.isEmpty(connections))
|
delete connections[id];
|
||||||
delete managedClient.users[username];
|
|
||||||
|
|
||||||
});
|
// Delete user entry after no connections remain
|
||||||
|
if (_.isEmpty(connections))
|
||||||
|
delete managedClient.users[username];
|
||||||
|
|
||||||
break;
|
});
|
||||||
|
|
||||||
default:
|
|
||||||
// Ignore - we only handle join/leave messages, which are
|
|
||||||
// currently the only messages defined at the protocol
|
|
||||||
// level.
|
|
||||||
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Automatically update the client thumbnail
|
// Automatically update the client thumbnail
|
||||||
|
Reference in New Issue
Block a user