How do I determine whether connecting to a room failed?
When I call realtime.Connect(), I need to determine if the method failed. There's already a didConnectToRoom event, but not one for if it fails.
10 Replies
Hi @Outlawdlaw. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
The
Realtime
class in NormalVR does not seem to provide a direct event for connection failure. However, you can infer a connection failure by checking the connected
property of the Realtime
instance. If the connected
property is false
after attempting to connect, it indicates that the connection has failed.
Here's an example of how you might use this:
Please note that this is a simple example and might not cover all edge cases. For instance, the connection process might still be ongoing when the connected
property is checked, leading to a false negative. You might need to implement additional logic to handle such scenarios.
For more information, you can refer to the Realtime class documentation (https://normcore.io/documentation/reference/classes/Normal.Realtime.Realtime).
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@290458313882337280> kapa.ai is still learning and improving, please let us know how it did by reacting below
@Normcore Assistant does it still fire the didConnectToRoom event if it fails to connect?
Let me check the knowledge base for you. One moment! :books:
----------------------
No, the
didConnectToRoom
event is only fired when the connection to the room is successful. If the connection fails, this event will not be triggered.
Here's the description from the Realtime class documentation (https://normcore.io/documentation/reference/classes/Normal.Realtime.Realtime):
didConnectToRoomevent RealtimeEvent didConnectToRoom An event that is fired when Realtime is connected to a room and all realtime prefabs and realtime views in the scene have been successfully connected to the datastore.So, if the connection fails, you won't receive this event. You'll need to implement your own logic to handle connection failures, such as checking the
connected
property of the Realtime
instance after attempting to connect.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@290458313882337280> kapa.ai is still learning and improving, please let us know how it did by reacting below
@Normcore Assistant when does the 'connected' property get set? Polling isn't great
Let me check the knowledge base for you. One moment! :books:
----------------------
The
connected
property of the Realtime
instance in NormalVR is set to true
when the instance is successfully connected to a room and all realtime prefabs and realtime views in the scene have been successfully connected to the datastore.
However, the documentation does not specify exactly when this property is set during the connection process. It's likely set internally by the NormalVR library once the connection is established.
While polling isn't ideal, you could consider using the didConnectToRoom
event to trigger a method when a successful connection is made. If the connection fails, this event won't be triggered, and the connected
property should remain false
.
Here's an example:
In this example, DidConnectToRoom
will only be called if the connection is successful. If the connection fails, this method won't be called, and _realtime.connected
should be false
.
For more information, refer to the Realtime class documentation (https://normcore.io/documentation/reference/classes/Normal.Realtime.Realtime).
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@290458313882337280> kapa.ai is still learning and improving, please let us know how it did by reacting below
you can register to room.connectionStateChanged and when it goes to Error or Disconnected then you'll know something went wrong
Thank you