forked from prozip/rsa_chat-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
43 lines (37 loc) · 956 Bytes
/
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
39
40
41
42
43
const express = require('express')
const path = require('path');
const http = require('http')
const {
Server
} = require('socket.io')
const app = express()
const server = http.createServer(app)
const io = new Server(server)
var userList = []
// Set static folder
app.use(express.static(path.join(__dirname, 'public')));
io.on('connection', (socket) => {
console.log('user connect')
socket.on('groupChat', data => {
console.log(data)
io.emit('groupChatFromServer', data)
})
socket.on('sendPublicKey', data => {
data.socket_id = socket.id
userList.push(data)
io.emit('getPublicKey', userList)
console.log(data)
})
socket.on('privateChat', data=>{
let id = data.receiveID
console.log(data)
io.to(userList[id].socket_id).emit('privateMsgFromServer', {
sendID: data.id,
encryptMsg: data.encryptMsg,
signedMsg: data.signedMsg,
})
})
})
server.listen(3000, () => {
console.log('Example app listening on port 3000!')
})