2017 © Pedro Peláez
 

library websocket-handler

websocket handler

image

alexboo/websocket-handler

websocket handler

  • Friday, January 26, 2018
  • by alexboo
  • Repository
  • 1 Watchers
  • 0 Stars
  • 202 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 0 % Grown

The README.md

WebSocketHandler

A small library to define a handler for web socket command, (*1)

Install

You can install it library with composer, (*2)

composer require alexboo/websocket-handler

Using

Yoy need create Handler factory for create handler for the processing of each command. It must implements HandlerFactoryInterface. In Handler factory you can add ACL before create handler., (*3)

Example handler factory


class HandlerFactory implements HandlerFactoryInterface { /** * Get handler for command * @param Client $client * @param $command * @return Handler */ public function getHandler(Client $client, $command) { $handler = new Handler(); switch ($command) { case "auth": $handler->setObject(new AuthService(), "auth"); break; case "message": $handler->setClosure(function(){ // do something }); break; } return $handler; } /** * Client open connection * @param Client $client * @return mixed */ public function open(Client $client){ } /** * Client close connection * @param Client $client * @return mixed */ public function close(Client $client) { } }

Then you can start web socket server, (*4)

$wsHandler =  WebSocketHandler::getInstance(new HandlerFactory());

$ioServer = IoServer::factory(
    new HttpServer(new \Ratchet\WebSocket\WsServer($wsHandler)),
    8001
);

$ioServer->run();

Parameters that must be passed to the handler defined on the basis ReflectionApi. You can request information about the client specifying the parameters of the "Client" class or query parameters in object implements Alexboo\WebSocketHandler\Interfaces\RequestInterface., (*5)

Example

``` class AuthRequest implements RequestInterface { public function setData($data){, (*6)

}

}, (*7)

class AuthService {, (*8)

public function auth(Client $client, AuthRequest $request)
{

}

}, (*9)

```, (*10)

The Versions

26/01 2018

dev-master

9999999-dev https://github.com/alexboo/websocket-handler

websocket handler

  Sources   Download

GPLv2 LGPL-3.0

The Requires

 

by Alexey Bulybin

websocket handler

11/01 2016

0.2.2.x-dev

0.2.2.9999999-dev https://github.com/alexboo/websocket-handler

websocket handler

  Sources   Download

GPLv2

The Requires

 

by Alexey Bulybin

websocket handler

11/01 2016

0.2.1.x-dev

0.2.1.9999999-dev https://github.com/alexboo/websocket-handler

websocket handler

  Sources   Download

GPLv2

The Requires

 

by Alexey Bulybin

websocket handler

10/01 2016

0.2.x-dev

0.2.9999999.9999999-dev https://github.com/alexboo/websocket-handler

websocket handler

  Sources   Download

GPLv2

The Requires

 

by Alexey Bulybin

websocket handler

02/12 2015

0.1.x-dev

0.1.9999999.9999999-dev https://github.com/alexboo/websocket-handler

websocket handler

  Sources   Download

GPLv2

The Requires

 

by Alexey Bulybin

websocket handler