Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Merge pull request #6644 from arcturus/dialer-headset
Browse files Browse the repository at this point in the history
Bug 809704 - [Dialer] can using headset button to answer/hangup the phone call
  • Loading branch information
arcturus committed Nov 28, 2012
2 parents 6680746 + 57ecb4a commit 05b87d7
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 8 deletions.
32 changes: 27 additions & 5 deletions apps/communications/dialer/js/dialer.js
Expand Up @@ -73,16 +73,38 @@ var CallHandler = (function callHandler() {
}

// Other commands needs to be handled from the call screen
if (!callScreenWindow)
sendCommandToCallScreen('BT', command);
}
window.navigator.mozSetMessageHandler('bluetooth-dialer-command',
btCommandHandler);

/* === Headset Support === */
function headsetCommandHandler(message) {
sendCommandToCallScreen('HS', message);
}
window.navigator.mozSetMessageHandler('headset-button',
headsetCommandHandler);

/*
Send commands to the callScreen via post message.
@type: Handler to be used in the CallHandler (currently 'BT': bluethood
and 'HS': headset)
@command: The specific message to each kind of type
*/
function sendCommandToCallScreen(type, command) {
if (!callScreenWindow) {
return;
}

var origin = document.location.protocol + '//' +
document.location.host;
document.location.host;
var message = {
type: type,
command: command
};

callScreenWindow.postMessage(command, origin);
callScreenWindow.postMessage(message, origin);
}
window.navigator.mozSetMessageHandler('bluetooth-dialer-command',
btCommandHandler);

/* === Calls === */
function call(number) {
Expand Down
42 changes: 39 additions & 3 deletions apps/communications/dialer/js/oncall.js
Expand Up @@ -426,9 +426,28 @@ var OnCallHandler = (function onCallHandler() {
window.close();
}

/* === Bluetooth Headset support ===*/
function handleBTCommand(evt) {
/* Handle commands send to the callscreen via postmessage */
function handleCommand(evt) {
var message = evt.data;
if (!message) {
return;
}

// Currently managing to kind of commands:
// BT: bluetooth
// HS: headset
switch (message.type) {
case 'BT':
handleBTCommand(message.command);
break;
case 'HS':
handleHSCommand(message.command);
break;
}
}

/* === Bluetooth Headset support ===*/
function handleBTCommand(message) {
switch (message) {
case 'CHUP':
end();
Expand All @@ -444,7 +463,24 @@ var OnCallHandler = (function onCallHandler() {
break;
}
}
window.addEventListener('message', handleBTCommand);

function handleHSCommand(message) {
// We will receive the message for button released,
// we will ignore it
if (message == 'headset-button-release') {
return;
}

if (telephony.active) {
end();
} else if (handledCalls.length > 1) {
holdAndAnswer();
} else {
answer();
}
}

window.addEventListener('message', handleCommand);

/* === User Actions === */
function answer() {
Expand Down
1 change: 1 addition & 0 deletions apps/communications/manifest.webapp
Expand Up @@ -109,6 +109,7 @@
"messages": [
{ "telephony-new-call": "/dialer/index.html#keyboard-view" },
{ "bluetooth-dialer-command": "/dialer/index.html#keyboard-view" },
{ "headset-button": "/dialer/index.html#keyboard-view" },
{ "alarm": "/facebook/fb_sync.html" }
]
}

0 comments on commit 05b87d7

Please sign in to comment.