Binary messaging support

Least obtrusive interface
This commit is contained in:
Chris Boden 2016-02-24 18:55:04 -05:00
parent 1b4c534e6a
commit 2283bdf288
3 changed files with 11 additions and 3 deletions

View File

@ -0,0 +1,8 @@
<?php
namespace Ratchet\WebSocket;
use Ratchet\MessageComponentInterface;
use Ratchet\ConnectionInterface;
interface BinaryMessageInterface extends MessageComponentInterface {
public function onMessage(ConnectionInterface $conn, $msg, $isBinary = false);
}

View File

@ -12,10 +12,10 @@ class WsConnection extends AbstractConnectionDecorator {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function send($msg) { public function send($msg, $isBinary = false) {
if (!$this->WebSocket->closing) { if (!$this->WebSocket->closing) {
if (!($msg instanceof DataInterface)) { if (!($msg instanceof DataInterface)) {
$msg = new Frame($msg); $msg = new Frame($msg, true, ((boolean)$isBinary ? Frame::OP_TEXT : Frame::OP_BINARY));
} }
$this->getConnection()->send($msg->getContents()); $this->getConnection()->send($msg->getContents());

View File

@ -7,6 +7,6 @@
] ]
, "cases": ["*"] , "cases": ["*"]
, "exclude-cases": ["1.2.*", "2.3", "2.4", "2.6", "9.2.*", "9.4.*", "9.6.*", "9.8.*"] , "exclude-cases": []
, "exclude-agent-cases": {} , "exclude-agent-cases": {}
} }