4

I wonder what I'm doing wrong.

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

pc.createAnswer( function (answer) {
  ...
}, fail, { offerToReceiveAudio: true, offerToReceiveVideo: true });

Any ideas?

Costa Michailidis
  • 7,691
  • 15
  • 72
  • 124
  • 1
    Chrome formatting is like this `sdpConstraints = { 'mandatory': { 'OfferToReceiveAudio': true, 'OfferToReceiveVideo': true } }`, which I believe will also work for FF – Benjamin Trent Jan 08 '15 at 01:49
  • I am the mentioned colleague. Here is the issue I opened in the chromium bug tracker: https://bugs.chromium.org/p/chromium/issues/detail?id=876212 It describes the problem how manipulating the Object.prototype may cause the "Malformed constraints object" error. – Trve Aug 21 '18 at 16:31

2 Answers2

6

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.

Svetlin Mladenov
  • 4,307
  • 24
  • 31
  • Yes, mine were lowercased, sorry, typo. – Costa Michailidis Jan 08 '15 at 16:30
  • Got it. Any idea on how to right a fallback statement? – Costa Michailidis Jan 08 '15 at 16:31
  • What do you mean "a fallback statement"? Just use the old form i.e. { mandatory: { OfferToReceiveAudio: true, OfferToReceiveVideo: true } } and it will work everywhere. When Chrome update their implementation then you should change it to { offerToReceiveAudio: true, offerToReceiveVideo: true }. Otherwise you would need to do some UserAgent parsing in order to detect browser version which is messy. – Svetlin Mladenov Jan 08 '15 at 16:35
  • So, I'm wondering if I could do the opposite. Use the new form, and revert to the old if it fails? Maybe a try...catch statement can work. – Costa Michailidis Jan 08 '15 at 16:46
  • Interesting idea. I guess it could work but I am not sure. Try it and see for yourself. – Svetlin Mladenov Jan 10 '15 at 09:27
  • I ended up doing a browser check. Check for chrome, if so, use old form, if not use the new form. – Costa Michailidis Jan 11 '15 at 04:33
  • 1
    **Update:** The new format `{'offerToReceiveAudio':true,'offerToReceiveVideo':true}` works for me in Chrome too now (see [this fiddle](http://jsfiddle.net/v7dcwvkg)). It was fixed in [this issue](https://code.google.com/p/webrtc/issues/detail?id=3282) which seems to have made it to Chrome release now. – jib Jun 22 '15 at 14:28
  • None of this stuff is in the WebRTC spec linked in the answer any more. Is it deprecated or something? – Dobes Vandermeer Dec 26 '16 at 11:08
1

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.)

Frederic Leitenberger
  • 1,949
  • 24
  • 32