feat(peers): removed the service itself
This commit is contained in:
parent
1ec06d360e
commit
844f79a989
11 changed files with 0 additions and 1610 deletions
|
|
@ -1,6 +0,0 @@
|
|||
# ignore .git and .cache folders
|
||||
.git
|
||||
.cache
|
||||
**/build.sh
|
||||
**/build_*.sh
|
||||
**/*deploy.sh
|
||||
6
peers/.gitignore
vendored
6
peers/.gitignore
vendored
|
|
@ -1,6 +0,0 @@
|
|||
.idea
|
||||
node_modules
|
||||
npm-debug.log
|
||||
.cache
|
||||
test.html
|
||||
/utils/
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
FROM node:23-alpine
|
||||
LABEL Maintainer="KRAIEM Taha Yassine<tahayk2@gmail.com>"
|
||||
ARG GIT_SHA
|
||||
LABEL GIT_SHA=$GIT_SHA
|
||||
RUN apk add --no-cache tini
|
||||
ARG envarg
|
||||
ENV PRIVATE_ENDPOINTS=false \
|
||||
GIT_SHA=$GIT_SHA \
|
||||
ENTERPRISE_BUILD=${envarg} \
|
||||
NODE_ENV=production
|
||||
|
||||
WORKDIR /work
|
||||
COPY package.json .
|
||||
COPY package-lock.json .
|
||||
RUN npm install
|
||||
COPY . .
|
||||
RUN adduser -u 1001 openreplay -D
|
||||
USER 1001
|
||||
ENTRYPOINT ["/sbin/tini", "--"]
|
||||
CMD npm start
|
||||
|
|
@ -1,73 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Script to build api module
|
||||
# flags to accept:
|
||||
# Default will be OSS build.
|
||||
|
||||
# Usage: IMAGE_TAG=latest DOCKER_REPO=myDockerHubID bash build.sh <ee>
|
||||
|
||||
git_sha=$(git rev-parse --short HEAD)
|
||||
image_tag=${IMAGE_TAG:-git_sha}
|
||||
check_prereq() {
|
||||
which docker || {
|
||||
echo "Docker not installed, please install docker."
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
source ../scripts/lib/_docker.sh
|
||||
|
||||
[[ $1 == ee ]] && ee=true
|
||||
|
||||
[[ $PATCH -eq 1 ]] && {
|
||||
image_tag="$(grep -ER ^.ppVersion ../scripts/helmcharts/openreplay/charts/$chart | xargs | awk '{print $2}' | awk -F. -v OFS=. '{$NF += 1 ; print}')"
|
||||
[[ $ee == "true" ]] && {
|
||||
image_tag="${image_tag}-ee"
|
||||
}
|
||||
}
|
||||
update_helm_release() {
|
||||
chart=$1
|
||||
HELM_TAG="$(grep -iER ^version ../scripts/helmcharts/openreplay/charts/$chart | awk '{print $2}' | awk -F. -v OFS=. '{$NF += 1 ; print}')"
|
||||
# Update the chart version
|
||||
sed -i "s#^version.*#version: $HELM_TAG# g" ../scripts/helmcharts/openreplay/charts/$chart/Chart.yaml
|
||||
# Update image tags
|
||||
sed -i "s#ppVersion.*#ppVersion: \"$image_tag\"#g" ../scripts/helmcharts/openreplay/charts/$chart/Chart.yaml
|
||||
# Commit the changes
|
||||
git add ../scripts/helmcharts/openreplay/charts/$chart/Chart.yaml
|
||||
git commit -m "chore(helm): Updating $chart image release"
|
||||
}
|
||||
|
||||
function build_api() {
|
||||
destination="_peers"
|
||||
[[ $1 == "ee" ]] && {
|
||||
destination="_peers_ee"
|
||||
}
|
||||
[[ -d ../${destination} ]] && {
|
||||
echo "Removing previous build cache"
|
||||
rm -rf ../${destination}
|
||||
}
|
||||
cp -R ../peers ../${destination}
|
||||
cd ../${destination}
|
||||
cp -R ../assist/utils .
|
||||
# Copy enterprise code
|
||||
[[ $1 == "ee" ]] && {
|
||||
cp -rf ../ee/peers/* ./
|
||||
}
|
||||
docker build -f ./Dockerfile --platform linux/${ARCH:-"amd64"} --build-arg GIT_SHA=$git_sha -t ${DOCKER_REPO:-'local'}/peers:${image_tag} .
|
||||
cd ../peers
|
||||
rm -rf ../${destination}
|
||||
[[ $PUSH_IMAGE -eq 1 ]] && {
|
||||
docker push ${DOCKER_REPO:-'local'}/peers:${image_tag}
|
||||
docker tag ${DOCKER_REPO:-'local'}/peers:${image_tag} ${DOCKER_REPO:-'local'}/peers:latest
|
||||
docker push ${DOCKER_REPO:-'local'}/peers:latest
|
||||
}
|
||||
[[ $SIGN_IMAGE -eq 1 ]] && {
|
||||
cosign sign --key $SIGN_KEY ${DOCKER_REPO:-'local'}/peers:${image_tag}
|
||||
}
|
||||
echo "peer docker build complted"
|
||||
}
|
||||
|
||||
check_prereq
|
||||
build_api $1
|
||||
if [[ $PATCH -eq 1 ]]; then
|
||||
update_helm_release peers
|
||||
fi
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
rm -rf ./utils
|
||||
1352
peers/package-lock.json
generated
1352
peers/package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
|
@ -1,25 +0,0 @@
|
|||
{
|
||||
"name": "peers-server",
|
||||
"version": "v1.22.0",
|
||||
"description": "peers server to handle peerjs connections",
|
||||
"main": "server.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"start": "node server.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/openreplay/openreplay.git"
|
||||
},
|
||||
"author": "KRAIEM Taha Yassine <tahayk2@gmail.com>",
|
||||
"license": "Elastic License 2.0 (ELv2)",
|
||||
"bugs": {
|
||||
"url": "https://github.com/openreplay/openreplay/issues"
|
||||
},
|
||||
"homepage": "https://github.com/openreplay/openreplay#readme",
|
||||
"dependencies": {
|
||||
"express": "^4.21.1",
|
||||
"peer": "^v1.0.1",
|
||||
"winston": "^3.13.0"
|
||||
}
|
||||
}
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
#!/bin/bash
|
||||
rsync -avr --exclude=".*" --ignore-existing ../assist/utils ./
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
#!/bin/bash
|
||||
set -a
|
||||
source .env
|
||||
set +a
|
||||
|
||||
npm start
|
||||
|
|
@ -1,48 +0,0 @@
|
|||
const dumps = require('./utils/HeapSnapshot');
|
||||
const {request_logger} = require('./utils/helper');
|
||||
const health = require("./utils/health");
|
||||
const assert = require('assert').strict;
|
||||
const {peerRouter, peerConnection, peerDisconnect, peerError} = require('./servers/peerjs-server');
|
||||
const express = require('express');
|
||||
const {ExpressPeerServer} = require('peer');
|
||||
|
||||
const debug = process.env.debug === "1";
|
||||
const heapdump = process.env.heapdump === "1";
|
||||
const HOST = process.env.LISTEN_HOST || '0.0.0.0';
|
||||
const PORT = process.env.LISTEN_PORT || 9000;
|
||||
assert.ok(process.env.ASSIST_KEY, 'The "ASSIST_KEY" environment variable is required');
|
||||
const P_KEY = process.env.ASSIST_KEY;
|
||||
|
||||
const app = express();
|
||||
|
||||
app.use(request_logger("[app]"));
|
||||
|
||||
app.use(`/${P_KEY}/assist`, peerRouter);
|
||||
heapdump && app.use(`/${P_KEY}/heapdump`, dumps.router);
|
||||
|
||||
const server = app.listen(PORT, HOST, () => {
|
||||
console.log(`App listening on http://${HOST}:${PORT}`);
|
||||
console.log('Press Ctrl+C to quit.');
|
||||
});
|
||||
|
||||
const peerServer = ExpressPeerServer(server, {
|
||||
debug: true,
|
||||
path: '/',
|
||||
proxied: true,
|
||||
allow_discovery: false,
|
||||
concurrent_limit: 100000
|
||||
});
|
||||
peerServer.on('connection', peerConnection);
|
||||
peerServer.on('disconnect', peerDisconnect);
|
||||
peerServer.on('error', peerError);
|
||||
app.use('/', peerServer);
|
||||
app.enable('trust proxy');
|
||||
module.exports = {server};
|
||||
|
||||
process.on('uncaughtException', err => {
|
||||
console.log(`Uncaught Exception: ${err.message}`);
|
||||
debug && console.log(err.stack);
|
||||
// process.exit(1);
|
||||
});
|
||||
|
||||
health.healthApp.listen(health.PORT, HOST, health.listen_cb);
|
||||
|
|
@ -1,69 +0,0 @@
|
|||
const express = require('express');
|
||||
const peerRouter = express.Router();
|
||||
const {extractPeerId} = require('../utils/helper');
|
||||
|
||||
let debug = process.env.debug === "1" || false;
|
||||
|
||||
const connectedPeers = {};
|
||||
|
||||
const peerConnection = (client) => {
|
||||
debug && console.log(`initiating ${client.id}`);
|
||||
const {projectKey, sessionId} = extractPeerId(client.id);
|
||||
if (projectKey === undefined || sessionId === undefined) {
|
||||
return;
|
||||
}
|
||||
connectedPeers[projectKey] = connectedPeers[projectKey] || [];
|
||||
if (connectedPeers[projectKey].indexOf(sessionId) === -1) {
|
||||
debug && console.log(`new connexion ${client.id}`);
|
||||
connectedPeers[projectKey].push(sessionId);
|
||||
} else {
|
||||
debug && console.log(`reconnecting peer ${client.id}`);
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
const peerDisconnect = (client) => {
|
||||
debug && console.log(`disconnect ${client.id}`);
|
||||
const {projectKey, sessionId} = extractPeerId(client.id);
|
||||
if (projectKey === undefined || sessionId === undefined) {
|
||||
return;
|
||||
}
|
||||
const i = (connectedPeers[projectKey] || []).indexOf(sessionId);
|
||||
if (i === -1) {
|
||||
debug && console.log(`session not found ${client.id}`);
|
||||
} else {
|
||||
connectedPeers[projectKey].splice(i, 1);
|
||||
}
|
||||
}
|
||||
|
||||
const peerError = (error) => {
|
||||
//https://peerjs.com/docs/#peeron-error
|
||||
console.error('Error detected in Peers');
|
||||
console.error('Error type:');
|
||||
console.error(error.type);
|
||||
console.error('Error message:');
|
||||
console.error(error);
|
||||
}
|
||||
|
||||
|
||||
peerRouter.get(`/peers`, function (req, res) {
|
||||
debug && console.log("looking for all available sessions");
|
||||
res.statusCode = 200;
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
res.end(JSON.stringify({"data": connectedPeers}));
|
||||
});
|
||||
peerRouter.get(`/peers/:projectKey`, function (req, res) {
|
||||
debug && console.log(`looking for available sessions for ${req.params.projectKey}`);
|
||||
res.statusCode = 200;
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
res.end(JSON.stringify({"data": connectedPeers[req.params.projectKey] || []}));
|
||||
});
|
||||
|
||||
|
||||
module.exports = {
|
||||
peerRouter,
|
||||
peerConnection,
|
||||
peerDisconnect,
|
||||
peerError,
|
||||
extractPeerId
|
||||
};
|
||||
Loading…
Add table
Reference in a new issue