W3C home > Mailing lists > Public > public-media-capture@w3.org > May 2015

Re: About onaddtrack/onremovetrack

From: Adam Bergkvist <adam.bergkvist@ericsson.com>
Date: Tue, 19 May 2015 05:38:54 +0000
To: Iņaki Baz Castillo <ibc@aliax.net>
CC: "public-media-capture@w3.org" <public-media-capture@w3.org>
Message-ID: <A222C88B6882744D8D4B9681B315889023ECE589@ESESSMB307.ericsson.se>
On 2015-05-18 10:32, Iņaki Baz Castillo wrote:
> 2015-05-13 8:35 GMT+02:00 Adam Bergkvist <adam.bergkvist@ericsson.com>:
>> The reason you get a close event when you do close() on a WebSocket is
>> because you initiate the closing handshake (state: CLOSING) and the
>> event tells you when it's completed (state: CLOSED).
>> I believe it's not common to fire events as a result of direct
>> manipulation of objects.
> RTCPeerConnection.close() fires "onsignalingstatechange" event
> (pc.signalingState = closed). I don't think it's so uncommon.

Correct me if I'm wrong, but I don't think it should according to the 

>> The task that fires an event is usually the
>> task that modifies the concerned script objects and the reason for the
>> event is to notify what happened. It's not compatible with a synchronous
>> operation that performs its action directly.
> I don't agree. Call close(), and react on the event listener. That is
> very common in many libraries and APIs.

I think that's true when a closing procedure is initiated by the close() 
call (like WebSocket), but not when it's a "hard" close (like 
EventSource). I believe this is the approach with standardized web 
platform APIs, I can't speak for JS libs in general.

Generally speaking, one reason for not firing events together with 
synchronous operations is that by the time the scheduler picks up the 
task that fires the event, the state may have changed synchronously 
again. The result is that the event doesn't reflect the correct state 
when fired. For example, an addtrack event fires with track as it's 
payload, but the track is no longer present on the MediaStream. That's 
why state updates are made synchronously by the task that fires them; so 
the event properly reflects the state it's supposed to when fired.


Received on Tuesday, 19 May 2015 05:39:21 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 16:26:33 UTC