Uploaded image for project: 'Wicket'
  1. Wicket
  2. WICKET-6762

Support manual initialization of websocket connections

    XMLWordPrintableJSON

Details

    Description

      BaseWebSocketBehavior currently calls Wicket.WebSocket.createDefaultConnection() on DOM ready. I would like to be able to delay connection creation and trigger it myself.

      Desktop users of our application tend to open quite a number of tabs from search result pages and other lists and Wicket creates a new websocket connection for all tabs opened in the background. 

      I implemented a solution that uses the Page Visibility API to open and close websocket connections when a page becomes visible or hidden. Since I currently cannot disable the default connection, I'm closing the connection immediately:

      if (document.hidden) {
        if (Wicket.WebSocket.INSTANCE) {
          Wicket.WebSocket.INSTANCE.close();
        }
      }
      
      var connectFunction = function () {
        if (document.hidden) {
          if (Wicket.WebSocket.INSTANCE) {
            Wicket.WebSocket.INSTANCE.close();
          }
        } else {
          if (!Wicket.WebSocket.INSTANCE) {
            Wicket.WebSocket.createDefaultConnection();
          }
        }
      };
      document.addEventListener('visibilitychange', connectFunction, false);
      

      This works, but most browsers log an error like this:

      Connection failed. WebSocket is closed before the connection is established.
      

      A configuration option to disable automatic connection creation would solve this.

      Attachments

        Issue Links

          Activity

            People

              mgrigorov Martin Tzvetanov Grigorov
              thomas.heigl Thomas Heigl
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: