ladybird/Tests/LibWeb/Text/input/WebSocket/echo.html

36 lines
939 B
HTML
Raw Permalink Normal View History

2025-03-18 15:28:35 -03:00
<!DOCTYPE html>
<script src="../include.js"></script>
<script>
asyncTest((done) => {
const ws = new WebSocket(`ws://localhost:${internals.getEchoServerPort()}/`);
let messageCount = 0;
ws.onopen = function (ev) {
println(ev.type);
ws.send(`WellHelloFriends${messageCount}`);
ws.onclose = function (ev) {
println(ev.type);
done();
}
ws.onerror = function (ev) {
println(ev.type);
done();
}
};
ws.onmessage = function (ev) {
println(`${ev.type} ${ev.data}`);
if (++messageCount === 5) {
ws.close();
return;
}
ws.send(`WellHelloFriends${messageCount}`);
}
ws.onerror = function (ev) {
println(ev.type);
done();
}
});
</script>