OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 | 120 |
121 return peerConnection.release(); | 121 return peerConnection.release(); |
122 } | 122 } |
123 | 123 |
124 RTCPeerConnection::RTCPeerConnection(ScriptExecutionContext* context, PassRefPtr
<RTCConfiguration> configuration, PassRefPtr<MediaConstraints> constraints, Exce
ptionCode& ec) | 124 RTCPeerConnection::RTCPeerConnection(ScriptExecutionContext* context, PassRefPtr
<RTCConfiguration> configuration, PassRefPtr<MediaConstraints> constraints, Exce
ptionCode& ec) |
125 : ActiveDOMObject(context, this) | 125 : ActiveDOMObject(context, this) |
126 , m_readyState(ReadyStateNew) | 126 , m_readyState(ReadyStateNew) |
127 , m_iceState(IceStateClosed) | 127 , m_iceState(IceStateClosed) |
128 , m_localStreams(MediaStreamList::create()) | 128 , m_localStreams(MediaStreamList::create()) |
129 , m_remoteStreams(MediaStreamList::create()) | 129 , m_remoteStreams(MediaStreamList::create()) |
| 130 , m_scheduledEventTimer(this, &RTCPeerConnection::scheduledEventTimerFired) |
130 { | 131 { |
131 m_peerHandler = RTCPeerConnectionHandler::create(this); | 132 m_peerHandler = RTCPeerConnectionHandler::create(this); |
132 if (!m_peerHandler || !m_peerHandler->initialize(configuration, constraints)
) | 133 if (!m_peerHandler || !m_peerHandler->initialize(configuration, constraints)
) |
133 ec = NOT_SUPPORTED_ERR; | 134 ec = NOT_SUPPORTED_ERR; |
134 } | 135 } |
135 | 136 |
136 RTCPeerConnection::~RTCPeerConnection() | 137 RTCPeerConnection::~RTCPeerConnection() |
137 { | 138 { |
138 } | 139 } |
139 | 140 |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 return; | 387 return; |
387 } | 388 } |
388 | 389 |
389 changeIceState(IceStateClosed); | 390 changeIceState(IceStateClosed); |
390 changeReadyState(ReadyStateClosed); | 391 changeReadyState(ReadyStateClosed); |
391 stop(); | 392 stop(); |
392 } | 393 } |
393 | 394 |
394 void RTCPeerConnection::negotiationNeeded() | 395 void RTCPeerConnection::negotiationNeeded() |
395 { | 396 { |
396 dispatchEvent(Event::create(eventNames().negotiationneededEvent, false, fals
e)); | 397 scheduleDispatchEvent(Event::create(eventNames().negotiationneededEvent, fal
se, false)); |
397 } | 398 } |
398 | 399 |
399 void RTCPeerConnection::didGenerateIceCandidate(PassRefPtr<RTCIceCandidateDescri
ptor> iceCandidateDescriptor) | 400 void RTCPeerConnection::didGenerateIceCandidate(PassRefPtr<RTCIceCandidateDescri
ptor> iceCandidateDescriptor) |
400 { | 401 { |
401 ASSERT(scriptExecutionContext()->isContextThread()); | 402 ASSERT(scriptExecutionContext()->isContextThread()); |
402 if (!iceCandidateDescriptor) | 403 if (!iceCandidateDescriptor) |
403 dispatchEvent(RTCIceCandidateEvent::create(false, false, 0)); | 404 scheduleDispatchEvent(RTCIceCandidateEvent::create(false, false, 0)); |
404 else { | 405 else { |
405 RefPtr<RTCIceCandidate> iceCandidate = RTCIceCandidate::create(iceCandid
ateDescriptor); | 406 RefPtr<RTCIceCandidate> iceCandidate = RTCIceCandidate::create(iceCandid
ateDescriptor); |
406 dispatchEvent(RTCIceCandidateEvent::create(false, false, iceCandidate.re
lease())); | 407 scheduleDispatchEvent(RTCIceCandidateEvent::create(false, false, iceCand
idate.release())); |
407 } | 408 } |
408 } | 409 } |
409 | 410 |
410 void RTCPeerConnection::didChangeReadyState(ReadyState newState) | 411 void RTCPeerConnection::didChangeReadyState(ReadyState newState) |
411 { | 412 { |
412 ASSERT(scriptExecutionContext()->isContextThread()); | 413 ASSERT(scriptExecutionContext()->isContextThread()); |
413 changeReadyState(newState); | 414 changeReadyState(newState); |
414 } | 415 } |
415 | 416 |
416 void RTCPeerConnection::didChangeIceState(IceState newState) | 417 void RTCPeerConnection::didChangeIceState(IceState newState) |
417 { | 418 { |
418 ASSERT(scriptExecutionContext()->isContextThread()); | 419 ASSERT(scriptExecutionContext()->isContextThread()); |
419 changeIceState(newState); | 420 changeIceState(newState); |
420 } | 421 } |
421 | 422 |
422 void RTCPeerConnection::didAddRemoteStream(PassRefPtr<MediaStreamDescriptor> str
eamDescriptor) | 423 void RTCPeerConnection::didAddRemoteStream(PassRefPtr<MediaStreamDescriptor> str
eamDescriptor) |
423 { | 424 { |
424 ASSERT(scriptExecutionContext()->isContextThread()); | 425 ASSERT(scriptExecutionContext()->isContextThread()); |
425 | 426 |
426 if (m_readyState == ReadyStateClosed) | 427 if (m_readyState == ReadyStateClosed) |
427 return; | 428 return; |
428 | 429 |
429 RefPtr<MediaStream> stream = MediaStream::create(scriptExecutionContext(), s
treamDescriptor); | 430 RefPtr<MediaStream> stream = MediaStream::create(scriptExecutionContext(), s
treamDescriptor); |
430 m_remoteStreams->append(stream); | 431 m_remoteStreams->append(stream); |
431 | 432 |
432 dispatchEvent(MediaStreamEvent::create(eventNames().addstreamEvent, false, f
alse, stream.release())); | 433 scheduleDispatchEvent(MediaStreamEvent::create(eventNames().addstreamEvent,
false, false, stream.release())); |
433 } | 434 } |
434 | 435 |
435 void RTCPeerConnection::didRemoveRemoteStream(MediaStreamDescriptor* streamDescr
iptor) | 436 void RTCPeerConnection::didRemoveRemoteStream(MediaStreamDescriptor* streamDescr
iptor) |
436 { | 437 { |
437 ASSERT(scriptExecutionContext()->isContextThread()); | 438 ASSERT(scriptExecutionContext()->isContextThread()); |
438 ASSERT(streamDescriptor->owner()); | 439 ASSERT(streamDescriptor->owner()); |
439 | 440 |
440 RefPtr<MediaStream> stream = static_cast<MediaStream*>(streamDescriptor->own
er()); | 441 RefPtr<MediaStream> stream = static_cast<MediaStream*>(streamDescriptor->own
er()); |
441 stream->streamEnded(); | 442 stream->streamEnded(); |
442 | 443 |
443 if (m_readyState == ReadyStateClosed) | 444 if (m_readyState == ReadyStateClosed) |
444 return; | 445 return; |
445 | 446 |
446 ASSERT(m_remoteStreams->contains(stream.get())); | 447 ASSERT(m_remoteStreams->contains(stream.get())); |
447 m_remoteStreams->remove(stream.get()); | 448 m_remoteStreams->remove(stream.get()); |
448 | 449 |
449 dispatchEvent(MediaStreamEvent::create(eventNames().removestreamEvent, false
, false, stream.release())); | 450 scheduleDispatchEvent(MediaStreamEvent::create(eventNames().removestreamEven
t, false, false, stream.release())); |
450 } | 451 } |
451 | 452 |
452 const AtomicString& RTCPeerConnection::interfaceName() const | 453 const AtomicString& RTCPeerConnection::interfaceName() const |
453 { | 454 { |
454 return eventNames().interfaceForRTCPeerConnection; | 455 return eventNames().interfaceForRTCPeerConnection; |
455 } | 456 } |
456 | 457 |
457 ScriptExecutionContext* RTCPeerConnection::scriptExecutionContext() const | 458 ScriptExecutionContext* RTCPeerConnection::scriptExecutionContext() const |
458 { | 459 { |
459 return ActiveDOMObject::scriptExecutionContext(); | 460 return ActiveDOMObject::scriptExecutionContext(); |
(...skipping 24 matching lines...) Expand all Loading... |
484 { | 485 { |
485 if (readyState == m_readyState || m_readyState == ReadyStateClosed) | 486 if (readyState == m_readyState || m_readyState == ReadyStateClosed) |
486 return; | 487 return; |
487 | 488 |
488 m_readyState = readyState; | 489 m_readyState = readyState; |
489 | 490 |
490 switch (m_readyState) { | 491 switch (m_readyState) { |
491 case ReadyStateOpening: | 492 case ReadyStateOpening: |
492 break; | 493 break; |
493 case ReadyStateActive: | 494 case ReadyStateActive: |
494 dispatchEvent(Event::create(eventNames().openEvent, false, false)); | 495 scheduleDispatchEvent(Event::create(eventNames().openEvent, false, false
)); |
495 break; | 496 break; |
496 case ReadyStateClosing: | 497 case ReadyStateClosing: |
497 case ReadyStateClosed: | 498 case ReadyStateClosed: |
498 break; | 499 break; |
499 case ReadyStateNew: | 500 case ReadyStateNew: |
500 ASSERT_NOT_REACHED(); | 501 ASSERT_NOT_REACHED(); |
501 break; | 502 break; |
502 } | 503 } |
503 | 504 |
504 dispatchEvent(Event::create(eventNames().statechangeEvent, false, false)); | 505 scheduleDispatchEvent(Event::create(eventNames().statechangeEvent, false, fa
lse)); |
505 } | 506 } |
506 | 507 |
507 void RTCPeerConnection::changeIceState(IceState iceState) | 508 void RTCPeerConnection::changeIceState(IceState iceState) |
508 { | 509 { |
509 if (iceState == m_iceState || m_readyState == ReadyStateClosed) | 510 if (iceState == m_iceState || m_readyState == ReadyStateClosed) |
510 return; | 511 return; |
511 | 512 |
512 m_iceState = iceState; | 513 m_iceState = iceState; |
513 dispatchEvent(Event::create(eventNames().icechangeEvent, false, false)); | 514 scheduleDispatchEvent(Event::create(eventNames().icechangeEvent, false, fals
e)); |
| 515 } |
| 516 |
| 517 void RTCPeerConnection::scheduleDispatchEvent(PassRefPtr<Event> event) |
| 518 { |
| 519 m_scheduledEvents.append(event); |
| 520 |
| 521 if (!m_scheduledEventTimer.isActive()) |
| 522 m_scheduledEventTimer.startOneShot(0); |
| 523 } |
| 524 |
| 525 void RTCPeerConnection::scheduledEventTimerFired(Timer<RTCPeerConnection>*) |
| 526 { |
| 527 Vector<RefPtr<Event> > events; |
| 528 events.swap(m_scheduledEvents); |
| 529 |
| 530 Vector<RefPtr<Event> >::iterator it = events.begin(); |
| 531 for (; it != events.end(); ++it) |
| 532 dispatchEvent((*it).release()); |
| 533 |
| 534 events.clear(); |
514 } | 535 } |
515 | 536 |
516 } // namespace WebCore | 537 } // namespace WebCore |
517 | 538 |
518 #endif // ENABLE(MEDIA_STREAM) | 539 #endif // ENABLE(MEDIA_STREAM) |
OLD | NEW |