Good morning everyone.
I have a project in Laravel in which I want to connect to a websocket of which I have the URI, the ClientToken and AccesToken. The problem I have is that I have tried several methods to use websockets in Laravel, but none of them works for me. I have the following code:
use WebSocketClient; class MewsWebSocket extends Controller { public function index() { $client = new Client("wss://ws.mews-demo.com/ws/connector?ClientToken=E0D439EE522F44368DC78E1BFB03710C-D24FB11DBE31D4621C4817E028D9E1D&AccessToken=C66EF7B239D24632943D115EDE9CB810-EA00F8FD8294692C940F6B5A8F9453D"); while (true) { $message = $client->receive(); echo “Message received: {$message}”; sleep(1); } } }
(There is no problem showing the tokens as they are public for the demo environment).
The problem I have is that I have copied the host and used it in another file that I have created in js to see if the URI works, and if I connect to the socket and receive messages, while with the PHP code does not.
const WebSocket = require('ws');
let ws = new WebSocket("wss://ws.mews-demo.com/ws/connector? ClientToken=E0D439EE522F44368DC78E1BFB03710C-D24FB11DBE31D4621C4817E028D9E1D&AccessToken=C66EF7B239D24632943D115EDE9CB810-EA00F8FD8294692C940F6B5A8F9453D");
ws.onmessage = function(ms) {
console.log(ms.data);
}
I wanted to know if anyone knows any way to use websockets in Laravel in the way I need it for my project.