Make a WebSocket example work with crawler.yt.lemnoslife.com

This commit is contained in:
Benjamin Loison 2023-01-31 01:05:09 +01:00
parent 411a3db465
commit 1fe92ec2d0
Signed by: Benjamin_Loison
SSH Key Fingerprint: SHA256:BtnEgYTlHdOg1u+RmYcDE0mnfz1rhv5dSbQ2gyxW8B8
2 changed files with 6 additions and 13 deletions

View File

@ -13,8 +13,7 @@ See <?php echoUrl('https://gitea.lemnoslife.com/Benjamin_Loison/YouTube_captions
<button>Search</button>
<script>
// Then some JavaScript in the browser:
var conn = new WebSocket('ws://localhost:8080/echo');
var conn = new WebSocket('wss://crawler.yt.lemnoslife.com:443/websocket');
conn.onmessage = function(e) { console.log(e.data); };
conn.onopen = function(e) { conn.send('Hello Me!'); };
</script>

View File

@ -7,8 +7,7 @@ use Ratchet\ConnectionInterface;
require __DIR__ . '/vendor/autoload.php';
/**
* chat.php
* Send any incoming messages to all connected clients (except sender)
* Send any incoming messages to all connected clients
*/
class MyChat implements MessageComponentInterface
{
@ -26,11 +25,7 @@ class MyChat implements MessageComponentInterface
public function onMessage(ConnectionInterface $from, $msg)
{
foreach ($this->clients as $client) {
if ($from != $client) {
$client->send($msg);
}
}
$from->send($msg);
}
public function onClose(ConnectionInterface $conn)
@ -44,8 +39,7 @@ class MyChat implements MessageComponentInterface
}
}
// Run the server application through the WebSocket protocol on port 8080
$app = new Ratchet\App('localhost', 8080);
$app->route('/chat', new MyChat(), array('*'));
$app->route('/echo', new Ratchet\Server\EchoServer(), array('*'));
// Run the server application through the WebSocket protocol on port 4430
$app = new Ratchet\App('crawler.yt.lemnoslife.com', 4430);
$app->route('/websocket', new MyChat(), array('*'));
$app->run();