Re: Mozilla/Cisco API Proposal - listening

On 7/15/2011 11:31 PM, Ian Hickson wrote:
>> var conn = new PeerConection(...);
>> conn.onRemoteStreamAdded = function(stream) {
>>    console.log("stream was added");
>> };
>> conn.connect();
>>
>> instead of omitting the connect() and hoping that your
>> onRemoteStreamAdded callback will be called magically.
>
> There's no magic here. The PeerConnection constructor invokes the
> signaling callback and as soon as the ICE agent has a stream negotiated,
> the event notifiying that a stream has been added is fired.

Yes, but what if the stream is established before you have a chance to 
attach a callback?

var conn = new PeerConnection(...);
conn.addStream(...);
// other time consuming things ...
conn.onRemoteStreamAdded = function() {}
// Too late, remote stream was already added on other end while you
// had no callback?

>> It also makes clear the distinction between streams that were added
>> before the RTP negotiation happened, and those that were added after and
>> sets expectations accordingly.
>
> No streams can be added from the remote peer before the ICE agent runs,
> since the ICE agent is how the UA learns of the remote streams. Do you
> mean local streams? Those wouldn't fire an event when added, so I don't
> really follow how it would help distinguish anything.

I do mean local streams. Streams added before are expected to start 
transmitting immediately after the connection is established, but local 
streams you add after will appear only after some delay because 
parameters have to be renegotiated. This may not be important at all :)

> As far as I can tell, adding connect() would just make the API
> error-prone: it adds no functionality, yet makes using the interface more
> complicated (you have to do more calls).

Speaking strictly as a JS programmer I find the earlier model a little 
uncomfortable. Whenever I add a callback or event listener in JS code, I 
always attach them first and only after that do the thing that would 
cause them to be fired. Then again I'm not a typical web developer; so 
I'm fine with dropping connect() if that's the standard thing to do.

Regards,
-Anant

Received on Saturday, 16 July 2011 17:34:01 UTC