0

I am preparing to build a WebSockets system to have a bidirectional communication from my server to my clients through WebSockets.

I know that Laravel now very well supports 3rd parties like Pusher Channels and Ably. There are also some other ways that are also very convenient and simple to use such as Laravel Websockets, soketi, laravel-echo-server.

But my problem is client-side cannot include 3rd party Client Library. My client-side is a Cross-platform Game based on Javascript and HTML5. I can only connect client-side to server-side through WebSocket. As far as I know, when using 3rd party for server-side, I should use their JS Client Library like pusher/pusher-js, laravel/echo ... Therefore, I can't find any documents if I want to use them with WebSocket.

My goal is to find the best and most suitable solution for both client and server side.

What I have tried?

IDEA 1: Convert pusher.js to my own js

I spent 2 weeks on this. I see this as possible and some functions might work. However, it will take a long time if I want to convert the whole thing.

IDEA 2: Using Pusher and connect the client via Pusher Channels Protocol

I have tested them as follows

var socket = new WebSocket('ws://ws-[cluster_name].pusher.com:[port]/app/[key]');

It worked. I can see them connected on the Pusher Debug Console. However, I can't find any documentation regarding the basics like Subcribe channel, Listening events, Send message to other client, Ping, Pong, ...

IDEA 3: Using Laravel Websockets

Like idea 2, I couldn't find any documentation or examples.

IDEA 4: Using NodeJS instead of Laravel. Choose ws packages

I tried it and it worked as expected. WS is really simple but it is exactly what I want. However I don't have many years of NodeJS experience. Therefore, I feel there are many risks if I choose it to build a new project.

Could you tell me a best way to deal with this problem?

Thanks

Ryo
  • 49
  • 1
  • 8
  • 1
    Please check: https://laravel.com/docs/9.x/broadcasting You missed this part: The laravel-websockets and soketi packages provide Pusher compatible WebSocket servers for Laravel. These packages allow you to leverage the full power of Laravel broadcasting without a commercial WebSocket provider. -> The documentation for their use is literally the same. – Daniel L Aug 11 '22 at 10:02
  • Hi @daniel-l, I have read and tested them before. ```laravel-websockets``` is actually interoperable with traditional Websocket. However, they do document how to use ```pusher-js``` on the client-side. Same with [link](https://github.com/beyondcode/laravel-websockets/issues/139) – Ryo Aug 11 '22 at 10:54
  • You use it exactly the same way you'd use it with Pusher. All you need is [a couple configuration variables](https://beyondco.de/docs/laravel-websockets/basic-usage/pusher#pusher-configuration) to point it at the `laravel-websockets` or `socketi` instance instead of Pusher.com. Everything else works the same. The `pusher-js` JS client is what you want, even if you're using a Pusher alternative on the server-side. – ceejayoz Nov 04 '22 at 00:42

1 Answers1

1

The Pusher and Laravel Echo JavaScript clients work with any Pusher-compatible websockets host. (Pusher uses websockets, too.)

All it takes is a little configuration; see, for example, Laravel Websockets' guide on configuring Laravel and then configuring Echo. Both steps point your Pusher requests at your chosen Pusher replacement instead.

No need to write your own library or manually consume websocket data.

ceejayoz
  • 176,543
  • 40
  • 303
  • 368