{"size": 2082, "ext": "js", "max_stars_repo_path": "chrome-cordova/plugins/chrome.bluetooth/bluetooth.js", "max_stars_repo_name": "joth76/mobile-chrome-apps", "max_stars_repo_stars_event_min_datetime": "2021-05-21T02:06:48.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-21T02:06:48.000Z", "max_issues_repo_path": "chrome-cordova/plugins/chrome.bluetooth/bluetooth.js", "max_issues_repo_name": "joth76/mobile-chrome-apps", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chrome-cordova/plugins/chrome.bluetooth/bluetooth.js", "max_forks_repo_name": "joth76/mobile-chrome-apps", "max_forks_repo_forks_event_min_datetime": "2015-07-24T11:38:45.000Z", "max_forks_repo_forks_event_max_datetime": "2015-09-22T07:18:58.000Z"}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": 2, "avg_line_length": 33.5806451613, "max_line_length": 84, "alphanum_fraction": 0.6906820365}
// Copyright (c) 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

var Event = require('org.chromium.common.events');
var platform = cordova.require('cordova/platform');
var exec = require('cordova/exec');
var callbackWithError = require('org.chromium.common.errors').callbackWithError;

var fail = function(callback) {
    return callback && function(msg) {
        callbackWithError(msg, callback);
    };
};

exports.getAdapterState = function(callback) {
    exec(callback, fail(callback), 'ChromeBluetooth', 'getAdapterState', []);
};

exports.getDevice = function(deviceAddress, callback) {
    exec(callback, fail(callback), 'ChromeBluetooth', 'getDevice', [deviceAddress]);
};

exports.getDevices = function(callback) {
    exec(callback, fail(callback), 'ChromeBluetooth', 'getDevices', []);
};

exports.startDiscovery = function(callback) {
    exec(callback, fail(callback), 'ChromeBluetooth', 'startDiscovery', []);
};

exports.stopDiscovery = function(callback) {
    exec(callback, fail(callback), 'ChromeBluetooth', 'stopDiscovery', []);
};

exports.onAdapterStateChanged = new Event('onAdapterStateChanged');
exports.onDeviceAdded = new Event('onDeviceAdded');
exports.onDeviceChanged = new Event('onDeviceChanged');
exports.onDeviceRemoved = new Event('onDeviceRemoved');

function registerEvents() {
    var onEventsCallback = function(eventType, info) {
        switch (eventType) {
        case 'onAdapterStateChanged':
            exports.onAdapterStateChanged.fire(info);
            break;
        case 'onDeviceAdded':
            exports.onDeviceAdded.fire(info);
            break;
        case 'onDeviceChanged':
            exports.onDeviceChanged.fire(info);
            break;
        case 'onDeviceRemoved':
            exports.onDeviceRemoved.fire(info);
            break;
        }
    };
    exec(onEventsCallback, null, 'ChromeBluetooth', 'registerBluetoothEvents', []);
}

require('org.chromium.common.helpers').runAtStartUp(registerEvents);
