diff --git a/lib/Ratchet/Application/WebSocket/App.php b/lib/Ratchet/Application/WebSocket/App.php index ed8b9f5..7e70461 100644 --- a/lib/Ratchet/Application/WebSocket/App.php +++ b/lib/Ratchet/Application/WebSocket/App.php @@ -39,6 +39,8 @@ class App implements ApplicationInterface, ConfiguratorInterface { , 'Hixie76' => null ); + protected $_mask_payload = false; + public function __construct(ApplicationInterface $app = null) { if (null === $app) { throw new \UnexpectedValueException("WebSocket requires an application to run"); @@ -171,7 +173,7 @@ class App implements ApplicationInterface, ConfiguratorInterface { } $version = $command->getConnection()->WebSocket->version; - return $command->setMessage($version->frame($command->getMessage())); + return $command->setMessage($version->frame($command->getMessage(), $this->_mask_payload)); } if ($command instanceof \Traversable) { @@ -226,4 +228,14 @@ class App implements ApplicationInterface, ConfiguratorInterface { unset($this->_versions[$name]); } + + /** + * Set the option to mask the payload upon sending to client + * If WebSocket is used as server, this should be false, client to true + * @param bool + * @todo User shouldn't have to know/set this, need to figure out how to do this automatically + */ + public function setMaskPayload($opt) { + $this->_mask_payload = (boolean)$opt; + } } \ No newline at end of file diff --git a/lib/Ratchet/Application/WebSocket/Version/Hixie76.php b/lib/Ratchet/Application/WebSocket/Version/Hixie76.php index 38e94d8..03fbe78 100644 --- a/lib/Ratchet/Application/WebSocket/Version/Hixie76.php +++ b/lib/Ratchet/Application/WebSocket/Version/Hixie76.php @@ -53,7 +53,7 @@ class Hixie76 implements VersionInterface { return new Hixie76\Frame; } - public function frame($message) { + public function frame($message, $mask = true) { return chr(0) . $message . chr(255); } diff --git a/lib/Ratchet/Application/WebSocket/Version/HyBi10.php b/lib/Ratchet/Application/WebSocket/Version/HyBi10.php index 80316b3..78efb88 100644 --- a/lib/Ratchet/Application/WebSocket/Version/HyBi10.php +++ b/lib/Ratchet/Application/WebSocket/Version/HyBi10.php @@ -61,10 +61,10 @@ class HyBi10 implements VersionInterface { * @param string * @return string */ - public function frame($message) { + public function frame($message, $mask = true) { $payload = $message; $type = 'text'; - $masked = true; + $masked = $mask; $frameHead = array(); $frame = ''; diff --git a/lib/Ratchet/Application/WebSocket/Version/VersionInterface.php b/lib/Ratchet/Application/WebSocket/Version/VersionInterface.php index b6078d9..461e149 100644 --- a/lib/Ratchet/Application/WebSocket/Version/VersionInterface.php +++ b/lib/Ratchet/Application/WebSocket/Version/VersionInterface.php @@ -35,8 +35,9 @@ interface VersionInterface { /** * @param string + * @param bool * @return string * @todo Change to use other classes, this will be removed eventually */ - function frame($message); + function frame($message, $mask = true); } \ No newline at end of file