Translations: Japanese

Text data

Text data associated with a user.
This data can be used to implement a nickname display and text chat.
The maximum amount of text data per user is 50KB.

const res = await VerseThree.start(...);
const { player } = res;
setupTextForm(player, adapter);

...

function setupTextForm(
	player, // verse-three#Player
	adapter // verse-three#EnvAdapter
) {
  const textOut = document.querySelector("#text-out");
  document.querySelector("input[name='nickname']").value =
    localStorage.nickname || "";

  const outputMessage = (data) => {
    const nickname = data.nickname.trim();
    const message = data.message.trim();
    if (nickname !== "" && message !== "") {
      textOut.value += `${nickname}: ${message}\n`;
    }
  };

  document.querySelector("#text-form").addEventListener("submit", (e) => {
    e.preventDefault();
    const data = Object.fromEntries(new FormData(e.target).entries());
    localStorage.nickname = data.nickname;
    // Set textData
    player.setTextData(JSON.stringify({ textMessage: data }));
    outputMessage(data);
  });
  // Receiving changes in others' textData
  adapter.addTextDataChangedListener((
  	otherPerson, // verse-three#OtherPerson
  	textData // string
  ) => {
    const data = JSON.parse(textData)?.textMessage;
    outputMessage(data);
  });
}
Last Updated: