Witam, uruchomiłem u siebie websocket z rysowaniem online korzystając z źródła
https://github.com/kallaspriit/PHP-HTML5-WebSocket-ServerUdało mi się uruchomić skrypt i działa mi on pod przeglądarkami ff i chrome, a nie działa pod safari. Z tego co wyczytałem chodzi o handshake jaki jest obsługiwany pod safari. Jest on inny niż pod chromem i ff.
w class SocketServer.php jest metoda:
public function performHandshake($buffer) {
if ($this->state != self::STATE_CONNECTING) {
throw new Exception( 'Unable to perform handshake, client is not in connecting state' );
}
$headers = $this->parseRequestHeader($buffer);
if (isset($headers['Sec-WebSocket-Key'])) { $key = $headers['Sec-WebSocket-Key'];
} else {
$key = $headers['Sec-WebSocket-Key1'];
}
sha1($key . '258EAFA5-E914-47DA-95CA-C5AB0DC85B11', true)
);
/* in ff and chrome in header exist Sec-WebSocket-Key, and safari has Sec-WebSocket-Key1 and Sec-WebSocket-Key2 */
if (isset($headers['Sec-WebSocket-Key'])) { 'HTTP/1.1 101 Switching Protocols',
'Upgrade: websocket',
'Connection: Upgrade',
'Sec-WebSocket-Accept: ' . $hash
);
} else {
"HTTP/1.1 101 Web Socket Protocol Handshake",
"Upgrade: WebSocket",
"Connection: Upgrade",
"WebSocket-Origin: <a href="http://localhost"" target="_blank">http://localhost"</a>,
"WebSocket-Location: ws://localhost:9300",
);
}
$headers = implode("\r\n", $headers) . "\r\n\r\n";
do {
$sent = @socket_send($this->socket, $headers, $left, 0);
if ($sent === false) {
$error = $this->server->getLastError();
throw new Exception(
'Sending handshake failed: : ' . $error->message .
' [' . $error->code . ']'
);
}
$left -= $sent;
if ($sent > 0) {
$headers = substr($headers, $sent); }
} while ($left > 0);
$this->state = self::STATE_OPEN;
}
Próbowałem zmieniać nagłówki dla safari, ale bez żadnego efektu. Pod Safari łączy mnie i od razu rozłącza. Problem jak myślę tkwi w tych nagłówkach. Nie wiem jak je dostosować aby także pod safari działało poprawnie. Ma ktoś pomysł jak zmodyfikować kod aby obsługiwał także safari?