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 2023/01/05 18:12:08 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_r1062112840


##########
guacamole-common-js/src/main/webapp/modules/Client.js:
##########
@@ -1824,3 +1845,31 @@ Guacamole.Client.DefaultTransferFunction = {
     }
 
 };
+
+/**
+ * A list of possible messages that can be sent by the server for processing
+ * by 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}
+     */
+    "GUAC_MESSAGE_USER_JOINED": 0x0001,

Review Comment:
   These should probably be `USER_JOINED`, etc. rather than `GUAC_MESSAGE_USER_JOINED`. There's no need to namespace what's already given via `Guacamole.Client.Message`.



##########
guacamole/src/main/frontend/src/app/client/directives/guacClientMessage.js:
##########
@@ -0,0 +1,87 @@
+/*
+ * 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');
+            
+            // Required services
+            var translationStringService = $injector.get('translationStringService');
+            
+            /**
+             * Uses the msgcode to retrieve the correct translation key for
+             * the client message.
+             * 
+             * @returns {string}
+             */
+            $scope.getMessageKey = function getMessageKey() {
+                
+                let msgString = "GUAC_MESSAGE_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 translationStringService.canonicalize('CLIENT.' + msgString);

Review Comment:
   I believe this will transform `CLIENT.` into `CLIENT_`. To add the `CLIENT` namespace, you'd need to instead:
   
   ```js
   'CLIENT.' + translationStringService.canonicalize(msgString)
   ```
   
   but you'll probably want something more like:
   
   ```js
   'CLIENT.MESSAGE_' + translationStringService.canonicalize(msgString)
   ```
   
   assuming the keys within `Guacamole.Client.Message` are `USER_JOINED`, etc.



-- 
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