bluetooth-helper
Advanced tools
Comparing version 0.0.2 to 0.0.3
{ | ||
"name": "bluetooth-helper", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"homepage": "https://github.com/evanxd/bluetooth-helper", | ||
@@ -5,0 +5,0 @@ "authors": [ |
@@ -10,9 +10,5 @@ /* global EventEmitter2 */ | ||
function BluetoothHelper(options) { | ||
if (options && (options.name || options.address)) { | ||
this.name = options.name; | ||
this.address = options.address; | ||
bluetooth.addEventListener('attributechanged', | ||
this._handleAttributechanged.bind(this)); | ||
} | ||
function BluetoothHelper(name, address) { | ||
this.name = name; | ||
this.address = address; | ||
} | ||
@@ -45,12 +41,13 @@ | ||
BluetoothHelper.prototype.connect = function() { | ||
return bluetooth.defaultAdapter.startDiscovery().catch(() => { | ||
// Retry to connect the BLE server if failed. | ||
this.connect(); | ||
}).then(discovery => { | ||
discovery.addEventListener('devicefound', | ||
this._handleDevicefound.bind(this)); | ||
}).catch(() => { | ||
// Retry to connect the BLE server if failed. | ||
this.connect(); | ||
}); | ||
if (bluetooth.defaultAdapter) { | ||
return bluetooth.defaultAdapter.startDiscovery().then(discovery => { | ||
discovery.addEventListener('devicefound', | ||
this._handleDevicefound.bind(this)); | ||
}).catch(() => { | ||
this.connect(); | ||
}); | ||
} else { | ||
bluetooth.addEventListener('attributechanged', | ||
this._handleAttributechanged.bind(this)); | ||
} | ||
}; | ||
@@ -75,2 +72,4 @@ | ||
case 'defaultAdapter': | ||
bluetooth.removeEventListener('attributechanged', | ||
this._handleAttributechanged); | ||
this.connect(); | ||
@@ -110,9 +109,4 @@ break; | ||
}); | ||
if (this._notifyChar && Array.isArray(this._notifyChar.descriptors)) { | ||
this.emit('connected'); | ||
this.isConnected = true; | ||
} else { | ||
// Retry to discover services if failed. | ||
this._discoverServices(); | ||
} | ||
this.emit('connected'); | ||
this.isConnected = true; | ||
}); | ||
@@ -119,0 +113,0 @@ }; |
{ | ||
"name": "bluetooth-helper", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"homepage": "https://github.com/evanxd/bluetooth-helper", | ||
@@ -5,0 +5,0 @@ "authors": [ |
@@ -18,7 +18,8 @@ # bluetooth-helper | ||
}); | ||
ble.connect(); | ||
``` | ||
### Send one byte data `EE` to BLE device. | ||
### Send data to device after connected. | ||
```js | ||
ble.on('connected', function() { | ||
// You need to send one byte or more data at one time. | ||
// You need to send one byte or more data in HEX format at one time. | ||
ble.send('EE'); | ||
@@ -25,0 +26,0 @@ }); |
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
34
5443
119