Compare commits

..

No commits in common. "de98e87655b91ee54db2f833a3ba4897b2337e03" and "89de4ed0a5b1247d387b28aebbbd357599264480" have entirely different histories.

10 changed files with 5071 additions and 1880 deletions

View file

@ -1,10 +1,10 @@
#!/bin/bash #!/bin/bash
set -eux set -Eeo pipefail
apt-get update > /dev/null apt-get update > /dev/null
apt-get upgrade -y > /dev/null apt-get upgrade -y > /dev/null
apt-get clean apt-get clean
npm install -g npm@latest npm install -g npm
npm ci npm ci
npm run build npm run build

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,6 @@
{ {
"name": "excalidraw-backend", "name": "excalidraw-backend",
"version": "1.1.0", "version": "1.0.0",
"main": "src/index.js", "main": "src/index.js",
"description": "Excalidraw backend", "description": "Excalidraw backend",
"repository": { "repository": {
@ -9,22 +9,22 @@
}, },
"private": true, "private": true,
"engines": { "engines": {
"node": ">=18.0.0", "node": ">=14.0.0",
"npm": ">=10.0.0" "npm": ">=7.0.0"
}, },
"dependencies": { "dependencies": {
"@types/debug": "4.1.10", "@types/debug": "4.1.5",
"@types/express": "4.17.20", "@types/express": "4.17.11",
"@types/ms": "0.7.33", "@types/node": "14.14.31",
"@types/node": "20.8.7", "@types/socket.io": "2.1.4",
"cross-env": "^7.0.3", "cross-env": "^7.0.3",
"debug": "4.3.4", "debug": "4.3.1",
"dotenv": "^16.0.0", "dotenv": "^10.0.0",
"express": "^4.18.2", "express": "4.17.1",
"socket.io": "^4.7.2", "socket.io": "^2.5.0",
"prom-client": "^15.0.0", "socket.io-prometheus-metrics": "^1.0.6",
"ts-node-dev": "^2.0.0", "ts-node-dev": "^1.1.8",
"typescript": "5.2.2" "typescript": "4.2.3"
}, },
"license": "MIT", "license": "MIT",
"scripts": { "scripts": {
@ -37,15 +37,16 @@
}, },
"devDependencies": { "devDependencies": {
"@jitsi/eslint-config": "^4.1.0", "@jitsi/eslint-config": "^4.1.0",
"@typescript-eslint/eslint-plugin": "6.8.0", "@types/dotenv": "^8.2.0",
"@typescript-eslint/parser": "6.8.0", "@typescript-eslint/eslint-plugin": "5.30.5",
"eslint": "^8.1.0", "@typescript-eslint/parser": "5.30.4",
"eslint-plugin-import": "2.28.1", "eslint": "8.1.0",
"eslint-plugin-jsdoc": "46.8.2", "eslint-plugin-import": "2.25.2",
"eslint-plugin-typescript-sort-keys": "^3.1.0" "eslint-plugin-jsdoc": "37.0.3",
"eslint-plugin-typescript-sort-keys": "^2.1.0"
}, },
"optionalDependencies": { "optionalDependencies": {
"bufferutil": "^4.0.6", "bufferutil": "^4.0.6",
"utf-8-validate": "^6.0.3" "utf-8-validate": "^5.0.9"
} }
} }

View file

@ -3,22 +3,11 @@
import debug from 'debug'; import debug from 'debug';
import dotenv from 'dotenv'; import dotenv from 'dotenv';
import express from 'express'; import express from 'express';
import { createServer } from 'node:http'; import http from 'http';
import { Server } from 'socket.io'; import socketIO from 'socket.io';
/*
import * as prometheus from 'socket.io-prometheus-metrics'; import * as prometheus from 'socket.io-prometheus-metrics';
do not use anymore, since 3 years no further progression, depends on debug 4.1.1, const serverDebug = debug('server');
wich is moderate vulnerable to regular expression denial of service when untrusted user
input is passed into the o formatter.
alternatively could be used prom-client
*/
const serverDebug = debug('httpServer');
const app = express();
const port = process.env.PORT || 80; // default port to listen
const httpServer = createServer(app);
dotenv.config( dotenv.config(
process.env.NODE_ENV === 'development' process.env.NODE_ENV === 'development'
@ -26,59 +15,53 @@ dotenv.config(
: { path: '.env.production' } : { path: '.env.production' }
); );
const app = express();
const port = process.env.PORT || 80; // default port to listen
app.get('/', (req, res) => { app.get('/', (req, res) => {
res.send('Excalidraw backend is up :)'); res.send('Excalidraw backend is up :)');
}); });
httpServer.listen(port, () => { const server = http.createServer(app);
server.listen(port, () => {
serverDebug(`listening on port: ${port}`); serverDebug(`listening on port: ${port}`);
}); });
const corsOptions = { const io = socketIO(server, {
origin: 'https://meet.jit.si', handlePreflightRequest: (req, res) => {
methods: ["GET", "POST"], const headers = {
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
};
const io = new Server(httpServer, { res.writeHead(200, headers);
allowEIO3: true, res.end();
cors: corsOptions, },
maxHttpBufferSize: 1e6, maxHttpBufferSize: 10e6,
pingTimeout: 10000 pingTimeout: 10000
}); });
// listens on host:9090/metrics // listens on host:9090/metrics
/* do not use
prometheus.metrics(io, { prometheus.metrics(io, {
collectDefaultMetrics: true collectDefaultMetrics: true
}); });
*/
/* alternatively could be used: io.on('connection', socket => {
const client = require('prom-client');
const collectDefaultMetrics = client.collectDefaultMetrics;
const Registry = client.Registry;
const register = new Registry();
collectDefaultMetrics({ register });
or more:
https://codersociety.com/blog/articles/nodejs-application-monitoring-with-prometheus-and-grafana
*/
io.on('connection', (socket) => {
serverDebug(`connection established! ${socket.conn.request.url}`); serverDebug(`connection established! ${socket.conn.request.url}`);
io.to(`${socket.id}`).emit('init-room'); io.to(`${socket.id}`).emit('init-room');
socket.on('join-room', roomID => { socket.on('join-room', roomID => {
serverDebug(`${socket.id} has joined ${roomID} for url ${socket.conn.request.url}`); serverDebug(`${socket.id} has joined ${roomID} for url ${socket.conn.request.url}`);
socket.join(roomID); socket.join(roomID);
if (io.sockets.adapter.rooms.get(roomID)?.size ?? 0 <= 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( io.in(roomID).emit(
'room-user-change', Array.from(io.sockets.adapter.rooms.get(roomID) ?? []) 'room-user-change',
Object.keys(io.sockets.adapter.rooms[roomID].sockets)
); );
}); });
@ -86,7 +69,8 @@ io.on('connection', (socket) => {
'server-broadcast', 'server-broadcast',
(roomID: string, encryptedData: ArrayBuffer, iv: Uint8Array) => { (roomID: string, encryptedData: ArrayBuffer, iv: Uint8Array) => {
socket.broadcast.to(roomID).emit('client-broadcast', encryptedData, iv); socket.broadcast.to(roomID).emit('client-broadcast', encryptedData, iv);
}); }
);
socket.on( socket.on(
'server-volatile-broadcast', 'server-volatile-broadcast',
@ -94,14 +78,15 @@ io.on('connection', (socket) => {
socket.volatile.broadcast socket.volatile.broadcast
.to(roomID) .to(roomID)
.emit('client-broadcast', encryptedData, iv); .emit('client-broadcast', encryptedData, iv);
}); }
);
socket.on('disconnecting', () => { socket.on('disconnecting', () => {
const rooms = io.sockets.adapter.rooms; const rooms = io.sockets.adapter.rooms;
for (const roomID of Object.keys(socket.rooms)) { for (const roomID of Object.keys(socket.rooms)) {
const clients = Array.from(rooms.get(roomID) ?? []).filter(id => id !== socket.id); const clients = Object.keys(rooms[roomID].sockets).filter(id => id !== socket.id);
if (roomID !== socket.id) { if (roomID !== socket.id) {
socket.to(roomID).emit('user has left', socket.id); socket.to(roomID).emit('user has left', socket.id);
} }

View file

@ -11,8 +11,7 @@
"forceConsistentCasingInFileNames": true, "forceConsistentCasingInFileNames": true,
"resolveJsonModule": true, "resolveJsonModule": true,
"isolatedModules": true, "isolatedModules": true,
"outDir": "dist", "outDir": "dist"
//"noImplicitAny": false
} }
} }

View file

@ -1,4 +1,4 @@
FROM jitsi/web:stable-8960-1 FROM jitsi/web:stable-8922-1
# Prepare Configuration # Prepare Configuration
ADD resources /tmp ADD resources /tmp

View file

@ -1,17 +1,4 @@
(ns dda.c4k-jitsi.jitsi (ns dda.c4k-jitsi.jitsi
<<<<<<< HEAD
(:require
[clojure.spec.alpha :as s]
#?(:cljs [shadow.resource :as rc])
#?(:clj [orchestra.core :refer [defn-spec]]
:cljs [orchestra.core :refer-macros [defn-spec]])
[dda.c4k-common.yaml :as yaml]
[dda.c4k-common.common :as cm]
[dda.c4k-common.ingress :as ing]
[dda.c4k-common.base64 :as b64]
[dda.c4k-common.predicate :as cp]
#?(:cljs [dda.c4k-common.macros :refer-macros [inline-resources]])))
=======
(:require (:require
[clojure.spec.alpha :as s] [clojure.spec.alpha :as s]
#?(:clj [orchestra.core :refer [defn-spec]] #?(:clj [orchestra.core :refer [defn-spec]]
@ -22,7 +9,6 @@
[dda.c4k-common.base64 :as b64] [dda.c4k-common.base64 :as b64]
[dda.c4k-common.predicate :as cp] [dda.c4k-common.predicate :as cp]
#?(:cljs [dda.c4k-common.macros :refer-macros [inline-resources]]))) #?(:cljs [dda.c4k-common.macros :refer-macros [inline-resources]])))
>>>>>>> 89de4ed0a5b1247d387b28aebbbd357599264480
(s/def ::fqdn cp/fqdn-string?) (s/def ::fqdn cp/fqdn-string?)
(s/def ::issuer cp/letsencrypt-issuer?) (s/def ::issuer cp/letsencrypt-issuer?)

View file

@ -17,7 +17,7 @@ spec:
spec: spec:
containers: containers:
- name: jicofo - name: jicofo
image: jitsi/jicofo:stable-8960-1 image: jitsi/jicofo:stable-8922-1
imagePullPolicy: IfNotPresent imagePullPolicy: IfNotPresent
env: env:
- name: XMPP_SERVER - name: XMPP_SERVER
@ -37,7 +37,7 @@ spec:
- name: TZ - name: TZ
value: Europe/Berlin value: Europe/Berlin
- name: prosody - name: prosody
image: jitsi/prosody:stable-8960-1 image: jitsi/prosody:stable-8922-1
imagePullPolicy: IfNotPresent imagePullPolicy: IfNotPresent
env: env:
- name: PUBLIC_URL - name: PUBLIC_URL
@ -68,7 +68,7 @@ spec:
- name: JVB_TCP_HARVESTER_DISABLED - name: JVB_TCP_HARVESTER_DISABLED
value: "true" value: "true"
- name: web - name: web
image: domaindrivenarchitecture/c4k-jitsi-webtest image: domaindrivenarchitecture/c4k-jitsi-web
imagePullPolicy: IfNotPresent imagePullPolicy: IfNotPresent
env: env:
- name: PUBLIC_URL - name: PUBLIC_URL
@ -102,7 +102,7 @@ spec:
- name: WHITEBOARD_COLLAB_SERVER_PUBLIC_URL - name: WHITEBOARD_COLLAB_SERVER_PUBLIC_URL
value: REPLACE_EXCALIDRAW_BACKEND_URL value: REPLACE_EXCALIDRAW_BACKEND_URL
- name: jvb - name: jvb
image: jitsi/jvb:stable-8960-1 image: jitsi/jvb:stable-8922-1
imagePullPolicy: IfNotPresent imagePullPolicy: IfNotPresent
env: env:
- name: PUBLIC_URL - name: PUBLIC_URL
@ -132,7 +132,7 @@ spec:
- name: TZ - name: TZ
value: Europe/Berlin value: Europe/Berlin
- name: etherpad - name: etherpad
image: etherpad/etherpad:1.9.3 image: etherpad/etherpad:1.9.2
env: env:
- name: XMPP_SERVER - name: XMPP_SERVER
value: localhost value: localhost

View file

@ -17,4 +17,4 @@ spec:
spec: spec:
containers: containers:
- name: excalidraw-backend - name: excalidraw-backend
image: domaindrivenarchitecture/c4k-jitsi-excalidraw-testbackend image: domaindrivenarchitecture/c4k-jitsi-excalidraw-backend

View file

@ -19,7 +19,7 @@
:spec :spec
{:containers {:containers
[{:name "jicofo", [{:name "jicofo",
:image "jitsi/jicofo:stable-8960-1", :image "jitsi/jicofo:stable-8922-1",
:imagePullPolicy "IfNotPresent", :imagePullPolicy "IfNotPresent",
:env :env
[{:name "XMPP_SERVER", :value "localhost"} [{:name "XMPP_SERVER", :value "localhost"}
@ -29,7 +29,7 @@
{:name "JICOFO_AUTH_PASSWORD", :valueFrom {:secretKeyRef {:name "jitsi-config", :key "JICOFO_AUTH_PASSWORD"}}} {:name "JICOFO_AUTH_PASSWORD", :valueFrom {:secretKeyRef {:name "jitsi-config", :key "JICOFO_AUTH_PASSWORD"}}}
{:name "TZ", :value "Europe/Berlin"}]} {:name "TZ", :value "Europe/Berlin"}]}
{:name "prosody", {:name "prosody",
:image "jitsi/prosody:stable-8960-1", :image "jitsi/prosody:stable-8922-1",
:imagePullPolicy "IfNotPresent", :imagePullPolicy "IfNotPresent",
:env :env
[{:name "PUBLIC_URL", :value "xy.xy.xy"} [{:name "PUBLIC_URL", :value "xy.xy.xy"}
@ -62,7 +62,7 @@
{:name "WHITEBOARD_ENABLED", :value "true"} {:name "WHITEBOARD_ENABLED", :value "true"}
{:name "WHITEBOARD_COLLAB_SERVER_PUBLIC_URL", :value "https://excalidraw-backend.xy.xy.xy"}]} {:name "WHITEBOARD_COLLAB_SERVER_PUBLIC_URL", :value "https://excalidraw-backend.xy.xy.xy"}]}
{:name "jvb", {:name "jvb",
:image "jitsi/jvb:stable-8960-1", :image "jitsi/jvb:stable-8922-1",
:imagePullPolicy "IfNotPresent", :imagePullPolicy "IfNotPresent",
:env :env
[{:name "PUBLIC_URL", :value "xy.xy.xy"} [{:name "PUBLIC_URL", :value "xy.xy.xy"}
@ -76,7 +76,7 @@
{:name "JICOFO_AUTH_PASSWORD", :valueFrom {:secretKeyRef {:name "jitsi-config", :key "JICOFO_AUTH_PASSWORD"}}} {:name "JICOFO_AUTH_PASSWORD", :valueFrom {:secretKeyRef {:name "jitsi-config", :key "JICOFO_AUTH_PASSWORD"}}}
{:name "TZ", :value "Europe/Berlin"}]} {:name "TZ", :value "Europe/Berlin"}]}
{:name "etherpad", {:name "etherpad",
:image "etherpad/etherpad:1.9.3", :image "etherpad/etherpad:1.9.2",
:env :env
[{:name "XMPP_SERVER", :value "localhost"} [{:name "XMPP_SERVER", :value "localhost"}
{:name "JICOFO_COMPONENT_SECRET", {:name "JICOFO_COMPONENT_SECRET",