Bug 1291715 - Generate RTCDTMFToneChangeEvent; r?jib draft
authorDan Minor <dminor@mozilla.com>
Mon, 12 Sep 2016 12:51:15 -0400
changeset 413581 bc4b591d36d22968104d8d26c0efebc8eca2fb1f
parent 413580 794837af48d75fdfc64e3bd26eb6c6186d888db4
child 531247 8b8f1676697fa7ac9aa4aadb67bc164ae1d5b758
push id29449
push userdminor@mozilla.com
push dateWed, 14 Sep 2016 12:58:37 +0000
reviewersjib
bugs1291715
milestone51.0a1
Bug 1291715 - Generate RTCDTMFToneChangeEvent; r?jib MozReview-Commit-ID: 9QQBUWrmOh9
media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp
--- a/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp
+++ b/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp
@@ -75,16 +75,17 @@
 #include "nsIURLParser.h"
 #include "nsIDOMDataChannel.h"
 #include "nsIDOMLocation.h"
 #include "nsNullPrincipal.h"
 #include "mozilla/PeerIdentity.h"
 #include "mozilla/dom/RTCCertificate.h"
 #include "mozilla/dom/RTCConfigurationBinding.h"
 #include "mozilla/dom/RTCDTMFSenderBinding.h"
+#include "mozilla/dom/RTCDTMFToneChangeEvent.h"
 #include "mozilla/dom/RTCRtpSenderBinding.h"
 #include "mozilla/dom/RTCStatsReportBinding.h"
 #include "mozilla/dom/RTCPeerConnectionBinding.h"
 #include "mozilla/dom/PeerConnectionImplBinding.h"
 #include "mozilla/dom/DataChannelBinding.h"
 #include "mozilla/dom/PerformanceTiming.h"
 #include "mozilla/dom/PluginCrashedEvent.h"
 #include "MediaStreamList.h"
@@ -2518,17 +2519,17 @@ PeerConnectionImpl::RemoveTrack(MediaStr
 }
 
 NS_IMETHODIMP
 PeerConnectionImpl::InsertDTMF(mozilla::dom::RTCRtpSender& sender,
                                const nsAString& tones, double duration,
                                double interToneGap) {
 #if !defined(MOZILLA_EXTERNAL_LINKAGE)
   JSErrorResult jrv;
-  RefPtr<dom::RTCDTMFSender> dtmfSender = sender.GetDtmf(jrv);
+  RefPtr<RTCDTMFSender> dtmfSender = sender.GetDtmf(jrv);
   if (jrv.Failed()) {
     NS_WARNING("Failed to retrieve DTMF object on RTCRtpSender!");
     return NS_ERROR_UNEXPECTED;
   }
 
   // Attempt to locate state for the DTMFSender
   DTMFState *state = nullptr;
   for (uint32_t i = 0; i < mDTMFStates.Length(); ++i) {
@@ -4121,18 +4122,46 @@ PeerConnectionImpl::DTMFSendTimerCallbac
   }
 }
 
 void
 PeerConnectionImpl::DTMFSentCallback_m(DTMFState *state)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
+#if !defined(MOZILLA_EXTERNAL_LINKAGE)
+  if (state->mNextTone >= 0) {
+    //TODO: https://www.w3.org/TR/webrtc/#rtcdtmftonechangeevent says
+    //      that an empty string for mTone indicates that the previous tone
+    //      has stopped playing, but doesn't say if we are required to
+    //      generate events in this case.
+    RTCDTMFToneChangeEventInit init;
+    MOZ_ASSERT(state->mNextTone < strlen(DTMF_TONECODES));
+    init.mTone = DTMF_TONECODES[state->mNextTone];
+
+    RefPtr<RTCDTMFToneChangeEvent> event =
+      RTCDTMFToneChangeEvent::Constructor(state->mDTMFSender,
+                                          NS_LITERAL_STRING("tonechange"),
+                                          init);
+
+    event->SetTrusted(true);
+
+    nsresult rv;
+    rv = EventDispatcher::DispatchDOMEvent(state->mDTMFSender, nullptr,
+                                           event, nullptr, nullptr);
+    if (NS_FAILED(rv)) {
+      NS_WARNING("Failed to dispatch the RTCDTMFToneChange event!");
+      return;
+    }
+  }
+
   if (!state->mTones.IsEmpty()) {
     state->mNextTone = state->mTones[0];
     state->mTones.RemoveElementAt(0);
-    state->mSendTimer->InitWithFuncCallback(DTMFSendTimerCallback_m, state,
+    state->mSendTimer->InitWithFuncCallback(DTMFSendTimerCallback_m,
+                                            state,
                                             state->mDuration + state->mInterToneGap,
                                             nsITimer::TYPE_ONE_SHOT);
   }
+#endif
 }
 
 }  // end mozilla namespace