Apply lint
This commit is contained in:
parent
48fc7767bd
commit
e6789b111f
3 changed files with 92 additions and 70 deletions
20
package-lock.json
generated
20
package-lock.json
generated
|
@ -24,6 +24,7 @@
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@jitsi/eslint-config": "^4.1.0",
|
"@jitsi/eslint-config": "^4.1.0",
|
||||||
|
"@types/dotenv": "^8.2.0",
|
||||||
"@typescript-eslint/eslint-plugin": "5.30.5",
|
"@typescript-eslint/eslint-plugin": "5.30.5",
|
||||||
"@typescript-eslint/parser": "5.30.4",
|
"@typescript-eslint/parser": "5.30.4",
|
||||||
"eslint": "8.1.0",
|
"eslint": "8.1.0",
|
||||||
|
@ -620,6 +621,16 @@
|
||||||
"resolved": "https://registry.npmjs.org/@types/debug/-/debug-4.1.5.tgz",
|
"resolved": "https://registry.npmjs.org/@types/debug/-/debug-4.1.5.tgz",
|
||||||
"integrity": "sha512-Q1y515GcOdTHgagaVFhHnIFQ38ygs/kmxdNpvpou+raI9UO3YZcHDngBSYKQklcKlvA7iuQlmIKbzvmxcOE9CQ=="
|
"integrity": "sha512-Q1y515GcOdTHgagaVFhHnIFQ38ygs/kmxdNpvpou+raI9UO3YZcHDngBSYKQklcKlvA7iuQlmIKbzvmxcOE9CQ=="
|
||||||
},
|
},
|
||||||
|
"node_modules/@types/dotenv": {
|
||||||
|
"version": "8.2.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/dotenv/-/dotenv-8.2.0.tgz",
|
||||||
|
"integrity": "sha512-ylSC9GhfRH7m1EUXBXofhgx4lUWmFeQDINW5oLuS+gxWdfUeW4zJdeVTYVkexEW+e2VUvlZR2kGnGGipAWR7kw==",
|
||||||
|
"deprecated": "This is a stub types definition. dotenv provides its own type definitions, so you do not need this installed.",
|
||||||
|
"dev": true,
|
||||||
|
"dependencies": {
|
||||||
|
"dotenv": "*"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/@types/express": {
|
"node_modules/@types/express": {
|
||||||
"version": "4.17.11",
|
"version": "4.17.11",
|
||||||
"resolved": "https://registry.npmjs.org/@types/express/-/express-4.17.11.tgz",
|
"resolved": "https://registry.npmjs.org/@types/express/-/express-4.17.11.tgz",
|
||||||
|
@ -5282,6 +5293,15 @@
|
||||||
"resolved": "https://registry.npmjs.org/@types/debug/-/debug-4.1.5.tgz",
|
"resolved": "https://registry.npmjs.org/@types/debug/-/debug-4.1.5.tgz",
|
||||||
"integrity": "sha512-Q1y515GcOdTHgagaVFhHnIFQ38ygs/kmxdNpvpou+raI9UO3YZcHDngBSYKQklcKlvA7iuQlmIKbzvmxcOE9CQ=="
|
"integrity": "sha512-Q1y515GcOdTHgagaVFhHnIFQ38ygs/kmxdNpvpou+raI9UO3YZcHDngBSYKQklcKlvA7iuQlmIKbzvmxcOE9CQ=="
|
||||||
},
|
},
|
||||||
|
"@types/dotenv": {
|
||||||
|
"version": "8.2.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/dotenv/-/dotenv-8.2.0.tgz",
|
||||||
|
"integrity": "sha512-ylSC9GhfRH7m1EUXBXofhgx4lUWmFeQDINW5oLuS+gxWdfUeW4zJdeVTYVkexEW+e2VUvlZR2kGnGGipAWR7kw==",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"dotenv": "*"
|
||||||
|
}
|
||||||
|
},
|
||||||
"@types/express": {
|
"@types/express": {
|
||||||
"version": "4.17.11",
|
"version": "4.17.11",
|
||||||
"resolved": "https://registry.npmjs.org/@types/express/-/express-4.17.11.tgz",
|
"resolved": "https://registry.npmjs.org/@types/express/-/express-4.17.11.tgz",
|
||||||
|
|
|
@ -36,6 +36,7 @@
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@jitsi/eslint-config": "^4.1.0",
|
"@jitsi/eslint-config": "^4.1.0",
|
||||||
|
"@types/dotenv": "^8.2.0",
|
||||||
"@typescript-eslint/eslint-plugin": "5.30.5",
|
"@typescript-eslint/eslint-plugin": "5.30.5",
|
||||||
"@typescript-eslint/parser": "5.30.4",
|
"@typescript-eslint/parser": "5.30.4",
|
||||||
"eslint": "8.1.0",
|
"eslint": "8.1.0",
|
||||||
|
|
141
src/index.ts
141
src/index.ts
|
@ -1,100 +1,101 @@
|
||||||
import debug from "debug";
|
import debug from 'debug';
|
||||||
import express from "express";
|
import dotenv from 'dotenv';
|
||||||
import http from "http";
|
import express from 'express';
|
||||||
import socketIO from "socket.io";
|
import http from 'http';
|
||||||
import * as prometheus from "socket.io-prometheus-metrics";
|
import socketIO from 'socket.io';
|
||||||
|
import * as prometheus from 'socket.io-prometheus-metrics';
|
||||||
|
|
||||||
const serverDebug = debug("server");
|
const serverDebug = debug('server');
|
||||||
const ioDebug = debug("io");
|
const ioDebug = debug('io');
|
||||||
const socketDebug = debug("socket");
|
const socketDebug = debug('socket');
|
||||||
|
|
||||||
require("dotenv").config(
|
dotenv.config(
|
||||||
process.env.NODE_ENV !== "development"
|
process.env.NODE_ENV === 'development'
|
||||||
? { path: ".env.production" }
|
? { path: '.env.development' }
|
||||||
: { path: ".env.development" },
|
: { path: '.env.production' }
|
||||||
);
|
);
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
const port = process.env.PORT || 80; // default port to listen
|
const port = process.env.PORT || 80; // default port to listen
|
||||||
|
|
||||||
app.use(express.static("public"));
|
app.use(express.static('public'));
|
||||||
|
|
||||||
app.get("/", (req, res) => {
|
app.get('/', (req, res) => {
|
||||||
res.send("Excalidraw backend is up :)");
|
res.send('Excalidraw backend is up :)');
|
||||||
});
|
});
|
||||||
|
|
||||||
const server = http.createServer(app);
|
const server = http.createServer(app);
|
||||||
|
|
||||||
server.listen(port, () => {
|
server.listen(port, () => {
|
||||||
serverDebug(`listening on port: ${port}`);
|
serverDebug(`listening on port: ${port}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
const io = socketIO(server, {
|
const io = socketIO(server, {
|
||||||
handlePreflightRequest: (req, res) => {
|
handlePreflightRequest: (req, res) => {
|
||||||
const headers = {
|
const headers = {
|
||||||
"Access-Control-Allow-Headers": "Content-Type, Authorization",
|
'Access-Control-Allow-Headers': 'Content-Type, Authorization',
|
||||||
"Access-Control-Allow-Origin":
|
'Access-Control-Allow-Origin': req.header?.origin ?? 'https://meet.jit.si',
|
||||||
(req.header && req.header.origin) || "https://meet.jit.si",
|
'Access-Control-Allow-Credentials': true
|
||||||
"Access-Control-Allow-Credentials": true,
|
};
|
||||||
};
|
|
||||||
res.writeHead(200, headers);
|
res.writeHead(200, headers);
|
||||||
res.end();
|
res.end();
|
||||||
},
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// listens on host:9090/metrics
|
// listens on host:9090/metrics
|
||||||
prometheus.metrics(io, {
|
prometheus.metrics(io, {
|
||||||
collectDefaultMetrics: true
|
collectDefaultMetrics: true
|
||||||
});
|
});
|
||||||
|
|
||||||
io.on("connection", (socket) => {
|
io.on('connection', socket => {
|
||||||
ioDebug("connection established!");
|
ioDebug('connection established!');
|
||||||
io.to(`${socket.id}`).emit("init-room");
|
io.to(`${socket.id}`).emit('init-room');
|
||||||
socket.on("join-room", (roomID) => {
|
socket.on('join-room', roomID => {
|
||||||
socketDebug(`${socket.id} has joined ${roomID}`);
|
socketDebug(`${socket.id} has joined ${roomID}`);
|
||||||
socket.join(roomID);
|
socket.join(roomID);
|
||||||
if (io.sockets.adapter.rooms[roomID].length <= 1) {
|
if (io.sockets.adapter.rooms[roomID].length <= 1) {
|
||||||
io.to(`${socket.id}`).emit("first-in-room");
|
io.to(`${socket.id}`).emit('first-in-room');
|
||||||
} else {
|
} else {
|
||||||
socket.broadcast.to(roomID).emit("new-user", socket.id);
|
socket.broadcast.to(roomID).emit('new-user', socket.id);
|
||||||
|
}
|
||||||
|
io.in(roomID).emit(
|
||||||
|
'room-user-change',
|
||||||
|
Object.keys(io.sockets.adapter.rooms[roomID].sockets)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
socket.on(
|
||||||
|
'server-broadcast',
|
||||||
|
(roomID: string, encryptedData: ArrayBuffer, iv: Uint8Array) => {
|
||||||
|
socketDebug(`${socket.id} sends update to ${roomID}`);
|
||||||
|
socket.broadcast.to(roomID).emit('client-broadcast', encryptedData, iv);
|
||||||
}
|
}
|
||||||
io.in(roomID).emit(
|
|
||||||
"room-user-change",
|
|
||||||
Object.keys(io.sockets.adapter.rooms[roomID].sockets),
|
|
||||||
);
|
);
|
||||||
});
|
|
||||||
|
|
||||||
socket.on(
|
socket.on(
|
||||||
"server-broadcast",
|
'server-volatile-broadcast',
|
||||||
(roomID: string, encryptedData: ArrayBuffer, iv: Uint8Array) => {
|
(roomID: string, encryptedData: ArrayBuffer, iv: Uint8Array) => {
|
||||||
socketDebug(`${socket.id} sends update to ${roomID}`);
|
socketDebug(`${socket.id} sends volatile update to ${roomID}`);
|
||||||
socket.broadcast.to(roomID).emit("client-broadcast", encryptedData, iv);
|
socket.volatile.broadcast
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
socket.on(
|
|
||||||
"server-volatile-broadcast",
|
|
||||||
(roomID: string, encryptedData: ArrayBuffer, iv: Uint8Array) => {
|
|
||||||
socketDebug(`${socket.id} sends volatile update to ${roomID}`);
|
|
||||||
socket.volatile.broadcast
|
|
||||||
.to(roomID)
|
.to(roomID)
|
||||||
.emit("client-broadcast", encryptedData, iv);
|
.emit('client-broadcast', encryptedData, iv);
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
socket.on("disconnecting", () => {
|
|
||||||
const rooms = io.sockets.adapter.rooms;
|
|
||||||
for (const roomID in socket.rooms) {
|
|
||||||
const clients = Object.keys(rooms[roomID].sockets).filter(
|
|
||||||
(id) => id !== socket.id,
|
|
||||||
);
|
|
||||||
if (clients.length > 0) {
|
|
||||||
socket.broadcast.to(roomID).emit("room-user-change", clients);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
);
|
||||||
|
|
||||||
socket.on("disconnect", () => {
|
socket.on('disconnecting', () => {
|
||||||
socket.removeAllListeners();
|
const rooms = io.sockets.adapter.rooms;
|
||||||
});
|
|
||||||
|
for (const roomID of Object.keys(socket.rooms)) {
|
||||||
|
const clients = Object.keys(rooms[roomID].sockets).filter(id => id !== socket.id);
|
||||||
|
|
||||||
|
if (clients.length > 0) {
|
||||||
|
socket.broadcast.to(roomID).emit('room-user-change', clients);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
socket.on('disconnect', () => {
|
||||||
|
socket.removeAllListeners();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue