...
There may be scenarios where it makes sense to connect to multiple space connections
...
concurrently in a single session. One could have a connected space dedicated to persistent RTC connection for communication while using another connection for loading snapshots of a space, perhaps viewing various journaled configurations of a car prototype. This is achieved by using Tags, which are user-defined identifiers for a CavrnusSpaceConnection.
Tags
Tags allow for multiple concurrent space connections by assigning a unique identifier to each JoinSpaceWithOptions() call, using the SpaceConnectionConfig object to provide a Tag. This enables scenarios like maintaining a persistent RTC connection for communication while using another connection for tasks such as space transitions or syncing data.
When either no Tag is provided or the same Tag value is used for a JoinSpaceWithOptions() call, then only one connection remains active at a time, with new space joins replacing the current connection. By applying different tags, multiple connections can coexist, supporting advanced use cases that require simultaneous space connections.
Info |
---|
JoinSpace() can also be used to provide a SpaceConnectionConfig, it is simply an optional parameter. If it’s not provided, the default empty string will be used as the tag |
...
Using JoinSpaceWithOptions
In this example, providing a Tag now marks the subsequent
...
language | c# |
---|
...
. |
...
Connecting to Multiple Spaces Example
By utilizing multiple JoinSpaceWithOptions() along with corresponding AwaitSpaceConnectionByTag() calls, multiple space connections will be created and independently handled allowing for multiple spaces to coexist simultaneously.
Code Block | ||
---|---|---|
| ||
public void Start()
{
CavrnusFunctionLibrary.AwaitAuthentication(auth => {
var configA = new CavrnusSpaceConnectionConfig {Tag = "A"};
CavrnusFunctionLibrary.JoinSpaceWithOptions("Space-A", configA, print, print);
var configB = new CavrnusSpaceConnectionConfig {Tag = "B"};
CavrnusFunctionLibrary.JoinSpaceWithOptions("Space-B", configB, print, print);
});
CavrnusFunctionLibrary.AwaitSpaceConnectionByTag("A", spaceConnection => {
print("Space A is now connected!");
});
CavrnusFunctionLibrary.AwaitSpaceConnectionByTag("B", spaceConnection => {
print("Space B is now connected!");
});
}
} |
Using Default Tag
...
language | c# |
---|
...
Multispace Connections Sample
Single Space Connection Sample
This sample scene demonstrates using a single tag for each space (this is the default behavior of JoinSpace). If you join a space with a tag that is already connected, you will rejoin the space and all the corresponding bindings will remap to the new connection. This can be a great way of saving snapshots of spaces that might provide different journaled configurations if needed!
Multiple Space Connection Sample Scene
In this sample, you may have a total of 3 concurrent space connections given there are 3 Tags in the scene. Space A and Space D both share a Tag value of 'A'. Selecting the various spaces will load their corresponding journals and all may be updated concurrently!