| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // Custom bindings for the Bluetooth API. |
| 6 |
| 7 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); |
| 8 var sendRequest = require('sendRequest').sendRequest; |
| 9 |
| 10 // Use custom bindings to create an undocumented event listener that will |
| 11 // receive events about device discovery and call the event listener that was |
| 12 // provided with the request to begin discovery. |
| 13 chromeHidden.registerCustomHook('experimental.bluetooth', function(api) { |
| 14 var apiFunctions = api.apiFunctions; |
| 15 |
| 16 chromeHidden.bluetooth = {}; |
| 17 chromeHidden.bluetooth.handler = null; |
| 18 chromeHidden.bluetooth.onDeviceDiscovered = |
| 19 new chrome.Event("experimental.bluetooth.onDeviceDiscovered"); |
| 20 |
| 21 function deviceDiscoveredListener(device) { |
| 22 if (chromeHidden.bluetooth.handler != null) |
| 23 chromeHidden.bluetooth.handler(device); |
| 24 } |
| 25 chromeHidden.bluetooth.onDeviceDiscovered.addListener( |
| 26 deviceDiscoveredListener); |
| 27 |
| 28 apiFunctions.setHandleRequest('startDiscovery', function() { |
| 29 var args = arguments; |
| 30 if (args.length > 0 && args[0] && args[0].deviceCallback) { |
| 31 chromeHidden.bluetooth.handler = args[0].deviceCallback; |
| 32 } |
| 33 sendRequest(this.name, args, this.definition.parameters); |
| 34 }); |
| 35 apiFunctions.setHandleRequest('stopDiscovery', function() { |
| 36 chromeHidden.bluetooth.handler = null; |
| 37 sendRequest(this.name, args, this.definition.parameters); |
| 38 }); |
| 39 }); |
| OLD | NEW |