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

MozReview-Commit-ID: JVZO5mlxvgW

--HG--
extra : rebase_source : b2ec734dc408e96c9a9f265c11c7308895c3b6ce
This commit is contained in:
Andreas Pehrson 2016-05-31 09:29:52 +02:00
Родитель 469fe5da74
Коммит 2597c73af2
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)
{

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

@ -362,6 +362,8 @@ public:
/** Identical to CloneInternal(TrackForwardingOption::EXPLICIT) */
already_AddRefed<DOMMediaStream> Clone();
IMPL_EVENT_HANDLER(addtrack)
// NON-WebIDL
/**
@ -522,7 +524,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);
@ -603,6 +610,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;
};