Download the PHP package votong/websocket-async without Composer
On this page you can find all versions of the php package votong/websocket-async. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download votong/websocket-async
More information about votong/websocket-async
Files in votong/websocket-async
Package websocket-async
Short Description Laravel Websocket based on Ratchet, support pub/sub feature.
License
Informations about the package websocket-async
Laravel WebSocket server
WebSocket server based on Ratchet. Built to be completely event driven so it can used in several different project without having to manipulate the base code.
Installation
Add require
and repositories
information in the projects composer.json
file:
Now its time to run composer update
in your terminal.
After the update is complete the service provider needs to be registered in app/config/app.php
inside the providers
array:
Server side configuration
Run the following command in the projects root folder to startup the WebSocket server. By default the server will be run on port 8080 but by adding --port=[number]
at the end of the command it is possible to change to any desired port.
This will startup a deamon service that will estsblish the WebSocket server. To make sure that command is constantly running it is recommended to use Supervisord to supervice the deamon.
Client side listener
This service comes included with the nessesary JavaScripts. To include these into the projects assets folder run the following command.
After that add thins line into the template file.
To estalish a WebSocket client add the following code.
The avilible configurations are:
Messages can be sent through the socket as soon as the connection is established. The first parameter is a event name that will be sent to the backend as a tracing event for easyer filtering. The second parameter is the message and can contain a string or a JSON.
Messages that are sent back from the server to the client contains a JSON with two elements, origData
and data
. OrigData contains any data that have been sent as a message and the server has responded to and data contains the reponse data from the server.
Add Event Listensers to responed/listen to anything that happneds in the WebSocket.
Events that will be fired is:
Server side listener
The server needs to be able to respond to any new connections or messages that are sent by the client. This is done by Laravels event listener. This can be setup in different ways but to recommented way is to use events.php
.
If events.php
is not already in the 'app/' folder create the file and after that open up 'app/start/global.php' and make sure the follwoing line is in the end of the file.
All events that will be handled by the server should now be placed inside events.php
:
$connection
or $from
(depending on the event) has the following functions.
The send
function will send the message to the client. If an event or sessionId needs to be specified this must be done before the message is sent.