dev-master
9999999-dev https://github.com/rapsspider/cake_ratchetRatchet Plugin for CakePHP 3.X
MIT
The Requires
by Jason Bourlard
plugin cakephp ratchet
Ratchet Plugin for CakePHP 3.X
ZeroMQ : http://www.zeromq.org/, (*1)
composer require rapsspider/cake_ratchet
Add this at the end of your config\app.php file:, (*2)
/** * Ratchet configuration */ 'CakeRatchet' => [ 'Server' => [ 'host' => '0.0.0.0', 'port' => 8080 ], 'ZMQServer' => [ 'host' => '127.0.0.1', 'port' => 5555 ], 'JSHelper' => true ]
Add this in your config\bootstrap.php file:, (*3)
Plugin::load('CakeRatchet', ['bootstrap' => true]);
It's possible you need to add this on your vendors/cakephp-plugins.php file:, (*4)
... 'plugins' => [ ... 'CakeRatchet' => $baseDir . '/vendor/rapsspider/cake_ratchet/', ... ]
First, you need to start the server, to do this just run this command on your cakephp folder : .\bin\cake ratchet start, (*5)
namespace App\Controller; use (@TODO)\Pusher; public class MyController { public function index() { Pusher::send('my_topic','my_message'); } }
If JSHelper is activate, an fonction will be available:, (*6)
<script> var onConnect = function(connection) { connection.subscribe('my_topic', function(topic, data) { // This is where you would add the new article to the DOM (beyond the scope of this tutorial) console.log('New article published to category "' + topic + '" : '); console.log(data); }); }; var onClose = function(connection) { }; CakeRatchet.connection(onConnect, onClose); </script>
Else, you can do this :, (*7)
<script src="http://autobahn.s3.amazonaws.com/js/autobahn.min.js"></script> <script> var conn = new ab.Session('ws://localhost:8080', function() { conn.subscribe('my_topic', function(topic, data) { // This is where you would add the new article to the DOM (beyond the scope of this tutorial) console.log('New article published to category "' + topic + '" : '); console.log(data); }); console.log('Connexion réussie'); }, function() { console.warn('WebSocket connection closed'); }, {'skipSubprotocolCheck': true} ); </script>
Ratchet Plugin for CakePHP 3.X
MIT
plugin cakephp ratchet