sfu creation added
This commit is contained in:
@@ -10,6 +10,7 @@ module.exports = {
|
||||
session_limit: parseInt(process.env.SESSION_LIMIT),
|
||||
log_path: "./logs/runtime.log",
|
||||
webrtc_server_path: process.env.WEBRTC_SERVER_PATH,
|
||||
sfu_server_path: process.env.SFU_SERVER_PATH,
|
||||
app_args: {
|
||||
runtime: {
|
||||
port: "-PixelStreamingPort="
|
||||
|
||||
@@ -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 not_found_error = require('../../lib/src/http/errors/not_found_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 {port} = require('../../config')
|
||||
|
||||
@@ -47,8 +47,16 @@ const run_session = async (req, res, next) => {
|
||||
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) {
|
||||
next(new server_error('can not add session to database'))
|
||||
|
||||
@@ -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()
|
||||
if (!db) {
|
||||
return false
|
||||
@@ -33,6 +33,7 @@ const add_running_session = async (session_id, title, app_pid, webrtc_pid, app_p
|
||||
title: title,
|
||||
app_pid: app_pid,
|
||||
webrtc_pid: webrtc_pid,
|
||||
sfu_pid: sfu_pid,
|
||||
app_port: app_port,
|
||||
webrtc_port: webrtc_port,
|
||||
sfu_port: sfu_port,
|
||||
|
||||
@@ -2,6 +2,7 @@ const {spawn, fork} = require('node:child_process')
|
||||
const is_running = require('is-running')
|
||||
const config = require('../../config')
|
||||
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_port_arg = config.app_args.runtime.port
|
||||
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) => {
|
||||
if (!is_proc_running(pid)) {
|
||||
return
|
||||
@@ -96,6 +119,7 @@ const kill_proc = (pid) => {
|
||||
module.exports = {
|
||||
run_webrtc,
|
||||
run_app,
|
||||
run_sfu,
|
||||
is_proc_running,
|
||||
is_proc_running_async,
|
||||
kill_proc
|
||||
|
||||
@@ -35,6 +35,7 @@ const check_sessions = async (sessions) => {
|
||||
// kill process if running
|
||||
kill_proc(session.webrtc_pid)
|
||||
kill_proc(session.app_pid)
|
||||
kill_proc(session.sfu_pid)
|
||||
// free ports allocated for processes
|
||||
free_webrtc_port(session.webrtc_port)
|
||||
free_app_port(session.app_port)
|
||||
|
||||
@@ -58,6 +58,11 @@ const test_config = () => {
|
||||
config_pass = false
|
||||
}
|
||||
|
||||
if (!config.sfu_server_path) {
|
||||
not_valid('sfu_server_path')
|
||||
config_pass = false
|
||||
}
|
||||
|
||||
if (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)')
|
||||
|
||||
Reference in New Issue
Block a user