Use the chrome.bluetooth API to connect to a Bluetooth device which works only on OS X, Windows and Chrome OS. All functions report failures via chrome.runtime.lastError.
You may make your chrome app connect to any device that supports RFCOMM or L2CAP services and that includes the majority of classic Bluetooth devices on the market.
As detailed in Chrome - Bluetooth, there are three things you need to make a connection to a device:
- A socket to make the connection with, created using
bluetoothSocket.create
- the address of the device you wish to connect to
- the UUID of the service itself.
Sample code implementation:
var uuid = '1105';
var onConnectedCallback = function() {
if (chrome.runtime.lastError) {
console.log("Connection failed: " + chrome.runtime.lastError.message);
} else {
// Profile implementation here.
}
};
chrome.bluetoothSocket.create(function(createInfo) {
chrome.bluetoothSocket.connect(createInfo.socketId,
device.address, uuid, onConnectedCallback);
});
Please note too that before making the connection, you should verify that the adapter is aware of the device by using bluetooth.getDevice
or the device discovery APIs.
More information and sample code implementations can be found in the documentation.