Sign In Register

How can we help you today?

Start a new topic
Answered

EndSessionRequest Interruption

In my current WebGL based game, everything appears to be working fine right up until the moment the player attempts to navigate away from the page, at which point I'm receiving the following error, which leads to a multitude of "unexpected abort" errors. I had originally thought that the issue stemmed from Unity's "preview" WebGL implementation, but closer inspection seems to point to an interrupted EndSessionRequest as being the root of the problem.

I've [removed] a few bits, but the gist of the error is: 

"The connection to wss://gsp-aeu000-se02.gamesparks.net/ws/[removed]?deviceOS=WP8&deviceID=[removed]&SDK=?deviceOS=WP8&deviceID=[removed]&SDK= was interrupted while the page was loading."
(Any idea why the deviceID & SDK bits are passed twice? *shrug*) 

I presume the interruption is occurring because the EndSessionRequest is being sent off, but not returned before the user navigates to another web page. Is there some way that I can keep the navigation from taking place until a response is returned, gracefully closing the connection, or is there some other way that I should be handling this? Any advice would be greatly appreciated.


Best Answer
For anyone curious, I managed to get rid of my giant cloudy window of JS Console errors (Chrome, Unity 5.1.2f WebGL build) and stop the EndSession request from being interrupted by adding the following code into the Start function of my connection manager script and adding an OnApplicationQuit function later to call EndSession manually. Seems to be working well now :)

 

void Start ()
	{
		string eval = "";
		eval += "function OnApplicationQuit()";
		eval += "{";
		eval += "   GetUnity().SendMessage('" + gameObject.name + "', 'OnApplicationQuit', '');";
		eval += "   return true;";
		eval += "}";
		eval += "window.onbeforeunload = OnApplicationQuit;";
		Application.ExternalEval(eval);
	}

	public void OnApplicationQuit()
	{
		new EndSessionRequest().SetDurable(true).Send((response) =>{}); // no response expected
	}

 

 


My apologies if this question came through several times. I was receiving errors from the site that made it look as though nothing had gone through.

Okay, so it looks like I need to make use of the Player Disconnected (and likely Connected) sections of the System specific Cloud Code area in order to somehow setup a graceful disconnect. Hopefully I can figure it out ;) I'll be poring over the documentation and trying a few experimental passes later today. With luck, I'll be able to figure out how to avoid the above interruption, as well as handle some additional disconnect logic, such as checking to see if the player was in the middle of a level when they closed the game, and then taking away a life if they were. Fun, fun.


As ever, any additional advice or information would be greatly appreciated since the existing documentation really doesn't supply much in the way of coding examples beyond JSON queries / responses.

Answer
For anyone curious, I managed to get rid of my giant cloudy window of JS Console errors (Chrome, Unity 5.1.2f WebGL build) and stop the EndSession request from being interrupted by adding the following code into the Start function of my connection manager script and adding an OnApplicationQuit function later to call EndSession manually. Seems to be working well now :)

 

void Start ()
	{
		string eval = "";
		eval += "function OnApplicationQuit()";
		eval += "{";
		eval += "   GetUnity().SendMessage('" + gameObject.name + "', 'OnApplicationQuit', '');";
		eval += "   return true;";
		eval += "}";
		eval += "window.onbeforeunload = OnApplicationQuit;";
		Application.ExternalEval(eval);
	}

	public void OnApplicationQuit()
	{
		new EndSessionRequest().SetDurable(true).Send((response) =>{}); // no response expected
	}

 

 

For anyone curious, I managed to get rid of my giant cloudy window of JS Console errors (Chrome, Unity 5.1.2f WebGL build) and stop the EndSession request from being interrupted by adding the following code into the Start function of my connection manager script and adding an OnApplicationQuit function later to call EndSession manually. Seems to be working well now :)

 

void Start ()
	{
		string eval = "";
		eval += "function OnApplicationQuit()";
		eval += "{";
		eval += "   GetUnity().SendMessage('" + gameObject.name + "', 'OnApplicationQuit', '');";
		eval += "   return true;";
		eval += "}";
		eval += "window.onbeforeunload = OnApplicationQuit;";
		Application.ExternalEval(eval);
	}

	public void OnApplicationQuit()
	{
		new EndSessionRequest().SetDurable(true).Send((response) =>{}); // no response expected
	}

 

 

Thanks for sharing the solution!

Login to post a comment