W3C home > Mailing lists > Public > public-webrtc@w3.org > October 2011

CHANGE: Use a JS Object as an argument to getUserMedia

From: Anant Narayanan <anant@mozilla.com>
Date: Mon, 3 Oct 2011 12:39:30 -0700
Message-Id: <C6E1330C-257C-485A-9E19-3D2E59A00B37@mozilla.com>
To: public-webrtc@w3.org
I'd like to propose that we use a JS Object instead of a string as the *only* argument to getUserMedia().

We're just now beginning with the implementation of the specification in Firefox and we'd rather not write a new string parser :) Parsing strings can be error prone, whereas JavaScript objects offer the same extensibility as strings (and can be stringified into JSON if required). Additionally, coming up with a new string format is extra work and will end up  very close to a structured object model anyway.

In order to avoid developers from providing empty objects in case they want default behavior, it is also necessary to eliminate any other arguments to getUserMedia. This change  will also align getUserMedia to behave closer to other web APIs, where changes to state are notified either via event listeners or callbacks that have been explicitly assigned.

It is proposed that getUserMedia takes only a single argument, a JavaScript object. To begin with, only two properties will be specified to be interpreted by the User-Agent:

  audio: true,
  video: true

Both audio and video default to true, thus this call:

var stream = navigator.media.getUserMedia();

will return a MediaStream object that records both video and audio. Since getUserMedia() only takes 1 argument, the developer has to attach an event listener or callback:

stream.onReadyStateChange = function() {} // Like XHR


stream.addEventListener("<event-name>", function() {}); // Event listener

Would love to hear what everyone thinks.

Received on Monday, 3 October 2011 19:39:33 UTC

This archive was generated by hypermail 2.3.1 : Monday, 23 October 2017 15:19:25 UTC