sfu creation added

This commit is contained in:
2023-04-20 09:02:44 +03:00
parent 9c2c413363
commit c8da3c8e38
6 changed files with 43 additions and 3 deletions
+1
View File
@@ -10,6 +10,7 @@ module.exports = {
session_limit: parseInt(process.env.SESSION_LIMIT), session_limit: parseInt(process.env.SESSION_LIMIT),
log_path: "./logs/runtime.log", log_path: "./logs/runtime.log",
webrtc_server_path: process.env.WEBRTC_SERVER_PATH, webrtc_server_path: process.env.WEBRTC_SERVER_PATH,
sfu_server_path: process.env.SFU_SERVER_PATH,
app_args: { app_args: {
runtime: { runtime: {
port: "-PixelStreamingPort=" port: "-PixelStreamingPort="
+10 -2
View File
@@ -3,7 +3,7 @@ const {get_webrtc_port, get_app_port, get_sfu_port} = require('../modules/port_a
const {get_app_path} = require('../modules/titles') const {get_app_path} = require('../modules/titles')
const not_found_error = require('../../lib/src/http/errors/not_found_error') const not_found_error = require('../../lib/src/http/errors/not_found_error')
const server_error = require('../../lib/src/http/errors/server_error') const server_error = require('../../lib/src/http/errors/server_error')
const {run_webrtc, run_app, kill_proc} = require('../modules/run_process') const {run_webrtc, run_app, run_sfu, kill_proc} = require('../modules/run_process')
const {create_websocket_url} = require('../modules/links') const {create_websocket_url} = require('../modules/links')
const {port} = require('../../config') const {port} = require('../../config')
@@ -47,8 +47,16 @@ const run_session = async (req, res, next) => {
return return
} }
let sfu_pid = await run_sfu(sfu_port)
if (!sfu_pid) {
kill_proc(app_pid)
kill_proc(webrtc_pid)
next(new server_error('can not run sfu'))
return
}
let add_runnning_session_result = await database.add_running_session(session_id, title, app_pid, webrtc_pid, app_port, webrtc_port, sfu_port)
let add_runnning_session_result = await database.add_running_session(session_id, title, app_pid, webrtc_pid, sfu_pid, app_port, webrtc_port, sfu_port)
if(!add_runnning_session_result) { if(!add_runnning_session_result) {
next(new server_error('can not add session to database')) next(new server_error('can not add session to database'))
+2 -1
View File
@@ -20,7 +20,7 @@ const get_db = async () => {
} }
} }
const add_running_session = async (session_id, title, app_pid, webrtc_pid, app_port, webrtc_port, sfu_port) => { const add_running_session = async (session_id, title, app_pid, webrtc_pid, sfu_pid, app_port, webrtc_port, sfu_port) => {
let db = await get_db() let db = await get_db()
if (!db) { if (!db) {
return false return false
@@ -33,6 +33,7 @@ const add_running_session = async (session_id, title, app_pid, webrtc_pid, app_p
title: title, title: title,
app_pid: app_pid, app_pid: app_pid,
webrtc_pid: webrtc_pid, webrtc_pid: webrtc_pid,
sfu_pid: sfu_pid,
app_port: app_port, app_port: app_port,
webrtc_port: webrtc_port, webrtc_port: webrtc_port,
sfu_port: sfu_port, sfu_port: sfu_port,
+24
View File
@@ -2,6 +2,7 @@ const {spawn, fork} = require('node:child_process')
const is_running = require('is-running') const is_running = require('is-running')
const config = require('../../config') const config = require('../../config')
const webrtc_server_path = config.webrtc_server_path const webrtc_server_path = config.webrtc_server_path
const sfu_server_path = config.sfu_server_path
const app_args_static = config.app_args.static const app_args_static = config.app_args.static
const app_port_arg = config.app_args.runtime.port const app_port_arg = config.app_args.runtime.port
const fs = require('fs') const fs = require('fs')
@@ -76,6 +77,28 @@ const run_app = async (app_path, app_port) => {
} }
const run_sfu = async (sfu_port) => {
if (!fs.existsSync(sfu_server_path)) {
return null
}
let sfu_proc
try {
let sfu_proc_arg = JSON.stringify({sfu_port:sfu_port})
sfu_proc = fork(sfu_server_path, [sfu_proc_arg], {
detached: true
})
//await tcp_port_used.waitUntilUsed(webrtc_port, webrtc_retry_time, webrtc_timeout)
} catch (err) {
console.error(err)
return null
}
//let proc_status = await is_proc_running_async(webrtc_proc.pid, 500)
return (sfu_proc) ? sfu_proc.pid : null
}
const kill_proc = (pid) => { const kill_proc = (pid) => {
if (!is_proc_running(pid)) { if (!is_proc_running(pid)) {
return return
@@ -96,6 +119,7 @@ const kill_proc = (pid) => {
module.exports = { module.exports = {
run_webrtc, run_webrtc,
run_app, run_app,
run_sfu,
is_proc_running, is_proc_running,
is_proc_running_async, is_proc_running_async,
kill_proc kill_proc
+1
View File
@@ -35,6 +35,7 @@ const check_sessions = async (sessions) => {
// kill process if running // kill process if running
kill_proc(session.webrtc_pid) kill_proc(session.webrtc_pid)
kill_proc(session.app_pid) kill_proc(session.app_pid)
kill_proc(session.sfu_pid)
// free ports allocated for processes // free ports allocated for processes
free_webrtc_port(session.webrtc_port) free_webrtc_port(session.webrtc_port)
free_app_port(session.app_port) free_app_port(session.app_port)
+5
View File
@@ -58,6 +58,11 @@ const test_config = () => {
config_pass = false config_pass = false
} }
if (!config.sfu_server_path) {
not_valid('sfu_server_path')
config_pass = false
}
if (config.webrtc_server_path) { if (config.webrtc_server_path) {
if (!fs.existsSync(config.webrtc_server_path)) { if (!fs.existsSync(config.webrtc_server_path)) {
not_valid('wbertc_server_path exists in config BUT not in the filesystem (file not exists)') not_valid('wbertc_server_path exists in config BUT not in the filesystem (file not exists)')