2017 © Pedro Peláez
 

cakephp-plugin ratchet-commands

Brings 2 way communication to wyrihaximus/ratchet.

image

wyrihaximus/ratchet-commands

Brings 2 way communication to wyrihaximus/ratchet.

  • Thursday, January 22, 2015
  • by WyriHaximus
  • Repository
  • 1 Watchers
  • 0 Stars
  • 47,047 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 5 Open issues
  • 2 Versions
  • 9 % Grown

The README.md

RatchetCommands

Build Status Latest Stable Version Total Downloads Coverage Status Bitdeli Badge, (*1)

RatchetCommands lets your application communicate messages to the Ratchet server instance., (*2)

Getting started

1. Requirements

This plugin depends on the following plugin and libraries and are pulled in by composer later on:, (*3)

2. Composer

Make sure you have composer installed and configured with the autoloader registering during bootstrap as described here. Make sure you have a composer.json and add the following to your required section., (*4)

composer require wyrihaximus/ratchet-commands 

3. Setup the plugin

Make sure you load RatchetCommands in your bootstrap and the Ratchet plugin is setup properly., (*5)

4. Building a command

Filename: Lib/MessageQueue/Command/BroadcastCommand.php, (*6)

class BroadcastCommand extends RatchetMessageQueueCommand {

    public function serialize() {
        return serialize(array(
            'data' => $this->data,
        ));
    }

    public function unserialize($commandString) {
        $commandString = unserialize($commandString);
        $this->setData($commandString['data']);
    }

    public function setData($data) {
        $this->data = $data;
    }

    public function getData() {
        return $this->data;
    }

    // Send a broadcast on the channel `channel` with the data sent with the command
    // (This runs in the Ratchet instance.)
    public function execute($eventSubject) {
        $topics = $eventSubject->getTopics();
        if (isset($topics['channel'])) {
            $topics['channel']->broadcast($this->getData());
        }

        return true;
    }

    // Handle the response
    // (This runs in the application.)
    public function response($response) {
        if ($response) {
            // Handle success
        } else {
            // Handle failure
        }
    }
}

Besure to App::uses the command in your bootstrap so the Ratchet instance knows where to load it from., (*7)

5. Sending the message

App::uses('TransportProxy', 'RatchetCommands.Lib/MessageQueue/Transports');
$command = new BroadcastCommand();
$command->setData([
    'time' => time(),
]);
TransportProxy::instance()->queueMessage($command);

Plugin License

(The MIT License), (*8)

Copyright © 2012 - 2013 Cees-Jan Kiewiet, (*9)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:, (*10)

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software., (*11)

THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE., (*12)

The Versions

22/01 2015

dev-master

9999999-dev http://github.com/WyriHaximus/RatchetCommands

Brings 2 way communication to wyrihaximus/ratchet.

  Sources   Download

MIT

The Requires

 

The Development Requires

cakephp

22/01 2015

0.1.0

0.1.0.0 http://github.com/WyriHaximus/RatchetCommands

Brings 2 way communication to wyrihaximus/ratchet.

  Sources   Download

MIT

The Requires

 

The Development Requires

cakephp