mirror of
https://github.com/edumeet/edumeet.git
synced 2026-01-23 02:34:58 +00:00
typescript: server support
This commit is contained in:
parent
dee3043405
commit
5fb5c40a3e
21 changed files with 4835 additions and 4067 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -8,8 +8,9 @@ node_modules/
|
|||
!/server/config/config.example.js
|
||||
/server/public/
|
||||
/server/certs/
|
||||
/server/dist/
|
||||
!/server/certs/mediasoup-demo.localhost.*
|
||||
.vscode
|
||||
/app/public/config/*.pem
|
||||
/server/yarn.lock
|
||||
#package-lock.json
|
||||
yarn-error.log
|
||||
|
|
|
|||
|
|
@ -104,7 +104,7 @@ This will build the client application and copy everythink to `server/public` fr
|
|||
```bash
|
||||
$ cd ..
|
||||
$ cd server
|
||||
$ npm install
|
||||
$ yarn
|
||||
```
|
||||
|
||||
## Run it locally
|
||||
|
|
@ -113,7 +113,7 @@ $ npm install
|
|||
|
||||
```bash
|
||||
$ cd server
|
||||
$ npm start
|
||||
$ yarn start
|
||||
```
|
||||
|
||||
* Note: Do not run the server as root. If you need to use port 80/443 make a iptables-mapping for that or use systemd configuration for that (see further down this doc).
|
||||
|
|
|
|||
|
|
@ -3,10 +3,10 @@ const os = require('os');
|
|||
|
||||
const userRoles = require('../userRoles');
|
||||
|
||||
const {
|
||||
import {
|
||||
BYPASS_ROOM_LOCK,
|
||||
BYPASS_LOBBY
|
||||
} = require('../access');
|
||||
} from '../access';
|
||||
|
||||
const {
|
||||
CHANGE_ROOM_LOCK,
|
||||
|
|
|
|||
1
server/.eslintignore
Normal file
1
server/.eslintignore
Normal file
|
|
@ -0,0 +1 @@
|
|||
dist
|
||||
|
|
@ -4,6 +4,89 @@
|
|||
"es6": true,
|
||||
"node": true
|
||||
},
|
||||
"overrides": [
|
||||
{
|
||||
"files":["**/*.ts"],
|
||||
"plugins": ["prettier", "@typescript-eslint"],
|
||||
"extends": ["airbnb-typescript/base", "prettier"],
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"parserOptions": {
|
||||
"project": "./tsconfig.json"
|
||||
},
|
||||
// "settings": {
|
||||
// "import/resolver": {
|
||||
// "typescript": {
|
||||
// "alwaysTryTypes": true
|
||||
// }
|
||||
// }
|
||||
// },
|
||||
"rules": {
|
||||
"no-underscore-dangle":"off",
|
||||
"object-curly-spacing": [
|
||||
"warn",
|
||||
"always"
|
||||
],
|
||||
"no-unused-vars": [
|
||||
"warn",
|
||||
{
|
||||
"vars": "all",
|
||||
"args": "none"
|
||||
}
|
||||
],
|
||||
"@typescript-eslint/semi": [
|
||||
"off"
|
||||
],
|
||||
"@typescript-eslint/no-unused-vars": [
|
||||
"warn",
|
||||
{
|
||||
"vars": "all",
|
||||
"args": "none"
|
||||
}
|
||||
],
|
||||
"max-len": [
|
||||
"warn",
|
||||
{
|
||||
"code": 100,
|
||||
"ignoreStrings": true,
|
||||
"ignoreTemplateLiterals": true,
|
||||
"ignoreComments": true
|
||||
}
|
||||
],
|
||||
"prefer-destructuring": [
|
||||
"error",
|
||||
{
|
||||
"VariableDeclarator": {
|
||||
"array": false,
|
||||
"object": true
|
||||
},
|
||||
"AssignmentExpression": {
|
||||
"array": false,
|
||||
"object": false
|
||||
}
|
||||
},
|
||||
{
|
||||
"enforceForRenamedProperties": false
|
||||
}
|
||||
],
|
||||
"no-plusplus": [
|
||||
"error",
|
||||
{
|
||||
"allowForLoopAfterthoughts": true
|
||||
}
|
||||
],
|
||||
"import/no-extraneous-dependencies": [
|
||||
"error",
|
||||
{
|
||||
"devDependencies": [
|
||||
"**/*.test.js",
|
||||
"**/*.test.ts",
|
||||
"src/tests/**/*"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"extends":
|
||||
[
|
||||
"eslint:recommended"
|
||||
|
|
|
|||
|
|
@ -1,11 +0,0 @@
|
|||
module.exports = {
|
||||
// The role(s) will gain access to the room
|
||||
// even if it is locked (!)
|
||||
BYPASS_ROOM_LOCK : 'BYPASS_ROOM_LOCK',
|
||||
// The role(s) will gain access to the room without
|
||||
// going into the lobby. If you want to restrict access to your
|
||||
// server to only directly allow authenticated users, you could
|
||||
// add the userRoles.AUTHENTICATED to the user in the userMapping
|
||||
// function, and change to BYPASS_LOBBY : [ userRoles.AUTHENTICATED ]
|
||||
BYPASS_LOBBY : 'BYPASS_LOBBY'
|
||||
};
|
||||
10
server/access.ts
Normal file
10
server/access.ts
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
// The role(s) will gain access to the room
|
||||
// even if it is locked (!)
|
||||
export const BYPASS_ROOM_LOCK = "BYPASS_ROOM_LOCK";
|
||||
|
||||
// The role(s) will gain access to the room without
|
||||
// going into the lobby. If you want to restrict access to your
|
||||
// server to only directly allow authenticated users, you could
|
||||
// add the userRoles.AUTHENTICATED to the user in the userMapping
|
||||
// function, and change to BYPASS_LOBBY : [ userRoles.AUTHENTICATED ]
|
||||
export const BYPASS_LOBBY = "BYPASS_LOBBY";
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
import Logger from './Logger';
|
||||
|
||||
const EventEmitter = require('events').EventEmitter;
|
||||
const Logger = require('./Logger');
|
||||
|
||||
const logger = new Logger('Lobby');
|
||||
|
||||
|
|
|
|||
|
|
@ -1,53 +0,0 @@
|
|||
const debug = require('debug');
|
||||
|
||||
const APP_NAME = 'edumeet-server';
|
||||
|
||||
class Logger
|
||||
{
|
||||
constructor(prefix)
|
||||
{
|
||||
if (prefix)
|
||||
{
|
||||
this._debug = debug(`${APP_NAME}:${prefix}`);
|
||||
this._info = debug(`${APP_NAME}:INFO:${prefix}`);
|
||||
this._warn = debug(`${APP_NAME}:WARN:${prefix}`);
|
||||
this._error = debug(`${APP_NAME}:ERROR:${prefix}`);
|
||||
}
|
||||
else
|
||||
{
|
||||
this._debug = debug(APP_NAME);
|
||||
this._info = debug(`${APP_NAME}:INFO`);
|
||||
this._warn = debug(`${APP_NAME}:WARN`);
|
||||
this._error = debug(`${APP_NAME}:ERROR`);
|
||||
}
|
||||
|
||||
/* eslint-disable no-console */
|
||||
this._debug.log = console.info.bind(console);
|
||||
this._info.log = console.info.bind(console);
|
||||
this._warn.log = console.warn.bind(console);
|
||||
this._error.log = console.error.bind(console);
|
||||
/* eslint-enable no-console */
|
||||
}
|
||||
|
||||
get debug()
|
||||
{
|
||||
return this._debug;
|
||||
}
|
||||
|
||||
get info()
|
||||
{
|
||||
return this._info;
|
||||
}
|
||||
|
||||
get warn()
|
||||
{
|
||||
return this._warn;
|
||||
}
|
||||
|
||||
get error()
|
||||
{
|
||||
return this._error;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Logger;
|
||||
50
server/lib/Logger.ts
Normal file
50
server/lib/Logger.ts
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
import debug from "debug";
|
||||
|
||||
const APP_NAME = "edumeet-server";
|
||||
|
||||
export default class Logger {
|
||||
private _debug: debug.Debugger;
|
||||
|
||||
private _info: debug.Debugger;
|
||||
|
||||
private _warn: debug.Debugger;
|
||||
|
||||
private _error: debug.Debugger;
|
||||
|
||||
constructor(prefix: string) {
|
||||
if (prefix) {
|
||||
this._debug = debug(`${APP_NAME}:${prefix}`);
|
||||
this._info = debug(`${APP_NAME}:INFO:${prefix}`);
|
||||
this._warn = debug(`${APP_NAME}:WARN:${prefix}`);
|
||||
this._error = debug(`${APP_NAME}:ERROR:${prefix}`);
|
||||
} else {
|
||||
this._debug = debug(APP_NAME);
|
||||
this._info = debug(`${APP_NAME}:INFO`);
|
||||
this._warn = debug(`${APP_NAME}:WARN`);
|
||||
this._error = debug(`${APP_NAME}:ERROR`);
|
||||
}
|
||||
|
||||
/* eslint-disable no-console */
|
||||
this._debug.log = console.info.bind(console);
|
||||
this._info.log = console.info.bind(console);
|
||||
this._warn.log = console.warn.bind(console);
|
||||
this._error.log = console.error.bind(console);
|
||||
/* eslint-enable no-console */
|
||||
}
|
||||
|
||||
get debug() {
|
||||
return this._debug;
|
||||
}
|
||||
|
||||
get info() {
|
||||
return this._info;
|
||||
}
|
||||
|
||||
get warn() {
|
||||
return this._warn;
|
||||
}
|
||||
|
||||
get error() {
|
||||
return this._error;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
import Logger from './Logger';
|
||||
|
||||
const EventEmitter = require('events').EventEmitter;
|
||||
const userRoles = require('../userRoles');
|
||||
const Logger = require('./Logger');
|
||||
|
||||
const logger = new Logger('Peer');
|
||||
|
||||
|
|
|
|||
|
|
@ -1,17 +1,18 @@
|
|||
import Logger from './Logger';
|
||||
|
||||
const EventEmitter = require('events').EventEmitter;
|
||||
const AwaitQueue = require('awaitqueue');
|
||||
const axios = require('axios');
|
||||
const Logger = require('./Logger');
|
||||
const Lobby = require('./Lobby');
|
||||
const { SocketTimeoutError, NotFoundInMediasoupError } = require('./errors');
|
||||
const { v4: uuidv4 } = require('uuid');
|
||||
const jwt = require('jsonwebtoken');
|
||||
const userRoles = require('../userRoles');
|
||||
|
||||
const {
|
||||
import {
|
||||
BYPASS_ROOM_LOCK,
|
||||
BYPASS_LOBBY
|
||||
} = require('../access');
|
||||
} from '../access';
|
||||
|
||||
const permissions = require('../permissions'), {
|
||||
CHANGE_ROOM_LOCK,
|
||||
|
|
|
|||
0
server/lib/configLoader.ts
Normal file
0
server/lib/configLoader.ts
Normal file
|
|
@ -1,9 +1,9 @@
|
|||
import Logger from '../Logger';
|
||||
|
||||
const promClient = require('prom-client');
|
||||
const pidusage = require('pidusage');
|
||||
const Stats = require('fast-stats').Stats;
|
||||
|
||||
const Logger = require('../Logger');
|
||||
|
||||
const logger = new Logger('metrics:aggregated');
|
||||
|
||||
//
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import Logger from '../Logger';
|
||||
|
||||
const { Resolver } = require('dns').promises;
|
||||
const prom = require('prom-client');
|
||||
const Logger = require('../Logger');
|
||||
|
||||
const logger = new Logger('metrics:default');
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
import Logger from './Logger';
|
||||
|
||||
const express = require('express');
|
||||
const mediasoup = require('mediasoup');
|
||||
const promClient = require('prom-client');
|
||||
|
||||
const Logger = require('./Logger');
|
||||
const collectDefaultMetrics = require('./metrics/default');
|
||||
const RegisterAggregated = require('./metrics/aggregated');
|
||||
|
||||
|
|
|
|||
3984
server/package-lock.json
generated
3984
server/package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
|
@ -14,9 +14,12 @@
|
|||
"license": "MIT",
|
||||
"main": "lib/index.js",
|
||||
"scripts": {
|
||||
"start": "node server.js",
|
||||
"connect": "node connect.js",
|
||||
"lint": "eslint -c .eslintrc.json --ext .js *.js lib/"
|
||||
"start": "npm run build && node dist/server.js",
|
||||
"build": "rm -rf dist && tsc && ln -s ../certs dist/certs",
|
||||
"dev": "nodemon --exec ts-node --ignore dist/ -e js,ts server.js",
|
||||
"connect": "ts-node connect.js",
|
||||
"lint": "eslint -c .eslintrc.json --ext .js,.ts *.js *.ts lib/",
|
||||
"format": "prettier --write '**/*.ts' && npm run lint --fix"
|
||||
},
|
||||
"dependencies": {
|
||||
"awaitqueue": "^1.0.0",
|
||||
|
|
@ -50,6 +53,32 @@
|
|||
"uuid": "^7.0.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"eslint": "6.8.0"
|
||||
"@types/base-64": "^0.1.3",
|
||||
"@types/body-parser": "^1.19.0",
|
||||
"@types/compression": "^1.7.0",
|
||||
"@types/connect-redis": "^0.0.16",
|
||||
"@types/cookie-parser": "^1.4.2",
|
||||
"@types/debug": "^4.1.5",
|
||||
"@types/express": "^4.17.11",
|
||||
"@types/express-session": "^1.17.3",
|
||||
"@types/helmet": "^4.0.0",
|
||||
"@types/jsonwebtoken": "^8.5.1",
|
||||
"@types/node": "^14.14.37",
|
||||
"@types/passport": "^1.0.6",
|
||||
"@types/passport-local": "^1.0.33",
|
||||
"@types/redis": "^2.8.28",
|
||||
"@types/uuid": "^8.3.0",
|
||||
"@typescript-eslint/eslint-plugin": "^4.21.0",
|
||||
"@typescript-eslint/parser": "^4.21.0",
|
||||
"eslint": "6.8.0",
|
||||
"eslint-config-airbnb-typescript": "^12.3.1",
|
||||
"eslint-config-prettier": "^8.1.0",
|
||||
"eslint-plugin-import": "^2.22.1",
|
||||
"eslint-plugin-prettier": "^3.3.1",
|
||||
"prettier": "^2.2.1",
|
||||
"prettier-cli": "^0.1.0",
|
||||
"prettier-eslint": "^12.0.0",
|
||||
"ts-node": "^9.1.1",
|
||||
"typescript": "^4.2.4"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
process.title = 'edumeet-server';
|
||||
|
||||
import Logger from './lib/Logger';
|
||||
|
||||
const bcrypt = require('bcrypt');
|
||||
const config = require('./config/config');
|
||||
const fs = require('fs');
|
||||
|
|
@ -13,7 +15,6 @@ const cookieParser = require('cookie-parser');
|
|||
const compression = require('compression');
|
||||
const mediasoup = require('mediasoup');
|
||||
const AwaitQueue = require('awaitqueue');
|
||||
const Logger = require('./lib/Logger');
|
||||
const Room = require('./lib/Room');
|
||||
const Peer = require('./lib/Peer');
|
||||
const base64 = require('base-64');
|
||||
|
|
|
|||
17
server/tsconfig.json
Normal file
17
server/tsconfig.json
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2017",
|
||||
"module": "commonjs",
|
||||
"esModuleInterop": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"allowJs": true,
|
||||
"moduleResolution": "node",
|
||||
"sourceMap": true,
|
||||
"outDir": "dist",
|
||||
"rootDir": "."
|
||||
},
|
||||
"include": [
|
||||
"**/*.ts",
|
||||
"**/*.js"
|
||||
],
|
||||
}
|
||||
4619
server/yarn.lock
Normal file
4619
server/yarn.lock
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue