Pass message value, isBinary indicator

Passing message contents instead of string to keep BC
Passing isBinary indicator regardless of interface
This commit is contained in:
Chris Boden 2016-02-27 13:04:10 -05:00
parent 365e8702ff
commit 7e42bfe2ac
2 changed files with 8 additions and 2 deletions

View File

@ -106,7 +106,7 @@ class WsServer implements HttpServerInterface {
$streamer = new MessageBuffer( $streamer = new MessageBuffer(
$this->closeFrameChecker, $this->closeFrameChecker,
function(MessageInterface $msg) use ($wsConn) { function(MessageInterface $msg) use ($wsConn) {
$this->delegate->onMessage($wsConn, $msg); $this->delegate->onMessage($wsConn, $msg->getPayload(), $msg->isBinary());
}, },
function(FrameInterface $frame) use ($wsConn) { function(FrameInterface $frame) use ($wsConn) {
$this->onControlFrame($frame, $wsConn); $this->onControlFrame($frame, $wsConn);

View File

@ -2,12 +2,18 @@
require dirname(dirname(dirname(__DIR__))) . '/vendor/autoload.php'; require dirname(dirname(dirname(__DIR__))) . '/vendor/autoload.php';
class BinaryEcho extends \Ratchet\Server\EchoServer implements \Ratchet\WebSocket\BinaryMessageInterface {
public function onMessage(\Ratchet\ConnectionInterface $from, $msg, $isBinary = false) {
$from->send($msg, $isBinary);
}
}
$port = $argc > 1 ? $argv[1] : 8000; $port = $argc > 1 ? $argv[1] : 8000;
$impl = sprintf('React\EventLoop\%sLoop', $argc > 2 ? $argv[2] : 'StreamSelect'); $impl = sprintf('React\EventLoop\%sLoop', $argc > 2 ? $argv[2] : 'StreamSelect');
$loop = new $impl; $loop = new $impl;
$sock = new React\Socket\Server($loop); $sock = new React\Socket\Server($loop);
$app = new Ratchet\Http\HttpServer(new Ratchet\WebSocket\WsServer(new Ratchet\Server\EchoServer)); $app = new Ratchet\Http\HttpServer(new Ratchet\WebSocket\WsServer(new BinaryEcho));
$sock->listen($port, '0.0.0.0'); $sock->listen($port, '0.0.0.0');