Index: Source/WebCore/Modules/mediastream/RTCPeerConnection.cpp |
=================================================================== |
--- Source/WebCore/Modules/mediastream/RTCPeerConnection.cpp (revision 132836) |
+++ Source/WebCore/Modules/mediastream/RTCPeerConnection.cpp (working copy) |
@@ -127,6 +127,7 @@ |
, m_iceState(IceStateClosed) |
, m_localStreams(MediaStreamList::create()) |
, m_remoteStreams(MediaStreamList::create()) |
+ , m_scheduledEventTimer(this, &RTCPeerConnection::scheduledEventTimerFired) |
{ |
m_peerHandler = RTCPeerConnectionHandler::create(this); |
if (!m_peerHandler || !m_peerHandler->initialize(configuration, constraints)) |
@@ -393,17 +394,17 @@ |
void RTCPeerConnection::negotiationNeeded() |
{ |
- dispatchEvent(Event::create(eventNames().negotiationneededEvent, false, false)); |
+ scheduleDispatchEvent(Event::create(eventNames().negotiationneededEvent, false, false)); |
} |
void RTCPeerConnection::didGenerateIceCandidate(PassRefPtr<RTCIceCandidateDescriptor> iceCandidateDescriptor) |
{ |
ASSERT(scriptExecutionContext()->isContextThread()); |
if (!iceCandidateDescriptor) |
- dispatchEvent(RTCIceCandidateEvent::create(false, false, 0)); |
+ scheduleDispatchEvent(RTCIceCandidateEvent::create(false, false, 0)); |
else { |
RefPtr<RTCIceCandidate> iceCandidate = RTCIceCandidate::create(iceCandidateDescriptor); |
- dispatchEvent(RTCIceCandidateEvent::create(false, false, iceCandidate.release())); |
+ scheduleDispatchEvent(RTCIceCandidateEvent::create(false, false, iceCandidate.release())); |
} |
} |
@@ -429,7 +430,7 @@ |
RefPtr<MediaStream> stream = MediaStream::create(scriptExecutionContext(), streamDescriptor); |
m_remoteStreams->append(stream); |
- dispatchEvent(MediaStreamEvent::create(eventNames().addstreamEvent, false, false, stream.release())); |
+ scheduleDispatchEvent(MediaStreamEvent::create(eventNames().addstreamEvent, false, false, stream.release())); |
} |
void RTCPeerConnection::didRemoveRemoteStream(MediaStreamDescriptor* streamDescriptor) |
@@ -446,7 +447,7 @@ |
ASSERT(m_remoteStreams->contains(stream.get())); |
m_remoteStreams->remove(stream.get()); |
- dispatchEvent(MediaStreamEvent::create(eventNames().removestreamEvent, false, false, stream.release())); |
+ scheduleDispatchEvent(MediaStreamEvent::create(eventNames().removestreamEvent, false, false, stream.release())); |
} |
const AtomicString& RTCPeerConnection::interfaceName() const |
@@ -491,7 +492,7 @@ |
case ReadyStateOpening: |
break; |
case ReadyStateActive: |
- dispatchEvent(Event::create(eventNames().openEvent, false, false)); |
+ scheduleDispatchEvent(Event::create(eventNames().openEvent, false, false)); |
break; |
case ReadyStateClosing: |
case ReadyStateClosed: |
@@ -501,7 +502,7 @@ |
break; |
} |
- dispatchEvent(Event::create(eventNames().statechangeEvent, false, false)); |
+ scheduleDispatchEvent(Event::create(eventNames().statechangeEvent, false, false)); |
} |
void RTCPeerConnection::changeIceState(IceState iceState) |
@@ -510,9 +511,29 @@ |
return; |
m_iceState = iceState; |
- dispatchEvent(Event::create(eventNames().icechangeEvent, false, false)); |
+ scheduleDispatchEvent(Event::create(eventNames().icechangeEvent, false, false)); |
} |
+void RTCPeerConnection::scheduleDispatchEvent(PassRefPtr<Event> event) |
+{ |
+ m_scheduledEvents.append(event); |
+ |
+ if (!m_scheduledEventTimer.isActive()) |
+ m_scheduledEventTimer.startOneShot(0); |
+} |
+ |
+void RTCPeerConnection::scheduledEventTimerFired(Timer<RTCPeerConnection>*) |
+{ |
+ Vector<RefPtr<Event> > events; |
+ events.swap(m_scheduledEvents); |
+ |
+ Vector<RefPtr<Event> >::iterator it = events.begin(); |
+ for (; it != events.end(); ++it) |
+ dispatchEvent((*it).release()); |
+ |
+ events.clear(); |
+} |
+ |
} // namespace WebCore |
#endif // ENABLE(MEDIA_STREAM) |