Add files via upload
This commit is contained in:
parent
071a6719f3
commit
9e0d4f7c2d
1 changed files with 63 additions and 0 deletions
63
Redditlikechatter.HTML
Normal file
63
Redditlikechatter.HTML
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Chatroom</title>
|
||||||
|
<style>
|
||||||
|
#chatbox {
|
||||||
|
width: 400px;
|
||||||
|
height: 300px;
|
||||||
|
border: 1px solid #ccc;
|
||||||
|
overflow-y: scroll;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="chatbox"></div>
|
||||||
|
<input type="text" id="message" placeholder="Type your message">
|
||||||
|
<button id="send">Send</button>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
const chatbox = document.getElementById('chatbox');
|
||||||
|
const messageInput = document.getElementById('message');
|
||||||
|
const sendButton = document.getElementById('send');
|
||||||
|
|
||||||
|
// Create a WebSocket connection using your WebSocket service's endpoint
|
||||||
|
const socket = new WebSocket('wss://free.blr2.piesocket.com/v3/1?api_key=C1ZujiijYNPNj8gvuGXhIPKsDR4WolCCKOBzMdbM¬ify_self=1');
|
||||||
|
|
||||||
|
// Handle WebSocket open event
|
||||||
|
socket.addEventListener('open', () => {
|
||||||
|
sendButton.disabled = false; // Enable the send button when the WebSocket is open
|
||||||
|
});
|
||||||
|
|
||||||
|
// Handle incoming messages from the server
|
||||||
|
socket.addEventListener('message', event => {
|
||||||
|
const message = event.data;
|
||||||
|
appendMessageToChatbox(message);
|
||||||
|
});
|
||||||
|
|
||||||
|
sendButton.addEventListener('click', sendMessage);
|
||||||
|
|
||||||
|
function sendMessage() {
|
||||||
|
const message = messageInput.value;
|
||||||
|
if (message.trim() === '') return;
|
||||||
|
|
||||||
|
if (socket.readyState === WebSocket.OPEN) {
|
||||||
|
// Send the message to the server
|
||||||
|
socket.send(message);
|
||||||
|
|
||||||
|
// Clear the input field
|
||||||
|
messageInput.value = '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function appendMessageToChatbox(message) {
|
||||||
|
const messageElement = document.createElement('div');
|
||||||
|
messageElement.textContent = message;
|
||||||
|
chatbox.appendChild(messageElement);
|
||||||
|
|
||||||
|
// Scroll to the bottom of the chatbox
|
||||||
|
chatbox.scrollTop = chatbox.scrollHeight;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Add table
Reference in a new issue