Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more doc about persistent entities #265

Open
vincentfretin opened this issue Mar 24, 2021 · 0 comments
Open

Add more doc about persistent entities #265

vincentfretin opened this issue Mar 24, 2021 · 0 comments

Comments

@vincentfretin
Copy link
Member

vincentfretin commented Mar 24, 2021

See #238 to add an example that use a persistent entity with persistent:true.

With persistent:true, each participant is responsible of creating the entity, it is only synced. Generally you have an entity in the html like the example in #238 or you create the entities dynamically before you enter the room, this is what Hubs does.

If you're using connectOnLoad:true or in other circumstances, you may receive an update for a persistent entity that is not created yet, the data is saved for later, see

if (entityData.persistent) {
// If we receive a firstSync for a persistent entity that we don't have yet,
// we assume the scene will create it at some point, so stash the update for later use.
this._persistentFirstSyncs[networkId] = entityData;

In an old version of Hubs, they used that with the applyPersistentFirstSync api to update the newly created entity with the data previously received. I searched in the history, here is an example mozilla/hubs@f2d779d
Today, Hubs doesn't use this API anymore, they maintain their own list of persistent entities received through Phoenix socket, and use their own api applyPersistentSync https://github.com/mozilla/hubs/search?q=applyPersistentSync

There is also an option NAF.options.firstSyncSource that is not documented

if (NAF.options.firstSyncSource && source !== NAF.options.firstSyncSource) {
NAF.log.write('Ignoring first sync from disallowed source', source);
} else {

to ignore firstSync persistent data coming from a source that we don't allow (naf adapter), this is used by hubs to only take care of the firstSync persistent data via the Phoenix socket so they can check permission on the backend side that the user can spawn entities and pin them.
https://github.com/mozilla/hubs/blob/614818eb2a1c3b23b49700a2023709a86532e283/src/hub.js#L225
If NAF.options.firstSyncSource !== null, the _persistentFirstSyncs and applyPersistentFirstSync api explained above become useless.

The persistent attribute was added to the table https://github.com/networked-aframe/networked-aframe#example-attachtemplatetolocalfalse in the documentation (that's the only doc!) by Hayden in commit 64a852f just after he merged the changes from Mozilla's fork that contains this PR MozillaReality#33
see the related PR on Hubs too mozilla/hubs#1556

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant