Events

Top  Previous  Next

The events parameter allows you to handle each one of the available ThinRDP events from the SDK.

 

events: {

         onServerConnecting           : function (reconnecting) { },

         onServerConnect              : function () { },

         onQueryDisconnect            : function () { },

         onServerConnectionError      : function (errMessage) { },

         onServerDisconnect           : function () { },

         onExecResult                 : function (cmd) { },

         onSessionStart               : function () { },

         onSessionEnd                 : function (message) { },

 }

 

 

Observe on the code above that all the event functions are empty. On the following table you can find a description, parameters and a use example for each one of the available events:

 

Event

Parameters

When it is triggered

Example

onServerConnecting

reconnecting

This event is fired during the server connection establishment.

The 'reconnecting' argument informs whether this is a reconnection or a first-time connection.

onServerConnecting  :

 

function (reconnecting) {

   $.blockUI("Establishing connection");

}

onServerConnect

obj

The "onServerConnect" event is fired every time a "connect" command is exchanged between the browser and the ThinRDP Server. It is a way of making sure the server received a sent "connect" command.

If you have shown a message on the onServerConnecting, this would be a good moment to hide that message ($.unblockUI();).

The 'obj' parameter ships the generated connection object.

onServerConnect  :

 

function (obj) {

    $.unblockUI();

}

onQueryDisconnect

-

Anytime the Web client is about to be disconnected, the "onQueryDisconnect" will

be triggered. This is useful to ask the user for confirmation before proceeding to disconnect.

onQueryDisconnect: function () {

 

if (confirm("A remote session is active. Are you sure you want to disconnect?"))

{

mythinrdp.disconnect();

}

}

onServerConnectionError

errMessage

If an error prevents the client connection to be established, this event will be fired. The errMessage argument brings the error message.

onServerConnectionError: function (errMessage){

 

alert("connect error: " + errMessage);

 

}

onServerDisconnect

-

Anytime the Web client gets disconnected from the ThinRDP server, the "onServerDisconnect" event will be fired. It could be triggered because the connection was lost incidentally or also because the user disconnected from the server on purpose.

onServerDisconnect: function () {

 

alert("disconnect");

$.unblockUI();

mythinrdp.updateTools();

$("#" + mythinrdp.rcParams.divId).hide();

 

}

onExecResult

cmd

This event fires only when the SDK is integrated with a remoteApp application.

Through this event it is possible to get to know if the remoteApp was started or if there was an error during the application start up.

If the application was started without errors, the cmd.rc is going to be 0, otherwise cmd.rc will carry the application error code. As you can see on the example below you can also get the executable name accessing the cmd.exename value.

onExecResult: function (cmd) {

 

alert("exename: " + cmd.exename + " rc: " + cmd.rc);

 

}

onSessionStart

-

This event will be fired when the client session has been started on ThinRDP Server.

onSessionStart: function () {

 

$("#" + mythinrdp.rcParams.divId).show();

mythinrdp.updateTools();

 

}

onSessionEnd

message

As soon as the client Session is closed, the "onSessionEnd" event will be fired.

onSessionEnd: function (message) {

 

alert(message);

 

},

 

note

 

These event usage reference can also be found in the sdk.html file, located in the application directory, under the "webrdp" directory.

note

 

In versions previous to 2.2.0.20 the SDK events had a different syntax. That old sintax is still compatible with newer versions. However, it is highly recommended to translate the old code to the method described above.

This is how the previous event names are related to new ones:

 

Old Event Name

Current Event Name

establishingConnection

onServerConnecting

serverConnect

onServerConnect

execResult

onServerConnect

sessionStart

onSessionStart

serverConnectionError

onServerConnectionError

disconnectConfirmRequest

onQueryDisconnect

serverDisconnect

onServerDisconnect

sessionEnd

onSessionEnd