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": {
|
||||
"@jitsi/eslint-config": "^4.1.0",
|
||||
"@types/dotenv": "^8.2.0",
|
||||
"@typescript-eslint/eslint-plugin": "5.30.5",
|
||||
"@typescript-eslint/parser": "5.30.4",
|
||||
"eslint": "8.1.0",
|
||||
|
@ -620,6 +621,16 @@
|
|||
"resolved": "https://registry.npmjs.org/@types/debug/-/debug-4.1.5.tgz",
|
||||
"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": {
|
||||
"version": "4.17.11",
|
||||
"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",
|
||||
"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": {
|
||||
"version": "4.17.11",
|
||||
"resolved": "https://registry.npmjs.org/@types/express/-/express-4.17.11.tgz",
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
},
|
||||
"devDependencies": {
|
||||
"@jitsi/eslint-config": "^4.1.0",
|
||||
"@types/dotenv": "^8.2.0",
|
||||
"@typescript-eslint/eslint-plugin": "5.30.5",
|
||||
"@typescript-eslint/parser": "5.30.4",
|
||||
"eslint": "8.1.0",
|
||||
|
|
83
src/index.ts
83
src/index.ts
|
@ -1,26 +1,27 @@
|
|||
import debug from "debug";
|
||||
import express from "express";
|
||||
import http from "http";
|
||||
import socketIO from "socket.io";
|
||||
import * as prometheus from "socket.io-prometheus-metrics";
|
||||
import debug from 'debug';
|
||||
import dotenv from 'dotenv';
|
||||
import express from 'express';
|
||||
import http from 'http';
|
||||
import socketIO from 'socket.io';
|
||||
import * as prometheus from 'socket.io-prometheus-metrics';
|
||||
|
||||
const serverDebug = debug("server");
|
||||
const ioDebug = debug("io");
|
||||
const socketDebug = debug("socket");
|
||||
const serverDebug = debug('server');
|
||||
const ioDebug = debug('io');
|
||||
const socketDebug = debug('socket');
|
||||
|
||||
require("dotenv").config(
|
||||
process.env.NODE_ENV !== "development"
|
||||
? { path: ".env.production" }
|
||||
: { path: ".env.development" },
|
||||
dotenv.config(
|
||||
process.env.NODE_ENV === 'development'
|
||||
? { path: '.env.development' }
|
||||
: { path: '.env.production' }
|
||||
);
|
||||
|
||||
const app = express();
|
||||
const port = process.env.PORT || 80; // default port to listen
|
||||
|
||||
app.use(express.static("public"));
|
||||
app.use(express.static('public'));
|
||||
|
||||
app.get("/", (req, res) => {
|
||||
res.send("Excalidraw backend is up :)");
|
||||
app.get('/', (req, res) => {
|
||||
res.send('Excalidraw backend is up :)');
|
||||
});
|
||||
|
||||
const server = http.createServer(app);
|
||||
|
@ -32,14 +33,14 @@ server.listen(port, () => {
|
|||
const io = socketIO(server, {
|
||||
handlePreflightRequest: (req, res) => {
|
||||
const headers = {
|
||||
"Access-Control-Allow-Headers": "Content-Type, Authorization",
|
||||
"Access-Control-Allow-Origin":
|
||||
(req.header && req.header.origin) || "https://meet.jit.si",
|
||||
"Access-Control-Allow-Credentials": true,
|
||||
'Access-Control-Allow-Headers': 'Content-Type, Authorization',
|
||||
'Access-Control-Allow-Origin': req.header?.origin ?? 'https://meet.jit.si',
|
||||
'Access-Control-Allow-Credentials': true
|
||||
};
|
||||
|
||||
res.writeHead(200, headers);
|
||||
res.end();
|
||||
},
|
||||
}
|
||||
});
|
||||
|
||||
// listens on host:9090/metrics
|
||||
|
@ -47,54 +48,54 @@ prometheus.metrics(io, {
|
|||
collectDefaultMetrics: true
|
||||
});
|
||||
|
||||
io.on("connection", (socket) => {
|
||||
ioDebug("connection established!");
|
||||
io.to(`${socket.id}`).emit("init-room");
|
||||
socket.on("join-room", (roomID) => {
|
||||
io.on('connection', socket => {
|
||||
ioDebug('connection established!');
|
||||
io.to(`${socket.id}`).emit('init-room');
|
||||
socket.on('join-room', 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");
|
||||
io.to(`${socket.id}`).emit('first-in-room');
|
||||
} 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),
|
||||
'room-user-change',
|
||||
Object.keys(io.sockets.adapter.rooms[roomID].sockets)
|
||||
);
|
||||
});
|
||||
|
||||
socket.on(
|
||||
"server-broadcast",
|
||||
'server-broadcast',
|
||||
(roomID: string, encryptedData: ArrayBuffer, iv: Uint8Array) => {
|
||||
socketDebug(`${socket.id} sends update to ${roomID}`);
|
||||
socket.broadcast.to(roomID).emit("client-broadcast", encryptedData, iv);
|
||||
},
|
||||
socket.broadcast.to(roomID).emit('client-broadcast', encryptedData, iv);
|
||||
}
|
||||
);
|
||||
|
||||
socket.on(
|
||||
"server-volatile-broadcast",
|
||||
'server-volatile-broadcast',
|
||||
(roomID: string, encryptedData: ArrayBuffer, iv: Uint8Array) => {
|
||||
socketDebug(`${socket.id} sends volatile update to ${roomID}`);
|
||||
socket.volatile.broadcast
|
||||
.to(roomID)
|
||||
.emit("client-broadcast", encryptedData, iv);
|
||||
},
|
||||
.emit('client-broadcast', encryptedData, iv);
|
||||
}
|
||||
);
|
||||
|
||||
socket.on("disconnecting", () => {
|
||||
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,
|
||||
);
|
||||
|
||||
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.broadcast.to(roomID).emit('room-user-change', clients);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
socket.on("disconnect", () => {
|
||||
socket.on('disconnect', () => {
|
||||
socket.removeAllListeners();
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue