Skip to content

How to show a message when someone join? #410

Discussion options

You must be logged in to vote

You can send your own message when you connect and do anything you want with it.
For example if you start with the nametag example where you have the player-info component. You could do something like this:

const sendJoinMessage = (playerInfo) => {
  const name = playerInfo.nametag;
  const data = { type: "joined", name: name };
  NAF.connection.broadcastDataGuaranteed("chatbox", data);
};

const receiveData = (_, dataType, data) => {
  if (data.type === "joined") {
    console.log(`${data.name} joined`);
  }
};

function onConnect() {
  NAF.connection.subscribeToDataChannel("chatbox", receiveData);
  sendJoinMessage(document.getElementById('rig').components['player-info'].data);
};

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by vincentfretin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant