observer added, database added to improve fault tolerance, config fixed, ping added, port allocation improved, session observer added, multiple checks added, run process improved, process running check added, fault tolerance improved
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
const database = require('../database/database')
|
||||
const {get_webrtc_port, get_app_port} = require('../modules/port_alloc')
|
||||
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} = require('../modules/run_process')
|
||||
const {external_url} = require('../../config')
|
||||
|
||||
|
||||
const run_session = async (req, res, next) => {
|
||||
const {title, session_id} = req.body
|
||||
|
||||
var app_path = get_app_path(title)
|
||||
if (!app_path) {
|
||||
next(new not_found_error('title or path does not exist'))
|
||||
return
|
||||
}
|
||||
|
||||
var webrtc_port = await get_webrtc_port()
|
||||
var app_port = await get_app_port()
|
||||
|
||||
if (!app_port || !webrtc_port) {
|
||||
next(new server_error('all ports busy'))
|
||||
return
|
||||
}
|
||||
|
||||
var webrtc_pid = await run_webrtc(webrtc_port, app_port)
|
||||
if (!webrtc_pid) {
|
||||
next(new server_error('can not run webrtc'))
|
||||
return
|
||||
}
|
||||
|
||||
var app_pid = await run_app(app_path, app_port)
|
||||
if (!app_pid) {
|
||||
next(new server_error('can not run app'))
|
||||
return
|
||||
}
|
||||
|
||||
var add_runnning_session_result = await database.add_running_session(session_id, app_pid, webrtc_pid)
|
||||
|
||||
if(!add_runnning_session_result) {
|
||||
next(new server_error('can not add session to database'))
|
||||
return
|
||||
}
|
||||
|
||||
res.json({websocket_url:`wss://${external_url}${webrtc_port}/`})
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
run_session
|
||||
}
|
||||
Reference in New Issue
Block a user