Skip to content

Commit

Permalink
add todos to no_p5
Browse files Browse the repository at this point in the history
  • Loading branch information
jbakse committed Jan 28, 2022
1 parent 5e70fb0 commit ca43435
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions public/examples/no_p5/index.js
Expand Up @@ -16,10 +16,12 @@ async function init() {
// clients should remove themselves from the room before they disconnect
// but sometimes they don't or can't
// clear out any disconnected clients
// @todo this should be taken care of for you, even if you are using party directly
room.removeDisconnectedClients();

console.log("Create Record");
// @todo fix next line to use room
// @todo fix next line to use room as factory to make record so user doesn't
// need to specify full record name
const record = new party.Record(client, "nop5-main/test");
await record.whenReady();
console.log("Record Ready");
Expand All @@ -28,18 +30,20 @@ async function init() {
shared.text = shared.text || "Hello!";

// sync input field
// it would be better to do this when the data changes
// but right now p5.party.js doesn't expose the subscription events
// so we poll here instead.
const input = document.querySelector("input");
input.oninput = function () {
shared.text = input.value;
};
// @todo it would be better to do this when the data changes
// but right now p5.party.js doesn't expose the subscription events
// so we poll here instead.
setInterval(() => {
if (input.value !== shared.text) input.value = shared.text;
}, 100);

// clean up on exit
// @todo, this proably shouldn't be left to user code
// p5.party wrapper handles this, maybe this can be handled by party classes directly?
window.addEventListener("beforeunload", () => {
room.leave();
client.close();
Expand Down

0 comments on commit ca43435

Please sign in to comment.