Source: js/telephony_monitor.js

  1. /* global BaseModule */
  2. 'use strict';
  3. (function() {
  4. var TelephonyMonitor = function(telephony) {
  5. this.telephony = telephony;
  6. };
  7. TelephonyMonitor.STATES = [
  8. 'inCall',
  9. 'hasActiveCall'
  10. ];
  11. BaseModule.create(TelephonyMonitor, {
  12. name: 'TelephonyMonitor',
  13. inCall: false,
  14. /**
  15. * Check if there is active call
  16. * @param {Number} index If not specified, it means any active call;
  17. * if specified, it means the active call at this SIM slot.
  18. * @return {Boolean} There is active call or not.
  19. */
  20. hasActiveCall: function(index) {
  21. if (index) {
  22. return this.telephony.active &&
  23. this.telephony.active.serviceId === index;
  24. } else {
  25. return !!this.telephony.active;
  26. }
  27. },
  28. handleEvent: function(evt) {
  29. this.inCall = this.telephony.calls.length > 0;
  30. this.publish('callschanged', {
  31. detail: evt.detail
  32. });
  33. },
  34. _start: function() {
  35. this.telephony.addEventListener('callschanged', this);
  36. },
  37. _stop: function() {
  38. this.telephony.removeEventListener('callschanged', this);
  39. }
  40. });
  41. }());