You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

114 lines
2.6 KiB

<!doctype html>
<html>
<head>
<title>Socket.IO chat</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font: 13px Helvetica, Arial;
}
form {
background: #000;
padding: 3px;
position: fixed;
bottom: 0;
width: 100%;
}
form input {
border: 0;
padding: 10px;
width: 90%;
margin-right: 0.5%;
}
form button {
width: 9%;
background: rgb(130, 224, 255);
border: none;
padding: 10px;
}
#messages {
list-style-type: none;
margin: 0;
padding: 0;
}
#messages li {
padding: 5px 10px;
}
#messages li:nth-child(odd) {
background: #eee;
}
</style>
</head>
<body>
<ul id="messages"></ul>
<form action="" id="messages-form">
<input id="m" autocomplete="off"/>
<button>Send</button>
</form>
<script src="https://code.jquery.com/jquery-3.5.1.min.js"
integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.3.0/socket.io.js"></script>
<script>
const params = new URLSearchParams(window.location.search);
// const auth = params.get('auth');
const auth = "j1ggYdoF0jccFuKesfcmboitSXYJjhJUPKGUI1Re6tdHeOJ5Fqa8K7k04APz";
let socket ='';
if (auth != null) {
socket = io({
query: {auth: auth, business:1}
});
} else {
socket = io({});
}
console.log(window.location.host);
</script>
<script>
$(document).ready(function () {
$('#messages-form').on('submit', function (e) {
e.preventDefault();
socket.emit('chat-message', $('#m').val());
$('#m').val('');
return false;
});
socket.on('new-chat', function(msg){
$('#messages').append($('<li>').text(msg));
});
socket.on('server-msg',function(msg){
$('#messages').append('<li><b>' + msg + '</b></li>');
});
socket.on('public-event',function(msg){
alert('public :' + msg);
});
socket.on('private-event', function(msg){
alert('private :' + msg);
});
socket.on('room-event', function(msg) {
$('#messages').append('<li><b>' + msg + '</b></li>');
})
});
</script>
</body>
</html>