Get support for WyriHaximus/RatchetCommands

If you're new to LTH, please see our FAQ for more information on what it is we do.

Support Options

Unfortunately, there are currently no active helpers for this repository on the platform. Until they become available, we reccomend the following actions:

View Open Issues

Take a look to see if anyone else has experienced the same issue as you and if they managed to solve it.

Open an Issue

Make sure to read any relevant guidelines for opening issues on this repo before posting a new issue.

Sponsor directly

Check out the page and see if there are any options to sponsor this project or it's developers directly.

WyriHaximus/RatchetCommands

RatchetCommands

Build Status Latest Stable Version Total Downloads Coverage Status Bitdeli Badge

RatchetCommands lets your application communicate messages to the Ratchet server instance.

Getting started

1. Requirements

This plugin depends on the following plugin and libraries and are pulled in by composer later on:

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.

composer require wyrihaximus/ratchet-commands 

3. Setup the plugin

Make sure you load RatchetCommands in your bootstrap and the Ratchet plugin is setup properly.

4. Building a command

Filename: Lib/MessageQueue/Command/BroadcastCommand.php

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.

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)

Copyright © 2012 - 2013 Cees-Jan Kiewiet

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:

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

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.

Our Mission

We want to make open source more sustainable. The entire platform was born from this and everything we do is in aid of this.

Interesting Articles

Thank you for checking out LiveTechHelper |
2025 © lth-dev incorporated

p-e622a1a2