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 an example of a shared sphere #238

Closed
vincentfretin opened this issue Feb 22, 2021 · 5 comments · Fixed by #326
Closed

Add an example of a shared sphere #238

vincentfretin opened this issue Feb 22, 2021 · 5 comments · Fixed by #326

Comments

@vincentfretin
Copy link
Member

vincentfretin commented Feb 22, 2021

Add an example in the repo of a shared sphere where each participant can click on it to change its color.
see discussion https://aframevr.slack.com/archives/C65MC3NSF/p1611344560006300
with the glitch https://glitch.com/edit/#!/naf-material-color that use a sphere in the html with persistent:true

@vincentfretin
Copy link
Member Author

vincentfretin commented Feb 22, 2021

Another example we could add #232 (comment)
A sphere with random color set by the first participant, the other participants see the same color. But the code was specific to the easyrtc adapter. The interesting code here was this:

NAF.connection.onConnect(() => {
  const scene = document.querySelector("a-scene");
  const room = scene.getAttribute("networked-scene")["room"];
  const initialOccupantsCount = Object.keys(NAF.connection.adapter.easyrtc.getRoomOccupantsAsMap(room)).filter((occupantId) => NAF.clientId !== occupantId).length;
  const mysphere = document.getElementById("mysphere");
  if (initialOccupantsCount === 0) {
    console.log("I'm the first participant");
    NAF.utils.takeOwnership(mysphere);
  }
});

@vincentfretin
Copy link
Member Author

When doing this example, look at the #178 issue about the different ownership events.

@vincentfretin
Copy link
Member Author

There is actually the http://localhost:8080/ownership-transfer.html example that demonstrate how to spawn a cube and take ownership of it. We may adapt it to add a raycaster component?

@vincentfretin
Copy link
Member Author

see also #258

@vincentfretin
Copy link
Member Author

When the creator (not owner) of a networked entity leaves the room, the entity is removed from the room. Using persistent:true disable the removal.
In the code, if using persistent:false and if the creator field is empty, it fallback to owner, so the entities with creator unknown are removed if the current owner leaves. The only case where creator is empty is when you're specifying the owner yourself, but not the creator. So actually you can have persistent by specifying persistent:false;creator:scene but this is confusing. :)

persistent:true;owner:scene in the html, specifying a non empty owner string that isn't a real participant, is used so that the user that join the room won't send this entity because not the current owner, the creator field is actually empty but we don't care because persistent:true.

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

Successfully merging a pull request may close this issue.

1 participant