-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
11 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,6 @@ | ||
# Laravel Ratchet Server | ||
|
||
**This is an updated fork of [Laravel Ratchet](https://github.com/Askedio/laravel-ratchet), built specifically to work with this [custom fork](https://github.com/simonhamp/echo) of Laravel Echo.** | ||
|
||
This fork enables you to create and run a fully functioning WebSocket server in your Laravel app that can receive messages from ZeroMQ. | ||
This package enables you to create and run a fully functioning WebSocket server in your Laravel app. It can optionally receive messages broadcast over ZeroMQ. | ||
|
||
## Requirements | ||
|
||
|
@@ -13,31 +11,21 @@ This fork enables you to create and run a fully functioning WebSocket server in | |
|
||
## Installation | ||
|
||
Because this is a custom fork and it relies on another custom package (and because I want to maintain compatibility with the original repos), the installation is a little more complicated (for now). You must do all of this in your `composer.json` manually: | ||
|
||
```json | ||
"require": { | ||
"askedio/laravel-ratchet": "^2.0" | ||
}, | ||
"repositories": [ | ||
{ | ||
"type": "git", | ||
"url": "[email protected]:simonhamp/laravel-ratchet.git" | ||
} | ||
] | ||
```bash | ||
$ composer require askedio/laravel-ratchet | ||
``` | ||
|
||
The service provider is loaded automatically in Laravel 5.5 using Package Autodiscovery. | ||
|
||
You **MUST** publish the vendor files so you can configure your server defaults. | ||
Publish the vendor files so you can configure your server defaults. | ||
|
||
```bash | ||
$ php artisan vendor:publish --provider=LaravelRatchetServiceProvider | ||
$ php artisan vendor:publish --provider="Askedio\LaravelRatchet\Providers\LaravelRatchetServiceProvider" | ||
``` | ||
|
||
## Starting the Server | ||
|
||
The quickest way to start a standard WebSocket server is simply by running: | ||
After completing installtion, the quickest way to start a standard WebSocket server is simply by running: | ||
|
||
```bash | ||
$ php artisan ratchet:serve --driver=WsServer | ||
|
@@ -51,26 +39,17 @@ You should create your own server class inside your `app` folder by extending on | |
|
||
Then update your `config/ratchet.php` file to point to your server `class`. | ||
|
||
## Use with Laravel Echo and Broadcasting | ||
## Use with Laravel Broadcasting | ||
|
||
To use broadcasting in your Laravel app with the server you create, you will need to tell the server to connect to a ZeroMQ socket. | ||
To use broadcasting in your Laravel app with the server you create, you will need a ZeroMQ broadcast driver for Laravel. | ||
|
||
You can do this simply by passing the `-z` option, i.e.: | ||
You will also need to tell your Ratchet server to bind to a ZeroMQ socket. You can do this simply by passing the `-z` option, i.e.: | ||
|
||
```bash | ||
$ php artisan ratchet:serve --driver=WsServer -z | ||
``` | ||
|
||
This will connect to the socket you define in your `config/ratchet.php` settings. | ||
|
||
**You MUST set the `ratchet.zmq.method` option to `\ZMQ::SOCKET_PULL` to work with broadcasting.** | ||
|
||
Be sure to install [my fork of `laravel-zmq`](https://github.com/simonhamp/laravel-zmq) to go along with this package. | ||
|
||
This will allow you to use ZeroMQ as the back-channel to broadcast your events from your Laravel application to your Ratchet WebSocket server. | ||
|
||
For your web clients to subscribe to channels through Ratchet, you will need to install [this custom fork of Laravel Echo](https://github.com/simonhamp/echo). | ||
This will connect to the socket you define in your `config/ratchet.php` settings and listen for messages from ZeroMQ. | ||
|
||
## Acknowledgements | ||
To handle messages published via ZeroMQ, simply add a `public function onEntry($messages)` method to your server class. This will allow you to receive messages inside your Ratchet server instance and determine how to route them. | ||
|
||
This package would not be possible without the initial [awesome work](https://github.com/Askedio/laravel-ratchet) of [@gcphost](https://github.com/gcphost) of [Asked.io](https://medium.com/asked-io). |