B2G/Architecture: Difference between revisions

Line 357: Line 357:
</pre>
</pre>


This ends up calling [https://mxr.mozilla.org/mozilla-central/source/dom/system/gonk/nsIRadioInterfaceLayer.idl#15 the <code>nsIRILTelephonyCallback::callStateChanged</code> method] of all registered telephony callback objects. Every HTML page that accesses the <code>navigator.mozTelephony</code> API has registered one such callback object.
This ends up calling [https://mxr.mozilla.org/mozilla-central/source/dom/system/gonk/nsIRadioInterfaceLayer.idl#15 the <code>nsIRILTelephonyCallback::callStateChanged</code> method] of all registered telephony callback objects. Every web app that accesses the <code>navigator.mozTelephony</code> API has registered one such callback object that [https://mxr.mozilla.org/mozilla-central/source/dom/telephony/Telephony.cpp#372 dispatches events to the JavaScript code in the web app], either as a state change of an existing call object or a new <code>incoming</code> event:
 
<pre>
NS_IMETHODIMP
Telephony::CallStateChanged(PRUint32 aCallIndex, PRUint16 aCallState,
                            const nsAString& aNumber, bool aIsActive)
{
  [...]
  if (modifiedCall) {
    // Change state.
    modifiedCall->ChangeState(aCallState);
    // See if this should replace our current active call.
    if (aIsActive) {
      mActiveCall = modifiedCall;
    }
    return NS_OK;
  }
  nsRefPtr<TelephonyCall> call =
    TelephonyCall::Create(this, aNumber, aCallState, aCallIndex);
  nsRefPtr<CallEvent> event = CallEvent::Create(call);
  nsresult rv =
    event->Dispatch(ToIDOMEventTarget(), NS_LITERAL_STRING("incoming"));
  NS_ENSURE_SUCCESS(rv, rv);
  return NS_OK;
}
</pre>


This sets off a chain of events that results in the currently-active dialer application being notified of an incoming call.  In gaia, this notification is received [https://github.com/andreasgal/gaia/blob/master/apps/dialer/js/dialer.js#L297 here]
The <em>Dialer</em> app [https://github.com/mozilla-b2g/gaia/blob/master/apps/dialer/js/dialer.js#L389 receives these events] and updates the UI etc.:
<pre>
<pre>
   handleEvent: function fm_handleEvent(evt) {
   handleEvent: function fm_handleEvent(evt) {
    console.log('Call changed state: ' + evt.call.state);
     switch (evt.call.state) {
     switch (evt.call.state) {
      case 'incoming':
        console.log('incoming call from ' + evt.call.number);
        this.incoming(evt.call);
        break;
       case 'connected':
       case 'connected':
         this.connected();
         this.connected();
Line 380: Line 402:
   },
   },
</pre>
</pre>
at the 'incoming' case in the switch statement.


=== DOM: Telephony ===
=== DOM: Telephony ===
canmove, Confirmed users
725

edits