Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
walkor committed Oct 9, 2017
1 parent e7f6433 commit 8dbef93
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/ChannelAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function del($id, $room)
{
unset($this->sids[$id][$room]);
unset($this->rooms[$room][$id]);
if(!empty($this->rooms[$room]))
if(empty($this->rooms[$room]))
{
unset($this->rooms[$room]);
$channel = "socket.io#/#$room#";
Expand Down
2 changes: 1 addition & 1 deletion src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public function close()
*/
public function packet($packet, $preEncoded = false, $volatile = false)
{
if('open' === $this->conn->readyState)
if(!empty($this->conn) && 'open' === $this->conn->readyState)
{
if (!$preEncoded)
{
Expand Down
17 changes: 10 additions & 7 deletions src/Engine/Engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,16 @@ protected function verify($req, $res, $upgrade, $fn)
{
return call_user_func($fn, self::ERROR_BAD_HANDSHAKE_METHOD, false, $req, $res);
}
return $this->checkRequest($req, $fn);
return $this->checkRequest($req, $res, $fn);
}
call_user_func($fn, null, true, $req, $res);
}

public function checkRequest($req, $fn)
public function checkRequest($req, $res, $fn)
{
if ($this->origins === "*:*" || empty($this->origins))
{
return call_user_func($fn, null, true, $req);
return call_user_func($fn, null, true, $req, $res);
}
$origin = null;
if (isset($req->headers['origin']))
Expand All @@ -153,7 +153,7 @@ public function checkRequest($req, $fn)

// file:// URLs produce a null Origin which can't be authorized via echo-back
if ('null' === $origin || null === $origin) {
return call_user_func($fn, null, true, $req);
return call_user_func($fn, null, true, $req, $res);
}

if ($origin)
Expand All @@ -168,10 +168,10 @@ public function checkRequest($req, $fn)
$allow_origin === $parts['scheme'] . '://' . $parts['host'] ||
$allow_origin === $parts['scheme'] . '://' . $parts['host'] . ':*' ||
$allow_origin === '*:' . $parts['port'];
return call_user_func($fn, null, $ok, $req);
return call_user_func($fn, null, $ok, $req, $res);
}
}
call_user_func($fn, null, false, $req);
call_user_func($fn, null, false, $req, $res);
}

protected function prepare($req)
Expand All @@ -189,7 +189,10 @@ protected function prepare($req)
public function handshake($transport, $req)
{
$id = bin2hex(pack('d', microtime(true)).pack('N', function_exists('random_int') ? random_int(1, 100000000): rand(1, 100000000)));
if (isset($req->_query['j']))
if ($transport == 'websocket') {
$transport = '\\PHPSocketIO\\Engine\\Transports\\WebSocket';
}
elseif (isset($req->_query['j']))
{
$transport = '\\PHPSocketIO\\Engine\\Transports\\PollingJsonp';
}
Expand Down
2 changes: 1 addition & 1 deletion src/Parser/Decoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function add($obj)
$this->emit('decoded', $packet);
}
}
else if (isBuf(obj) || !empty($obj['base64']))
else if (isBuf($obj) || !empty($obj['base64']))
{ // raw binary data
if (!$this->reconstructor)
{
Expand Down

0 comments on commit 8dbef93

Please sign in to comment.