Bug 1208328 - Implement MediaStream.onaddtrack. r=jib, r=smaug

MozReview-Commit-ID: JVZO5mlxvgW

--HG--
extra : rebase_source : 49b0ebaff593c28b727602d7b61bab5feea80485
extra : source : ba0529f6b0733534d50fa842dfebd52c6b477140
This commit is contained in:
Andreas Pehrson 2016-05-31 09:29:52 +02:00
Родитель fedd99c881
Коммит e93d5f7b7d
4 изменённых файлов: 38 добавлений и 10 удалений

Просмотреть файл

@ -10,6 +10,7 @@
#include "nsIUUIDGenerator.h"
#include "nsPIDOMWindow.h"
#include "mozilla/dom/MediaStreamBinding.h"
#include "mozilla/dom/MediaStreamTrackEvent.h"
#include "mozilla/dom/LocalMediaStreamBinding.h"
#include "mozilla/dom/AudioNode.h"
#include "AudioChannelAgent.h"
@ -1002,6 +1003,9 @@ DOMMediaStream::CreateDOMTrack(TrackID aTrackID, MediaSegment::Type aType,
new TrackPort(mPlaybackPort, track, TrackPort::InputPortOwnership::EXTERNAL));
NotifyTrackAdded(track);
DispatchTrackEvent(NS_LITERAL_STRING("addtrack"), track);
return track;
}
@ -1241,6 +1245,22 @@ DOMMediaStream::NotifyTrackRemoved(const RefPtr<MediaStreamTrack>& aTrack)
// track has been confirmed removed by the graph. See BlockPlaybackTrack().
}
nsresult
DOMMediaStream::DispatchTrackEvent(const nsAString& aName,
const RefPtr<MediaStreamTrack>& aTrack)
{
MOZ_ASSERT(aName == NS_LITERAL_STRING("addtrack"),
"Only 'addtrack' is supported at this time");
MediaStreamTrackEventInit init;
init.mTrack = aTrack;
RefPtr<MediaStreamTrackEvent> event =
MediaStreamTrackEvent::Constructor(this, aName, init);
return DispatchTrustedEvent(event);
}
void
DOMMediaStream::CreateAndAddPlaybackStreamListener(MediaStream* aStream)
{

Просмотреть файл

@ -363,6 +363,8 @@ public:
/** Identical to CloneInternal(TrackForwardingOption::EXPLICIT) */
already_AddRefed<DOMMediaStream> Clone();
IMPL_EVENT_HANDLER(addtrack)
// NON-WebIDL
/**
@ -523,7 +525,12 @@ public:
* Called for each track in our owned stream to indicate to JS that we
* are carrying that track.
*
* Creates a MediaStreamTrack, adds it to mTracks and returns it.
* Creates a MediaStreamTrack, adds it to mTracks, raises "addtrack" and
* returns it.
*
* Note that "addtrack" is raised synchronously and only has an effect if
* this MediaStream is already exposed to script. For spec compliance this is
* to be called from an async task.
*/
MediaStreamTrack* CreateDOMTrack(TrackID aTrackID, MediaSegment::Type aType,
MediaStreamTrackSource* aSource);
@ -604,6 +611,10 @@ protected:
// Dispatches NotifyTrackRemoved() to all registered track listeners.
void NotifyTrackRemoved(const RefPtr<MediaStreamTrack>& aTrack);
// Dispatches "addtrack" or "removetrack".
nsresult DispatchTrackEvent(const nsAString& aName,
const RefPtr<MediaStreamTrack>& aTrack);
class OwnedStreamListener;
friend class OwnedStreamListener;

Просмотреть файл

@ -43,7 +43,7 @@ interface MediaStream : EventTarget {
// readonly attribute boolean active;
// attribute EventHandler onactive;
// attribute EventHandler oninactive;
// attribute EventHandler onaddtrack;
attribute EventHandler onaddtrack;
// attribute EventHandler onremovetrack;
readonly attribute double currentTime;
};

Просмотреть файл

@ -8,15 +8,12 @@
*/
dictionary MediaStreamTrackEventInit : EventInit {
MediaStreamTrack? track = null;
RTCRtpReceiver? receiver = null;
MediaStream? stream = null;
required MediaStreamTrack track;
};
[Pref="media.peerconnection.enabled",
Constructor(DOMString type, optional MediaStreamTrackEventInit eventInitDict)]
[Exposed=Window,
Constructor (DOMString type, MediaStreamTrackEventInit eventInitDict)]
interface MediaStreamTrackEvent : Event {
readonly attribute RTCRtpReceiver? receiver;
readonly attribute MediaStreamTrack? track;
readonly attribute MediaStream? stream;
[SameObject]
readonly attribute MediaStreamTrack track;
};