-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
39 lines (31 loc) · 1.15 KB
/
Copy pathserver.js
File metadata and controls
39 lines (31 loc) · 1.15 KB
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
const admin = require("./admin.js");
const Administrator = new admin();
const io = require('socket.io')(3000, {
cors: {
origin: "http://localhost:5500",
methods: ["GET", "POST"]
}
});
io.on("connection", socket => {
console.log("Connection established");
socket.emit('connect-test', "Connection established");
socket.on("create_user", data => {
console.log("Request to create user has come in");
data = JSON.parse(data);
let dataScopes = [data.voip, data.pstn, data.chat];
Administrator.createUser(name = data.username, scopes = dataScopes);
});
socket.on("get_users", async () => {
console.log("Request for all user data has come in");
let all_users = await Administrator.getUsers();
all_users = JSON.stringify(all_users);
// console.log(all_users);
socket.emit('users_data', all_users);
});
socket.on("refresh_user", async (data) => {
console.log("A request to refresh a user's token has come in");
data = JSON.parse(data);
Administrator.refreshUser(data);
socket.emit('refresh_complete', null);
})
})