stun and turn servers added, http listen after streamer connection added, player connection detection added
This commit is contained in:
@@ -275,9 +275,13 @@ if(config.EnableWebserver) {
|
||||
}
|
||||
|
||||
//Setup http and https servers
|
||||
http.listen(httpPort, function () {
|
||||
console.logColor(logging.Green, 'Http listening on *: ' + httpPort);
|
||||
});
|
||||
var isHttpWorking = false
|
||||
|
||||
// http listen moved to streamer connection because webrtc server starts liten after application running
|
||||
|
||||
// http.listen(httpPort, function () {
|
||||
// console.logColor(logging.Green, 'Http listening on *: ' + httpPort);
|
||||
// });
|
||||
|
||||
if (config.UseHTTPS) {
|
||||
https.listen(httpsPort, function () {
|
||||
@@ -343,6 +347,7 @@ function sendMessageToPlayer(playerId, msg) {
|
||||
|
||||
let WebSocket = require('ws');
|
||||
const { URL } = require('url');
|
||||
const { exit } = require('process')
|
||||
|
||||
console.logColor(logging.Green, `WebSocket listening for Streamer connections on :${streamerPort}`)
|
||||
let streamerServer = new WebSocket.Server({ port: streamerPort, backlog: 1 });
|
||||
@@ -359,6 +364,13 @@ streamerServer.on('connection', function (ws, req) {
|
||||
console.logColor(logging.Green, `Streamer connected: ${req.connection.remoteAddress}`);
|
||||
sendStreamerConnectedToMatchmaker();
|
||||
|
||||
if (!isHttpWorking) {
|
||||
isHttpWorking = true
|
||||
http.listen(httpPort, function () {
|
||||
console.logColor(logging.Green, 'Http listening on *: ' + httpPort);
|
||||
});
|
||||
}
|
||||
|
||||
ws.on('message', (msgRaw) => {
|
||||
|
||||
var msg;
|
||||
@@ -526,6 +538,49 @@ sfuServer.on('connection', function (ws, req) {
|
||||
|
||||
let playerCount = 0;
|
||||
|
||||
const get_time_in_seconds = () => {
|
||||
return new Date().getTime() / 1000;
|
||||
}
|
||||
|
||||
var session_start_time = get_time_in_seconds()
|
||||
|
||||
// timeouts
|
||||
const first_connection_timeout = 40
|
||||
const player_reconnection_timeout = 30
|
||||
|
||||
// players connection detection
|
||||
var has_player_ever_connected = false
|
||||
var last_player_connection_time
|
||||
|
||||
const check_players = () => {
|
||||
// if first player connection timeout reached destory session
|
||||
if (!has_player_ever_connected) {
|
||||
has_player_ever_connected = playerCount > 0
|
||||
|
||||
// if player never connected and timeout reached destroy session by exit
|
||||
if ((get_time_in_seconds() - session_start_time) > first_connection_timeout) {
|
||||
exit()
|
||||
}
|
||||
// if player never connected skip everything
|
||||
return
|
||||
}
|
||||
// if player not connected in reconnection timeout destory session
|
||||
if (playerCount) {
|
||||
last_player_connection_time = get_time_in_seconds()
|
||||
} else {
|
||||
if ((get_time_in_seconds() - last_player_connection_time) > player_reconnection_timeout) {
|
||||
exit()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const start_players_check = () => {
|
||||
check_players()
|
||||
setTimeout(() => start_players_check(), 1000)
|
||||
}
|
||||
|
||||
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) {
|
||||
|
||||
@@ -16,5 +16,6 @@
|
||||
"StreamerPort": 8888,
|
||||
"SFUPort": 8889,
|
||||
"MaxPlayerCount": -1,
|
||||
"peerConnectionOptions": "{ \"iceServers\": [{\"urls\": [\"stun:stun1.l.google.com:19302\",\"stun:stun1.l.google.com:19302\"]}] }"
|
||||
"peerConnectionOptions": "{\"iceServers\": [{\"urls\": [\"stun:stun1.l.google.com:19302\",\"stun:stun2.l.google.com:19302\",\"stun:stun3.l.google.com:19302\",\"stun:stun4.l.google.com:19302\"]},{\"urls\":[\"turn:13.250.13.83:3478?transport=udp\"],\"username\":\"YzYNCouZM1mhqhmseWk6\",\"credential\":\"YzYNCouZM1mhqhmseWk6\"},{\"urls\": [\"turn:192.158.29.39:3478?transport=tcp\"],\"credential\": \"JZEOEt2V3Qb0y27GRntt2u2PAYA=\",\"username\": \"28224511:1379330808\"}]}"
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user