Update to socket.io v4
This commit is contained in:
parent
79b77da808
commit
4272e5f598
13 changed files with 47 additions and 57 deletions
|
@ -4,9 +4,9 @@ from pybuilder.core import task, init
|
||||||
from ddadevops import *
|
from ddadevops import *
|
||||||
|
|
||||||
name = "c4k-jitsi"
|
name = "c4k-jitsi"
|
||||||
MODULE = "excalidraw-backend"
|
MODULE = "excalidraw-testbackend"
|
||||||
PROJECT_ROOT_PATH = "../.."
|
PROJECT_ROOT_PATH = "../.."
|
||||||
version = "1.5.2-SNAPSHOT"
|
version = "1.0.1-SNAPSHOT"
|
||||||
|
|
||||||
|
|
||||||
@init
|
@init
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -Eeo pipefail
|
set -eux
|
||||||
|
|
||||||
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
|
npm install -g npm@latest
|
||||||
npm ci
|
npm ci
|
||||||
npm run build
|
npm run build
|
||||||
|
|
|
@ -3,8 +3,8 @@
|
||||||
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 http from 'http';
|
import { createServer } from 'node:http';
|
||||||
import {Server} from 'socket.io';
|
import { Server } from 'socket.io';
|
||||||
/*
|
/*
|
||||||
import * as prometheus from 'socket.io-prometheus-metrics';
|
import * as prometheus from 'socket.io-prometheus-metrics';
|
||||||
|
|
||||||
|
@ -13,10 +13,12 @@ wich is moderate vulnerable to regular expression denial of service when untrust
|
||||||
input is passed into the o formatter.
|
input is passed into the o formatter.
|
||||||
|
|
||||||
alternatively could be used prom-client
|
alternatively could be used prom-client
|
||||||
import
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const serverDebug = debug('server');
|
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'
|
||||||
|
@ -24,25 +26,24 @@ 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 :)');
|
||||||
});
|
});
|
||||||
|
|
||||||
const server = http.createServer(app);
|
httpServer.listen(port, () => {
|
||||||
|
|
||||||
server.listen(port, () => {
|
|
||||||
serverDebug(`listening on port: ${port}`);
|
serverDebug(`listening on port: ${port}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
const io = require("socket.io")(Server, {
|
const corsOptions = {
|
||||||
cors: {
|
origin: 'https://meet.jit.si',
|
||||||
origin: "https://jitsi.test.meissa.de",
|
methods: ["GET", "POST"],
|
||||||
credentials: true
|
credentials: true
|
||||||
},
|
};
|
||||||
maxHttpBufferSize: 10e6,
|
|
||||||
|
const io = new Server(httpServer, {
|
||||||
|
allowEIO3: true,
|
||||||
|
cors: corsOptions,
|
||||||
|
maxHttpBufferSize: 1e6,
|
||||||
pingTimeout: 10000
|
pingTimeout: 10000
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -65,21 +66,19 @@ or more:
|
||||||
https://codersociety.com/blog/articles/nodejs-application-monitoring-with-prometheus-and-grafana
|
https://codersociety.com/blog/articles/nodejs-application-monitoring-with-prometheus-and-grafana
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
io.on('connection', (socket) => {
|
||||||
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[roomID].length <= 1) {
|
if (io.sockets.adapter.rooms.get(roomID)?.size ?? 0 <= 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',
|
'room-user-change', Array.from(io.sockets.adapter.rooms.get(roomID) ?? [])
|
||||||
Object.keys(io.sockets.adapter.rooms[roomID].sockets)
|
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -87,8 +86,7 @@ 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',
|
||||||
|
@ -96,15 +94,14 @@ 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 = Object.keys(rooms[roomID].sockets).filter(id => id !== socket.id);
|
const clients = Array.from(rooms.get(roomID) ?? []).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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
"resolveJsonModule": true,
|
"resolveJsonModule": true,
|
||||||
"isolatedModules": true,
|
"isolatedModules": true,
|
||||||
"outDir": "dist",
|
"outDir": "dist",
|
||||||
"noImplicitAny": false
|
//"noImplicitAny": false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,9 +4,9 @@ from pybuilder.core import task, init
|
||||||
from ddadevops import *
|
from ddadevops import *
|
||||||
|
|
||||||
name = "c4k-jitsi"
|
name = "c4k-jitsi"
|
||||||
MODULE = "web"
|
MODULE = "webtest"
|
||||||
PROJECT_ROOT_PATH = "../.."
|
PROJECT_ROOT_PATH = "../.."
|
||||||
version = "1.5.2-SNAPSHOT"
|
version = "1.0.1-SNAPSHOT"
|
||||||
|
|
||||||
|
|
||||||
@init
|
@init
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -Eeo pipefail
|
set -eux
|
||||||
|
|
||||||
apt-get update > /dev/null
|
apt-get update > /dev/null
|
||||||
apt-get upgrade -y > /dev/null
|
apt-get upgrade -y > /dev/null
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
"name": "c4k-jitsi",
|
"name": "c4k-jitsi",
|
||||||
"description": "Generate c4k yaml for a jitsi deployment.",
|
"description": "Generate c4k yaml for a jitsi deployment.",
|
||||||
"author": "meissa GmbH",
|
"author": "meissa GmbH",
|
||||||
"version": "1.5.2-SNAPSHOT",
|
"version": "1.6.0-SNAPSHOT",
|
||||||
"homepage": "https://gitlab.com/domaindrivenarchitecture/c4k-jitsi#readme",
|
"homepage": "https://gitlab.com/domaindrivenarchitecture/c4k-jitsi#readme",
|
||||||
"repository": "https://www.npmjs.com/package/c4k-jitsi",
|
"repository": "https://www.npmjs.com/package/c4k-jitsi",
|
||||||
"license": "APACHE2",
|
"license": "APACHE2",
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
(defproject org.domaindrivenarchitecture/c4k-jitsi "1.5.2-SNAPSHOT"
|
(defproject org.domaindrivenarchitecture/c4k-jitsi "1.6.0-SNAPSHOT"
|
||||||
:description "jitsi c4k-installation package"
|
:description "jitsi c4k-installation package"
|
||||||
:url "https://domaindrivenarchitecture.org"
|
:url "https://domaindrivenarchitecture.org"
|
||||||
:license {:name "Apache License, Version 2.0"
|
:license {:name "Apache License, Version 2.0"
|
||||||
:url "https://www.apache.org/licenses/LICENSE-2.0.html"}
|
:url "https://www.apache.org/licenses/LICENSE-2.0.html"}
|
||||||
:dependencies [[org.clojure/clojure "1.11.1"]
|
:dependencies [[org.clojure/clojure "1.11.1"]
|
||||||
[org.clojure/tools.reader "1.3.6"]
|
[org.clojure/tools.reader "1.3.7"]
|
||||||
[org.domaindrivenarchitecture/c4k-common-clj "6.0.3"]
|
[org.domaindrivenarchitecture/c4k-common-clj "6.1.0"]
|
||||||
[hickory "0.7.1" :exclusions [viebel/codox-klipse-theme]]]
|
[hickory "0.7.1" :exclusions [viebel/codox-klipse-theme]]]
|
||||||
:target-path "target/%s/"
|
:target-path "target/%s/"
|
||||||
:source-paths ["src/main/cljc"
|
:source-paths ["src/main/cljc"
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
"src/test/cljc"
|
"src/test/cljc"
|
||||||
"src/test/cljs"
|
"src/test/cljs"
|
||||||
"src/test/resources"]
|
"src/test/resources"]
|
||||||
:dependencies [[org.domaindrivenarchitecture/c4k-common-cljs "6.0.3"]
|
:dependencies [[org.domaindrivenarchitecture/c4k-common-cljs "6.1.0"]
|
||||||
[hickory "0.7.1"]]
|
[hickory "0.7.1"]]
|
||||||
:builds {:frontend {:target :browser
|
:builds {:frontend {:target :browser
|
||||||
:modules {:main {:init-fn dda.c4k-jitsi.browser/init}}
|
:modules {:main {:init-fn dda.c4k-jitsi.browser/init}}
|
||||||
|
|
|
@ -8,7 +8,8 @@
|
||||||
[dda.c4k-common.common :as cm]
|
[dda.c4k-common.common :as cm]
|
||||||
[dda.c4k-common.ingress :as ing]
|
[dda.c4k-common.ingress :as ing]
|
||||||
[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]])))
|
||||||
|
|
||||||
(s/def ::fqdn cp/fqdn-string?)
|
(s/def ::fqdn cp/fqdn-string?)
|
||||||
(s/def ::issuer cp/letsencrypt-issuer?)
|
(s/def ::issuer cp/letsencrypt-issuer?)
|
||||||
|
@ -25,16 +26,8 @@
|
||||||
|
|
||||||
#?(:cljs
|
#?(:cljs
|
||||||
(defmethod yaml/load-resource :jitsi [resource-name]
|
(defmethod yaml/load-resource :jitsi [resource-name]
|
||||||
(case resource-name
|
(get (inline-resources "jitsi") resource-name)))
|
||||||
"jitsi/deployment.yaml" (rc/inline "jitsi/deployment.yaml")
|
|
||||||
"jitsi/etherpad-service.yaml" (rc/inline "jitsi/etherpad-service.yaml")
|
|
||||||
"jitsi/jvb-service.yaml" (rc/inline "jitsi/jvb-service.yaml")
|
|
||||||
"jitsi/excalidraw-backend-service.yaml" (rc/inline "jitsi/excalidraw-backend-service.yaml")
|
|
||||||
"jitsi/excalidraw-deployment.yaml" (rc/inline "jitsi/excalidraw-deployment.yaml")
|
|
||||||
"jitsi/secret.yaml" (rc/inline "jitsi/secret.yaml")
|
|
||||||
"jitsi/web-service.yaml" (rc/inline "jitsi/web-service.yaml")
|
|
||||||
(throw (js/Error. "Undefined Resource!")))))
|
|
||||||
|
|
||||||
(defn-spec generate-ingress-web cp/map-or-seq?
|
(defn-spec generate-ingress-web cp/map-or-seq?
|
||||||
[config config?]
|
[config config?]
|
||||||
(ing/generate-ingress-and-cert
|
(ing/generate-ingress-and-cert
|
||||||
|
|
|
@ -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-web
|
image: domaindrivenarchitecture/c4k-jitsi-webtest
|
||||||
imagePullPolicy: IfNotPresent
|
imagePullPolicy: IfNotPresent
|
||||||
env:
|
env:
|
||||||
- name: PUBLIC_URL
|
- name: PUBLIC_URL
|
||||||
|
|
|
@ -17,4 +17,4 @@ spec:
|
||||||
spec:
|
spec:
|
||||||
containers:
|
containers:
|
||||||
- name: excalidraw-backend
|
- name: excalidraw-backend
|
||||||
image: domaindrivenarchitecture/c4k-jitsi-excalidraw-backend
|
image: domaindrivenarchitecture/c4k-jitsi-excalidraw-testbackend
|
|
@ -19,7 +19,7 @@
|
||||||
:spec
|
:spec
|
||||||
{:containers
|
{:containers
|
||||||
[{:name "jicofo",
|
[{:name "jicofo",
|
||||||
:image "jitsi/jicofo:stable-8922-1",
|
:image "jitsi/jicofo:stable-8960-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-8922-1",
|
:image "jitsi/prosody:stable-8960-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-8922-1",
|
:image "jitsi/jvb:stable-8960-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.2",
|
:image "etherpad/etherpad:1.9.3",
|
||||||
:env
|
:env
|
||||||
[{:name "XMPP_SERVER", :value "localhost"}
|
[{:name "XMPP_SERVER", :value "localhost"}
|
||||||
{:name "JICOFO_COMPONENT_SECRET",
|
{:name "JICOFO_COMPONENT_SECRET",
|
||||||
|
|
Loading…
Reference in a new issue