Sharing Data Between Participants
Lens Studio provides several APIs to enable users to pass data between participants in a multiplayer Lens session (i.e. Connected Lens).
Overview
Before going deeper, take a look at the following terminologies to help you understand how the different pieces are connected!
- ConnectedLensModule: The module that allows for networked Lens communication capabilities. Using it, multiple participants can connect to one
MultiplayerSession
.- MultiplayerSession: An instance of a Connected Lens session among a group of participants who were successfully invited into the experience. Provides APIs to relay messages to other participants.
- CreateRealtimeStore: A method in
MultiplayerSession
that creates aGeneralDataStore
that automatically syncs between all participants in the multiplayer session. It provides the ability to configure the owner of the store and the lifetime of data stored in the store. Along with automatic synchronization, all participants will get notified when this store undergoes changes to the data it stores, or the store’s ownership.- Prior to 4.19, participants would have to take care of this themselves in the JavaScript layer via the
MultiplayerSession
API. This architecture is now deprecated in favor of this more robustRealtimeStore
solution.
- Prior to 4.19, participants would have to take care of this themselves in the JavaScript layer via the
- CreateRealtimeStore: A method in
- MultiplayerSession: An instance of a Connected Lens session among a group of participants who were successfully invited into the experience. Provides APIs to relay messages to other participants.
- CloudStorageModule: A standalone storage solution which will allow for storing and retrieving data across login sessions of a user. You can optionally attach a
MultiplayerSession
to share the data in the store with other participants.- It is similar to
PersistentStorageSystem
, except it’s backed by the cloud rather than on device. - Note that while both these stores provide an in memory key value store,
CloudStorageModule
provides aCloudStore
, while thePersistentStorageSystem
andRealtimeStore
provides aGeneralDataStore
. - If you have a
CloudStorageModule
with aMultiplayerSession
attached, you can think of this in the same way as how Prior to 4.19, you would call all thestore
related method in the multiplayer session.
- It is similar to
RealtimeStore vs CloudStorageModule
As described above, it is possible to share data between multiple users by using these two APIs.
Some differences:
- Realtime Store is created within a
MultiplayerSession
, whereasCloudStorageModule
can be created independently (i.e. not part of a MultiplayerSession). - As with the local
PersistentStorageSystem
,CloudStorageModule
can store large data sizes in comparison to Realtime Store. Each user may have a CloudStore, but only oneCloudStore
can be shared in aMultiplayerSession
, whereas aMultiplayerSession
may have multipleRealtimeStores
.
Some examples of where you might use one over the other:
- If you wanted to synchronize the position of two objects between all participants of a session, Realtime Store is likely the right option as the data does not need to persist beyond the session.
- If you wanted to build a Lens where you maintain state, such as to create a gardening Lens where the user will come back every day to do things,
CloudStorage
is likely the right option as the data will be stored across login.
It’s possible to have very similar outcomes from these two APIs. For example, you might make a Realtime Store persist even after everyone has left the session, which would act similarly to a CloudStore
.
Related Guides
Was this page helpful?