Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ws server push method param is error #186

Merged
merged 1 commit into from
Aug 31, 2018
Merged
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
14 changes: 9 additions & 5 deletions src/websocket-server/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