TwoStream is a WebSocket server for Laravel 5, built upon Ratchet. This package is currently in beta stage and not complete. The most important functionality has been built but could use some more testing.
TwoStream is Laravel 5 only.
TwoStream currently depends on a slightly modified version of Ratchet, which I hope will be added in the 4.x release. However, for the time being to get this dependency you need to add the repository and requirement below in your composer.json
.
For more information on how to install TwoStream, please visit the Documentation
"repositories": [
{
"type": "vcs",
"url": "https://github.com/CupOfTea696/Ratchet"
}
],
"require": {
"cboden/ratchet": "dev-master",
},
- ServiceProvider and Facades, add
'CupOfTea\TwoStream\TwoStreamServiceProvider',
to your providers, and'TwoStream' => 'CupOfTea\TwoStream\Facades\TwoStream',
and'WsRoute' => 'CupOfTea\TwoStream\Facades\WsRoute',
to your aliases inconfig/app.php
- Installation command; run
twostream:install
before trying to use anything. (seriously!) - WebSocket Server, boot with
twostream:listen
. - Routing, use
WsRoute::call
,WsRoute::publish
,WsRoute::subscribe
,WsRoute::unsubscribe
orWsRoute::controller
to define WebSocket routes inapp/Ws/routes.php
. For implicit controllers, use the verbscall
,publish
,subscribe
orunsubscribe
and define your functions according to the Laravel Docs. - Read-only Session data available in Ws Controllers via the WsSession Facade, add
'WsSession' => 'CupOfTea\TwoStream\Facades\WsSession',
to your aliases inconfig/app.php
- Send response to all subscribers, all excluding requestee or requestee.
- Push events from server to all or specific user (using sessionId)
- Push events from server to all or specific user. (to sessionId = ✓, to username/user object ✖) (zmq)
- Clean up some code
- Improve Error Handling
TwoStream is heavily based on Latchet. Some of the internal workings and public API is entirely different, other parts are near copy-pasted from the original code. The main difference between TwoStream and Latchet is Laravel 5 support and read-only access to Session data. If you are using Laravel 4, please do go and use Latchet since it is pretty good. (Although the creator claims it's not even an alpha version. Believe me, it is.) If you use Laravel 5 however, feel free to start testing this out and contribute.