Websocket problem

Hi. I try to use Websocket in adonis, but i get a error on the client side, when perform this code:

<html>
<head>
<script src="https://unpkg.com/@adonisjs/websocket-client"></script>
<script 
const ws = adonis.Ws('ws://localhost:3333')
</script>
</head>
<body>

</body>
</html>

Error: Uncaught TypeError: adonis.Ws is not a function
Please, help! Sorry for my english.

Hi greycat,

The build requires the regenerator-runtime polyfill, you will need babel-polyfill .

thank you!

can i use native browser websockets on the client side with adonis websocket system on the server side?
I have tried do it already, server response the 400 code with message ‘Bad request’

Can you share what exactly you trying to do?

try this simple example.

<html>
  <head>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/babel-polyfill/7.4.4/polyfill.min.js"></script>
    <script src="https://unpkg.com/@adonisjs/websocket-client"></script>
    <script>
      function startWebSocket() {
        ws = adonis.Ws("ws://127.0.0.1:3333").connect();

        ws.on("open", () => {
          subscribeToChannel();
        });

        ws.on("error", () => {
          console.log('error: open websocket')
        });
      }

      function subscribeToChannel() {
        const chat = ws.subscribe("room");

        chat.on("error", () => {
          console.log("error: subscribe to channel room");
        });

        chat.on("message", message => {
          console.log("message=" + message);
        });
      }

      startWebSocket()
    </script>
  </head>
  <body></body>
</html>

it works! but what about npm?

Hey @greycat! :wave:

Here’s the documentation on same: https://babeljs.io/docs/en/babel-polyfill