The proposed data channel API

After looking at the two versions submitted by Justin

* http://lists.w3.org/Archives/Public/public-webrtc/2011Oct/0119.html
and
* http://lists.w3.org/Archives/Public/public-webrtc/2011Nov/0000.html)

I prefer one aspect of the older one: creating the DataStream from a
PeerConnection object definitely makes more sense than creating it stand
alone (as things like send, priority, ... has no meaning without a
PeerConnection). But I would like to remove the "addDataStream" method,
this should happen automatically as a result of doing "createDataStream".

This would result in the following changes to the PeerConnection API:

interface PeerConnection {

[...]

// Creates a data stream, either reliable or unreliable.
// Reliability and priority cannot be changed for a stream after it
is created.
DataStream createDataStream(in DOMString label, in optional boolean
reliable, in optional int priority);
// Removes a datastream from this PeerConnection. Will trigger new
signaling.
void removeDataStream (in DataStream stream);

[...]
};

I also think that the DataStreams should be uni-directional to fit
better with the MediaStream's (and share an ancestor object), as well as 
with localStreams and remoteStreams.


A simple example (sorry for the sloppy syntax at places):


1. Sender side setup
====================
// standard setup from existing example
var pc = new PeerConnection('TURNS example.net', sendSignalingChannel);

// create a data stream; automatically appended to localStreams
var aLocalDataStream = pc.createDataStream("myChannel");


2. Receiver side setup
======================
// standard setup from existing example
var pc = new PeerConnection('TURNS example.net', sendSignalingChannel);

//take care of onaddstream
pc.onaddstream(function (evt) {
//the type of stream (data or media) must be identifiable
//if we use the same event
var receiveDataStream = evt;
}


Now, if the sender side does:

aLocalDataStream.send("foo");

// the message is delivered to the receiver

receiveDataStream.onmessage("foo");


The sending side can discard the stream
pc.removeStream(aLocalDataStream)

// new signaling is generated, resulting in onRemoveStream for the receiver

pc.onremovestream(receiveDataStream);

Would this make sense?

Br,
Stefan

Received on Wednesday, 9 November 2011 15:10:02 UTC