-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
1,536 additions
and
7,072 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
node_modules | ||
node_modules | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Socket.IO Test</title> | ||
<script src="https://cdn.socket.io/4.0.0/socket.io.min.js"></script> | ||
</head> | ||
<body> | ||
<h2>Socket.IO Chat Test</h2> | ||
<input id="roomInput" placeholder="Room ID" /> | ||
<button onclick="joinRoom()">Join Room</button> | ||
<br><br> | ||
<input id="messageInput" placeholder="Message" /> | ||
<button onclick="sendMessage()">Send Message</button> | ||
<div id="messages"></div> | ||
|
||
<script> | ||
const socket = io("http://localhost:3002"); | ||
|
||
socket.on("connect", () => { | ||
console.log("Connected to Socket.IO server"); | ||
}); | ||
|
||
socket.on("chatMessage", (message) => { | ||
const messagesDiv = document.getElementById("messages"); | ||
const messageElem = document.createElement("p"); | ||
messageElem.textContent = `Received: ${message.text}`; | ||
messagesDiv.appendChild(messageElem); | ||
}); | ||
|
||
function joinRoom() { | ||
const roomId = document.getElementById("roomInput").value; | ||
socket.emit("joinRoom", roomId); | ||
console.log(`Joined room: ${roomId}`); | ||
} | ||
|
||
function sendMessage() { | ||
const roomId = document.getElementById("roomInput").value; | ||
const text = document.getElementById("messageInput").value; | ||
const message = { roomId, userId: "user1", text }; | ||
socket.emit("sendMessage", message); | ||
console.log(`Sent message: ${text}`); | ||
} | ||
</script> | ||
</body> | ||
</html> | ||
|
Oops, something went wrong.