-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
162 lines (140 loc) · 4.7 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
const express = require("express");
const http = require("http");
// const socketIO = require("socket.io");
const morgan = require("morgan");
const { auth } = require("express-openid-connect");
const solace = require("solclientjs");
const app = express();
const server = http.createServer(app);
// const io = socketIO(server);
// const factoryProps = new solace.SolclientFactoryProperties();
// factoryProps.profile = solace.SolclientFactoryProfiles.version10;
// const solaceFactory = solace.SolclientFactory.init(factoryProps);
// solaceFactory.setLogLevel(solace.LogLevel.WARN);
// const session = solace.SolclientFactory.createSession({
// url: "wss://mr-connection-aw8kuvu82tr.messaging.solace.cloud:443",
// vpnName: "beyondbe-drawdata",
// userName: "solace-cloud-client",
// password: "7lq5dtc8ktvp1qs9vnnikqe50n"
// });
// try {
// session.connect();
// } catch (error) {
// console.log(error);
// }
// Auth0 Configuration
const config = {
authRequired: false,
auth0Logout: true,
secret: "rFgRn0v9KQIRpj9a6v4Urfnc7jjA6PcJRr7LVyzFHRBLhlM8m7fN7MlomoTopt3B",
baseURL: "http://localhost:3000",
clientID: "5eqCZzqXygj0QD8gHf3HcQfq33KQpyfM",
issuerBaseURL: "https://dev-628rmf4fk1o6ahth.us.auth0.com",
};
// const factoryProps = new solace.SolclientFactoryProperties();
// factoryProps.profile = solace.SolclientFactoryProfiles.version10;
// const solaceFactory = solace.SolclientFactory.init(factoryProps);
// solaceFactory.setLogLevel(solace.LogLevel.WARN);
// const session = solaceFactory.createSession({
// url: "wss://mr-connection-aw8kuvu82tr.messaging.solace.cloud:443",
// vpnName: "beyondbe-drawdata",
// userName: "solace-cloud-client",
// password: "7lq5dtc8ktvp1qs9vnnikqe50n",
// });
// try {
// session.connect();
// } catch (error) {
// console.log(error);
// }
// session.on(solace.SessionEventCode.UP_NOTICE, function (sessionEvent) {
// try {
// session.subscribe(
// solace.SolclientFactory.createTopic(`Room/>`),
// true,
// `Room`,
// 10000,
// );
// } catch (error) {
// console.log(error.toString());
// }
// });
// roomData = {};
// session.on(solace.SessionEventCode.MESSAGE, function (message) {
// let roomNum = message.getDestination().getName().split("/")[1];
// if (!roomData[roomNum]) {
// roomData[roomNum] = {
// drawData: {},
// textData: "",
// };
// }
// });
// Auth router attaches /login, /logout, and /callback routes to the baseURL
app.use(auth(config));
// Define your routes and middleware here
app.use(express.static(__dirname + "/client"));
app.use(
morgan(":method :url :status :response-time ms - :res[content-length]"),
);
// Redirect root URL to /login
app.get("/", (req, res) => {
res.redirect("/login");
});
app.get("/room/:roomNo", (req, res) => {
res.sendFile(__dirname + "/client" + "/draw.html");
});
app.get("/login", (req, res) => {
res.oidc.login({ returnTo: "/room/1" });
});
app.get("/admin", (req, res) => {
res.sendFile(__dirname + "/client" + "/admin.html");
});
// Socket.io logic goes here
// io.on("connection", function (socket) {
// const socketUrl = socket.handshake.headers.referer;
// const roomNo = socketUrl.split("/").pop();
// const roomName = `room${roomNo}`;
// console.log(`User ${socket.id} connected to room ${roomNo}`);
// socket.join(roomName);
// if (!roomData[roomName]) {
// roomData[roomName] = {
// users: [],
// drawData: {},
// textData: "",
// };
// } else {
// for (const user in roomData[roomName].drawData) {
// if (user !== socket.id) {
// roomData[roomName].drawData[user].forEach((data) => {
// if (data !== -1) socket.emit("draw update", data);
// else socket.emit("draw finish");
// });
// }
// }
// socket.emit("text update", roomData[roomName].textData);
// }
// roomData[roomName].users.push(socket.id);
// roomData[roomName].drawData[socket.id] = [];
// socket.on("disconnect", function () {
// console.log(`A user disconnected ${socket.id}`);
// });
// // Draw Stroke
// socket.on("draw", function (data) {
// roomData[roomName].drawData[socket.id].push(data);
// io.to(roomName).emit("draw update", data);
// });
// // Finished Stroke
// socket.on("draw finish", function () {
// roomData[roomName].drawData[socket.id].push(-1);
// io.to(roomName).emit("draw finish");
// });
// // Text
// socket.on("text", function (data) {
// roomData[roomName].textData = data;
// io.to(roomName).emit("text update", data);
// });
// });
const port = process.env.PORT || 3000;
server.listen(port, () => {
console.log(`Server is running on port ${port}`);
console.log(`http://localhost:${port}`);
});