bluetooth-helper
Advanced tools
Comparing version 0.0.6 to 0.0.7
{ | ||
"name": "bluetooth-helper", | ||
"version": "0.0.6", | ||
"version": "0.0.7", | ||
"homepage": "https://github.com/evanxd/bluetooth-helper", | ||
@@ -5,0 +5,0 @@ "authors": [ |
@@ -1,2 +0,2 @@ | ||
/* global EventEmitter2 */ | ||
/* global Bluetooth, EventEmitter2 */ | ||
'use strict'; | ||
@@ -12,12 +12,6 @@ | ||
['writeCharacteristic', 'notifyCharacteristic'].forEach(function(item) { | ||
Object.defineProperty(BluetoothDevice.prototype, item, { | ||
set: function(value) { | ||
this['_' + item] = value; | ||
}, | ||
get: function() { | ||
return this['_' + item]; | ||
} | ||
}); | ||
}); | ||
BluetoothDevice.prototype.gatt = null; | ||
BluetoothDevice.prototype.writeCharacteristic = null; | ||
BluetoothDevice.prototype.notifyCharacteristic = null; | ||
BluetoothDevice.prototype._isNotificationsStarted = false; | ||
@@ -29,2 +23,30 @@ BluetoothDevice.prototype.send = function(data) { | ||
BluetoothDevice.prototype.startNotifications = function() { | ||
if (this._isNotificationsStarted) { | ||
return; | ||
} else { | ||
this._isNotificationsStarted = true; | ||
} | ||
var characteristic = this.notifyCharacteristic; | ||
this.gatt.addEventListener('characteristicchanged', (evt) => { | ||
this.emit('data', evt.characteristic.value); | ||
}); | ||
characteristic.startNotifications(); | ||
var descriptor = characteristic.descriptors.find(function(descriptor) { | ||
return descriptor.uuid === Bluetooth.CCCD_UUID; | ||
}); | ||
if (descriptor) { | ||
var arrayBuffer = new ArrayBuffer(2); | ||
var uint8Array = new Uint8Array(arrayBuffer); | ||
uint8Array[0] = 0x01; | ||
uint8Array[1] = 0x00; | ||
descriptor.writeValue(arrayBuffer); | ||
} | ||
}; | ||
BluetoothDevice.prototype.stopNotifications = function() { | ||
this._isNotificationsStarted = false; | ||
this.notifyCharacteristic.stopNotifications(); | ||
}; | ||
BluetoothDevice.prototype._parseHexString = function(str) { | ||
@@ -31,0 +53,0 @@ var arrayBuffer = new ArrayBuffer(Math.ceil(str.length / 2)); |
@@ -17,2 +17,3 @@ /* global BluetoothDevice */ | ||
BluetoothHelper.CONNECTING_TIMEOUT = 1000; | ||
BluetoothHelper.prototype.CCCD_UUID = '00002902-0000-1000-8000-00805f9b34fb'; | ||
@@ -91,2 +92,3 @@ BluetoothHelper.prototype._scan = null; | ||
// XXX: Workaround to connect multiple devices correctly. | ||
devcie.gatt = gatt; | ||
setTimeout(() => { | ||
@@ -93,0 +95,0 @@ gatt.connect().then(() => { |
{ | ||
"name": "bluetooth-helper", | ||
"version": "0.0.6", | ||
"version": "0.0.7", | ||
"homepage": "https://github.com/evanxd/bluetooth-helper", | ||
@@ -5,0 +5,0 @@ "authors": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7801
182