mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-07 05:31:22 +00:00
GUAC-605: Fix usage of scope within client and tunnel.
This commit is contained in:
@@ -312,7 +312,7 @@ angular.module('client').directive('guacClient', [function guacClient() {
|
|||||||
|
|
||||||
// Get new client instance
|
// Get new client instance
|
||||||
var tunnel = guacTunnelFactory.getInstance($scope);
|
var tunnel = guacTunnelFactory.getInstance($scope);
|
||||||
client = guacClientFactory.getInstance(tunnel, $scope);
|
client = guacClientFactory.getInstance($scope, tunnel);
|
||||||
|
|
||||||
// Init display
|
// Init display
|
||||||
display = client.getDisplay();
|
display = client.getDisplay();
|
||||||
|
@@ -32,15 +32,11 @@ angular.module('client').factory('guacClientFactory', ['$rootScope',
|
|||||||
* Returns a new Guacamole client instance which connects using the
|
* Returns a new Guacamole client instance which connects using the
|
||||||
* provided tunnel.
|
* provided tunnel.
|
||||||
*
|
*
|
||||||
|
* @param {Scope} $scope The current scope.
|
||||||
* @param {Guacamole.Tunnel} tunnel The tunnel to connect through.
|
* @param {Guacamole.Tunnel} tunnel The tunnel to connect through.
|
||||||
* @param {Scope} [$scope] The current scope. If ommitted, the root scope
|
|
||||||
* will be used.
|
|
||||||
* @returns {Guacamole.Client} A new Guacamole client instance.
|
* @returns {Guacamole.Client} A new Guacamole client instance.
|
||||||
*/
|
*/
|
||||||
service.getInstance = function getClientInstance(tunnel, $scope) {
|
service.getInstance = function getClientInstance($scope, tunnel) {
|
||||||
|
|
||||||
// Use root scope if no other scope provided
|
|
||||||
$scope = $scope || $rootScope;
|
|
||||||
|
|
||||||
// Instantiate client
|
// Instantiate client
|
||||||
var guacClient = new Guacamole.Client(tunnel);
|
var guacClient = new Guacamole.Client(tunnel);
|
||||||
@@ -49,47 +45,52 @@ angular.module('client').factory('guacClientFactory', ['$rootScope',
|
|||||||
* Fire guacClientStateChange events when client state changes.
|
* Fire guacClientStateChange events when client state changes.
|
||||||
*/
|
*/
|
||||||
guacClient.onstatechange = function onClientStateChange(clientState) {
|
guacClient.onstatechange = function onClientStateChange(clientState) {
|
||||||
|
$scope.safeApply(function() {
|
||||||
|
|
||||||
switch (clientState) {
|
switch (clientState) {
|
||||||
|
|
||||||
// Idle
|
// Idle
|
||||||
case 0:
|
case 0:
|
||||||
$rootScope.$broadcast('guacClientStateChange', guacClient, "idle");
|
$scope.$emit('guacClientStateChange', guacClient, "idle");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Connecting
|
// Connecting
|
||||||
case 1:
|
case 1:
|
||||||
$rootScope.$broadcast('guacClientStateChange', guacClient, "connecting");
|
$scope.$emit('guacClientStateChange', guacClient, "connecting");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Connected + waiting
|
// Connected + waiting
|
||||||
case 2:
|
case 2:
|
||||||
$rootScope.$broadcast('guacClientStateChange', guacClient, "waiting");
|
$scope.$emit('guacClientStateChange', guacClient, "waiting");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Connected
|
// Connected
|
||||||
case 3:
|
case 3:
|
||||||
$rootScope.$broadcast('guacClientStateChange', guacClient, "connected");
|
$scope.$emit('guacClientStateChange', guacClient, "connected");
|
||||||
|
|
||||||
// Update server clipboard with current data
|
// Update server clipboard with current data
|
||||||
if ($rootScope.clipboard)
|
if ($scope.clipboard)
|
||||||
guacClient.setClipboard($rootScope.clipboard);
|
guacClient.setClipboard($scope.clipboard);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Disconnecting / disconnected are handled by tunnel instead
|
// Disconnecting / disconnected are handled by tunnel instead
|
||||||
case 4:
|
case 4:
|
||||||
case 5:
|
case 5:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Fire guacClientName events when a new name is received.
|
* Fire guacClientName events when a new name is received.
|
||||||
*/
|
*/
|
||||||
guacClient.onname = function onClientName(name) {
|
guacClient.onname = function onClientName(name) {
|
||||||
$rootScope.$broadcast('guacClientName', guacClient, name);
|
$scope.safeApply(function() {
|
||||||
|
$scope.$emit('guacClientName', guacClient, name);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -97,39 +98,43 @@ angular.module('client').factory('guacClientFactory', ['$rootScope',
|
|||||||
* error.
|
* error.
|
||||||
*/
|
*/
|
||||||
guacClient.onerror = function onClientError(status) {
|
guacClient.onerror = function onClientError(status) {
|
||||||
|
$scope.safeApply(function() {
|
||||||
|
|
||||||
// Disconnect, if connected
|
// Disconnect, if connected
|
||||||
guacClient.disconnect();
|
guacClient.disconnect();
|
||||||
|
|
||||||
$rootScope.$broadcast('guacClientError', guacClient, status.code);
|
$scope.$emit('guacClientError', guacClient, status.code);
|
||||||
|
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Fire guacClientClipboard events after new clipboard data is received.
|
* Fire guacClientClipboard events after new clipboard data is received.
|
||||||
*/
|
*/
|
||||||
guacClient.onclipboard = function onClientClipboard(stream, mimetype) {
|
guacClient.onclipboard = function onClientClipboard(stream, mimetype) {
|
||||||
|
$scope.safeApply(function() {
|
||||||
|
|
||||||
// Only text/plain is supported for now
|
// Only text/plain is supported for now
|
||||||
if (mimetype !== "text/plain") {
|
if (mimetype !== "text/plain") {
|
||||||
stream.sendAck("Only text/plain supported", Guacamole.Status.Code.UNSUPPORTED);
|
stream.sendAck("Only text/plain supported", Guacamole.Status.Code.UNSUPPORTED);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var reader = new Guacamole.StringReader(stream);
|
var reader = new Guacamole.StringReader(stream);
|
||||||
var data = "";
|
var data = "";
|
||||||
|
|
||||||
// Append any received data to buffer
|
// Append any received data to buffer
|
||||||
reader.ontext = function clipboard_text_received(text) {
|
reader.ontext = function clipboard_text_received(text) {
|
||||||
data += text;
|
data += text;
|
||||||
stream.sendAck("Received", Guacamole.Status.Code.SUCCESS);
|
stream.sendAck("Received", Guacamole.Status.Code.SUCCESS);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Emit event when done
|
// Emit event when done
|
||||||
reader.onend = function clipboard_text_end() {
|
reader.onend = function clipboard_text_end() {
|
||||||
$rootScope.$broadcast('guacClientClipboard', guacClient, data);
|
$scope.$emit('guacClientClipboard', guacClient, data);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -137,32 +142,34 @@ angular.module('client').factory('guacClientFactory', ['$rootScope',
|
|||||||
* the receipt of files.
|
* the receipt of files.
|
||||||
*/
|
*/
|
||||||
guacClient.onfile = function onClientFile(stream, mimetype, filename) {
|
guacClient.onfile = function onClientFile(stream, mimetype, filename) {
|
||||||
|
$scope.safeApply(function() {
|
||||||
|
|
||||||
// Begin file download
|
// Begin file download
|
||||||
var guacFileStartEvent = $rootScope.$broadcast('guacFileStart', guacClient, stream.index, mimetype, filename);
|
var guacFileStartEvent = $scope.$emit('guacFileStart', guacClient, stream.index, mimetype, filename);
|
||||||
if (!guacFileStartEvent.defaultPrevented) {
|
if (!guacFileStartEvent.defaultPrevented) {
|
||||||
|
|
||||||
var blob_reader = new Guacamole.BlobReader(stream, mimetype);
|
var blob_reader = new Guacamole.BlobReader(stream, mimetype);
|
||||||
|
|
||||||
// Update progress as data is received
|
// Update progress as data is received
|
||||||
blob_reader.onprogress = function onprogress() {
|
blob_reader.onprogress = function onprogress() {
|
||||||
$rootScope.$broadcast('guacFileProgress', guacClient, stream.index, mimetype, filename);
|
$scope.$emit('guacFileProgress', guacClient, stream.index, mimetype, filename);
|
||||||
stream.sendAck("Received", Guacamole.Status.Code.SUCCESS);
|
stream.sendAck("Received", Guacamole.Status.Code.SUCCESS);
|
||||||
};
|
};
|
||||||
|
|
||||||
// When complete, prompt for download
|
// When complete, prompt for download
|
||||||
blob_reader.onend = function onend() {
|
blob_reader.onend = function onend() {
|
||||||
$rootScope.$broadcast('guacFileEnd', guacClient, stream.index, mimetype, filename);
|
$scope.$emit('guacFileEnd', guacClient, stream.index, mimetype, filename);
|
||||||
};
|
};
|
||||||
|
|
||||||
stream.sendAck("Ready", Guacamole.Status.Code.SUCCESS);
|
stream.sendAck("Ready", Guacamole.Status.Code.SUCCESS);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
// Respond with UNSUPPORTED if download (default action) canceled within event handler
|
||||||
|
else
|
||||||
// Respond with UNSUPPORTED if download (default action) canceled within event handler
|
stream.sendAck("Download canceled", Guacamole.Status.Code.UNSUPPORTED);
|
||||||
else
|
|
||||||
stream.sendAck("Download canceled", Guacamole.Status.Code.UNSUPPORTED);
|
|
||||||
|
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
return guacClient;
|
return guacClient;
|
||||||
|
@@ -32,15 +32,11 @@ angular.module('client').factory('guacTunnelFactory', ['$rootScope', '$window',
|
|||||||
* Returns a new Guacamole tunnel instance, using an implementation that is
|
* Returns a new Guacamole tunnel instance, using an implementation that is
|
||||||
* supported by the web browser.
|
* supported by the web browser.
|
||||||
*
|
*
|
||||||
* @param {Scope} [$scope] The current scope. If ommitted, the root scope
|
* @param {Scope} $scope The current scope.
|
||||||
* will be used.
|
|
||||||
* @returns {Guacamole.Tunnel} A new Guacamole tunnel instance.
|
* @returns {Guacamole.Tunnel} A new Guacamole tunnel instance.
|
||||||
*/
|
*/
|
||||||
service.getInstance = function getTunnelInstance($scope) {
|
service.getInstance = function getTunnelInstance($scope) {
|
||||||
|
|
||||||
// Use root scope if no other scope provided
|
|
||||||
$scope = $scope || $rootScope;
|
|
||||||
|
|
||||||
var tunnel;
|
var tunnel;
|
||||||
|
|
||||||
// If WebSocket available, try to use it.
|
// If WebSocket available, try to use it.
|
||||||
@@ -56,32 +52,36 @@ angular.module('client').factory('guacTunnelFactory', ['$rootScope', '$window',
|
|||||||
|
|
||||||
// Fire events for tunnel errors
|
// Fire events for tunnel errors
|
||||||
tunnel.onerror = function onTunnelError(status) {
|
tunnel.onerror = function onTunnelError(status) {
|
||||||
$rootScope.$broadcast('guacTunnelError', tunnel, status.code);
|
$scope.safeApply(function() {
|
||||||
|
$scope.$emit('guacTunnelError', tunnel, status.code);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// Fire events for tunnel state changes
|
// Fire events for tunnel state changes
|
||||||
tunnel.onstatechange = function onTunnelStateChange(state) {
|
tunnel.onstatechange = function onTunnelStateChange(state) {
|
||||||
|
$scope.safeApply(function() {
|
||||||
|
|
||||||
|
switch (state) {
|
||||||
|
|
||||||
|
case Guacamole.Tunnel.State.CONNECTING:
|
||||||
|
$scope.$emit('guacTunnelStateChange', tunnel, 'connecting');
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Guacamole.Tunnel.State.OPEN:
|
||||||
|
$scope.$emit('guacTunnelStateChange', tunnel, 'open');
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Guacamole.Tunnel.State.CLOSED:
|
||||||
|
$scope.$emit('guacTunnelStateChange', tunnel, 'closed');
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
switch (state) {
|
});
|
||||||
|
|
||||||
case Guacamole.Tunnel.State.CONNECTING:
|
|
||||||
$rootScope.$broadcast('guacTunnelStateChange', tunnel, 'connecting');
|
|
||||||
break;
|
|
||||||
|
|
||||||
case Guacamole.Tunnel.State.OPEN:
|
|
||||||
$rootScope.$broadcast('guacTunnelStateChange', tunnel, 'open');
|
|
||||||
break;
|
|
||||||
|
|
||||||
case Guacamole.Tunnel.State.CLOSED:
|
|
||||||
$rootScope.$broadcast('guacTunnelStateChange', tunnel, 'closed');
|
|
||||||
break;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return tunnel;
|
return tunnel;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return service;
|
return service;
|
||||||
|
Reference in New Issue
Block a user