From 99c4b12c8782e00e4e91b5df34f24c4f988b2563 Mon Sep 17 00:00:00 2001 From: Gabriel Schulhof Date: Wed, 29 Aug 2018 15:15:12 -0400 Subject: [PATCH] Remove usage of Buffer constructor (#83) Replace `new Buffer(...)` with `Buffer.from(...)` and `Buffer.alloc(...)` --- bleu-station/bleu-station.js | 16 ++++++------- bleu-station/pseudo.js | 40 +++++++++++++++---------------- estimote-sticker/pseudo.js | 14 +++++------ estimote/estimote.js | 18 +++++++------- estimote/pseudo.js | 34 +++++++++++++------------- radbeacon/pseudo-radbeacon-tag.js | 18 +++++++------- radbeacon/pseudo-radbeacon-usb.js | 20 ++++++++-------- radbeacon/radbeacon-tag.js | 20 ++++++++-------- 8 files changed, 90 insertions(+), 90 deletions(-) diff --git a/bleu-station/bleu-station.js b/bleu-station/bleu-station.js index c0228b1..e452f64 100644 --- a/bleu-station/bleu-station.js +++ b/bleu-station/bleu-station.js @@ -164,8 +164,8 @@ BleuStation.prototype.writeDataCharacteristic = function(uuid, data, callback) { BleuStation.prototype.writeStringCharacteristic = function(uuid, value, callback) { var valueLength = value.length; - var data = new Buffer(valueLength + 1); - var valueData = new Buffer(value); + var data = Buffer.alloc(valueLength + 1); + var valueData = Buffer.alloc(value); data[0] = valueLength; for (var i = 0; i < valueLength; i++) { @@ -176,7 +176,7 @@ BleuStation.prototype.writeStringCharacteristic = function(uuid, value, callback }; BleuStation.prototype.writeUInt16Characteristic = function(uuid, value, callback) { - var data = new Buffer(2); + var data = Buffer.alloc(2); data.writeUInt16BE(value, 0); @@ -184,7 +184,7 @@ BleuStation.prototype.writeUInt16Characteristic = function(uuid, value, callback }; BleuStation.prototype.writeInt8Characteristic = function(uuid, value, callback) { - var data = new Buffer(1); + var data = Buffer.alloc(1); data.writeInt8(value, 0); @@ -192,7 +192,7 @@ BleuStation.prototype.writeInt8Characteristic = function(uuid, value, callback) }; BleuStation.prototype.writeUInt8Characteristic = function(uuid, value, callback) { - var data = new Buffer(1); + var data = Buffer.alloc(1); data.writeUInt8(value, 0); @@ -200,7 +200,7 @@ BleuStation.prototype.writeUInt8Characteristic = function(uuid, value, callback) }; BleuStation.prototype.writeDoubleCharacteristic = function(uuid, value, callback) { - var data = new Buffer(8); + var data = Buffer.alloc(8); data.writeDoubleLE(value, 0); @@ -220,7 +220,7 @@ BleuStation.prototype.login = function(password, callback) { } } - clientCharacteristicConfigurationDescriptor.writeValue(new Buffer('0000', 'hex'), function(error) { + clientCharacteristicConfigurationDescriptor.writeValue(Buffer.from('0000', 'hex'), function(error) { this.writeAdminPassword(password, function(result) { callback(result === 0); }.bind(this)); @@ -279,7 +279,7 @@ BleuStation.prototype.readAdminDeviceName = function(callback) { }; BleuStation.prototype.writeUuid = function(uuid, callback) { - this.writeDataCharacteristic(ADMIN_IBEACON_UUID_UUID, new Buffer(uuid, 'hex'), callback); + this.writeDataCharacteristic(ADMIN_IBEACON_UUID_UUID, Buffer.from(uuid, 'hex'), callback); }; BleuStation.prototype.writeMajor = function(major, callback) { diff --git a/bleu-station/pseudo.js b/bleu-station/pseudo.js index 556147e..6ee3131 100644 --- a/bleu-station/pseudo.js +++ b/bleu-station/pseudo.js @@ -30,22 +30,22 @@ bleno.on('advertisingStart', function(error) { new BlenoCharacteristic({ uuid: '2a29', properties: ['read'], - value: new Buffer('TwoCanoes') + value: Buffer.from('TwoCanoes') }), new BlenoCharacteristic({ uuid: '2a24', properties: ['read'], - value: new Buffer('iBeacon Demo') + value: Buffer.from('iBeacon Demo') }), new BlenoCharacteristic({ uuid: '2a27', properties: ['read'], - value: new Buffer('0.0.0') + value: Buffer.from('0.0.0') }), new BlenoCharacteristic({ uuid: '2a26', properties: ['read'], - value: new Buffer('0.0.0') + value: Buffer.from('0.0.0') }) ] }), @@ -55,22 +55,22 @@ bleno.on('advertisingStart', function(error) { new BlenoCharacteristic({ uuid: 'b0702881a295a8abf734031a98a512de', properties: ['read'], - value: new Buffer('e2c56db5dffb48d2b060d0f5a71096e0', 'hex') + value: Buffer.from('e2c56db5dffb48d2b060d0f5a71096e0', 'hex') }), new BlenoCharacteristic({ uuid: 'b0702882a295a8abf734031a98a512de', properties: ['read'], - value: new Buffer('0001', 'hex') + value: Buffer.from('0001', 'hex') }), new BlenoCharacteristic({ uuid: 'b0702883a295a8abf734031a98a512de', properties: ['read'], - value: new Buffer('0002', 'hex') + value: Buffer.from('0002', 'hex') }), new BlenoCharacteristic({ uuid: 'b0702884a295a8abf734031a98a512de', properties: ['read'], - value: new Buffer('c4', 'hex') + value: Buffer.from('c4', 'hex') }) ] }), @@ -94,7 +94,7 @@ bleno.on('advertisingStart', function(error) { onReadRequest: function(offset, callback) { console.log('c8f21a07078a42df86600946ffd109be onReadRequest'); - callback(BlenoCharacteristic.RESULT_SUCCESS, new Buffer('e2c56db5dffb48d2b060d0f5a71096e0', 'hex')); + callback(BlenoCharacteristic.RESULT_SUCCESS, Buffer.from('e2c56db5dffb48d2b060d0f5a71096e0', 'hex')); }, onWriteRequest: function(data, offset, withoutResponse, callback) { console.log('c8f21a07078a42df86600946ffd109be onWriteRequest ' + data.toString('hex')); @@ -108,7 +108,7 @@ bleno.on('advertisingStart', function(error) { onReadRequest: function(offset, callback) { console.log('677ec16a743d42fcafe1d9f4a02a726f onReadRequest'); - callback(BlenoCharacteristic.RESULT_SUCCESS, new Buffer('0001', 'hex')); + callback(BlenoCharacteristic.RESULT_SUCCESS, Buffer.from('0001', 'hex')); }, onWriteRequest: function(data, offset, withoutResponse, callback) { console.log('677ec16a743d42fcafe1d9f4a02a726f onWriteRequest ' + data.toString('hex')); @@ -122,7 +122,7 @@ bleno.on('advertisingStart', function(error) { onReadRequest: function(offset, callback) { console.log('7722712a07f4433f8e305a6dc26356ba onReadRequest'); - callback(BlenoCharacteristic.RESULT_SUCCESS, new Buffer('0002', 'hex')); + callback(BlenoCharacteristic.RESULT_SUCCESS, Buffer.from('0002', 'hex')); }, onWriteRequest: function(data, offset, withoutResponse, callback) { console.log('7722712a07f4433f8e305a6dc26356ba onWriteRequest ' + data.toString('hex')); @@ -136,7 +136,7 @@ bleno.on('advertisingStart', function(error) { onReadRequest: function(offset, callback) { console.log('8aa2414e8e614d9cae14508ee3192dee onReadRequest'); - callback(BlenoCharacteristic.RESULT_SUCCESS, new Buffer('0f', 'hex')); + callback(BlenoCharacteristic.RESULT_SUCCESS, Buffer.from('0f', 'hex')); }, onWriteRequest: function(data, offset, withoutResponse, callback) { console.log('8aa2414e8e614d9cae14508ee3192dee onWriteRequest ' + data.toString('hex')); @@ -150,7 +150,7 @@ bleno.on('advertisingStart', function(error) { onReadRequest: function(offset, callback) { console.log('0b4700c35c5346519601b7e1e06b1bbf onReadRequest'); - callback(BlenoCharacteristic.RESULT_SUCCESS, new Buffer('c4', 'hex')); + callback(BlenoCharacteristic.RESULT_SUCCESS, Buffer.from('c4', 'hex')); }, onWriteRequest: function(data, offset, withoutResponse, callback) { console.log('0b4700c35c5346519601b7e1e06b1bbf onWriteRequest ' + data.toString('hex')); @@ -164,7 +164,7 @@ bleno.on('advertisingStart', function(error) { onReadRequest: function(offset, callback) { console.log('980ac81e94fd43f48b9a260a65dd3adc onReadRequest'); - callback(BlenoCharacteristic.RESULT_SUCCESS, new Buffer('TC000000')); + callback(BlenoCharacteristic.RESULT_SUCCESS, Buffer.from('TC000000')); }, onWriteRequest: function(data, offset, withoutResponse, callback) { console.log('980ac81e94fd43f48b9a260a65dd3adc onWriteRequest ' + data.toString('hex')); @@ -178,7 +178,7 @@ bleno.on('advertisingStart', function(error) { onReadRequest: function(offset, callback) { console.log('12d8cca8b1cc4e48abf7767b5e0f3ff6 onReadRequest'); - callback(BlenoCharacteristic.RESULT_SUCCESS, new Buffer('', 'hex')); + callback(BlenoCharacteristic.RESULT_SUCCESS, Buffer.from('', 'hex')); }, onWriteRequest: function(data, offset, withoutResponse, callback) { console.log('12d8cca8b1cc4e48abf7767b5e0f3ff6 onWriteRequest ' + data.toString('hex')); @@ -197,7 +197,7 @@ bleno.on('advertisingStart', function(error) { onReadRequest: function(offset, callback) { console.log('fffc3dbb92d148f1aa5289a3d9517d79 onReadRequest'); - var data = new Buffer(8); + var data = Buffer.alloc(8); data.writeDoubleLE(123.456789, 0); callback(BlenoCharacteristic.RESULT_SUCCESS, data); @@ -214,7 +214,7 @@ bleno.on('advertisingStart', function(error) { onReadRequest: function(offset, callback) { console.log('9e5f3adf337f4acfb54d929da486f512 onReadRequest'); - var data = new Buffer(8); + var data = Buffer.alloc(8); data.writeDoubleLE(999.123456, 0); callback(BlenoCharacteristic.RESULT_SUCCESS, data); @@ -231,7 +231,7 @@ bleno.on('advertisingStart', function(error) { onReadRequest: function(offset, callback) { console.log('676e5ff15cd7484ab98f97f3c96e6361 onReadRequest'); - var data = new Buffer([1]); + var data = Buffer.from([1]); callback(BlenoCharacteristic.RESULT_SUCCESS, data); }, @@ -252,7 +252,7 @@ bleno.on('advertisingStart', function(error) { onReadRequest: function(offset, callback) { console.log('98a5a965efd34d16924718fd88bb8a30 onReadRequest'); - var data = new Buffer('/https://twocanoes.com/bleu/config/default.plist'); + var data = Buffer.from('/https://twocanoes.com/bleu/config/default.plist'); callback(BlenoCharacteristic.RESULT_SUCCESS, data); }, @@ -268,7 +268,7 @@ bleno.on('advertisingStart', function(error) { onReadRequest: function(offset, callback) { console.log('3e8501d8aa3943368908b6e79d81a050 onReadRequest'); - var data = new Buffer(''); + var data = Buffer.from(''); callback(BlenoCharacteristic.RESULT_SUCCESS, data); }, diff --git a/estimote-sticker/pseudo.js b/estimote-sticker/pseudo.js index a10c286..f49d0e3 100644 --- a/estimote-sticker/pseudo.js +++ b/estimote-sticker/pseudo.js @@ -11,19 +11,19 @@ bleno.on('stateChange', function(state) { if (state === 'poweredOn') { var advertisement = Buffer.concat([ - new Buffer('03030f18', 'hex'), - new Buffer('17ff', 'hex'), - new Buffer('5d0101', 'hex'), - new Buffer('0398290ef72bcff9', 'hex'), + Buffer.from('03030f18', 'hex'), + Buffer.from('17ff', 'hex'), + Buffer.from('5d0101', 'hex'), + Buffer.from('0398290ef72bcff9', 'hex'), - new Buffer('0401', 'hex') , - new Buffer('000000000000000000', 'hex') + Buffer.from('0401', 'hex') , + Buffer.from('000000000000000000', 'hex') ]); if (platform === 'darwin') { bleno.startAdvertisingWithEIRData(advertisement); } else if (platform === 'linux') { - var scan = new Buffer(0); + var scan = Buffer.alloc(0); bleno.startAdvertisingWithEIRData(advertisement, scan); } } else { diff --git a/estimote/estimote.js b/estimote/estimote.js index 75ab765..4000958 100644 --- a/estimote/estimote.js +++ b/estimote/estimote.js @@ -41,7 +41,7 @@ var Estimote = function(peripheral) { var serviceData = peripheral.advertisement.serviceData[0].data; this.address = serviceData.slice(0, 6).toString('hex').match(/.{1,2}/g).reverse().join(':'); - this.addressData = new Buffer(this.address.split(':').join(''), 'hex'); + this.addressData = Buffer.from(this.address.split(':').join(''), 'hex'); this.measuredPower = serviceData.readInt8(6); this.major = serviceData.readUInt16LE(7); @@ -96,7 +96,7 @@ Estimote.prototype.pair = function(callback) { sec = bignum(authService1Value).powm(exp, mod); - var authService2Data = new Buffer(16); + var authService2Data = Buffer.alloc(16); // fill in authService2Data with address authService2Data[0] = this.addressData[5]; @@ -122,8 +122,8 @@ Estimote.prototype.pair = function(callback) { 'c54fc29163e4457b8a9ac9868e1b3a9a' : // "new" fixed key (v3) 'ff8af207013625c2d810097f20d3050f'; // original fixed key - var key = new Buffer(fixedKeyHexString, 'hex'); - var iv = new Buffer('00000000000000000000000000000000', 'hex'); + var key = Buffer.from(fixedKeyHexString, 'hex'); + var iv = Buffer.from('00000000000000000000000000000000', 'hex'); var cipher = crypto.createCipheriv('aes128', key, iv); @@ -131,7 +131,7 @@ Estimote.prototype.pair = function(callback) { authService2Data = cipher.update(authService2Data); // fill in key with sec - var secData = new Buffer(4); + var secData = Buffer.alloc(4); secData.writeUInt32BE(sec, 0); key[0] = secData[3]; @@ -196,7 +196,7 @@ Estimote.prototype.readUuid1 = function(callback) { }; Estimote.prototype.writeUuid1 = function(uuid1, callback) { - this.writeDataCharacteristic(ESTIMOTE_SERVICE_UUID, UUID_1_UUID, new Buffer(uuid1, 'hex'), callback); + this.writeDataCharacteristic(ESTIMOTE_SERVICE_UUID, UUID_1_UUID, Buffer.from(uuid1, 'hex'), callback); }; Estimote.prototype.readUuid2 = function(callback) { @@ -210,7 +210,7 @@ Estimote.prototype.readUuid2 = function(callback) { }; Estimote.prototype.writeUuid2 = function(uuid2, callback) { - this.writeDataCharacteristic(ESTIMOTE_SERVICE_UUID, UUID_2_UUID, new Buffer(uuid2, 'hex'), callback); + this.writeDataCharacteristic(ESTIMOTE_SERVICE_UUID, UUID_2_UUID, Buffer.from(uuid2, 'hex'), callback); }; Estimote.prototype.readPowerLevel = function(callback) { @@ -361,7 +361,7 @@ Estimote.prototype.readEddystoneUidNamespace = function(callback) { }; Estimote.prototype.writeEddystoneUidNamespace = function(uidNamespace, callback) { - this.writeDataCharacteristic(ESTIMOTE_SERVICE_UUID, EDDYSTONE_UID_NAMESPACE_UUID, new Buffer(uidNamespace, 'hex'), callback); + this.writeDataCharacteristic(ESTIMOTE_SERVICE_UUID, EDDYSTONE_UID_NAMESPACE_UUID, Buffer.from(uidNamespace, 'hex'), callback); }; Estimote.prototype.readEddystoneUidInstance = function(callback) { @@ -375,7 +375,7 @@ Estimote.prototype.readEddystoneUidInstance = function(callback) { }; Estimote.prototype.writeEddystoneUidInstance = function(uidInstance, callback) { - this.writeDataCharacteristic(ESTIMOTE_SERVICE_UUID, EDDYSTONE_UID_INSTANCE_UUID, new Buffer(uidInstance, 'hex'), callback); + this.writeDataCharacteristic(ESTIMOTE_SERVICE_UUID, EDDYSTONE_UID_INSTANCE_UUID, Buffer.from(uidInstance, 'hex'), callback); }; Estimote.prototype.readEddystoneUrl = function(callback) { diff --git a/estimote/pseudo.js b/estimote/pseudo.js index e7368d7..e578757 100644 --- a/estimote/pseudo.js +++ b/estimote/pseudo.js @@ -18,8 +18,8 @@ bleno.on('stateChange', function(state) { if (state === 'poweredOn') { bleno.startAdvertisingWithEIRData( - new Buffer('0201061aff4c000215b9407f30f5f8466eaff925556b57fe6d00010002b6', 'hex'), - new Buffer('0909657374696d6f74650e160a182eb8855fb5ddb601000200', 'hex') + Buffer.from('0201061aff4c000215b9407f30f5f8466eaff925556b57fe6d00010002b6', 'hex'), + Buffer.from('0909657374696d6f74650e160a182eb8855fb5ddb601000200', 'hex') ); } else { bleno.stopAdvertising(); @@ -54,57 +54,57 @@ bleno.on('advertisingStart', function(error) { new BlenoCharacteristic({ uuid: 'b9403001f5f8466eaff925556b57fe6d', properties: ['read', 'write'], - value: new Buffer('0200', 'hex') + value: Buffer.from('0200', 'hex') }), new BlenoCharacteristic({ uuid: 'b9403002f5f8466eaff925556b57fe6d', properties: ['read', 'write'], - value: new Buffer('0100', 'hex') + value: Buffer.from('0100', 'hex') }), new BlenoCharacteristic({ uuid: 'b9403003f5f8466eaff925556b57fe6d', properties: ['read', 'write'], - value: new Buffer('b9407f30f5f8466eaff925556b57fe6d', 'hex') + value: Buffer.from('b9407f30f5f8466eaff925556b57fe6d', 'hex') }), new BlenoCharacteristic({ uuid: 'b9403004f5f8466eaff925556b57fe6d', properties: ['read', 'write'], - value: new Buffer('b9407f30f5f8466eaff925556b57fe6d', 'hex') + value: Buffer.from('b9407f30f5f8466eaff925556b57fe6d', 'hex') }), new BlenoCharacteristic({ uuid: 'b9403011f5f8466eaff925556b57fe6d', properties: ['read', 'write'], - value: new Buffer('f4', 'hex') + value: Buffer.from('f4', 'hex') }), new BlenoCharacteristic({ uuid: 'b9403012f5f8466eaff925556b57fe6d', properties: ['read', 'write'], - value: new Buffer('4001', 'hex') + value: Buffer.from('4001', 'hex') }), new BlenoCharacteristic({ uuid: 'b9403021f5f8466eaff925556b57fe6d', properties: ['read', 'write'], - value: new Buffer('0000', 'hex') + value: Buffer.from('0000', 'hex') }), new BlenoCharacteristic({ uuid: 'b9403031f5f8466eaff925556b57fe6d', properties: ['read', 'indicate'], - value: new Buffer('00', 'hex') + value: Buffer.from('00', 'hex') }), new BlenoCharacteristic({ uuid: 'b9403032f5f8466eaff925556b57fe6d', properties: ['read', 'write'], - value: new Buffer('00000000', 'hex') + value: Buffer.from('00000000', 'hex') }), new BlenoCharacteristic({ uuid: 'b9403051f5f8466eaff925556b57fe6d', properties: ['read', 'write'], - value: new Buffer('00000000', 'hex') + value: Buffer.from('00000000', 'hex') }), new BlenoCharacteristic({ uuid: 'b9403041f5f8466eaff925556b57fe6d', properties: ['read', 'write'], - value: new Buffer('64', 'hex') + value: Buffer.from('64', 'hex') }) ] }), @@ -114,12 +114,12 @@ bleno.on('advertisingStart', function(error) { new BlenoCharacteristic({ uuid: 'b9402001f5f8466eaff925556b57fe6d', properties: ['read', 'write'], - value: new Buffer('00000000', 'hex') + value: Buffer.from('00000000', 'hex') }), new BlenoCharacteristic({ uuid: 'b9402002f5f8466eaff925556b57fe6d', properties: ['read', 'write'], - value: new Buffer('00000000000000000000000000000000', 'hex') + value: Buffer.from('00000000000000000000000000000000', 'hex') }) ] }), @@ -129,12 +129,12 @@ bleno.on('advertisingStart', function(error) { new BlenoCharacteristic({ uuid: 'b9404001f5f8466eaff925556b57fe6d', properties: ['read'], - value: new Buffer('A1.9') + value: Buffer.from('A1.9') }), new BlenoCharacteristic({ uuid: 'b9404002f5f8466eaff925556b57fe6d', properties: ['read'], - value: new Buffer('D3.2') + value: Buffer.from('D3.2') }) ] }), diff --git a/radbeacon/pseudo-radbeacon-tag.js b/radbeacon/pseudo-radbeacon-tag.js index 959f059..46d888b 100644 --- a/radbeacon/pseudo-radbeacon-tag.js +++ b/radbeacon/pseudo-radbeacon-tag.js @@ -69,23 +69,23 @@ bleno.on('advertisingStart', function(error) { var data; if (lastCommand === 'pin') { - data = new Buffer('01', 'hex'); // 01 - correct pin, 00 - incorrect pin + data = Buffer.from('01', 'hex'); // 01 - correct pin, 00 - incorrect pin } else if (lastCommand === 0x87) { - data = new Buffer('RadBeacon Tag'); + data = Buffer.from('RadBeacon Tag'); } else if (lastCommand === 0x90) { - data = new Buffer('e2c56db5dffb48d2b060d0f5a71096e0', 'hex'); + data = Buffer.from('e2c56db5dffb48d2b060d0f5a71096e0', 'hex'); } else if (lastCommand === 0x91) { - data = new Buffer('0001', 'hex'); + data = Buffer.from('0001', 'hex'); } else if (lastCommand === 0x92) { - data = new Buffer('0002', 'hex'); + data = Buffer.from('0002', 'hex'); } else if (lastCommand === 0x93) { - data = new Buffer('c5', 'hex'); + data = Buffer.from('c5', 'hex'); } else if (lastCommand === 0x84) { - data = new Buffer('04', 'hex'); + data = Buffer.from('04', 'hex'); } else if (lastCommand === 0x82) { - data = new Buffer('0064', 'hex'); + data = Buffer.from('0064', 'hex'); } else if (lastCommand === 0xa0) { - data = new Buffer('32', 'hex'); + data = Buffer.from('32', 'hex'); } callback(BlenoCharacteristic.RESULT_SUCCESS, data); diff --git a/radbeacon/pseudo-radbeacon-usb.js b/radbeacon/pseudo-radbeacon-usb.js index 5e5bd9c..e421591 100644 --- a/radbeacon/pseudo-radbeacon-usb.js +++ b/radbeacon/pseudo-radbeacon-usb.js @@ -35,7 +35,7 @@ bleno.on('advertisingStart', function(error) { onReadRequest: function(offset, callback) { console.log('aaa0 onReadRequest'); - callback(BlenoCharacteristic.RESULT_SUCCESS, new Buffer('526164426561636f6e20555342000000000000000000000000000000000000000000000000', 'hex')); + callback(BlenoCharacteristic.RESULT_SUCCESS, Buffer.from('526164426561636f6e20555342000000000000000000000000000000000000000000000000', 'hex')); }, onWriteRequest: function(data, offset, withoutResponse, callback) { console.log('aaa0 onWriteRequest ' + data.toString('hex')); @@ -49,7 +49,7 @@ bleno.on('advertisingStart', function(error) { onReadRequest: function(offset, callback) { console.log('aaa1 onReadRequest'); - callback(BlenoCharacteristic.RESULT_SUCCESS, new Buffer('303235354433', 'hex')); + callback(BlenoCharacteristic.RESULT_SUCCESS, Buffer.from('303235354433', 'hex')); } }), new BlenoCharacteristic({ @@ -58,7 +58,7 @@ bleno.on('advertisingStart', function(error) { onReadRequest: function(offset, callback) { console.log('aaa2 onReadRequest'); - callback(BlenoCharacteristic.RESULT_SUCCESS, new Buffer('526164426561636f6e20555342000000000000000000000000000000000000000000000000', 'hex')); + callback(BlenoCharacteristic.RESULT_SUCCESS, Buffer.from('526164426561636f6e20555342000000000000000000000000000000000000000000000000', 'hex')); }, onWriteRequest: function(data, offset, withoutResponse, callback) { console.log('aaa2 onWriteRequest ' + data.toString('hex')); @@ -72,7 +72,7 @@ bleno.on('advertisingStart', function(error) { onReadRequest: function(offset, callback) { console.log('aaa3 onReadRequest'); - callback(BlenoCharacteristic.RESULT_SUCCESS, new Buffer('2f234454cf6d4a0fadf2f4911ba9ffa6', 'hex')); + callback(BlenoCharacteristic.RESULT_SUCCESS, Buffer.from('2f234454cf6d4a0fadf2f4911ba9ffa6', 'hex')); }, onWriteRequest: function(data, offset, withoutResponse, callback) { console.log('aaa3 onWriteRequest ' + data.toString('hex')); @@ -86,7 +86,7 @@ bleno.on('advertisingStart', function(error) { onReadRequest: function(offset, callback) { console.log('aaa4 onReadRequest'); - callback(BlenoCharacteristic.RESULT_SUCCESS, new Buffer('0001', 'hex')); + callback(BlenoCharacteristic.RESULT_SUCCESS, Buffer.from('0001', 'hex')); }, onWriteRequest: function(data, offset, withoutResponse, callback) { console.log('aaa4 onWriteRequest ' + data.toString('hex')); @@ -100,7 +100,7 @@ bleno.on('advertisingStart', function(error) { onReadRequest: function(offset, callback) { console.log('aaa5 onReadRequest'); - callback(BlenoCharacteristic.RESULT_SUCCESS, new Buffer('0001', 'hex')); + callback(BlenoCharacteristic.RESULT_SUCCESS, Buffer.from('0001', 'hex')); }, onWriteRequest: function(data, offset, withoutResponse, callback) { console.log('aaa5 onWriteRequest ' + data.toString('hex')); @@ -114,7 +114,7 @@ bleno.on('advertisingStart', function(error) { onReadRequest: function(offset, callback) { console.log('aaa6 onReadRequest'); - callback(BlenoCharacteristic.RESULT_SUCCESS, new Buffer('be', 'hex')); + callback(BlenoCharacteristic.RESULT_SUCCESS, Buffer.from('be', 'hex')); }, onWriteRequest: function(data, offset, withoutResponse, callback) { console.log('aaa6 onWriteRequest ' + data.toString('hex')); @@ -128,7 +128,7 @@ bleno.on('advertisingStart', function(error) { onReadRequest: function(offset, callback) { console.log('aaa7 onReadRequest'); - callback(BlenoCharacteristic.RESULT_SUCCESS, new Buffer('0f', 'hex')); + callback(BlenoCharacteristic.RESULT_SUCCESS, Buffer.from('0f', 'hex')); }, onWriteRequest: function(data, offset, withoutResponse, callback) { console.log('aaa7 onWriteRequest ' + data.toString('hex')); @@ -142,7 +142,7 @@ bleno.on('advertisingStart', function(error) { onReadRequest: function(offset, callback) { console.log('aaa8 onReadRequest'); - callback(BlenoCharacteristic.RESULT_SUCCESS, new Buffer('a000', 'hex')); + callback(BlenoCharacteristic.RESULT_SUCCESS, Buffer.from('a000', 'hex')); }, onWriteRequest: function(data, offset, withoutResponse, callback) { console.log('aaa8 onWriteRequest ' + data.toString('hex')); @@ -156,7 +156,7 @@ bleno.on('advertisingStart', function(error) { onReadRequest: function(offset, callback) { console.log('aaa9 onReadRequest'); - callback(BlenoCharacteristic.RESULT_SUCCESS, new Buffer('00000000', 'hex')); + callback(BlenoCharacteristic.RESULT_SUCCESS, Buffer.from('00000000', 'hex')); }, onWriteRequest: function(data, offset, withoutResponse, callback) { console.log('aaa9 onWriteRequest ' + data.toString('hex')); diff --git a/radbeacon/radbeacon-tag.js b/radbeacon/radbeacon-tag.js index e12aa58..fae11fe 100644 --- a/radbeacon/radbeacon-tag.js +++ b/radbeacon/radbeacon-tag.js @@ -98,7 +98,7 @@ RadBeaconTag.prototype.discoverServicesAndCharacteristics = function(callback) { }; RadBeaconTag.prototype.readValue = function(command, callback) { - this._characteristics[COMMAND_UUID].write(new Buffer([command]), false, function() { + this._characteristics[COMMAND_UUID].write(Buffer.from([command]), false, function() { this._characteristics[RESPONSE_UUID].read(function(error, data) { callback(data); }.bind(this)); @@ -164,7 +164,7 @@ RadBeaconTag.prototype.readBatteryLevel = function(callback) { }; RadBeaconTag.prototype.login = function(pin, callback) { - var data = new Buffer(4); + var data = Buffer.alloc(4); pin += ''; @@ -180,15 +180,15 @@ RadBeaconTag.prototype.login = function(pin, callback) { }; RadBeaconTag.prototype.writeName = function(name, callback) { - this.writeValue(0x07, new Buffer(name), callback); + this.writeValue(0x07, Buffer.from(name), callback); }; RadBeaconTag.prototype.writeUuid = function(uuid, callback) { - this.writeValue(0x10, new Buffer(uuid, 'hex'), callback); + this.writeValue(0x10, Buffer.from(uuid, 'hex'), callback); }; RadBeaconTag.prototype.writeMajor = function(major, callback) { - var data = new Buffer(2); + var data = Buffer.alloc(2); data.writeUInt16BE(major, 0); @@ -196,7 +196,7 @@ RadBeaconTag.prototype.writeMajor = function(major, callback) { }; RadBeaconTag.prototype.writeMinor = function(minor, callback) { - var data = new Buffer(2); + var data = Buffer.alloc(2); data.writeUInt16BE(minor, 0); @@ -204,7 +204,7 @@ RadBeaconTag.prototype.writeMinor = function(minor, callback) { }; RadBeaconTag.prototype.writeMeasuredTxPower = function(measureTxPower, callback) { - var data = new Buffer(1); + var data = Buffer.alloc(1); data.writeInt8(measureTxPower, 0); @@ -212,7 +212,7 @@ RadBeaconTag.prototype.writeMeasuredTxPower = function(measureTxPower, callback) }; RadBeaconTag.prototype.writeAdvertisementInterval = function(advertisementInterval, callback) { - var data = new Buffer(2); + var data = Buffer.alloc(2); data.writeUInt16BE(advertisementInterval, 0); @@ -220,7 +220,7 @@ RadBeaconTag.prototype.writeAdvertisementInterval = function(advertisementInterv }; RadBeaconTag.prototype.writeTxPower = function(txPower, callback) { - var data = new Buffer(1); + var data = Buffer.alloc(1); data.writeInt8(txPower, 0); @@ -228,7 +228,7 @@ RadBeaconTag.prototype.writeTxPower = function(txPower, callback) { }; RadBeaconTag.prototype.writePin = function(currentpin, newpin, callback) { - var data = new Buffer(4); + var data = Buffer.alloc(4); newpin += '';