diff --git a/meshcentral.js b/meshcentral.js index 4c78ed2f..63e019ad 100644 --- a/meshcentral.js +++ b/meshcentral.js @@ -1520,7 +1520,17 @@ function CreateMeshCentralServer(config, args) { if (obj.args.redirport == null) obj.args.redirport = 80; if (obj.args.minifycore == null) obj.args.minifycore = false; if (typeof obj.args.agentidletimeout != 'number') { obj.args.agentidletimeout = 150000; } else { obj.args.agentidletimeout *= 1000 } // Default agent idle timeout is 2m, 30sec. - if ((obj.args.lanonly != true) && (obj.args.webrtconfig == null)) { obj.args.webrtconfig = { iceservers: [{ urls: 'stun:stun.l.google.com:19302' }, { urls: 'stun:stun.services.mozilla.com' }] }; } // Setup default WebRTC STUN servers + if ((obj.args.lanonly != true) && (typeof obj.args.webrtconfig == 'object')) { // fix incase you are using an old mis-spelt webrtconfig + obj.args.webrtcconfig = obj.args.webrtconfig; + delete obj.args.webrtconfig; + } + if ((obj.args.lanonly != true) && (obj.args.webrtcconfig == null)) { obj.args.webrtcconfig = { iceServers: [{ urls: 'stun:stun.l.google.com:19302' }, { urls: 'stun:stun.cloudflare.com:3478' }] }; } // Setup default WebRTC STUN servers + else if ((obj.args.lanonly != true) && (typeof obj.args.webrtcconfig == 'object')) { + if (obj.args.webrtcconfig.iceservers) { // webrtc is case-sensitive, so must rename iceservers to iceServers! + obj.args.webrtcconfig.iceServers = obj.args.webrtcconfig.iceservers; + delete obj.args.webrtcconfig.iceservers; + } + } if (typeof obj.args.ignoreagenthashcheck == 'string') { if (obj.args.ignoreagenthashcheck == '') { delete obj.args.ignoreagenthashcheck; } else { obj.args.ignoreagenthashcheck = obj.args.ignoreagenthashcheck.split(','); } } // Setup a site administrator diff --git a/public/scripts/agent-redir-ws-0.1.1.js b/public/scripts/agent-redir-ws-0.1.1.js index 747860b7..63274522 100644 --- a/public/scripts/agent-redir-ws-0.1.1.js +++ b/public/scripts/agent-redir-ws-0.1.1.js @@ -23,6 +23,7 @@ var CreateAgentRedirect = function (meshserver, module, serverPublicNamePort, au obj.ctrlMsgAllowed = true; obj.attemptWebRTC = false; obj.webRtcActive = false; + obj.webrtcconfig = null; obj.webSwitchOk = false; obj.webchannel = null; obj.webrtc = null; @@ -158,7 +159,7 @@ var CreateAgentRedirect = function (meshserver, module, serverPublicNamePort, au if (obj.attemptWebRTC == true) { // Try to get WebRTC setup - var configuration = null; //{ "iceServers": [ { 'urls': 'stun:stun.services.mozilla.com' }, { 'urls': 'stun:stun.l.google.com:19302' } ] }; + var configuration = obj.webrtcconfig; //{ "iceServers": [ { 'urls': 'stun:stun.cloudflare.com:3478' }, { 'urls': 'stun:stun.l.google.com:19302' } ] }; if (typeof RTCPeerConnection !== 'undefined') { obj.webrtc = new RTCPeerConnection(configuration); } else if (typeof webkitRTCPeerConnection !== 'undefined') { obj.webrtc = new webkitRTCPeerConnection(configuration); } if ((obj.webrtc != null) && (obj.webrtc.createDataChannel)) { diff --git a/views/default.handlebars b/views/default.handlebars index 5e827945..85ba49a1 100644 --- a/views/default.handlebars +++ b/views/default.handlebars @@ -1560,6 +1560,8 @@ var debugmode = 0; var windowsBrowser = detectWindowsBrowser(); var attemptWebRTC = ((features & 128) != 0); + var webrtcconfiguration = '{{{webrtcconfig}}}'; + if (webrtcconfiguration == '') { webrtcconfiguration = null; } else { try { webrtcconfiguration = JSON.parse(decodeURIComponent(webrtcconfiguration)); } catch (ex) { console.log('Invalid WebRTC config: "' + webrtcconfiguration + '".'); webrtcconfiguration = null; } } var passRequirements = '{{{passRequirements}}}'; if (passRequirements != '') { passRequirements = JSON.parse(decodeURIComponent(passRequirements)); } var customui = '{{{customui}}}'; @@ -9292,6 +9294,7 @@ desktop.debugmode = debugmode; desktop.m.debugmode = debugmode; desktop.attemptWebRTC = attemptWebRTC; + desktop.webrtcconfig = webrtcconfiguration; desktop.options = {}; if (tsid != null) { desktop.options.tsid = tsid; } if (consent != null) { desktop.options.consent = consent; } diff --git a/views/messenger.handlebars b/views/messenger.handlebars index 84f824aa..cf0d9115 100644 --- a/views/messenger.handlebars +++ b/views/messenger.handlebars @@ -83,7 +83,7 @@ var meshMessengerImage = '{{{meshMessengerImage}}}'; var remoteUserName = '{{{username}}}'; var remoteUserId = '{{{userid}}}'; - var webrtcconfiguration = '{{{webrtconfig}}}'; + var webrtcconfiguration = '{{{webrtcconfig}}}'; if (webrtcconfiguration == '') { webrtcconfiguration = null; } else { try { webrtcconfiguration = JSON.parse(decodeURIComponent(webrtcconfiguration)); } catch (ex) { console.log('Invalid WebRTC config: "' + webrtcconfiguration + '".'); webrtcconfiguration = null; } } var windowFocus = true; var chatTextSession = new Date().toString() + '\r\n'; diff --git a/webserver.js b/webserver.js index 667646d7..22e9b932 100644 --- a/webserver.js +++ b/webserver.js @@ -3127,6 +3127,11 @@ module.exports.CreateWebServer = function (parent, db, args, certificates, doneF if ((serverFeatures & 2) != 0) { serverFeatures -= 2; } // Disallow simple server restore } + // Get WebRTC configuration + var webRtcConfig = null; + if (obj.parent.config.settings && obj.parent.config.settings.webrtcconfig && (typeof obj.parent.config.settings.webrtcconfig == 'object')) { webRtcConfig = encodeURIComponent(JSON.stringify(obj.parent.config.settings.webrtcconfig)).replace(/'/g, '%27'); } + else if (args.webrtcconfig && (typeof args.webrtcconfig == 'object')) { webRtcConfig = encodeURIComponent(JSON.stringify(args.webrtcconfig)).replace(/'/g, '%27'); } + // Refresh the session render(dbGetFunc.req, dbGetFunc.res, getRenderPage('default', dbGetFunc.req, domain), getRenderArgs({ authCookie: authCookie, @@ -3155,7 +3160,8 @@ module.exports.CreateWebServer = function (parent, db, args, certificates, doneF webRelayDns: ((args.relaydns != null) ? args.relaydns[0] : ''), hidePowerTimeline: (domain.hidepowertimeline ? 'true' : 'false'), showNotesPanel: (domain.shownotespanel ? 'true' : 'false'), - userSessionsSort: (domain.usersessionssort ? domain.usersessionssort : 'SessionId') + userSessionsSort: (domain.usersessionssort ? domain.usersessionssort : 'SessionId'), + webrtcconfig: webRtcConfig }, dbGetFunc.req, domain), user); } xdbGetFunc.req = req; @@ -3632,11 +3638,11 @@ module.exports.CreateWebServer = function (parent, db, args, certificates, doneF // Get WebRTC configuration var webRtcConfig = null; - if (obj.parent.config.settings && obj.parent.config.settings.webrtconfig && (typeof obj.parent.config.settings.webrtconfig == 'object')) { webRtcConfig = encodeURIComponent(JSON.stringify(obj.parent.config.settings.webrtconfig)).replace(/'/g, '%27'); } - else if (args.webrtconfig && (typeof args.webrtconfig == 'object')) { webRtcConfig = encodeURIComponent(JSON.stringify(args.webrtconfig)).replace(/'/g, '%27'); } + if (obj.parent.config.settings && obj.parent.config.settings.webrtcconfig && (typeof obj.parent.config.settings.webrtcconfig == 'object')) { webRtcConfig = encodeURIComponent(JSON.stringify(obj.parent.config.settings.webrtcconfig)).replace(/'/g, '%27'); } + else if (args.webrtcconfig && (typeof args.webrtcconfig == 'object')) { webRtcConfig = encodeURIComponent(JSON.stringify(args.webrtcconfig)).replace(/'/g, '%27'); } // Setup other options - var options = { webrtconfig: webRtcConfig }; + var options = { webrtcconfig: webRtcConfig }; if (typeof domain.meshmessengertitle == 'string') { options.meshMessengerTitle = domain.meshmessengertitle; } else { options.meshMessengerTitle = '!'; } // Get the userid and name