add timeout thing to sdp creation

This commit is contained in:
RandomityGuy 2024-05-22 23:15:25 +05:30
parent 7dded40ae7
commit f3195b2fe7
2 changed files with 50 additions and 27 deletions

View file

@ -141,21 +141,23 @@ class MPServerListGui extends GuiImage {
nextButton.accelerators = [hxd.Key.ENTER]; nextButton.accelerators = [hxd.Key.ENTER];
nextButton.gamepadAccelerator = ["X"]; nextButton.gamepadAccelerator = ["X"];
nextButton.pressedAction = (e) -> { nextButton.pressedAction = (e) -> {
MarbleGame.canvas.setContent(new MultiplayerLoadingGui("Connecting")); if (curSelection != -1) {
var failed = true; MarbleGame.canvas.setContent(new MultiplayerLoadingGui("Connecting"));
haxe.Timer.delay(() -> { var failed = true;
if (failed) { haxe.Timer.delay(() -> {
var loadGui:MultiplayerLoadingGui = cast MarbleGame.canvas.content; if (failed) {
if (loadGui != null) { var loadGui:MultiplayerLoadingGui = cast MarbleGame.canvas.content;
loadGui.setErrorStatus("Failed to connect to server"); if (loadGui != null) {
Net.disconnect(); loadGui.setErrorStatus("Failed to connect to server");
Net.disconnect();
}
} }
} }, 15000);
}, 15000); Net.joinServer(ourServerList[curSelection].name, false, () -> {
Net.joinServer(ourServerList[curSelection].name, false, () -> { failed = false;
failed = false; Net.remoteServerInfo = ourServerList[curSelection];
Net.remoteServerInfo = ourServerList[curSelection]; });
}); }
}; };
bottomBar.addChild(nextButton); bottomBar.addChild(nextButton);
} }

View file

@ -115,14 +115,23 @@ class Net {
if (c != "") if (c != "")
candidates.push('a=${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) -> { peer.onGatheringStateChange = (s) -> {
if (s == RTC_GATHERING_COMPLETE) { if (s == RTC_GATHERING_COMPLETE) {
var sdpObj = StringTools.trim(peer.localDescription); finishSdp();
sdpObj = sdpObj + '\r\n' + candidates.join('\r\n') + '\r\n';
onFinishSdp(Json.stringify({
sdp: sdpObj,
type: "answer"
}));
} }
} }
var reliable:datachannel.RTCDataChannel = null; var reliable:datachannel.RTCDataChannel = null;
@ -159,18 +168,30 @@ class Net {
candidates.push('a=${c}'); 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) -> { client.onGatheringStateChange = (s) -> {
if (s == RTC_GATHERING_COMPLETE) { if (s == RTC_GATHERING_COMPLETE) {
Console.log("Local Description Set!"); finishSdp();
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);
} }
} }
haxe.Timer.delay(() -> {
finishSdp();
}, 5000);
clientDatachannel = client.createDatachannel("mp"); clientDatachannel = client.createDatachannel("mp");
clientDatachannelUnreliable = client.createDatachannelWithOptions("unreliable", false, 0, 600); clientDatachannelUnreliable = client.createDatachannelWithOptions("unreliable", false, 0, 600);