2017 © Pedro PelĂĄez
 

plugin cake_ratchet

Ratchet Plugin for CakePHP 3.X

image

rapsspider/cake_ratchet

Ratchet Plugin for CakePHP 3.X

  • Wednesday, July 8, 2015
  • by rapsspider
  • Repository
  • 1 Watchers
  • 2 Stars
  • 12 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Ratchet Plugin for CakePHP 3.X

Requirements

ZeroMQ : http://www.zeromq.org/, (*1)

Installation

composer require rapsspider/cake_ratchet

Configuration

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/',
    ...
]

Start

First, you need to start the server, to do this just run this command on your cakephp folder : .\bin\cake ratchet start, (*5)

Examples

Server

namespace App\Controller;
use (@TODO)\Pusher;

public class MyController {

    public function index() {
        Pusher::send('my_topic','my_message');
    }

}

Client

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>

The Versions

08/07 2015

dev-master

9999999-dev https://github.com/rapsspider/cake_ratchet

Ratchet Plugin for CakePHP 3.X

  Sources   Download

MIT

The Requires

 

by Jason Bourlard

plugin cakephp ratchet