SFU support added, SFU configured, IPC support session server added
This commit is contained in:
@@ -16,11 +16,13 @@ try {
|
||||
var express = require('express');
|
||||
var app = express();
|
||||
|
||||
const {fork} = require('node:child_process')
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const querystring = require('querystring');
|
||||
const bodyParser = require('body-parser');
|
||||
const logging = require('./modules/logging.js');
|
||||
var request = require('request')
|
||||
logging.RegisterConsoleLogger();
|
||||
|
||||
// Command line argument --configFile needs to be checked before loading the config, all other command line arguments are dealt with through the config object
|
||||
@@ -52,7 +54,33 @@ const config = require('./modules/config.js').init(configFile, defaultConfig);
|
||||
|
||||
config.StreamerPort = server_settings.app_port
|
||||
config.HttpPort = server_settings.webrtc_port
|
||||
config.SFUPort = 0
|
||||
config.SFUPort = server_settings.sfu_port
|
||||
const session_server_url = server_settings.session_server_url
|
||||
const session_id = server_settings.session_id
|
||||
const useSFU = true
|
||||
console.log('useSFU: ', useSFU)
|
||||
|
||||
function runSFU() {
|
||||
const sfu_file_path = __dirname + '/../SFU/sfu_server.js'
|
||||
if (!fs.existsSync(sfu_file_path)) {
|
||||
console.logColor(logging.Red, 'can not run sfu: sfu file not exists!')
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
var sfu_proc_args = JSON.stringify({sfu_port:config.SFUPort})
|
||||
fork(sfu_file_path, [sfu_proc_args], {
|
||||
detached: true
|
||||
})
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
if (useSFU) {
|
||||
runSFU()
|
||||
}
|
||||
|
||||
if (config.LogToFile) {
|
||||
logging.RegisterFileLogger('./logs/');
|
||||
@@ -552,6 +580,22 @@ var has_player_ever_connected = false
|
||||
var last_player_connection_time
|
||||
|
||||
const check_players = () => {
|
||||
// update player count on session server
|
||||
try {
|
||||
request.post(
|
||||
session_server_url + '/cirrus/update_users_count',
|
||||
{ json: { session_id: session_id, users_count: playerCount } },
|
||||
function (error, response, body) {
|
||||
if (!error && response.statusCode == 200) {
|
||||
console.log(body);
|
||||
}
|
||||
}
|
||||
)
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
}
|
||||
|
||||
|
||||
// if first player connection timeout reached destory session
|
||||
if (!has_player_ever_connected) {
|
||||
has_player_ever_connected = playerCount > 0
|
||||
@@ -573,6 +617,7 @@ const check_players = () => {
|
||||
}
|
||||
console.log('reconnection time: ', (get_time_in_seconds() - last_player_connection_time))
|
||||
if ((get_time_in_seconds() - last_player_connection_time) > player_reconnection_timeout) {
|
||||
//console.log('should exit, but wont for debug')
|
||||
exit()
|
||||
}
|
||||
}
|
||||
@@ -588,6 +633,7 @@ start_players_check()
|
||||
console.logColor(logging.Green, `WebSocket listening for Players connections on :${httpPort}`);
|
||||
let playerServer = new WebSocket.Server({ server: config.UseHTTPS ? https : http});
|
||||
playerServer.on('connection', function (ws, req) {
|
||||
|
||||
// Reject connection if streamer is not connected
|
||||
if (!streamer || streamer.readyState != 1 /* OPEN */) {
|
||||
ws.close(1013 /* Try again later */, 'Streamer is not connected');
|
||||
@@ -597,7 +643,7 @@ playerServer.on('connection', function (ws, req) {
|
||||
var url = require('url');
|
||||
const parsedUrl = url.parse(req.url);
|
||||
const urlParams = new URLSearchParams(parsedUrl.search);
|
||||
const preferSFU = urlParams.has('preferSFU') && urlParams.get('preferSFU') !== 'false';
|
||||
const preferSFU = useSFU//urlParams.has('preferSFU') && urlParams.get('preferSFU') !== 'false';
|
||||
const skipSFU = !preferSFU;
|
||||
const skipStreamer = preferSFU && sfu;
|
||||
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
* Class definitions
|
||||
* TODO: Move these to seperate files once we introduce a bundler
|
||||
*/
|
||||
|
||||
|
||||
class TwoWayMap {
|
||||
constructor(map = {}) {
|
||||
this.map = map;
|
||||
@@ -881,7 +883,7 @@ function setupHtmlEvents() {
|
||||
}
|
||||
|
||||
// Setup toggle and pair with some URL query string param.
|
||||
setupToggleWithUrlParams("prefer-sfu-tgl", "preferSFU");
|
||||
//setupToggleWithUrlParams("prefer-sfu-tgl", "preferSFU");
|
||||
setupToggleWithUrlParams("use-mic-tgl", "useMic");
|
||||
setupToggleWithUrlParams("force-turn-tgl", "ForceTURN");
|
||||
setupToggleWithUrlParams("force-mono-tgl", "ForceMonoAudio");
|
||||
|
||||
@@ -75,7 +75,8 @@ function webRtcPlayer(parOptions) {
|
||||
}
|
||||
|
||||
// Prefer SFU or P2P connection
|
||||
this.preferSFU = urlParams.has('preferSFU');
|
||||
this.preferSFU = true//urlParams.has('preferSFU');
|
||||
console.log('USING SFU: ', this.preferSFU)
|
||||
console.log(this.preferSFU ?
|
||||
"The browser will signal it would prefer an SFU connection. Remove ?preferSFU from the url to signal for P2P usage." :
|
||||
"The browser will signal for a P2P connection. Pass ?preferSFU in the url to signal for SFU usage.");
|
||||
|
||||
Reference in New Issue
Block a user