mirror of
https://github.com/abrendan/MicDropMessages.git
synced 2025-08-25 14:02:03 +02:00
Initial commit
This commit is contained in:
39
index.js
Normal file
39
index.js
Normal file
@@ -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 entered the chat.");
|
||||
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);
|
||||
})
|
||||
})
|
Reference in New Issue
Block a user