Files
Testing/testsocket3.php
sean 0e8a8b3028
Some checks are pending
deploy-testing / deploy (push) Waiting to run
Initial testing snapshot
2026-11-17 16:15:01 -05:00

84 lines
1.5 KiB
PHP

<html><head><title>WebSocket</title>
</head>
<body>
<div id="root"></div>
<script>
var host = "wss://bateworld.com/wss/"; //'wss://mojo.bateworld.com:8080/chatsocket.php?task=chatting';
connected=false;
let socket = new WebSocket(host);
socket.onopen = function(e) {
alert("[open] Connection established");
// alert(grabCookie("user_id"));
vars=JSON.stringify({
task: "chatting",
//userid: grabCookie("user_id")
});
socket.send(vars);
connected=true;
};
socket.onmessage = function(event) {
//alert(`[message] Data received from server: ${event.data}`);
};
socket.onclose = function(event) {
if (event.wasClean) {
//alert(`[close] Connection closed cleanly, code=${event.code} reason=${event.reason}`);
} else {
// e.g. server process killed or network down
// event.code is usually 1006 in this case
//alert('[close] Connection died');
}
};
/* document.addEventListener('visibilitychange', function(){
if (document.visibilityState === 'hidden') {
// highlight-start
setTimeout(function(){
socket.close();
connected=false;
}, 5000);
// highlight-end
} else {
// highlight-start
clearTimeout();
if (!connected) {
connecttowss();
connected=true;
}
// highlight-end
}
});*/
// document.removeEventListener('visibilitychange', handleVisibilityChange);
socket.onerror = function(error) {
//alert(`[error] ${error.message}`);
};
</script>
</body>
</html>