Created
March 1, 2012 17:32
-
-
Save robnyman/1951560 to your computer and use it in GitHub Desktop.
WebTelephony API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Telephony object | |
var tel = navigator.mozTelephony; | |
// Check if the phone is muted (read/write property) | |
console.log(tel.muted); | |
// Check if the speaker is enabled (read/write property) | |
console.log(tel.speakerEnabled); | |
// Place a call | |
var call = tel.dial("123456789"); | |
// Events for that call | |
call.onstatechange = function (event) { | |
/* | |
Possible values for state: | |
"dialing", "ringing", "busy", "connecting", "connected", | |
"disconnecting", "disconnected", "incoming" | |
*/ | |
console.log(event.state); | |
}; | |
// Above options as direct events | |
call.onconnected = function () { | |
// Call was connected | |
}; | |
call.ondisconnected = function () { | |
// Call was disconnected | |
}; | |
// Receiving a call | |
tel.onincoming = function (event) { | |
var incomingCall = event.call; | |
// Get the number of the incoming call | |
console.log(incomingCall.number); | |
// Answer the call | |
incomingCall.answer(); | |
}; | |
// Disconnect a call | |
call.hangUp(); | |
// Iterating over calls, and taking action depending on their changed status | |
tel.oncallschanged = function (event) { | |
tel.calls.forEach(function (call) { | |
// Log the state of each call | |
console.log(call.state); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment