diff --git a/src/net/MasterServerClient.hx b/src/net/MasterServerClient.hx index 42226bc5..4816ed2b 100644 --- a/src/net/MasterServerClient.hx +++ b/src/net/MasterServerClient.hx @@ -69,6 +69,12 @@ class MasterServerClient { } } + public function heartBeat() { + ws.sendString(Json.stringify({ + type: "heartbeat" + })); + } + public function sendServerInfo(serverInfo:ServerInfo) { ws.sendString(Json.stringify({ type: "serverInfo", @@ -180,5 +186,8 @@ class MasterServerClient { loadGui.setErrorStatus(conts.reason); } } + if (conts.type == "turnserver") { + Net.turnServer = conts.server; // Turn server! + } } } diff --git a/src/net/Net.hx b/src/net/Net.hx index 9f89ea78..9f0dac98 100644 --- a/src/net/Net.hx +++ b/src/net/Net.hx @@ -80,11 +80,16 @@ class Net { public static var remoteServerInfo:RemoteServerInfo; static var stunServers = [ - "stun.l.google.com:19302", "stun1.l.google.com:19302", "stun2.l.google.com:19302", "stun3.l.google.com:19302", "stun4.l.google.com:19302", - "stun:relay.metered.ca:80", "stun.ekiga.net", "stun.ideasip.com", "stun.rixtelecom.se", "stun.schlund.de", "stun.stunprotocol.org:3478", - "stun.voiparound.com", "stun.voipbuster.com", "stun.voipstunt.com", "stun.voxgratia.org" + "stun:stun.l.google.com:19302", + "stun:stun1.l.google.com:19302", + "stun:stun2.l.google.com:19302", + "stun:stun3.l.google.com:19302", + "stun:stun4.l.google.com:19302", + "stun:relay.metered.ca:80", ]; + public static var turnServer:String = ""; + public static function hostServer(name:String, maxPlayers:Int, privateSlots:Int, privateServer:Bool, onHosted:() -> Void) { serverInfo = new ServerInfo(name, 1, maxPlayers, privateSlots, privateServer, Std.int(999999 * Math.random()), "LOBBY", getPlatform()); MasterServerClient.connectToMasterServer(() -> { @@ -98,7 +103,7 @@ class Net { } public static function addClientFromSdp(sdpString:String, privateJoin:Bool, onFinishSdp:String->Void) { - var peer = new RTCPeerConnection(stunServers, "0.0.0.0"); + var peer = new RTCPeerConnection(stunServers.concat([turnServer]), "0.0.0.0"); var sdpObj = Json.parse(sdpString); peer.setRemoteDescription(sdpObj.sdp, sdpObj.type); addClient(peer, privateJoin, onFinishSdp); @@ -146,7 +151,7 @@ class Net { public static function joinServer(serverName:String, isInvite:Bool, connectedCb:() -> Void) { MasterServerClient.connectToMasterServer(() -> { - client = new RTCPeerConnection(stunServers, "0.0.0.0"); + client = new RTCPeerConnection(stunServers.concat([turnServer]), "0.0.0.0"); var candidates = []; client.onLocalCandidate = (c) -> { @@ -338,6 +343,9 @@ class Net { if (Net.isHost) { MasterServerClient.instance.sendServerInfo(serverInfo); // Heartbeat } + if (Net.isClient) { + MasterServerClient.instance.heartBeat(); + } } }