-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
85 lines (74 loc) · 2.75 KB
/
index.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Import packages
const express = require("express");
// const socketIO = require("socket.io");
const path = require("path");
const api = express();
// Configuration
const PORT = process.env.PORT || 3000;
const INDEX = path.join(__dirname, 'index.html');
// Start server
express()
.use((req, res) => res.sendFile(INDEX))
.listen(PORT, () => console.log("Listening on localhost:" + PORT));
// Initiatlize SocketIO
// const io = socketIO(server);
// Register "connection" events to the WebSocket
// io.on("connection", function (socket) {
// // const safeJoin = currentId => {
// // socket.leave(previousId);
// // socket.join(currentId);
// // previousId = currentId;
// // };
// // Register "join" events, requested by a connected client
// socket.on("join", function (room, username) {
// // join channel provided by client
// socket.join(room)
// socket.room = room;
// socket.username = username;
// socket.broadcast.to(socket.room).emit("chat", '🔵 <i>' + socket.username + ' join the chat..</i>');
// // Register "image" events, sent by the client
// // socket.on("image", function (msg) {
// // console.log(msg)
// // // Broadcast the "image" event to all other clients in the room
// // socket.broadcast.to(room).emit("image", msg);
// // });
// // socket.on("text", function (msg) {
// // console.log(room)
// // // Broadcast the "image" event to all other clients in the room
// // socket.broadcast.to(room).emit("text", msg);
// // });
// });
// socket.on("chat", function (msg) {
// // console.log(room)
// // Broadcast the "image" event to all other clients in the room
// socket.broadcast.to(socket.room).emit("chat", '<strong style="text-transform:uppercase">' + socket.username + '</strong>: ' + msg);
// })
// socket.on("image", function (msg) {
// socket.broadcast.to(socket.room).emit("image", msg);
// });
// socket.on('disconnect',function(un){
// socket.broadcast.to(socket.room).emit("chat", '🔴 <i>' + socket.username + ' left the chat..</i>');
// })
// socket.on('leave',function(un){
// socket.leave(socket.username);
// })
// // socket.on("getDoc", function (docId) {
// // safeJoin(docId);
// // socket.emit("document", documents[docId]);
// // })
// });
/////PEER/////
// const PORT1 = process.env.PORT || 9000;
// const app = express();
// const { ExpressPeerServer } = require('peer');
// app.get('/', (req, res, next) => { res.send('Hello world!'); });
// // =======
// const server1 = app.listen(PORT1);
// const options = {
// debug: true
// }
// const peerserver = ExpressPeerServer(server1, options);
// peerserver.on('connection', function (id) {
// console.log(id);
// })
// app.use('/api', peerserver);