Search code examples
webrtckurento

Modify Kurento group call example to support only audio


I need to modify the Kurento group call example from Link

to send only audio if one participant has no camera. Right now only audio is received when a camera is used. When only a microphone is available I receive a DeviceMediaError.

I managed to filter whether a camera device is connected or not and then send only audio, but this doesn't work. Maybe the participant should've an audio tag instead of a video tag?

EDIT: It's only working on Firefox and not in Chrome. Any ideas?


Solution

  • in file - https://github.com/Kurento/kurento-tutorial-java/blob/master/kurento-group-call/src/main/java/org/kurento/tutorial/groupcall/UserSession.java.

    change following line -

      sender.getOutgoingWebRtcPeer().connect(incoming, MediaType.AUDIO);
    

    and set offer media constraints to video:false in browser js file.

    updated code -

      let constraints = {
        audio: true,
        video: false
    };
    
    let localParticipant = new Participant(sessionId);
    participants[sessionId] = localParticipant;
    localVideo = document.getElementById('local_video');
    
    let video = localVideo;
    
    let options = {
        localVideo: video,
        mediaConstraints: constraints,
        onicecandidate: localParticipant.onIceCandidate.bind(localParticipant),
        configuration : { iceServers : [
                   {"url":"stun:74.125.200.127:19302"},
                   ] }  
    };
    
    localParticipant.rtcPeer = new kurentoUtils.WebRtcPeer.WebRtcPeerSendonly(options, function(error) {
        if (error) {
            return console.error(error);
        }
    
        localVideoCurrentId = sessionId;
    
        localVideo = document.getElementById('local_video');
        localVideo.src = localParticipant.rtcPeer.localVideo.src;
        localVideo.muted = true;
    
        this.generateOffer(localParticipant.offerToReceiveVideo.bind(localParticipant));
    });
    

    server.js code

      function join(socket, room, callback) {
    let userSession = userRegister.getById(socket.id);
    userSession.setRoomName(room.name);
    
    room.pipeline.create('WebRtcEndpoint', {mediaProfile : 'WEBM_AUDIO_ONLY'}, (error, outgoingMedia) => {
        if (error) {
            console.error('no participant in room');
            if (Object.keys(room.participants).length === 0) {
                room.pipeline.release();
            }
            return callback(error);
        }
    
        // else
        outgoingMedia.setMaxAudioRecvBandwidth(100);
    

    add media profile parameter on server side while joining room.

    function getEndpointForUser(userSession, sender, callback) {
    
    if (userSession.id === sender.id) {
        return callback(null, userSession.outgoingMedia);
    }
    
    let incoming = userSession.incomingMedia[sender.id];
    
    if (incoming == null) {
        console.log(`user : ${userSession.id} create endpoint to receive video from : ${sender.id}`);
        getRoom(userSession.roomName, (error, room) => {
            if (error) {
                return callback(error);
            }
            room.pipeline.create('WebRtcEndpoint', {mediaProfile : 'WEBM_AUDIO_ONLY'}, (error, incomingMedia) => {
                if (error) {
                    if (Object.keys(room.participants).length === 0) {
                        room.pipeline.release();
                    }
                    return callback(error);
                }
    
                console.log(`user: ${userSession.id} successfully create pipeline`);
                incomingMedia.setMaxAudioRecvBandwidth(0);
                incomingMedia.getMaxAudioRecvBandwidth(0);
    

    add media profile parameter when accepting call.

    hope this helps.