mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-07 05:31:22 +00:00
GUAC-605: Reduce use of $scope for variables that are local in spirit.
This commit is contained in:
@@ -62,61 +62,9 @@ angular.module('client').directive('guacClient', [function guacClient() {
|
|||||||
guacVideo = $injector.get('guacVideo'),
|
guacVideo = $injector.get('guacVideo'),
|
||||||
localStorageUtility = $injector.get('localStorageUtility');
|
localStorageUtility = $injector.get('localStorageUtility');
|
||||||
|
|
||||||
var authToken = localStorageUtility.get('authToken'),
|
|
||||||
uniqueId = encodeURIComponent($scope.type + '/' + $scope.id);
|
|
||||||
|
|
||||||
// Get elements for DOM manipulation
|
// Get elements for DOM manipulation
|
||||||
$scope.main = $element[0];
|
var main = $element[0];
|
||||||
|
|
||||||
// Settings and constants
|
|
||||||
$.extend(true, $scope, {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* All error codes for which automatic reconnection is appropriate when a
|
|
||||||
* tunnel error occurs.
|
|
||||||
*/
|
|
||||||
"tunnel_auto_reconnect": {
|
|
||||||
0x0200: true,
|
|
||||||
0x0202: true,
|
|
||||||
0x0203: true,
|
|
||||||
0x0308: true
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* All error codes for which automatic reconnection is appropriate when a
|
|
||||||
* client error occurs.
|
|
||||||
*/
|
|
||||||
"client_auto_reconnect": {
|
|
||||||
0x0200: true,
|
|
||||||
0x0202: true,
|
|
||||||
0x0203: true,
|
|
||||||
0x0301: true,
|
|
||||||
0x0308: true
|
|
||||||
},
|
|
||||||
|
|
||||||
/* Constants */
|
|
||||||
|
|
||||||
"KEYBOARD_AUTO_RESIZE_INTERVAL" : 30, /* milliseconds */
|
|
||||||
"RECONNECT_PERIOD" : 15, /* seconds */
|
|
||||||
"TEXT_INPUT_PADDING" : 128, /* characters */
|
|
||||||
"TEXT_INPUT_PADDING_CODEPOINT" : 0x200B,
|
|
||||||
|
|
||||||
/* Current connection parameters */
|
|
||||||
|
|
||||||
/* The user defined named for this connection */
|
|
||||||
"connectionName" : "Guacamole",
|
|
||||||
|
|
||||||
/* The attached client instance */
|
|
||||||
"attachedClient" : null,
|
|
||||||
|
|
||||||
/* Mouse emulation */
|
|
||||||
|
|
||||||
"emulate_absolute" : true,
|
|
||||||
"touch" : null,
|
|
||||||
"touch_screen" : null,
|
|
||||||
"touch_pad" : null
|
|
||||||
});
|
|
||||||
|
|
||||||
var CLIENT_PROPERTY_DEFAULTS = {
|
var CLIENT_PROPERTY_DEFAULTS = {
|
||||||
scale: 1
|
scale: 1
|
||||||
};
|
};
|
||||||
@@ -138,8 +86,8 @@ angular.module('client').directive('guacClient', [function guacClient() {
|
|||||||
|
|
||||||
// Calculate scale to fit screen
|
// Calculate scale to fit screen
|
||||||
$scope.clientProperties.minScale = Math.min(
|
$scope.clientProperties.minScale = Math.min(
|
||||||
$scope.main.offsetWidth / Math.max(guac.getDisplay().getWidth(), 1),
|
main.offsetWidth / Math.max(guac.getDisplay().getWidth(), 1),
|
||||||
$scope.main.offsetHeight / Math.max(guac.getDisplay().getHeight(), 1)
|
main.offsetHeight / Math.max(guac.getDisplay().getHeight(), 1)
|
||||||
);
|
);
|
||||||
|
|
||||||
// Calculate appropriate maximum zoom level
|
// Calculate appropriate maximum zoom level
|
||||||
@@ -230,14 +178,13 @@ angular.module('client').directive('guacClient', [function guacClient() {
|
|||||||
// Listen for clipboard events not sent by the client
|
// Listen for clipboard events not sent by the client
|
||||||
$scope.$on('guacClipboard', function onClipboardChange(event, data) {
|
$scope.$on('guacClipboard', function onClipboardChange(event, data) {
|
||||||
// Update server clipboard with current data
|
// Update server clipboard with current data
|
||||||
$scope.guac.setClipboard(data);
|
$scope.attachedClient.setClipboard(data);
|
||||||
});
|
});
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Emit a name change event
|
* Emit a name change event
|
||||||
*/
|
*/
|
||||||
guac.onname = function(name) {
|
guac.onname = function(name) {
|
||||||
$scope.connectionDisplayName = name;
|
|
||||||
$scope.$emit('name', guac, name);
|
$scope.$emit('name', guac, name);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -249,7 +196,7 @@ angular.module('client').directive('guacClient', [function guacClient() {
|
|||||||
// Disconnect, if connected
|
// Disconnect, if connected
|
||||||
guac.disconnect();
|
guac.disconnect();
|
||||||
|
|
||||||
$scope.$emit('guacClientError', guac, status.code, $scope.connect);
|
$scope.$emit('guacClientError', guac, status.code);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -384,12 +331,12 @@ angular.module('client').directive('guacClient', [function guacClient() {
|
|||||||
|
|
||||||
// Determine mouse position within view
|
// Determine mouse position within view
|
||||||
var guac_display = guac.getDisplay().getElement();
|
var guac_display = guac.getDisplay().getElement();
|
||||||
var mouse_view_x = mouseState.x + guac_display.offsetLeft - $scope.main.scrollLeft;
|
var mouse_view_x = mouseState.x + guac_display.offsetLeft - main.scrollLeft;
|
||||||
var mouse_view_y = mouseState.y + guac_display.offsetTop - $scope.main.scrollTop;
|
var mouse_view_y = mouseState.y + guac_display.offsetTop - main.scrollTop;
|
||||||
|
|
||||||
// Determine viewport dimensions
|
// Determine viewport dimensions
|
||||||
var view_width = $scope.main.offsetWidth;
|
var view_width = main.offsetWidth;
|
||||||
var view_height = $scope.main.offsetHeight;
|
var view_height = main.offsetHeight;
|
||||||
|
|
||||||
// Determine scroll amounts based on mouse position relative to document
|
// Determine scroll amounts based on mouse position relative to document
|
||||||
|
|
||||||
@@ -410,8 +357,8 @@ angular.module('client').directive('guacClient', [function guacClient() {
|
|||||||
scroll_amount_y = 0;
|
scroll_amount_y = 0;
|
||||||
|
|
||||||
// Scroll (if necessary) to keep mouse on screen.
|
// Scroll (if necessary) to keep mouse on screen.
|
||||||
$scope.main.scrollLeft += scroll_amount_x;
|
main.scrollLeft += scroll_amount_x;
|
||||||
$scope.main.scrollTop += scroll_amount_y;
|
main.scrollTop += scroll_amount_y;
|
||||||
|
|
||||||
// Scale event by current scale
|
// Scale event by current scale
|
||||||
var scaledState = new Guacamole.Mouse.State(
|
var scaledState = new Guacamole.Mouse.State(
|
||||||
@@ -467,22 +414,24 @@ angular.module('client').directive('guacClient', [function guacClient() {
|
|||||||
*/
|
*/
|
||||||
$scope.connect = function connect() {
|
$scope.connect = function connect() {
|
||||||
|
|
||||||
|
var tunnel;
|
||||||
|
|
||||||
// If WebSocket available, try to use it.
|
// If WebSocket available, try to use it.
|
||||||
if ($window.WebSocket)
|
if ($window.WebSocket)
|
||||||
$scope.tunnel = new Guacamole.ChainedTunnel(
|
tunnel = new Guacamole.ChainedTunnel(
|
||||||
new Guacamole.WebSocketTunnel("websocket-tunnel"),
|
new Guacamole.WebSocketTunnel("websocket-tunnel"),
|
||||||
new Guacamole.HTTPTunnel("tunnel")
|
new Guacamole.HTTPTunnel("tunnel")
|
||||||
);
|
);
|
||||||
|
|
||||||
// If no WebSocket, then use HTTP.
|
// If no WebSocket, then use HTTP.
|
||||||
else
|
else
|
||||||
$scope.tunnel = new Guacamole.HTTPTunnel("tunnel");
|
tunnel = new Guacamole.HTTPTunnel("tunnel");
|
||||||
|
|
||||||
// Instantiate client
|
// Instantiate client
|
||||||
$scope.guac = new Guacamole.Client($scope.tunnel);
|
var guac = new Guacamole.Client(tunnel);
|
||||||
|
|
||||||
// Tie UI to client
|
// Tie UI to client
|
||||||
$scope.attach($scope.guac);
|
$scope.attach(guac);
|
||||||
|
|
||||||
// Calculate optimal width/height for display
|
// Calculate optimal width/height for display
|
||||||
var pixel_density = $window.devicePixelRatio || 1;
|
var pixel_density = $window.devicePixelRatio || 1;
|
||||||
@@ -502,6 +451,9 @@ angular.module('client').directive('guacClient', [function guacClient() {
|
|||||||
// all parameters should be preserved and passed on for
|
// all parameters should be preserved and passed on for
|
||||||
// the sake of authentication.
|
// the sake of authentication.
|
||||||
|
|
||||||
|
var authToken = localStorageUtility.get('authToken'),
|
||||||
|
uniqueId = encodeURIComponent($scope.type + '/' + $scope.id);
|
||||||
|
|
||||||
var connectString =
|
var connectString =
|
||||||
"id=" + uniqueId + ($scope.connectionParameters ? '&' + $scope.connectionParameters : '')
|
"id=" + uniqueId + ($scope.connectionParameters ? '&' + $scope.connectionParameters : '')
|
||||||
+ "&authToken="+ authToken
|
+ "&authToken="+ authToken
|
||||||
@@ -521,26 +473,26 @@ angular.module('client').directive('guacClient', [function guacClient() {
|
|||||||
|
|
||||||
|
|
||||||
// Fire events for tunnel errors
|
// Fire events for tunnel errors
|
||||||
$scope.tunnel.onerror = function onerror(status) {
|
tunnel.onerror = function onerror(status) {
|
||||||
$scope.$emit('guacTunnelError', $scope.guac, status.code, $scope.connect);
|
$scope.$emit('guacTunnelError', guac, status.code);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// Fire events for tunnel state changes
|
// Fire events for tunnel state changes
|
||||||
$scope.tunnel.onstatechange = function onstatechange(state) {
|
tunnel.onstatechange = function onstatechange(state) {
|
||||||
|
|
||||||
switch (state) {
|
switch (state) {
|
||||||
|
|
||||||
case Guacamole.Tunnel.State.CONNECTING:
|
case Guacamole.Tunnel.State.CONNECTING:
|
||||||
$scope.$emit('guacTunnelStateChange', $scope.guac, "connecting");
|
$scope.$emit('guacTunnelStateChange', guac, "connecting");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Guacamole.Tunnel.State.OPEN:
|
case Guacamole.Tunnel.State.OPEN:
|
||||||
$scope.$emit('guacTunnelStateChange', $scope.guac, "open");
|
$scope.$emit('guacTunnelStateChange', guac, "open");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Guacamole.Tunnel.State.CLOSED:
|
case Guacamole.Tunnel.State.CLOSED:
|
||||||
$scope.$emit('guacTunnelStateChange', $scope.guac, "closed");
|
$scope.$emit('guacTunnelStateChange', guac, "closed");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -548,7 +500,8 @@ angular.module('client').directive('guacClient', [function guacClient() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Connect
|
// Connect
|
||||||
$scope.guac.connect(connectString);
|
guac.connect(connectString);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Adjust scale if modified externally
|
// Adjust scale if modified externally
|
||||||
@@ -560,11 +513,11 @@ angular.module('client').directive('guacClient', [function guacClient() {
|
|||||||
|
|
||||||
// If at minimum zoom level, hide scroll bars
|
// If at minimum zoom level, hide scroll bars
|
||||||
if (scale === $scope.clientProperties.minScale)
|
if (scale === $scope.clientProperties.minScale)
|
||||||
$scope.main.style.overflow = "hidden";
|
main.style.overflow = "hidden";
|
||||||
|
|
||||||
// If not at minimum zoom level, show scroll bars
|
// If not at minimum zoom level, show scroll bars
|
||||||
else
|
else
|
||||||
$scope.main.style.overflow = "auto";
|
main.style.overflow = "auto";
|
||||||
|
|
||||||
// Apply scale if client attached
|
// Apply scale if client attached
|
||||||
if ($scope.attachedClient)
|
if ($scope.attachedClient)
|
||||||
|
Reference in New Issue
Block a user