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 #14353 from eric30/Bug-945631
Browse files Browse the repository at this point in the history
Bug 945631 - Listen to event discoverystatechanged, r=arthurcc
  • Loading branch information
eric30 authored and rvandermeulen committed May 27, 2014
1 parent 9f72c3d commit 1c30a76
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions apps/settings/js/bluetooth.js
Expand Up @@ -411,6 +411,20 @@ navigator.mozL10n.ready(function bluetoothSettings() {
showDevicePaired(evt.status, 'Authentication Failed');
};

defaultAdapter.ondiscoverystatechanged =
function bt_discoveryStateChanged(evt) {
if (!evt.discovering) {
searchAgainBtn.disabled = false;
searchingItem.hidden = true;

clearTimeout(discoverTimeout);
discoverTimeout = null;
} else {
searchAgainBtn.disabled = true;
searchingItem.hidden = false;
}
};

defaultAdapter.onhfpstatuschanged = function bt_hfpStatusChanged(evt) {
showDeviceConnected(evt.address, evt.status, Profiles.HFP);
};
Expand Down Expand Up @@ -844,13 +858,11 @@ navigator.mozL10n.ready(function bluetoothSettings() {

var req = defaultAdapter.startDiscovery();
req.onsuccess = function bt_discoveryStart() {
searchAgainBtn.disabled = true;
if (!discoverTimeout)
discoverTimeout = setTimeout(stopDiscovery, discoverTimeoutTime);
};
req.onerror = function bt_discoveryFailed() {
searchingItem.hidden = true;
searchAgainBtn.disabled = false;
console.error('Can not discover nearby device');
};
}

Expand All @@ -864,16 +876,12 @@ navigator.mozL10n.ready(function bluetoothSettings() {
function stopDiscovery() {
if (!bluetooth.enabled || !defaultAdapter || !discoverTimeout)
return;

var req = defaultAdapter.stopDiscovery();
req.onsuccess = function bt_discoveryStopped() {
searchAgainBtn.disabled = false;
searchingItem.hidden = true;
};
req.onerror = function bt_discoveryStopFailed() {
console.error('Can not stop discover nearby device');
searchAgainBtn.disabled = true;
searchingItem.hidden = false;
};

clearTimeout(discoverTimeout);
discoverTimeout = null;
}
Expand Down

0 comments on commit 1c30a76

Please sign in to comment.