This tutorial guides you through the process of implementing connection reconnection logic in your project. Follow the steps below to ensure a smoother experience for users during network instability by controlling display behavior and handling connection events efficiently.
Step 1: Adding disableDisplayWhileReconnecting Option
- Locate the vnc.js file within your project directory.
- Insert the following configuration option:

disableDisplayWhileReconnecting: true/false
This option dictates whether to display the interface during the reconnection process. Set it to true to activate this feature.
Step 2: Adding Connection Event Handlers
- In the
customSettings.vnc.js file, search for the following code segment:

vnc.onConnectionLost = function (jData) {
// -- TO CUSTOMIZE
helper.console.log("onConnectionLost", arguments);
};
vnc.onConnectionRestored = function (jData) {
// -- TO CUSTOMIZE
helper.console.log("onConnectionRestored", arguments);
};
Tailor the logic within each event handler according to your project's needs. You might want to display a notification to the user or execute certain operations when the connection is lost or successfully restored.
Step 3: Modifying Logic with Event Subscription
To adjust the default behavior, follow these steps to subscribe to the events and implement your customized logic:
Add return true; within each event handler to ensure your custom logic is utilized:

vnc.onConnectionLost = function (jData) {
// -- TO CUSTOMIZE
helper.console.log("onConnectionLost", arguments);
return true;
};
vnc.onConnectionRestored = function (jData) {
// -- TO CUSTOMIZE
helper.console.log("onConnectionRestored", arguments);
return true;
};
- Ensure that
return true; is included at the conclusion of each handler. This step is crucial for preventing the default handling mechanism or for the disableDisplayWhileReconnecting setting to be respected.
By carefully following these steps, you can effectively manage connection disruptions, providing a more resilient and user-friendly application environment.