WebRTC - getting 'malformed constraints object' from Chrome but not Firefox

后端 未结 2 1767
栀梦
栀梦 2021-01-19 07:49

I wonder what I\'m doing wrong.

I\'m getting \'malformed constraints object\' errors from this:

pc.createAnswer( function (answer) {
  ...
}, fail, {         


        
相关标签:
2条回答
  • 2021-01-19 07:58

    According to the newest Webrtc spec the correct form of the constraint parameter should be:

    { offerToReceiveAudio: true, offerToReceiveVideo: true }
    

    Note the lowercase 'o's at the beginnings of offerToReceiveAudio and offerToReceiveVideo.

    This is currently supported only by FF 33 or newer.

    Chrome supports only the own way:

    { mandatory: { OfferToReceiveAudio: true, OfferToReceiveVideo: true } }
    

    Chrome will throw and error if you give it a constraint object that has a structure according to the new spec.

    The good news is that Firefox still accepts the old form. It just prints a warning message in that case. So, at least for now, use the old version.

    0 讨论(0)
  • 2021-01-19 08:10

    I have fought with this problem for many hours and just a moment ago I found something interesting:

    When i add any method to the Object.prototype i get the Uncaught TypeError: Failed to construct 'RTCPeerConnection': Malformed constraints object.

    Example:

    Object.prototype.nothingSpecial = function() {
        console.log("Here goes nothing ...");
    };
    

    This will cause the exception.

    Solution: Remove any/all modifications to the Object.prototype.

    I believe this is a bug in the browser.

    -

    Edit: My collegue figured out the exact reason for this error:

    • When adding enumerable fields to Object.prototype the error appears.
    • When adding only non-enumerable fields it works (eg. using defineProperty)

    -

    I am using the erizo video-streaming library.

    Testes with: JX Browser 6.21 (Chromium based)
    Version: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.24 Safari/537.36

    The full error looks like this:

    Uncaught TypeError: Failed to construct 'RTCPeerConnection': Malformed constraints object.
        at Object.Erizo.ChromeStableStack (erizo.js:2405)
        at Object.Erizo.Connection (erizo.js:2910)
        at erizo.js:3670
        at c.<anonymous> (erizo.js:3373)
        at c.onPacket (erizo.js:890)
        at d.onPacket (erizo.js:722)
        at d.c.onPacket (erizo.js:465)
        at d.c.onData (erizo.js:453)
        at WebSocket.websocket.onmessage (erizo.js:929)
    

    The first exception caused a secondary exception:

    Uncaught TypeError: Cannot read property 'processSignalingMessage' of undefined
        at c.<anonymous> (erizo.js:3253)
        at c.emit [as $emit] (erizo.js:213)
        at c.onPacket (erizo.js:887)
        at d.onPacket (erizo.js:722)
        at d.c.onPacket (erizo.js:465)
        at d.c.onData (erizo.js:453)
        at WebSocket.websocket.onmessage (erizo.js:929)
    

    (In case you wonder about the erizo.js filename and line numbers: i was using a pretty-printed version of the erizo.min.js for easier debugging.)

    0 讨论(0)
提交回复
热议问题