Created
September 21, 2018 10:12
-
-
Save isaurssaurav/9319cbe60cd3db164a7d096dd8a69dae to your computer and use it in GitHub Desktop.
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
var app = require("express")(); | |
var http = require("http").Server(app); | |
var io = require("socket.io")(http); | |
var Usercounter = 0; | |
app.get("/", function(req, res) { | |
res.sendFile(__dirname + "/index.html"); | |
}); | |
io.on("connection", function(socket) { | |
Usercounter = Usercounter + 1; | |
io.emit("user", Usercounter); | |
console.log("a user is connected"); | |
socket.on("disconnect", function() { | |
Usercounter = Usercounter - 1; | |
io.emit("user", Usercounter); | |
console.log("user disconnected"); | |
}); | |
socket.on("audioMessage", function(msg) { | |
io.emit("audioMessage", msg); | |
}); | |
}); | |
http.listen(3000, function() { | |
console.log("listening to port:3000"); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment