Roma Romin
Roma Romin

Reputation: 127

Firefox doesn't create an offer: Cannot create an offer with no local tracks, no offerToReceiveAudio/Video, and no DataChannel

I have a problem with Firefox. This code works in Chrome impeccably.

function create_offer() {
    pc = new peer_connection({iceServers: [
        {urls: "stun:stun.l.google.com:19302"}
    ]});
    //pc.createDataChannel('channel');

    pc.createOffer(
        create_offer_success,
        create_offer_error,
        setSdpConstraints()
    );

    pc.onaddstream = on_add_stream;
    pc.onicecandidate = on_ice_candidate;
}

function create_offer_success(desc) {
    pc.setLocalDescription(desc);
}

function create_offer_error(error) {
    console.error("create_offer_error() error:", error);
}

function on_ice_candidate(event){
    if (event.candidate) {
        ice.push(event.candidate);
    } else {
        return send('/offer', {
            'id': id,
            'desc': pc.localDescription,
            'ice': ice
        })
        .then(function(data) {
            return pc.setRemoteDescription(new session_description(data.desc), function() {
                for(var i = 0, l = data.ice.length; i < l; i++) {
                    pc.addIceCandidate(new ice_candidate(data.ice[i]));
                }
                return data;
             }, function(err) {
                console.error(err);
            });
        })
        .catch(function(err) {
            console.error('on_ice_candidate() catch: ', err);
        });
    }
}

function on_add_stream(event) {
    console.log(event);
    stream = event.stream;
    var vid = document.getElementById("stream");
    if(isFirefox) {
        vid.mozSrcObject = stream;
    } else {
        vid.src = URL.createObjectURL(stream)
    }
}

function setSdpConstraints() {
    return !!navigator.mozGetUserMedia && firefoxVersion > 34 ?
    {
        OfferToReceiveAudio: true,
        OfferToReceiveVideo: true
    } :
    {
        optional: [],
        mandatory: {
            OfferToReceiveAudio: true,
            OfferToReceiveVideo: true
        }
    };
}

Firefox shows an error: Cannot create an offer with no local tracks, no offerToReceiveAudio/Video, and no DataChannel. Firefox version is 44. What am I doing wrong?

Upvotes: 3

Views: 1710

Answers (2)

mpromonet
mpromonet

Reputation: 11952

The answer of Philipp Hancke is correct, there is a case problem in the mediacontraints.

To simplify the constraints configuration you can merge Chrome & Firefox contraints like this :

var mediaConstraints = {
    mandatory: {
        'OfferToReceiveAudio': true,
        'OfferToReceiveVideo': true
    },
    'offerToReceiveAudio': true,
    'offerToReceiveVideo': true    
};

This will allow you to create the offer with same code on Chrome and Firefox :

if (typeof RTCPeerConnection === "undefined") {
	RTCPeerConnection = window.mozRTCPeerConnection || window.webkitRTCPeerConnection;
}
	
var pcConfig = {"iceServers": [] };
var pc = new RTCPeerConnection(pcConfig);

var mediaConstraints = {
    mandatory: {
        'OfferToReceiveAudio': true,
        'OfferToReceiveVideo': true
    },
    'offerToReceiveAudio': true,
    'offerToReceiveVideo': true    
};
pc.createOffer(function(session) { alert("Create offer ok"); }
             , function(error)   { alert("Create offer error:" + error);  }
             , mediaConstraints); 				

Upvotes: 2

Philipp Hancke
Philipp Hancke

Reputation: 17330

You are setting wrong constraints for Firefox:

{
    OfferToReceiveAudio: true,
    OfferToReceiveVideo: true
}

What you need to set (and Chrome supports this as well since Chrome 38) should be:

{
    offerToReceiveAudio: 1,
    offerToReceiveVideo: 1
}

Note the case difference.

Upvotes: 4

Related Questions