Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 14 additions & 20 deletions PHPDaemon/Servers/WebSocket/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,20 @@ public function handshake($extraHeaders = null) {
return false;
}

if ($extraHeaders === null && method_exists($this->route, 'onBeforeHandshake')) {
$this->route->onWakeup();
$this->route->onBeforeHandshake();

$extraHeaders = '';
foreach ($this->headers as $k => $line) {
if ($k !== 'STATUS') {
$extraHeaders .= $line . "\r\n";
}
}

$this->route->onSleep();
}

// Handshaking...
$handshake = $this->protocol->getHandshakeReply($this->buf, $extraHeaders);
if ($handshake === 0) { // not enough data yet
Expand All @@ -259,26 +273,6 @@ public function handshake($extraHeaders = null) {
$this->finish();
return false;
}
if ($extraHeaders === null && method_exists($this->route, 'onBeforeHandshake')) {
$this->route->onWakeup();
$ret = $this->route->onBeforeHandshake(function($cb) {
$h = '';
foreach ($this->headers as $k => $line) {
if ($k !== 'STATUS') {
$h .= $line . "\r\n";
}
}
if ($this->handshake($h)) {
if ($cb !== null) {
call_user_func($cb);
}
}
});
$this->route->onSleep();
if ($ret !== false) {
return;
}
}

if (!isset($this->protocol)) {
Daemon::$process->log(get_class($this) . '::' . __METHOD__ . ' : Cannot find session-related websocket protocol for client "' . $this->addr . '"');
Expand Down
5 changes: 2 additions & 3 deletions PHPDaemon/SockJS/WebSocketRouteProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,13 @@ public function onPacket($frame, $type) {

/**
* realRoute onBeforeHandshake
* @param callable $cb
* @return void|false
*/
public function onBeforeHandshake($cb) {
public function onBeforeHandshake() {
if (!method_exists($this->realRoute, 'onBeforeHandshake')) {
return false;
}
$this->realRoute->onBeforeHandshake($cb);
$this->realRoute->onBeforeHandshake();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion PHPDaemon/WebSocket/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ protected function getSessionState() {
* @return void
*/
public function setcookie($name, $value = '', $maxage = 0, $path = '', $domain = '', $secure = false, $HTTPOnly = false) {
$this->header(
$this->client->header(
'Set-Cookie: ' . $name . '=' . rawurlencode($value)
. (empty($domain) ? '' : '; Domain=' . $domain)
. (empty($maxage) ? '' : '; Max-Age=' . $maxage)
Expand Down