I'm using the room occupant listener to listen for updates on the users that are in the room. In the demos, the user list gets updated with the new users and they have buttons for calling each user, similar to the contact list in an instant messaging program. What I want to do is a conference call, where whenever a user connects, they're automatically called by everyone else.
Here's how my code currently looks like:
var calledUsers = {};
easyrtc.setRoomOccupantListener(function (roomName, userList, selfInfo) {
for (easyrtcid in userList) {
if (easyrtcid in calledUsers && calledUsers[easyrtcid]) {
console.log('already in call with', easyrtcid);
} else {
easyrtc.call(
easyrtcid,
function success(otherCaller, mediaType) {
calledUsers[easyrtc] = true;
},
function failure(errorCode, errorMessage) {
calledUsers[easyrtc] = false;
}
);
}
}
});
I tested this in Chrome and Firefox on desktop and mobile.
Am I using the correct listener? Is there some other way to automatically initiate calls with peers when a new user enters the room?
Instead of trying to call any new users in the userList whenever it gets updated, it should be the responsibility of the user just joining the room to call everyone else. In this way you set up a chain:
And so on. The way to do this is by keeping track of when the user first enters the room.
When entering a room, the event listeners are executed in the following order:
For other users who are already in the room, only the room occupant listener will be executed.
This means that when you enter a room, you get the current user list and then you can loop through and call each user. But the second time you get an updated user list, in the room occupant listener, you do not call any other user.
The solution for calling other users whenever the user list is updated is:
var needToCallOtherUsers;
easyrtc.setRoomEntryListener(function(entry, roomName) {
needToCallOtherUsers = true;
});
easyrtc.setRoomOccupantListener(function(roomName, userList, selfInfo) {
var easyrtcid;
if (needToCallOtherUsers) {
for (easyrtcid in userList) {
easyrtc.call(
easyrtcid,
function success(otherCaller, mediaType) {
console.log('success: ', otherCaller, mediaType);
},
function failure(errorCode, errorMessage) {
console.log('failure: ', errorCode, errorMessage);
}
);
}
needToCallOtherUsers = false;
}
});