Skip to content

Commit

Permalink
fix: ws server push method param is error (swoft-cloud/swoft-componen…
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere authored and huangzhhui committed Aug 31, 2018
1 parent a8a91ad commit a463143
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/WebSocketServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,21 @@ public function log(string $msg, array $data = [], string $type = 'info')
/**
* @param string $fd
* @param string $data
* @param bool $isBinary
* @param int $opcode The data type.
* allow:
* WEBSOCKET_OPCODE_TEXT = 1
* WEBSOCKET_OPCODE_BINARY = 2
* WEBSOCKET_OPCODE_PING = 9
* @param bool $finish
* @return bool
*/
public function push(string $fd, string $data, $isBinary = false, bool $finish = true): bool
public function push(string $fd, string $data, int $opcode = 1, bool $finish = true): bool
{
if (!$this->server->exist($fd)) {
return false;
}

return $this->server->push($fd, $data, $isBinary, $finish);
return $this->server->push($fd, $data, $opcode, $finish);
}

/**
Expand Down Expand Up @@ -164,11 +168,11 @@ public function send(string $data, $receivers = 0, $excluded = 0, int $sender =
* @param int $sender 发送者 fd
* @return int
*/
public function sendTo(int $receiver, string $data, int $sender = 0): int
public function sendTo(int $receiver, string $data, int $sender = -1): int
{
$finish = true;
$opcode = 1;
$fromUser = $sender < 1 ? 'SYSTEM' : $sender;
$fromUser = $sender < 0 ? 'SYSTEM' : $sender;

$this->log("(private)The #{$fromUser} send message to the user #{$receiver}. Data: {$data}");

Expand Down

0 comments on commit a463143

Please sign in to comment.