Next open terminal and cd into your Laravel project directory.
run php artisan list and confirm you see the brainsocket: command in the list of commands. It should look like this:
Once you have confirmed the list, run the following command to start the WebSocket server:
php artisan brainsocket:start
Note: The websocket server runs on port 8080 by default. You can change this with the optional --port=port_number on the end of the artisan command.
php artisan brainsocket:start --port=8081
At this point you should see a message in the terminal saying the websocket has been started on the selected port. Terminal will be locked down / unusable at this point, to stop the WebSocket server
hit ctrl+c in the terminal.
Note: Any changes to your laravel app / code while the ws server is running are not taken into account. You need to restart the ws server to see any of your changes.
Lets stop the ws server now by hitting ctrl+c in the terminal.
Next in your app/ folder create a file called events.php
Lets add the following code to events.php:
returnBrainSocket::message('generic.event',array('message'=>'A message from a generic event fired in Laravel!'));
returnBrainSocket::success(array('There was a Laravel App Success Event!'));
returnBrainSocket::error(array('There was a Laravel App Error!'));
Note: The $client_data parameter passed into the event listener is a POPO (Plain Old PHP Object) with all of the data passed from the client side.
Note: The app.success and app.error events are not required but are helper events for dealing with flash messaging.
Now in app/start/global.php add the following line at the end of the file:
Great! Now we have a few events to test out on the client side. Run the artisan command php artisan brainsocket:start to start the ws server again.
To make things easier we have created a simple js helper that allows us to interact with our new ws server a bit easier.
It's not required but it handles some minor formatting tasks in the background so you don't have to and pairs nicely with our BrainSocket Facade.