MenuMenu

RTCMultiConnection.onNewParticipant

Validate participation requests

This event is fired as soon as someone tries to join you. You can either reject his request or set preferences.

How to use

connection.onNewParticipant = function(participantId, userPreferences) {
    // if OfferToReceiveAudio/OfferToReceiveVideo should be enabled for specific users
    userPreferences.localPeerSdpConstraints.OfferToReceiveAudio = true;
    userPreferences.localPeerSdpConstraints.OfferToReceiveVideo = true;

    userPreferences.dontAttachStream = false; // according to situation
    userPreferences.dontGetRemoteStream = false;  // according to situation

    // below line must be included. Above all lines are optional.
    // if below line is NOT included; "join-request" will be considered rejected.
    connection.acceptParticipationRequest(participantId, userPreferences);
};

// or do not allow a user twice
var alreadyAllowed = {};
connection.onNewParticipant = function(participantId, userPreferences) {
    if(alreadyAllowed[participantId]) {
        connection.addParticipationRequest(participantId, userPreferences);
        return;
    }

    var message = participantId + ' is trying to join your room. Confirm to accept his request.';
    if( window.confirm(messsage ) ) {
        connection.addParticipationRequest(participantId, userPreferences);
    }
};