Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
OutRed authored Feb 25, 2023
1 parent 71935c7 commit 1c5d605
Show file tree
Hide file tree
Showing 7 changed files with 2,043 additions and 0 deletions.
Binary file added Ding.mp3
Binary file not shown.
43 changes: 43 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<!DOCTYPE HTML>
<html>
<head>
<title>OutRed Chatbox</title>
<meta name = "charset" charset = "utf-8">
<meta name = "viewport" content = "width=device-width">
<link rel = "stylesheet" type = "text/css" href = "style.css">
<script src = "script.js"></script>
<script src= "socket.io/socket.io.js"></script>
</head>
<body onload = "onload()">
<div id = "Main">
<audio id = "Ding" src = "Ding.mp3"> </audio>
<center><h1 id = "Title"> OutRed Chatbox</h1></center>
<center><p>Talk to anybody by connecting or creating a chatroom!</p></center>
<div id = "AccessPort">
<label id = "NameLabel"> </label>
<input id = "NameInput" placeholder="Enter Username" type = "text">
<br><br>
<label id = "IDLabel"> </label>
<input id = "IDInput" value = "" placeholder="Join/Create Chatroom" type = "text">
<input id = "ConnectButton" class = "Button" type = "submit" value = "Connect" onclick = "Connect()">
</div>
<h2 id = "RoomID"> Chatroom : None </h2>
<div id = "Chat">
<p id = "Message0" class = "Message"> - </p>
<p id = "Message1" class = "Message"> - </p>
<p id = "Message2" class = "Message"> - </p>
<p id = "Message3" class = "Message"> - </p>
<p id = "Message4" class = "Message"> - </p>
<p id = "Message5" class = "Message"> - </p>
<p id = "Message6" class = "Message"> - </p>
<p id = "Message7" class = "Message"> - </p>
<p id = "Message8" class = "Message"> - </p>
<p id = "Message9" class = "Message"> - </p>
<label id = "MessageLabel"> </label>
<input id = "ComposedMessage" placeholder="Your Message"type = "text">
<input id = "SendMessage" onclick="Send()" value = "Send" class = "Button" type = "submit">
</div>
<br><br>
</div>
</body>
</html>
39 changes: 39 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const http = require("http");
const express = require("express");
const socketio = require("socket.io");
const path = require("path");

const app = express();
const httpserver = http.Server(app);
const io = socketio(httpserver);

const gamedirectory = path.join(__dirname, "html");

app.use(express.static(gamedirectory));

httpserver.listen(3000);

var rooms = [];
var usernames = [];

io.on('connection', function(socket){

socket.on("join", function(room, username){
if (username != ""){
rooms[socket.id] = room;
usernames[socket.id] = username;
socket.leaveAll();
socket.join(room);
io.in(room).emit("recieve", "Server: " + username + " has joined a chatroom.");
socket.emit("join", room);
}
})

socket.on("send", function(message){
io.in(rooms[socket.id]).emit("recieve", usernames[socket.id] +" : " + message);
})

socket.on("recieve", function(message){
socket.emit("recieve", message);
})
})
Loading

0 comments on commit 1c5d605

Please sign in to comment.