in src/global_map.js [30:57]
async function addNewParticipants(map, participantsStartValue) {
async function addNewParticipantsToMap(event) {
const newPeersIds = []
const newCount = event.newValue
const oldCount = event.oldValue
for (let i = oldCount; i < newCount; i++) {
const allPeersIds = await getAllPeersIds()
newPeersIds.push(allPeersIds[i])
}
for (const newPeerId of newPeersIds) {
if (!Object.prototype.hasOwnProperty.call(map, newPeerId)) {
await map.set(newPeerId, participantsStartValue)
}
}
return newPeersIds
}
Participants.otherParticipantCount.monitor().subscribe(addNewParticipantsToMap)
map.setOnNewPeerCallback = (callback) => {
Participants.otherParticipantCount.monitor().subscribe(async (event) => {
const newPeersIds = await addNewParticipantsToMap(event)
for (const newPeerId of newPeersIds) {
callback(newPeerId)
}
})
}
}