You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@guacamole.apache.org by GitBox <gi...@apache.org> on 2022/11/29 01:34:45 UTC

[GitHub] [guacamole-client] mike-jumper commented on a diff in pull request #668: GUACAMOLE-1293: Add client-side support for receiving join and leave notifications.

mike-jumper commented on code in PR #668:
URL: https://github.com/apache/guacamole-client/pull/668#discussion_r1032752393


##########
guacamole/src/main/java/org/apache/guacamole/tunnel/TunnelRequestService.java:
##########
@@ -340,6 +340,11 @@ public GuacamoleTunnel createTunnel(TunnelRequest request)
         GuacamoleSession session = authenticationService.getGuacamoleSession(authToken);
         AuthenticatedUser authenticatedUser = session.getAuthenticatedUser();
         UserContext userContext = session.getUserContext(authProviderIdentifier);
+        
+        // Attempt to get the user's name and set it for the tunnel client.
+        String name = authenticatedUser.getCredentials().getName();

Review Comment:
   This should instead be `authenticatedUser.getIdentifier()`, which is always the identity of the user regardless of whether their credentials include their username. I think this may have been meant as `authenticatedUser.getCredentials().getUsername()`, which will _often_ return the same value but is not guaranteed to do so.



##########
guacamole-common-js/src/main/webapp/modules/Client.js:
##########
@@ -687,6 +687,20 @@ Guacamole.Client = function(tunnel) {
      *     A status object which describes the error.
      */
     this.onerror = null;
+    
+    /**
+     * Fired when a message is received from the remote tunnel and needs to be
+     * displayed to the user.
+     * 
+     * @event
+     * @param {!number} msgcode
+     *     A status code sent by the remote server that indicates the message
+     *     that should be displayed to the client.
+     * @param {string[]} args
+     *     An array of arguments that can be added to the message that will be
+     *     displayed to the client. 
+     */

Review Comment:
   I think this should be documented more along the lines of receiving a message indicating some sort of arbitrary event or state change, not necessarily something that _needs_ or _will_ to be displayed to the user.



##########
guacamole/src/main/frontend/src/app/client/directives/guacClientMessage.js:
##########
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * Directive which displays a message for the client.
+ */
+angular.module('client').directive('guacClientMessage', [function guacClientMessage() {
+
+    return {
+        restrict: 'E',
+        replace: true,
+        scope: {
+
+            /**
+             * The message to display to the client.
+             * 
+             * @type {!ManagedClientMessage}
+             */
+            message : '='
+
+        },
+
+        templateUrl: 'app/client/templates/guacClientMessage.html',
+        
+        controller: ['$scope', '$injector', '$element',
+                function guacClientMessageController($scope, $injector, $element) {
+            
+            // Required types
+            const ManagedClientMessage = $injector.get('ManagedClientMessage');
+            
+            /**
+             * Uses the msgcode to retrieve the correct translation key for
+             * the client message.
+             * 
+             * @returns {string}
+             */
+            $scope.getMessageKey = function getMessageKey() {
+                
+                let msgString = "DEFAULT";
+                if (Object.values(Guacamole.Client.Message).includes($scope.message.msgcode))
+                    msgString = Object.keys(Guacamole.Client.Message).find(key => Guacamole.Client.Message[key] === $scope.message.msgcode);
+                
+                return "CLIENT.CLIENT_MESSAGE_" + msgString.toUpperCase();

Review Comment:
   This should probably be a call to [`translationStringService.canonicalize()`](https://github.com/apache/guacamole-client/blob/165bd413c0ab9c55b0c0e3614fcb829ef5f8ca95/guacamole/src/main/frontend/src/app/locale/services/translationStringService.js#L28-L42).



##########
guacamole-common-js/src/main/webapp/modules/Client.js:
##########
@@ -1824,3 +1844,31 @@ Guacamole.Client.DefaultTransferFunction = {
     }
 
 };
+
+/**
+ * A list of possible messages that can be sent by the server and displayed to
+ * the client.
+ * 
+ * @type {!Object.<string, number>}
+ */
+Guacamole.Client.Message = {
+    
+    /**
+     * A client message that indicates that a user has joined an existing
+     * connection. This message expects a single additional argument - the
+     * name of the user who has joined the connection.
+     * 
+     * @type {!number}
+     */
+    "JOINED": 0x0001,
+    
+    /**
+     * A client message that indicates that a user has left an existing
+     * connection. This message expects a single additional argument - the
+     * name of the user who has left the connection.
+     * 
+     * @type {!number}
+     */
+    "LEFT": 0x0002

Review Comment:
   I suggest renaming these to `USER_JOINED` and `USER_LEFT` to (1) align with the `GUAC_MESSAGE_USER_JOINED` and `GUAC_MESSAGE_USER_LEFT` constants and (2) clarify the context of the event.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@guacamole.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org