Unity-Technologies / UnityRenderStreaming

Streaming server for Unity
Other
1.3k stars 352 forks source link

[BUG]: WebApp lost connection after 60 seconds #804

Open ThePatrykOOO opened 1 year ago

ThePatrykOOO commented 1 year ago

Package version

3.1.0-exp.4

Environment

* OS: Windows 10 x64
* Unity version: Unity 2021.3.0f1
* Graphics API: DirectX11
* Browser: Chrome (actual the newest)

Steps To Reproduce

  1. Open unity app
  2. Run node backend
  3. Run browser app multiplay sample
  4. I connected to stream [POLITE] iceConnectionState changed:connected
  5. I show stream image, I can click and so on
  6. After 60 seconds I have a log [POLITE] iceConnectionState changed:disconnected
  7. I lost peer connection.

Current Behavior

I don't see web streaming from unity app.

Expected Behavior

I should be connected with stream until when I close the connection or close the Unity App.

Anything else?

No response

karasusan commented 1 year ago

@ThePatrykOOO Could you attach the log? How about another sample?

ThePatrykOOO commented 1 year ago

I researched the problem and the situation is very strange because the Unity application first receives a signal of the "disconnect" type, which sends the same info further to the connected client. This one, upon receiving this, immediately disconnects and the message follows: [POLITE] iceConnectionState changed:disconnected I checked the place where the received signal is read and I commented the line that passes the information to other places:

`//WebSocketSignaling.cs file else if (routedMessage.type == "disconnect") { msg = JsonUtility.FromJson(content);

//This is my code to see when exactly I am getting this signal to compare with the frontend
string timestamp = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss.fff", CultureInfo.InvariantCulture);
Debug.LogError($"OnDestroyConnection called: {timestamp}");

//This line of code I commented
//m_mainThreadContext.Post(d => OnDestroyConnection?.Invoke(this, msg.connectionId), null);

}`

The sent signal looks like this:

Signaling: Receiving message: {"type":"disconnect","connectionId":"505ecf2b-51d6-45d0-8164-857bc75f793e"}

After commenting this code, the problem was fixed (but in an ugly way): m_mainThreadContext.Post(d => OnDestroyConnection?.Invoke(this, msg.connectionId), null);

Of course, the unity application still receives a signal after a minute from the last received message that it is time to disconnect, but this signal does not go any further, so the connection does not break and the client can continue to use the application without refreshing the page. But the problem is very weird

Additionally I send you logs from my web console:

[POLITE] SRD(answer)
logger.js:20 [POLITE] iceConnectionState changed:checking
logger.js:20 [POLITE] signalingState changed:stable
logger.js:20 On got Answer on 5442dd14-5c2c-47c5-8a38-e85d06149d9e.
[POLITE] iceConnectionState changed:connected
...
[POLITE] SRD(offer)
logger.js:20 [POLITE] signalingState changed:have-remote-offer
logger.js:20 [POLITE] ontrack:[object RTCTrackEvent]
logger.js:20 [POLITE] SLD to get back to stable
logger.js:20 [POLITE] signalingState changed:stable
....
[POLITE] iceConnectionState changed:disconnected

Futher I noticed that the bugs appear on remote setup. UnityApp - remote Node - remote Frontend App - remote. I lost connection after 60 seconds.

When I setup all localy this bug doesn't appear.

karasusan commented 1 year ago

@ThePatrykOOO It sounds strange. Does the browser send the "disconnect" message?

karasusan commented 1 year ago

It would be possible that the iceConnectionState could change the state when the network status is changed. We need more time to check the behaviour. https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/iceConnectionState

karasusan commented 1 year ago

memo: URS-557