/**
   * This starts a websocket connection with pub and if successful, sends a "assetIdToUrl" command
   * to pub to get the url to launch for the resource that was specifed in the launch configuration
   *
   * @param pubCallback - users should pass in a method to process the response for the
   *     "assetIdToUrl" command
   * @return true if the websocket connection was established and the command sent
   */
  public boolean connectToPub(PubCallback<String> pubCallback) {

    if (pubConnection != null && pubConnection.isConnected()) {
      return sendGetUrlCommand(pubCallback);
    } else {

      try {
        pubConnection =
            new PubConnection(new URI(NLS.bind(WEBSOCKET_URL, LOCAL_HOST_ADDR, PORT_NUMBER)));

        pubConnection.addConnectionListener(
            new PubConnectionListener() {
              @Override
              public void connectionClosed(PubConnection connection) {
                pubConnection = null;
              }
            });

        pubConnection.connect();

        return sendGetUrlCommand(pubCallback);

      } catch (URISyntaxException e) {
        DartDebugCorePlugin.logError(e);
        return false;
      } catch (IOException e) {
        DartDebugCorePlugin.logError(e);
        return false;
      }
    }
  }