title: Web Socket connection with Basic Access Authentication
body: <p>I'm trying to establish connection (client side) with Web Socket which requires Basic Access Authentication. From documentation I know that I should use username and password with base64 encryption. It's node.js application so I decide to use npm package SockJS-client. It seems to be good solution because:</p>
  
  <blockquote>
    <p>Under the hood SockJS tries to use native WebSockets first. If that fails it can use a variety of browser-specific transport protocols and presents them through WebSocket-like abstractions.</p>
  </blockquote>
  
  <p>But I have no clue how to establish connection using Basic Access Authentication. I have tried solution from <a href="https://stackoverflow.com/questions/4361173/http-headers-in-websockets-client-api">here</a>, but this one</p>
  
  <pre><code>var ws = new WebSocket("ws://username:password@example.com/service");
  </code></pre>
  
  <p>does not work, I got an error like: </p>
  
  <blockquote>
    <p>SyntaxError: The URL's scheme must be either 'http:' or 'https:'. 'ws:' is not allowed.</p>
  </blockquote>
  
  <p>When I'm trying with <em>http/https</em> I got:</p>
  
  <blockquote>
    <p>Error: InvalidStateError: The connection has not been established yet</p>
  </blockquote>
  
  <p>When I'm trying to call </p>
  
  <pre><code>sock.send('test');
  </code></pre>
  
  <p>Another solutions like that below is impossible to implement because I have no access to server side of Web Socket.</p>
  
  <pre><code>var ws = new WebSocket("ws://example.com/service?key1=value1&amp;key2=value2");
  </code></pre>
  
  <p>I have no idea how to correctly establish authenticated connection with Web Socket, if you know any solutions let me know.</p>