canmove, Confirmed users
725
edits
| 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 | 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> | |||
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) { | ||
switch (evt.call.state) { | switch (evt.call.state) { | ||
case 'connected': | case 'connected': | ||
this.connected(); | this.connected(); | ||
| Line 380: | Line 402: | ||
}, | }, | ||
</pre> | </pre> | ||
=== DOM: Telephony === | === DOM: Telephony === | ||