You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DTMF.js 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /* global APP */
  2. /**
  3. * A module for sending DTMF tones.
  4. */
  5. var DTMFSender;
  6. var initDtmfSender = function() {
  7. // TODO: This needs to reset this if the peerconnection changes
  8. // (e.g. the call is re-made)
  9. if (DTMFSender)
  10. return;
  11. var localAudio = APP.RTC.localAudio;
  12. if (localAudio && localAudio.getTracks().length > 0)
  13. {
  14. var peerconnection
  15. = APP.xmpp.getConnection().jingle.activecall.peerconnection;
  16. if (peerconnection) {
  17. DTMFSender =
  18. peerconnection.peerconnection
  19. .createDTMFSender(localAudio.getTracks()[0]);
  20. console.log("Initialized DTMFSender");
  21. }
  22. else {
  23. console.log("Failed to initialize DTMFSender: no PeerConnection.");
  24. }
  25. }
  26. else {
  27. console.log("Failed to initialize DTMFSender: no audio track.");
  28. }
  29. };
  30. var DTMF = {
  31. sendTones: function (tones, duration, pause) {
  32. if (!DTMFSender)
  33. initDtmfSender();
  34. if (DTMFSender){
  35. DTMFSender.insertDTMF(tones,
  36. (duration || 200),
  37. (pause || 200));
  38. }
  39. }
  40. };
  41. module.exports = DTMF;