-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathserver.js
38 lines (33 loc) · 1.05 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const express = require("express");
const path = require("path");
const app = express();
const server = require("http").createServer(app);
const io = require("socket.io")(server);
app.use(express.static(path.join(__dirname, "/public")));
io.on("connection", function (socket) {
socket.on("sender-join", function (data) {
socket.join(data.uid);
});
socket.on("receiver-join", function (data) {
socket.join(data.uid);
socket.in(data.sender_uid).emit("init", data.uid);
});
socket.on("file-meta", function (data) {
socket.in(data.uid).emit("fs-meta", data.metadata);
});
socket.on("fs-start", function (data) {
socket.in(data.uid).emit("fs-share", {});
});
socket.on("file-raw", function (data) {
socket.in(data.uid).emit("fs-share", data.buffer);
});
});
app.get("/send", (req, res) => {
res.sendFile(path.join(__dirname, "/public/sender.html"));
});
app.get("/receive",(req,res)=> {
res.sendFile(path.join(__dirname,"/public/receiver.html"))
})
server.listen(5000, () => {
console.log("Server is running on port 5000");
});