mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2026-04-27 13:11:42 +00:00
turn server support?
This commit is contained in:
parent
84f251614a
commit
3c4927e52e
2 changed files with 22 additions and 5 deletions
|
|
@ -69,6 +69,12 @@ class MasterServerClient {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function heartBeat() {
|
||||||
|
ws.sendString(Json.stringify({
|
||||||
|
type: "heartbeat"
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
public function sendServerInfo(serverInfo:ServerInfo) {
|
public function sendServerInfo(serverInfo:ServerInfo) {
|
||||||
ws.sendString(Json.stringify({
|
ws.sendString(Json.stringify({
|
||||||
type: "serverInfo",
|
type: "serverInfo",
|
||||||
|
|
@ -180,5 +186,8 @@ class MasterServerClient {
|
||||||
loadGui.setErrorStatus(conts.reason);
|
loadGui.setErrorStatus(conts.reason);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (conts.type == "turnserver") {
|
||||||
|
Net.turnServer = conts.server; // Turn server!
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -80,11 +80,16 @@ class Net {
|
||||||
public static var remoteServerInfo:RemoteServerInfo;
|
public static var remoteServerInfo:RemoteServerInfo;
|
||||||
|
|
||||||
static var stunServers = [
|
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:stun.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:stun1.l.google.com:19302",
|
||||||
"stun.voiparound.com", "stun.voipbuster.com", "stun.voipstunt.com", "stun.voxgratia.org"
|
"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) {
|
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());
|
serverInfo = new ServerInfo(name, 1, maxPlayers, privateSlots, privateServer, Std.int(999999 * Math.random()), "LOBBY", getPlatform());
|
||||||
MasterServerClient.connectToMasterServer(() -> {
|
MasterServerClient.connectToMasterServer(() -> {
|
||||||
|
|
@ -98,7 +103,7 @@ class Net {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function addClientFromSdp(sdpString:String, privateJoin:Bool, onFinishSdp:String->Void) {
|
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);
|
var sdpObj = Json.parse(sdpString);
|
||||||
peer.setRemoteDescription(sdpObj.sdp, sdpObj.type);
|
peer.setRemoteDescription(sdpObj.sdp, sdpObj.type);
|
||||||
addClient(peer, privateJoin, onFinishSdp);
|
addClient(peer, privateJoin, onFinishSdp);
|
||||||
|
|
@ -146,7 +151,7 @@ class Net {
|
||||||
|
|
||||||
public static function joinServer(serverName:String, isInvite:Bool, connectedCb:() -> Void) {
|
public static function joinServer(serverName:String, isInvite:Bool, connectedCb:() -> Void) {
|
||||||
MasterServerClient.connectToMasterServer(() -> {
|
MasterServerClient.connectToMasterServer(() -> {
|
||||||
client = new RTCPeerConnection(stunServers, "0.0.0.0");
|
client = new RTCPeerConnection(stunServers.concat([turnServer]), "0.0.0.0");
|
||||||
var candidates = [];
|
var candidates = [];
|
||||||
|
|
||||||
client.onLocalCandidate = (c) -> {
|
client.onLocalCandidate = (c) -> {
|
||||||
|
|
@ -338,6 +343,9 @@ class Net {
|
||||||
if (Net.isHost) {
|
if (Net.isHost) {
|
||||||
MasterServerClient.instance.sendServerInfo(serverInfo); // Heartbeat
|
MasterServerClient.instance.sendServerInfo(serverInfo); // Heartbeat
|
||||||
}
|
}
|
||||||
|
if (Net.isClient) {
|
||||||
|
MasterServerClient.instance.heartBeat();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue