add debug library and replace console.logs
This commit is contained in:
parent
c39832dc2c
commit
230ccd1baf
@ -24,7 +24,7 @@
|
||||
},
|
||||
"homepage": "https://github.com/excalidraw/excalidraw-room#readme",
|
||||
"dependencies": {
|
||||
"@types/socket.io": "^2.1.4",
|
||||
"debug": "^4.1.1",
|
||||
"eslint": "6.8.0",
|
||||
"eslint-config-prettier": "6.10.0",
|
||||
"eslint-plugin-prettier": "3.1.2",
|
||||
@ -33,6 +33,8 @@
|
||||
"socket.io": "^2.3.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/socket.io": "^2.1.4",
|
||||
"@types/debug": "^4.1.5",
|
||||
"@types/express": "^4.17.3",
|
||||
"@types/node": "^13.9.0",
|
||||
"typescript": "^3.8.3"
|
||||
|
15
src/index.ts
15
src/index.ts
@ -1,6 +1,11 @@
|
||||
import express from "express";
|
||||
import http, { ServerResponse } from "http";
|
||||
import socketIO from "socket.io";
|
||||
import debug from "debug";
|
||||
|
||||
const serverDebug = debug("server");
|
||||
const ioDebug = debug("io");
|
||||
const socketDebug = debug("socket");
|
||||
|
||||
const app = express();
|
||||
const port = process.env.PORT || 80; // default port to listen
|
||||
@ -8,7 +13,7 @@ const port = process.env.PORT || 80; // default port to listen
|
||||
const server = http.createServer(app);
|
||||
|
||||
server.listen(port, () => {
|
||||
console.log(`listening on port: ${port}`);
|
||||
serverDebug(`listening on port: ${port}`);
|
||||
});
|
||||
|
||||
const io = socketIO(server, {
|
||||
@ -24,10 +29,10 @@ const io = socketIO(server, {
|
||||
});
|
||||
|
||||
io.on("connection", socket => {
|
||||
console.log("connection established!");
|
||||
ioDebug("connection established!");
|
||||
io.to(`${socket.id}`).emit("init-room");
|
||||
socket.on("join-room", roomID => {
|
||||
console.log(`${socket.id} has joined ${roomID}`);
|
||||
socketDebug(`${socket.id} has joined ${roomID}`);
|
||||
socket.join(roomID);
|
||||
if (io.sockets.adapter.rooms[roomID].length <= 1) {
|
||||
io.to(`${socket.id}`).emit("first-in-room");
|
||||
@ -43,7 +48,7 @@ io.on("connection", socket => {
|
||||
socket.on(
|
||||
"server-broadcast",
|
||||
(roomID: string, encryptedData: ArrayBuffer, iv: Uint8Array) => {
|
||||
console.log(`${socket.id} sends update to ${roomID}`);
|
||||
socketDebug(`${socket.id} sends update to ${roomID}`);
|
||||
socket.broadcast.to(roomID).emit("client-broadcast", encryptedData, iv);
|
||||
}
|
||||
);
|
||||
@ -51,7 +56,7 @@ io.on("connection", socket => {
|
||||
socket.on(
|
||||
"server-volatile-broadcast",
|
||||
(roomID: string, encryptedData: ArrayBuffer, iv: Uint8Array) => {
|
||||
console.log(`${socket.id} sends volatile update to ${roomID}`);
|
||||
socketDebug(`${socket.id} sends volatile update to ${roomID}`);
|
||||
socket.volatile.broadcast
|
||||
.to(roomID)
|
||||
.emit("client-broadcast", encryptedData, iv);
|
||||
|
@ -38,6 +38,11 @@
|
||||
dependencies:
|
||||
"@types/node" "*"
|
||||
|
||||
"@types/debug@^4.1.5":
|
||||
version "4.1.5"
|
||||
resolved "https://registry.yarnpkg.com/@types/debug/-/debug-4.1.5.tgz#b14efa8852b7768d898906613c23f688713e02cd"
|
||||
integrity sha512-Q1y515GcOdTHgagaVFhHnIFQ38ygs/kmxdNpvpou+raI9UO3YZcHDngBSYKQklcKlvA7iuQlmIKbzvmxcOE9CQ==
|
||||
|
||||
"@types/express-serve-static-core@*":
|
||||
version "4.17.2"
|
||||
resolved "https://registry.yarnpkg.com/@types/express-serve-static-core/-/express-serve-static-core-4.17.2.tgz#f6f41fa35d42e79dbf6610eccbb2637e6008a0cf"
|
||||
@ -371,7 +376,7 @@ debug@2.6.9:
|
||||
dependencies:
|
||||
ms "2.0.0"
|
||||
|
||||
debug@^4.0.1, debug@~4.1.0:
|
||||
debug@^4.0.1, debug@^4.1.1, debug@~4.1.0:
|
||||
version "4.1.1"
|
||||
resolved "https://registry.yarnpkg.com/debug/-/debug-4.1.1.tgz#3b72260255109c6b589cee050f1d516139664791"
|
||||
integrity sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==
|
||||
|
Loading…
x
Reference in New Issue
Block a user