Sharing Data Between Participants
- Snapchat: not supported
- SPECS: fully supported
- Camera Kit Web: not supported
- Camera Kit Mobile: not supported
- SnapchatNot supported
- SPECSFully supported
- Camera Kit WebNot supported
- Camera Kit MobileNot supported
Lens Studio provides several APIs to enable users to pass data between participants in a multiplayer Lens session (that is, 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
MultiplayerSessionthat creates aGeneralDataStorethat 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
MultiplayerSessionAPI. This architecture is now deprecated in favor of this more robustRealtimeStoresolution.
- 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
MultiplayerSessionto 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,
CloudStorageModuleprovides aCloudStore, while thePersistentStorageSystemandRealtimeStoreprovides aGeneralDataStore. - If you have a
CloudStorageModulewith aMultiplayerSessionattached, you can think of this in the same way as how Prior to 4.19, you would call all thestorerelated 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, whereasCloudStorageModulecan be created independently (that is, not part of a MultiplayerSession). - As with the local
PersistentStorageSystem,CloudStorageModulecan store large data sizes in comparison to Realtime Store. Each user may have a CloudStore, but only oneCloudStorecan be shared in aMultiplayerSession, whereas aMultiplayerSessionmay have multipleRealtimeStores.
- ConnectedLensModule: The module that allows for networked Lens communication capabilities. Using it, multiple participants can connect to one
MultiplayerSession. See ConnectedLensModule.- 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. See MultiplayerSession.
- createRealtimeStore: A method in
MultiplayerSessionthat creates a GeneralDataStore 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. SeecreateRealtimeStore.- Earlier, participants had to take care of this themselves with the
MultiplayerSessionstorage methods (getStoredValue,setStoredValue,listStoredValues, anddeleteStoredValue). Those methods are deprecated in favor of this more robustRealtimeStoresolution.
- Earlier, participants had to take care of this themselves with 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. See MultiplayerSession.
On SPECS, Sync Kit is built on Realtime Stores: each Sync Entity keeps its storage properties in a Realtime Store, so your Lens shares data through Sync Kit's components.
Choose where to keep data on SPECS
When building for SPECS, a Realtime Store keeps its data only while at least one user is in the session: the Persist persistence option is deprecated in Sync Kit. Keep data that must survive after everyone leaves in a Snap Cloud database.
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,
CloudStorageis likely the right option as the data will be stored across login.
It’s possible to have 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.
- If you wanted to synchronize the position of two objects between all participants of a session, a Realtime Store is the right option, as the data does not need to persist beyond the session. Sync Kit's Sync Transform does this for you.
- If you wanted to build a Lens where you maintain state, such as a gardening Lens the user comes back to every day, keep that state in a Snap Cloud database and apply it to the session's shared data when the Lens loads it. Sync Entity describes the steps, and Databases in the Snap Cloud docs covers reading and writing the data.
Each message a Connected Lens sends is limited in size and rate; Payload and Rate Limits gives the numbers.