voxeet / comms-sdk-unreal

Dolby.io Virtual Worlds plugin for Unreal Engine
http://api-references.dolby.io/comms-sdk-unreal/
MIT License
26 stars 7 forks source link

Attempting a new connection right after the 'OnDisconnected' event fired leads to an error #266

Closed andreibazi closed 1 year ago

andreibazi commented 1 year ago

Describe the bug

When attempting to connect to a new conference from inside a method bound to the OnDisconnected event, the SDK returns an error: LogDolbyIO: Error: Caught dolbyio::comms::exception: Invalid session state: 2, required: 0 (conference status: destroyed, line: 383).

Adding a 0.5 second delay after the OnDisconnected event right before calling the Connect method again stops the error from being thrown and things work as expected.

This happens regardless of the implementation of the client logic (C++ or Blueprint).

Tested and reproduced on my end in Unreal Engine 5.1.1 using both the 1.1.0-beta.9 and 1.0.2 releases.

Expected Behavior

When OnDisconnected fires, the underlying SDK is fully ready for a new connection. Therefore, calling Connect from inside a function bound to OnDisconnected should work without throwing the error.

Minimalistic code (recommended)

A sample UE 5.1.1 project repository demonstrating the issue can be found here.

To reproduce the issue without cloning the project:

This will lead to the aforementioned error being thrown. Adding a delay between these two nodes (it can be a small 0.5s delay) fixes the issue.

Specifications

Engine log

Here is a log that includes the error/conference IDs for back-end checks.

PIE: Play in editor total start time 0.086 seconds.
LogDolbyIO: Initializing with token: <token here>
LogDolbyIO: Initialized
LogDolbyIO: Audio device changed for direction: output to device - Speakers (Intel® Smart Sound Technology for MIPI SoundWire® Audio), direction: output, native_id: {0.0.0.00000000}.{02dfa4f7-dedb-4a4e-9546-689132abf63f}
LogDolbyIO: Connecting to conference main-conference with user name "dev-debug" (EDolbyIOConnectionMode::Active, EDolbyIOSpatialAudioStyle::Shared)
LogDolbyIO: Conference status: creating
LogDolbyIO: Conference status: created
LogDolbyIO: Conference status: joining
LogDolbyIO: Conference status: joined
LogDolbyIO: Connected to conference ID bf7ce84f-bc97-4414-9fc0-d9cd82f1b7f4 with user ID 5e8027f1-991e-3d93-887b-cb9931b89c8c
LogBlueprintUserMessages: [BP_Dolby_Debug_Actor_C_1] Connected to the main conference!
LogDolbyIO: Disconnecting
LogDolbyIO: Conference status: leaving
LogDolbyIO: Conference status: left
LogDolbyIO: Conference status: destroyed
LogDolbyIO: Connecting to conference sub-conference with user name "dev-debug" (EDolbyIOConnectionMode::Active, EDolbyIOSpatialAudioStyle::Shared)
LogDolbyIO: Error: Caught dolbyio::comms::exception: Invalid session state: 2, required: 0 (conference status: destroyed, line: 402)
LogSlate: Updating window title bar state: overlay mode, drag disabled, window buttons hidden, title bar hidden
LogWorld: BeginTearingDown for /Game/UEDPIE_0_L_Dolby_Debug
LogWorld: UWorld::CleanupWorld for L_Dolby_Debug, bSessionEnded=true, bCleanupResources=true
LogSlate: InvalidateAllWidgets triggered.  All widgets were invalidated
LogPlayLevel: Display: Shutting down PIE online subsystems
kubaau commented 1 year ago

I can confirm this issue is easy to reproduce. This is because the Connect function first tries to open a user session (using the user name, external ID and avatar URL) and only then actually connects to a conference. When you disconnect and connect immediately it is possible (almost certain) that you will disconnect from the conference, but the session will still be open for a short while. This requires fixing some logic in when On Disconnected is triggered, so that it is only fired when the session is closed or a fatal conference error occurs.

kubaau commented 1 year ago

@Adam1-3 FYI

kubaau commented 1 year ago

@Adam1-3 We may also want to consider moving session.open out of Connect and session.close out of Disconnect somehow. For example if a user wants to quickly switch conferences by chaining Disconnect(old)->Connect(new), it is pointless to redo the session. Without breaking compatibility, we could for example save the user data and only open a new session if it changes.

kubaau commented 1 year ago

@andreibazi Fixed in 1.1.0 release.

andreibazi commented 1 year ago

@kubaau Thank you very much for the fast fix!