Data Navigation Session is not Closed After Browser is Closed

Updated Jan 4, 2023

Reported In

Software

  • SystemLink Server
  • SystemLink TDM DataFinder Module
  • G Web Development Software

Issue Details

I am creating a web application. It uses Javascript to communicate with SystemLink Server via HTTP API. I realise that the opened Data Navigation session is not closed automatically after the browser is closed.

Since each opened Data Navigation session will consume one of the purchased SystemLink TDM Datafinder Module user licenses, how can I have the session close automatically once the browser or its tab is closed to let the end user have a better user experience?

Solution

This is an expected behaviour. Data Navigation session will not be closed automatically when the browser or its tab is closed. The developer has to capture the close browser event using onbeforeunload event to close the session programmatically. 

Simple HTML below can be used as a reference to understand how this can be implemneted
<!DOCTYPE html>
<html lang="en">

    <body>
        Hello world!
    </body>
    <script>
        var id = "";
    
        window.addEventListener("beforeunload", (event) => {
            event.preventDefault()
            event.returnValue = '';
            closeSession();
        });
        
        window.addEventListener("load", (event) => {
            alert("Welcome. Datafinder session will be created next.");
            createSession();
        });
        
        function createSession(){
            var data = JSON.stringify({"variables":{"$URL":{"stringArray":{"values":["corbaname::#DataFinder_Name.ASAM-ODS"]}}}});
            var xhr = new XMLHttpRequest();
            xhr.withCredentials = true;
            xhr.addEventListener("readystatechange", function() {
              if(this.readyState === 4) {
                id = this.getResponseHeader("Location").split("/").pop();
                alert("Session created: " + id);
              }
            });
            xhr.open("POST", "https://SystemLink_Server_IP_Address/ni/asam/ods");
            xhr.setRequestHeader("Accept", "application/x-asamods+json");
            xhr.setRequestHeader("Content-Type", "application/x-asamods+json");
            xhr.setRequestHeader("X-NI-Auth-Method", "Basic");
            xhr.setRequestHeader("Authorization", "Basic Base64_Encoded_Username:Password");
            xhr.send(data);
        }
        
        function closeSession(){
            var xhr = new XMLHttpRequest();
            xhr.withCredentials = true;
            xhr.open("DELETE", "https://SystemLink_Server_IP_Address/ni/asam/ods/ni/asam/ods/" + id);
            xhr.setRequestHeader("Accept", "application/x-asamods+json");
            xhr.setRequestHeader("Content-Type", "application/x-asamods+json");
            xhr.setRequestHeader("X-NI-Auth-Method", "Basic");
            xhr.setRequestHeader("Authorization", "Basic Base64_Encoded_Username:Password");
            xhr.send();
        }
    </script>
</html>


 

Additional Information

When the HTML is opened in Google Chrome, it will create a Data Navigation session. When the browser is closed or refreshed, the session will be closed.