Skip to content

New members also receive onPeerJoin event #124

@andres-kovalev

Description

@andres-kovalev

Hi there,

Looks like new joiners also receive onPeerJoin event for every old peer. With the example code below:

console.log('joining...');
const room = joinRoom(
  { appId: 'app', password: 'password' },
  'chat_root'
);

room.onPeerJoin((peerId) => {
   console.log('joined', peerId);
});

room.onPeerLeave((peerId) => {
  console.log('left', peerId);
});

When two peers join the room they see the following in their console:

// first peer
joining...
joined second_peer_id

// second peer
joining...
joined first_peer_id

Because of this there is no way to find out who is the new peer and who is the older one - both peers consider themselves as first peer.
Also, because of this the following example code from the docs doesn't make much sense:

...
// we don't need to call this one because the onPeerJoin subscription below will do the same work
// since newjoiner have it triggered for every old peer in the room
sendName('Oedipa')

room.onPeerJoin(peerId => sendName('Oedipa', peerId))
...

Is this behaviour expected?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions