title: How to pass message to websocket?
body: <p>I have a twig template and I am trying to send message having same token in url Meaning message send from <code>http://url/{token1}</code> from should only be recived by another url with same token.</p>
  <p>But I am not being able to pass any message from twig to node to symfony.</p>
  <h2>index.html.twig</h2>
  <pre><code>&lt;div id=&quot;chat&quot;&gt;
  
  &lt;/div&gt;
  &lt;div&gt;
      &lt;div class=&quot;form-group&quot;&gt;
          &lt;label for=&quot;name&quot;&gt;Name:&lt;/label&gt; &lt;input type=&quot;text&quot; id=&quot;name&quot;&gt;
      &lt;/div&gt;
      &lt;div class=&quot;form-group&quot;&gt;
          &lt;label for=&quot;message&quot;&gt;Message:&lt;/label&gt; &lt;input type=&quot;text&quot; id=&quot;message&quot;&gt;
      &lt;/div&gt;
      &lt;button type=&quot;button&quot; id=&quot;sendBtn&quot; class=&quot;btn-primary&quot;&gt;Send&lt;/button&gt;
  &lt;/div&gt;
  
  &lt;script src=&quot;/bin/ws-broker.js&quot;&gt;&lt;/script&gt;
  &lt;script&gt;
      const socket = new WebSocket(&quot;ws://localhost:8080&quot;);
      document.getElementById(&quot;sendBtn&quot;).addEventListener(&quot;click&quot;, function() {
          const message = {
              name: document.getElementById(&quot;name&quot;).value,
              message: document.getElementById(&quot;message&quot;).value
          };
          socket.send(JSON.stringify(message));
      });
  &lt;/script&gt;
  </code></pre>
  <h2>/bin/ws-broker.js</h2>
  <pre class="lang-js prettyprint-override"><code>const WebSocket = require('ws');
  const qs = require('querystring');
  const wss = new WebSocket.Server({ port: 8080 });
  const http = require('http');
  
      wss.on('connection', function connection(ws, req)
      {
          console.log('Connection Received from IP: ' + req.socket.remoteAddress);
          ws.on('message', function incoming(message) {
              if ('' === message) {
                  //empty message
                  return;
              }
              try {
                  //process message as JSON object
                  message = JSON.parse(message);
              } catch (e) {
                  //failed parsing the message as JSON
                  return;
              }
      
          });
      });
      
      console.log('Listening on port 8080');
  </code></pre>
  <h2>Controller</h2>
  <pre class="lang-php prettyprint-override"><code>    /**
       * @Route(&quot;/{token}&quot;, name=&quot;home&quot;)
       */
      public function index(): Response
      {
          return $this-&gt;render('home/index.html.twig', [
              'controller_name' =&gt; 'HomeController',
          ]);
      }
  </code></pre>