bluetooth-serial-port
Advanced tools
Comparing version 1.3.1 to 2.0.0
@@ -136,7 +136,11 @@ /* | ||
if (process.platform !== 'linux') return; | ||
if (process.platform !== 'linux') { | ||
return; | ||
} | ||
var util = require('util'), | ||
EventEmitter = require('events').EventEmitter, | ||
btSerial = require('bindings')('BluetoothSerialPortServer.node') | ||
btSerial = require('bindings')('BluetoothSerialPortServer.node'), | ||
_SERIAL_PORT_PROFILE_UUID = '1101', | ||
_DEFAULT_SERVER_CHANNEL = 1; | ||
@@ -149,3 +153,2 @@ /** | ||
EventEmitter.call(this); | ||
var self = this; | ||
} | ||
@@ -156,3 +159,14 @@ | ||
BluetoothSerialPortServer.prototype.listen = function (uuid, listeningChannel, successCallback, errorCallback) { | ||
BluetoothSerialPortServer.prototype.listen = function (successCallback, errorCallback, options) { | ||
var _options = {}; | ||
if(errorCallback && | ||
typeof errorCallback !== 'function'){ | ||
_options = errorCallback; | ||
errorCallback = null; | ||
} | ||
options = options || _options; | ||
options.uuid = options.uuid || _SERIAL_PORT_PROFILE_UUID; | ||
options.channel = options.channel || _DEFAULT_SERVER_CHANNEL; | ||
var self = this, | ||
@@ -173,3 +187,3 @@ read = function () { | ||
}, | ||
server = new btSerial.BTSerialPortBindingServer(uuid, listeningChannel, function (clientAddress) { | ||
server = new btSerial.BTSerialPortBindingServer(function (clientAddress) { | ||
self.server = server; | ||
@@ -191,7 +205,7 @@ self.on('data', function (buffer) { | ||
if (errorCallback) { | ||
if (typeof errorCallback === 'function') { | ||
errorCallback(err); | ||
} | ||
}); | ||
} | ||
}, options); | ||
}; | ||
@@ -198,0 +212,0 @@ BluetoothSerialPortServer.prototype.write = function (buffer, callback) { |
{ | ||
"name": "bluetooth-serial-port", | ||
"version": "1.3.1", | ||
"version": "2.0.0", | ||
"description": "Bluetooth serial port communication for Node.js", | ||
@@ -5,0 +5,0 @@ "author": "Eelco Cramer <eelco@hailendal.org>", |
@@ -12,4 +12,4 @@ # Bluetooth serial port communication for Node.js | ||
* Fixes compilation problem on Windows | ||
* Adds experimental RFCOMM server socket (Linux only) | ||
* Improvements and API changes of the experimental RFCOMM server socket (Linux only) | ||
* No changes in the client | ||
@@ -22,2 +22,22 @@ ## Pre-requests on Linux | ||
### Note on RFCOMM Server Sockets | ||
As the initial implementation of the RFCOMM server sockets is based on BlueZ4, in order to work with SDP we need to change the bluetoothd service configuration file by modifing the systemd unit file: bluetooth.service: | ||
(Debian based distro) | ||
`sudo vim /lib/systemd/system/bluetooth.service` | ||
(RedHat based distro) | ||
`sudo vim /usr/lib/systemd/system/bluetooth.service` | ||
and adding the --compat flag to the ExecStart value: | ||
`ExecStart=/usr/lib/bluetooth/bluetoothd `**`--compat`** | ||
Finally, restart the service: | ||
`systemctl daemon-reload | ||
systemctl restart bluetooth` | ||
## Pre-request on OS X | ||
@@ -80,6 +100,6 @@ | ||
var PORT = 1; | ||
var UUID = '38e851bc-7144-44b4-9cd8-80549c6f2912'; | ||
var CHANNEL = 10; // My service channel. Defaults to 1 if omitted. | ||
var UUID = '38e851bc-7144-44b4-9cd8-80549c6f2912'; // My own service UUID. Defaults to '1101' if omitted | ||
server.listen(UUID, PORT, function (clientAddress) { | ||
server.listen(function (clientAddress) { | ||
console.log('Client: ' + clientAddress + ' connected!'); | ||
@@ -100,10 +120,5 @@ server.on('data' function(buffer) { | ||
}); | ||
}); | ||
server.advertise(UUID, function(err) { | ||
if (err) { | ||
console.log('Cannot advertise the server'); | ||
} | ||
}); | ||
}, function(error){ | ||
console.error("Something wrong happened!:" + error); | ||
}, {uuid: UUID, channel: PORT} ); | ||
``` | ||
@@ -184,11 +199,18 @@ | ||
#### BluetoothSerialPortServer.listen(uuid, channel, callback[, errorCallback]) | ||
#### BluetoothSerialPortServer.listen(callback[, errorCallback, options]) | ||
Listens for an incoming bluetooth connection. It will automatically advertise the server via SDP | ||
* uuid - the UUID of the server | ||
* channel - the RFCOMM channel the server is listening on, in the range of 1-30. | ||
* callback(address) - is called when a new client is connecting. | ||
* errorCallback(err) - is called when an error occurs. | ||
* options - An object with these properties: | ||
* uuid - [String] The UUID of the server. If omitted the default value will be 1101 (corresponding to Serial Port Profile UUID). Can be a 16 bit or 32 bit UUID. | ||
* channel - [Number] The RFCOMM channel the server is listening on, in the range of 1-30. If omitted the default value will be 1. | ||
Example: | ||
`var options = { | ||
uuid: 'ffffffff-ffff-ffff-ffff-fffffffffff1', | ||
channel: 10 | ||
}` | ||
#### BluetoothSerialPortServer.write(buffer, callback) | ||
@@ -195,0 +217,0 @@ |
## RELEASE NOTES | ||
### 2.0.0 | ||
* Improvements and API changes of the experimental RFCOMM server socket (Linux only) | ||
* No changes in the client | ||
### 1.3.1 | ||
@@ -4,0 +9,0 @@ |
Sorry, the diff of this file is not supported yet
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
215127
249
245