mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2026-02-17 19:51:06 +00:00
add timeout thing to sdp creation
This commit is contained in:
parent
7dded40ae7
commit
f3195b2fe7
2 changed files with 50 additions and 27 deletions
|
|
@ -141,21 +141,23 @@ class MPServerListGui extends GuiImage {
|
|||
nextButton.accelerators = [hxd.Key.ENTER];
|
||||
nextButton.gamepadAccelerator = ["X"];
|
||||
nextButton.pressedAction = (e) -> {
|
||||
MarbleGame.canvas.setContent(new MultiplayerLoadingGui("Connecting"));
|
||||
var failed = true;
|
||||
haxe.Timer.delay(() -> {
|
||||
if (failed) {
|
||||
var loadGui:MultiplayerLoadingGui = cast MarbleGame.canvas.content;
|
||||
if (loadGui != null) {
|
||||
loadGui.setErrorStatus("Failed to connect to server");
|
||||
Net.disconnect();
|
||||
if (curSelection != -1) {
|
||||
MarbleGame.canvas.setContent(new MultiplayerLoadingGui("Connecting"));
|
||||
var failed = true;
|
||||
haxe.Timer.delay(() -> {
|
||||
if (failed) {
|
||||
var loadGui:MultiplayerLoadingGui = cast MarbleGame.canvas.content;
|
||||
if (loadGui != null) {
|
||||
loadGui.setErrorStatus("Failed to connect to server");
|
||||
Net.disconnect();
|
||||
}
|
||||
}
|
||||
}
|
||||
}, 15000);
|
||||
Net.joinServer(ourServerList[curSelection].name, false, () -> {
|
||||
failed = false;
|
||||
Net.remoteServerInfo = ourServerList[curSelection];
|
||||
});
|
||||
}, 15000);
|
||||
Net.joinServer(ourServerList[curSelection].name, false, () -> {
|
||||
failed = false;
|
||||
Net.remoteServerInfo = ourServerList[curSelection];
|
||||
});
|
||||
}
|
||||
};
|
||||
bottomBar.addChild(nextButton);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -115,14 +115,23 @@ class Net {
|
|||
if (c != "")
|
||||
candidates.push('a=${c}');
|
||||
}
|
||||
var sdpFinished = false;
|
||||
|
||||
var finishSdp = () -> {
|
||||
if (sdpFinished)
|
||||
return;
|
||||
sdpFinished = true;
|
||||
var sdpObj = StringTools.trim(peer.localDescription);
|
||||
sdpObj = sdpObj + '\r\n' + candidates.join('\r\n') + '\r\n';
|
||||
onFinishSdp(Json.stringify({
|
||||
sdp: sdpObj,
|
||||
type: "answer"
|
||||
}));
|
||||
}
|
||||
|
||||
peer.onGatheringStateChange = (s) -> {
|
||||
if (s == RTC_GATHERING_COMPLETE) {
|
||||
var sdpObj = StringTools.trim(peer.localDescription);
|
||||
sdpObj = sdpObj + '\r\n' + candidates.join('\r\n') + '\r\n';
|
||||
onFinishSdp(Json.stringify({
|
||||
sdp: sdpObj,
|
||||
type: "answer"
|
||||
}));
|
||||
finishSdp();
|
||||
}
|
||||
}
|
||||
var reliable:datachannel.RTCDataChannel = null;
|
||||
|
|
@ -159,18 +168,30 @@ class Net {
|
|||
candidates.push('a=${c}');
|
||||
}
|
||||
|
||||
var sdpFinished = false;
|
||||
var finishSdp = () -> {
|
||||
if (sdpFinished)
|
||||
return;
|
||||
sdpFinished = true;
|
||||
Console.log("Local Description Set!");
|
||||
var sdpObj = StringTools.trim(client.localDescription);
|
||||
sdpObj = sdpObj + '\r\n' + candidates.join('\r\n') + '\r\n';
|
||||
MasterServerClient.instance.sendConnectToServer(serverName, Json.stringify({
|
||||
sdp: sdpObj,
|
||||
type: "offer"
|
||||
}), isInvite);
|
||||
}
|
||||
|
||||
client.onGatheringStateChange = (s) -> {
|
||||
if (s == RTC_GATHERING_COMPLETE) {
|
||||
Console.log("Local Description Set!");
|
||||
var sdpObj = StringTools.trim(client.localDescription);
|
||||
sdpObj = sdpObj + '\r\n' + candidates.join('\r\n') + '\r\n';
|
||||
MasterServerClient.instance.sendConnectToServer(serverName, Json.stringify({
|
||||
sdp: sdpObj,
|
||||
type: "offer"
|
||||
}), isInvite);
|
||||
finishSdp();
|
||||
}
|
||||
}
|
||||
|
||||
haxe.Timer.delay(() -> {
|
||||
finishSdp();
|
||||
}, 5000);
|
||||
|
||||
clientDatachannel = client.createDatachannel("mp");
|
||||
clientDatachannelUnreliable = client.createDatachannelWithOptions("unreliable", false, 0, 600);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue