[whatwg] Thoughts on the media stream bootstrap mechanism

Rich Tibbett rich.tibbett at gmail.com
Tue Mar 15 08:24:16 PDT 2011


Hi,

We noticed a number of deficiencies with the way a developer can
obtain a GeneratedStream object. Hopefully I can explain those
succinctly below.

A callback-based model fires a single success event. An events-based
API allows for ongoing intermediate readyState changes to be fired at
web pages following an initial success state change. With an
events-based model we would be able to provide ongoing events such as
'disconnected' and, theoretically at least, extend that with events
like 'unplugged', 'sleeping', etc.

Secondly, getUserMedia is restricted to only handle audio/video
streams. In the original proposal there was potential for us to
connect and disconnect other device classes, such as USB or RS232
device types.

Essentially, our proposal is to improve the device bootstrap mechanism
four-fold:

1) Use an events-dispatch model instead of callbacks
2) Allow for future device classes to inherit standard
connect/disconnect functionality from a standard bootstrap interface
called 'Device'.
3) Provide additional generic device state information in the
events-dispatch model (a DISCONNECT readyState providing feedback to a
web page that the device has been disconnected by the user and/or the
connected device has been ripped out of the USB socket).
4) Allow developers to instantiate a particular device class (e.g.
UserMedia) with constructor parameters applicable to that device
class.

We want to replace the success callback with a 'connect' event and the
error callback with an 'error' event. We would also like to introduce
a 'disconnect' event as mentioned in point 3) above.

The IDL is as follows:

[NoInterfaceObject]
interface Device {
  const unsigned short WAITING = 0;
  const unsigned short CONNECTED = 1;
  const unsigned short DISCONNECTED = 2;
  const unsigned short ERROR = 3;
  readonly attribute unsigned short readyState;

  // event handler attributes
           attribute Function onconnect;
           attribute Function ondisconnect;
           attribute Function onerror;

  readonly attribute any data;

  void disconnect();
}

// Specific Device Classes with independent constructors

[Constructor(in DOMString options)]
interface UserMedia : Device {}


Here's a quick example for obtaining user media:

var m = new UserMedia('audio, video');
m.onconnect = function( evt ) {
  var ... = evt.target.data; // ... is a GeneratedStream object in a
UserMedia context
}


The Stream and GeneratedStream interfaces included in the current spec
are not affected by this proposal.

Thoughts would be welcome.

- Rich


More information about the whatwg mailing list