Best JavaScript code snippet using playwright-internal
BluetoothPluginIOSDiscoverServices.js
Source:BluetoothPluginIOSDiscoverServices.js
1define([2 'sherettewebs',3 'ErrorModel'4], function(SheretteWebs, ErrorModel){5 var DiscoverServicesPlugin = function(options){6 var _this = this,7 _action = "Discover Services",8 _serviceUuids = [],9 _characteristicUuids = [],10 _curServiceIndex,11 _curServiceUuid,12 _curCharacteristicUuids,13 _curCharacteristicIndex,14 _serviceMap = {},15 _timeoutTimer = null;16 function _init(){17 options = options || {};18 19 if(!options.deviceAddress){20 throw new Error("Discover Services: options.deviceAddress is undefined.");21 }22 }23 function _run(){24 _init();25 26 if(bluetoothle && bluetoothle.initialize){27 bluetoothle.services(28 // success29 function(response){30 _serviceUuids = response.serviceUuids;31 _curServiceIndex = 0;32 _readNextService();33 },34 35 //error36 function(response){37 _onMethodFailure(new ErrorModel(JSON.stringify(response)));38 },39 40 // params41 {42 address: options.deviceAddress43 }44 );//--end services45 }else{46 _onMethodFailure(new ErrorModel("Bluetooth feature not installed in this app."));47 }48 }//--end _run49 50 function _readNextService(){51 var serviceUuid,52 characteristicUuids;53 54 // check to see if there are no more services to read55 if(_curServiceIndex >= _serviceUuids.length){56 // completed entire reading sequence, call success57 _onMethodSuccess();58 59 // prevent further exectuion60 return;61 }62 63 _curServiceUuid = _serviceUuids[_curServiceIndex];64 65 _curCharacteristicUuids = [];66 67 bluetoothle.characteristics(68 // success69 function(response){70 // loop through all characterisitcs and add the uuid to an array for searching for71 for(var x = 0; x < response.characteristics.length; x+= 1){72 _curCharacteristicUuids.push(response.characteristics[x].characteristicUuid);73 }74 75 // read descriptor for these characteristics76 _curCharacteristicIndex = 0;77 _readNextCharacteristic();78 },79 80 // error81 function(response){82 // ignore for now83 _curServiceIndex+= 1;84 _readNextService();85 },86 87 // params88 {89 address: options.deviceAddress,90 serviceUuid: _curServiceUuid91 }92 );//--end characteristics93 }//--end readNextService94 95 96 function _readNextCharacteristic(){97 var characteristicUuid;98 99 // check if there if sequence has ended100 if(_curCharacteristicIndex >= _curCharacteristicUuids.length){101 // read sequence completed102 _curServiceIndex+= 1;103 _readNextService();104 105 // prevent further execution106 return;107 }108 109 characteristicUuid = _curCharacteristicUuids[_curCharacteristicIndex];110 111 bluetoothle.descriptors(112 // success113 function(response){ 114 _curCharacteristicIndex+= 1;115 _readNextCharacteristic();116 },117 118 // error119 function(response){120 // ignore for now121 _curCharacteristicIndex+= 1;122 _readNextCharacteristic();123 },124 125 // params126 {127 address: options.deviceAddress,128 serviceUuid: _curServiceUuid,129 characteristicUuid: characteristicUuid130 }131 );//--end descxriptors132 }//--end readDescriptors133 134 /**135 * Starts the timeout timer.136 */137 function _startTimeout(){138 //_timeoutTimer = window.setTimeout(_onTimeout, options.timeoutLength);139 _timeoutTimer = window.setTimeout(_onTimeout, 10000); // ten seconds140 }141 142 /**143 * Stops/clears the timeout timer.144 */145 function _stopTimeout(){146 // clear the internal timer147 if (_timeoutTimer !== null) {148 window.clearTimeout(_timeoutTimer);149 _timeoutTimer = null;150 }151 }152 153 /**154 * The event that the action was timed out.155 */156 function _onTimeout(){157 _stopTimeout();158 _onConnectFailure({159 160 });161 //_onMethodFailure(new ErrorModel('Could not connect. Your device is turned off or out of range.'));162 //_onMethodFailure(new ErrorModel('Could not connect. Your device is turned off or out of range.'));163 //_disconnect();164 }165 166 167 /**168 * The event that this method was successful. calls _options.success method.169 */170 function _onMethodSuccess() {171 _stopTimeout();172 options.success();173 }174 /**175 * Stops any timeouts, and invokes the options.error method.176 * @param {Error} errorModel the model with the error data in it.177 */178 function _onMethodFailure(errorModel) {179 _stopTimeout();180 options.error(errorModel);181 };182 183 /* run this method */184 _run();185 };186 187 return DiscoverServicesPlugin;...
1109.js
Source:1109.js
1var att = require('./att');2var btle = require('./btle');3var EventEmitter = require('events').EventEmitter;4var gatt = require('./gatt');5var util = require('util');6var UUID = require('./uuid');7// Characteristic Property bit field8module.exports.Properties = Properties = {9 BROADCAST : 0x01,10 READ : 0x02,11 WRITE_WITHOUT_RESP : 0x04,12 WRITE : 0x08,13 NOTIFY : 0x10,14 INDICATE : 0x20,15 AUTH : 0x40,16 EXT_PROPER : 0x8017}18function Characteristic(handle, properties, uuid, value, descriptors) {19 EventEmitter.call(this);20 if (!properties) throw new TypeError('Properties must be specified');21 if (!uuid) throw new TypeError('UUID must be specified');22 if (handle) this.endHandle = handle + 1 + (descriptors ? descriptors.length : 0);23 // Construct the value for the declaration24 uuid = UUID.getUUID(uuid);25 var declValue = new Buffer(uuid.length() + 3);26 declValue[0] = properties;27 if (handle) declValue.writeUInt16LE(handle+1, 1);28 uuid.toBuffer().copy(declValue, 3);29 this.attributes = [];30 this.properties = properties;31 // The declaration32 var declaration = att.createAttribute(handle, gatt.AttributeTypes.CHARACTERISTIC, declValue, this.endHandle);33 declaration.properties = Properties.READ;34 this.attributes.push(declaration);35 // The value36 var valAttr = att.createAttribute(handle && handle+1, uuid, value);37 valAttr.properties = properties;38 valAttr.on('valueChanged', function(attrib) {39 this.emit('valueChanged', attrib);40 });41 this.attributes.push(valAttr);42 // Set a write callback so we can emit a 'write' event43 // when this characteristic value is written44 if (properties & (Properties.WRITE | Properties.WRITE_WITHOUT_RESP)) {45 var self = this;46 this.attributes[1].writeCallback = function() {47 console.log(self.listeners('write'));48 self.emit('write', self);49 }50 }51 // The descriptors52 if (descriptors) {53 for (var i = 0; i < descriptors.length; ++i) {54 descriptors[i].handle = handle && handle+2+i;55 descriptors[i].properties = Properties.READ;56 this.attributes.push(descriptors[i]);57 }58 }59}60util.inherits(Characteristic, EventEmitter);61Object.defineProperty(Characteristic.prototype, 'value', {62 get: function() {63 return this.attributes[1].value;64 },65 set: function(value) {66 this.attributes[1].value = value;67 }68});69Object.defineProperty(Characteristic.prototype, 'uuid', {70 get: function() {71 return this.attributes[1].type;72 },73 set: function(value) {74 this.attributes[1].type = UUID.getUUID(value);75 }76});77module.exports.create = function(handle, properties, uuid, value, descriptors) {78 return new Characteristic(handle, properties, uuid, value, descriptors);79}80Characteristic.prototype.setHandle = function(handle) {81 // Write the handle value to the declaration82 this.attributes[0].value.writeUInt16LE(handle+1, 1);83 for (var i = 0; i < this.attributes.length; ++i) {84 this.attributes[i].handle = handle+i;85 }86 this.endHandle = this.attributes[0].endHandle = handle + this.attributes.length - 1;87}88// Populate the value field89Characteristic.prototype.readValue = function(callback) {90 var self = this;91 // Only attempt to read if the read property is set92 if (this.properties & Properties.READ) {93 this.service.device.readHandle(this.declaration.valueHandle, function(err, value) {94 try {95 if (!err) {96 self.value.value = value;97 }98 return callback(err, self);99 } catch (e) {100 return callback(e, null);101 }102 });103 } else {104 return callback(new Error('Characteristic is not readable'), this);105 }106}107Characteristic.prototype.writeValue = function(buffer, callback) {108 if (this.properties & Properties.WRITE_WITHOUT_RESP ||109 this.properties & Properties.WRITE) {110 this.service.device.writeCommand(this.valueHandle, buffer, callback);111 } else {112 return callback(new Error('Characteristic is not writable'));113 }114}115// Get the descriptors116Characteristic.prototype.readDescriptors = function(callback) {117 var self = this;118 if (this.endHandle > this.valueHandle) {119 this.service.device.findInformation(this.valueHandle+1, this.endHandle, function(err, list) {120 try {121 if (err) return callback(err, null);122 self.descriptors = [];123 var item = list.shift();124 while (item) {125 self.descriptors.push(new Descriptor(self.service, item.handle, item.type));126 item = list.shift();127 }128 return callback(err, self);129 } catch (e) {130 return callback(e, null);131 }132 });133 } else {134 return callback(null, self);135 }136}137Characteristic.prototype.listenForNotifications = function(callback) {138 var self = this;139 this.service.device.addNotificationListener(this.valueHandle, function(err, value) {140 if (!err) self.value = value;141 return callback(err, self);142 });...
1074.js
Source:1074.js
1var att = require('./att');2var btle = require('./btle');3var EventEmitter = require('events').EventEmitter;4var gatt = require('./gatt');5var util = require('util');6var UUID = require('./uuid');7// Characteristic Property bit field8module.exports.Properties = Properties = {9 BROADCAST : 0x01,10 READ : 0x02,11 WRITE_WITHOUT_RESP : 0x04,12 WRITE : 0x08,13 NOTIFY : 0x10,14 INDICATE : 0x20,15 AUTH : 0x40,16 EXT_PROPER : 0x8017}18function Characteristic(handle, properties, uuid, value, descriptors) {19 EventEmitter.call(this);20 if (!properties) throw new TypeError('Properties must be specified');21 if (!uuid) throw new TypeError('UUID must be specified');22 if (handle) this.endHandle = handle + 1 + (descriptors ? descriptors.length : 0);23 // Construct the value for the declaration24 uuid = UUID.getUUID(uuid);25 var declValue = new Buffer(uuid.length() + 3);26 declValue[0] = properties;27 if (handle) declValue.writeUInt16LE(handle+1, 1);28 uuid.toBuffer().copy(declValue, 3);29 this.attributes = [];30 this.properties = properties;31 // The declaration32 var declaration = att.createAttribute(handle, gatt.AttributeTypes.CHARACTERISTIC, declValue, this.endHandle);33 declaration.properties = Properties.READ;34 this.attributes.push(declaration);35 // The value36 var valAttr = att.createAttribute(handle && handle+1, uuid, value);37 valAttr.properties = properties;38 valAttr.on('valueChanged', function(attrib) {39 this.emit('valueChanged', attrib);40 });41 this.attributes.push(valAttr);42 // Set a write callback so we can emit a 'write' event43 // when this characteristic value is written44 if (properties & (Properties.WRITE | Properties.WRITE_WITHOUT_RESP)) {45 var self = this;46 this.attributes[1].writeCallback = function() {47 console.log(self.listeners('write'));48 self.emit('write', self);49 }50 }51 // The descriptors52 if (descriptors) {53 for (var i = 0; i < descriptors.length; ++i) {54 descriptors[i].handle = handle && handle+2+i;55 descriptors[i].properties = Properties.READ;56 this.attributes.push(descriptors[i]);57 }58 }59}60util.inherits(Characteristic, EventEmitter);61Object.defineProperty(Characteristic.prototype, 'value', {62 get: function() {63 return this.attributes[1].value;64 },65 set: function(value) {66 this.attributes[1].value = value;67 }68});69Object.defineProperty(Characteristic.prototype, 'uuid', {70 get: function() {71 return this.attributes[1].type;72 },73 set: function(value) {74 this.attributes[1].type = UUID.getUUID(value);75 }76});77module.exports.create = function(handle, properties, uuid, value, descriptors) {78 return new Characteristic(handle, properties, uuid, value, descriptors);79}80Characteristic.prototype.setHandle = function(handle) {81 // Write the handle value to the declaration82 this.attributes[0].value.writeUInt16LE(handle+1, 1);83 for (var i = 0; i < this.attributes.length; ++i) {84 this.attributes[i].handle = handle+i;85 }86 this.endHandle = this.attributes[0].endHandle = handle + this.attributes.length - 1;87}88// Populate the value field89Characteristic.prototype.readValue = function(callback) {90 var self = this;91 // Only attempt to read if the read property is set92 if (this.properties & Properties.READ) {93 this.service.device.readHandle(this.declaration.valueHandle, function(err, value) {94 try {95 if (!err) {96 self.value.value = value;97 }98 return callback(err, self);99 } catch (e) {100 return callback(e, null);101 }102 });103 } else {104 return callback(new Error('Characteristic is not readable'), this);105 }106}107Characteristic.prototype.writeValue = function(buffer, callback) {108 if (this.properties & Properties.WRITE_WITHOUT_RESP ||109 this.properties & Properties.WRITE) {110 this.service.device.writeCommand(this.valueHandle, buffer, callback);111 } else {112 return callback(new Error('Characteristic is not writable'));113 }114}115// Get the descriptors116Characteristic.prototype.readDescriptors = function(callback) {117 var self = this;118 if (this.endHandle > this.valueHandle) {119 this.service.device.findInformation(this.valueHandle+1, this.endHandle, function(err, list) {120 try {121 if (err) return callback(err, null);122 self.descriptors = [];123 var item = list.shift();124 while (item) {125 self.descriptors.push(new Descriptor(self.service, item.handle, item.type));126 item = list.shift();127 }128 return callback(err, self);129 } catch (e) {130 return callback(e, null);131 }132 });133 } else {134 return callback(null, self);135 }136}137Characteristic.prototype.listenForNotifications = function(callback) {138 var self = this;139 this.service.device.addNotificationListener(this.valueHandle, function(err, value) {140 if (!err) self.value = value;141 return callback(err, self);142 });...
1108.js
Source:1108.js
1var att = require('./att');2var btle = require('./btle');3var EventEmitter = require('events').EventEmitter;4var gatt = require('./gatt');5var util = require('util');6var UUID = require('./uuid');7// Characteristic Property bit field8module.exports.Properties = Properties = {9 BROADCAST : 0x01,10 READ : 0x02,11 WRITE_WITHOUT_RESP : 0x04,12 WRITE : 0x08,13 NOTIFY : 0x10,14 INDICATE : 0x20,15 AUTH : 0x40,16 EXT_PROPER : 0x8017}18function Characteristic(handle, properties, uuid, value, descriptors) {19 EventEmitter.call(this);20 if (!properties) throw new TypeError('Properties must be specified');21 if (!uuid) throw new TypeError('UUID must be specified');22 if (handle) this.endHandle = handle + 1 + (descriptors ? descriptors.length : 0);23 // Construct the value for the declaration24 uuid = UUID.getUUID(uuid);25 var declValue = new Buffer(uuid.length() + 3);26 declValue[0] = properties;27 if (handle) declValue.writeUInt16LE(handle+1, 1);28 uuid.toBuffer().copy(declValue, 3);29 this.attributes = [];30 this.properties = properties;31 // The declaration32 var declaration = att.createAttribute(handle, gatt.AttributeTypes.CHARACTERISTIC, declValue, this.endHandle);33 declaration.properties = Properties.READ;34 this.attributes.push(declaration);35 // The value36 var valAttr = att.createAttribute(handle && handle+1, uuid, value);37 valAttr.properties = properties;38 valAttr.on('valueChanged', function(attrib) {39 this.emit('valueChanged', attrib);40 });41 this.attributes.push(valAttr);42 // Set a write callback so we can emit a 'write' event43 // when this characteristic value is written44 if (properties & (Properties.WRITE | Properties.WRITE_WITHOUT_RESP)) {45 var self = this;46 this.attributes[1].writeCallback = function() {47 console.log(self.listeners('write'));48 self.emit('write', self);49 }50 }51 // The descriptors52 if (descriptors) {53 for (var i = 0; i < descriptors.length; ++i) {54 descriptors[i].handle = handle && handle+2+i;55 descriptors[i].properties = Properties.READ;56 this.attributes.push(descriptors[i]);57 }58 }59}60util.inherits(Characteristic, EventEmitter);61Object.defineProperty(Characteristic.prototype, 'value', {62 get: function() {63 return this.attributes[1].value;64 },65 set: function(value) {66 this.attributes[1].value = value;67 }68});69Object.defineProperty(Characteristic.prototype, 'uuid', {70 get: function() {71 return this.attributes[1].type;72 },73 set: function(value) {74 this.attributes[1].type = UUID.getUUID(value);75 }76});77module.exports.create = function(handle, properties, uuid, value, descriptors) {78 return new Characteristic(handle, properties, uuid, value, descriptors);79}80Characteristic.prototype.setHandle = function(handle) {81 // Write the handle value to the declaration82 this.attributes[0].value.writeUInt16LE(handle+1, 1);83 for (var i = 0; i < this.attributes.length; ++i) {84 this.attributes[i].handle = handle+i;85 }86 this.endHandle = this.attributes[0].endHandle = handle + this.attributes.length - 1;87}88// Populate the value field89Characteristic.prototype.readValue = function(callback) {90 var self = this;91 // Only attempt to read if the read property is set92 if (this.properties & Properties.READ) {93 this.service.device.readHandle(this.declaration.valueHandle, function(err, value) {94 try {95 if (!err) {96 self.value.value = value;97 }98 return callback(err, self);99 } catch (e) {100 return callback(e, null);101 }102 });103 } else {104 return callback(new Error('Characteristic is not readable'), this);105 }106}107Characteristic.prototype.writeValue = function(buffer, callback) {108 if (this.properties & Properties.WRITE_WITHOUT_RESP ||109 this.properties & Properties.WRITE) {110 this.service.device.writeCommand(this.valueHandle, buffer, callback);111 } else {112 return callback(new Error('Characteristic is not writable'));113 }114}115// Get the descriptors116Characteristic.prototype.readDescriptors = function(callback) {117 var self = this;118 if (this.endHandle > this.valueHandle) {119 this.service.device.findInformation(this.valueHandle+1, this.endHandle, function(err, list) {120 try {121 if (err) return callback(err, null);122 self.descriptors = [];123 var item = list.shift();124 while (item) {125 self.descriptors.push(new Descriptor(self.service, item.handle, item.type));126 item = list.shift();127 }128 return callback(err, self);129 } catch (e) {130 return callback(e, null);131 }132 });133 } else {134 return callback(null, self);135 }136}137Characteristic.prototype.listenForNotifications = function(callback) {138 var self = this;139 this.service.device.addNotificationListener(this.valueHandle, function(err, value) {140 if (!err) self.value = value;141 return callback(err, self);142 });...
1106.js
Source:1106.js
1var att = require('./att');2var btle = require('./btle');3var EventEmitter = require('events').EventEmitter;4var gatt = require('./gatt');5var util = require('util');6var UUID = require('./uuid');7// Characteristic Property bit field8module.exports.Properties = Properties = {9 BROADCAST : 0x01,10 READ : 0x02,11 WRITE_WITHOUT_RESP : 0x04,12 WRITE : 0x08,13 NOTIFY : 0x10,14 INDICATE : 0x20,15 AUTH : 0x40,16 EXT_PROPER : 0x8017}18function Characteristic(handle, properties, uuid, value, descriptors) {19 EventEmitter.call(this);20 if (!properties) throw new TypeError('Properties must be specified');21 if (!uuid) throw new TypeError('UUID must be specified');22 if (handle) this.endHandle = handle + 1 + (descriptors ? descriptors.length : 0);23 // Construct the value for the declaration24 uuid = UUID.getUUID(uuid);25 var declValue = new Buffer(uuid.length() + 3);26 declValue[0] = properties;27 if (handle) declValue.writeUInt16LE(handle+1, 1);28 uuid.toBuffer().copy(declValue, 3);29 this.attributes = [];30 this.properties = properties;31 // The declaration32 var declaration = att.createAttribute(handle, gatt.AttributeTypes.CHARACTERISTIC, declValue, this.endHandle);33 declaration.properties = Properties.READ;34 this.attributes.push(declaration);35 // The value36 var valAttr = att.createAttribute(handle && handle+1, uuid, value);37 valAttr.properties = properties;38 valAttr.on('valueChanged', function(attrib) {39 this.emit('valueChanged', attrib);40 });41 this.attributes.push(valAttr);42 // Set a write callback so we can emit a 'write' event43 // when this characteristic value is written44 if (properties & (Properties.WRITE | Properties.WRITE_WITHOUT_RESP)) {45 var self = this;46 this.attributes[1].writeCallback = function() {47 console.log(self.listeners('write'));48 self.emit('write', self);49 }50 }51 // The descriptors52 if (descriptors) {53 for (var i = 0; i < descriptors.length; ++i) {54 descriptors[i].handle = handle && handle+2+i;55 descriptors[i].properties = Properties.READ;56 this.attributes.push(descriptors[i]);57 }58 }59}60util.inherits(Characteristic, EventEmitter);61Object.defineProperty(Characteristic.prototype, 'value', {62 get: function() {63 return this.attributes[1].value;64 },65 set: function(value) {66 this.attributes[1].value = value;67 }68});69Object.defineProperty(Characteristic.prototype, 'uuid', {70 get: function() {71 return this.attributes[1].type;72 },73 set: function(value) {74 this.attributes[1].type = UUID.getUUID(value);75 }76});77module.exports.create = function(handle, properties, uuid, value, descriptors) {78 return new Characteristic(handle, properties, uuid, value, descriptors);79}80Characteristic.prototype.setHandle = function(handle) {81 // Write the handle value to the declaration82 this.attributes[0].value.writeUInt16LE(handle+1, 1);83 for (var i = 0; i < this.attributes.length; ++i) {84 this.attributes[i].handle = handle+i;85 }86 this.endHandle = this.attributes[0].endHandle = handle + this.attributes.length - 1;87}88// Populate the value field89Characteristic.prototype.readValue = function(callback) {90 var self = this;91 // Only attempt to read if the read property is set92 if (this.properties & Properties.READ) {93 this.service.device.readHandle(this.declaration.valueHandle, function(err, value) {94 try {95 if (!err) {96 self.value.value = value;97 }98 return callback(err, self);99 } catch (e) {100 return callback(e, null);101 }102 });103 } else {104 return callback(new Error('Characteristic is not readable'), this);105 }106}107Characteristic.prototype.writeValue = function(buffer, callback) {108 if (this.properties & Properties.WRITE_WITHOUT_RESP ||109 this.properties & Properties.WRITE) {110 this.service.device.writeCommand(this.valueHandle, buffer, callback);111 } else {112 return callback(new Error('Characteristic is not writable'));113 }114}115// Get the descriptors116Characteristic.prototype.readDescriptors = function(callback) {117 var self = this;118 if (this.endHandle > this.valueHandle) {119 this.service.device.findInformation(this.valueHandle+1, this.endHandle, function(err, list) {120 try {121 if (err) return callback(err, null);122 self.descriptors = [];123 var item = list.shift();124 while (item) {125 self.descriptors.push(new Descriptor(self.service, item.handle, item.type));126 item = list.shift();127 }128 return callback(err, self);129 } catch (e) {130 return callback(e, null);131 }132 });133 } else {134 return callback(null, self);135 }136}137Characteristic.prototype.listenForNotifications = function(callback) {138 var self = this;139 this.service.device.addNotificationListener(this.valueHandle, function(err, value) {140 if (!err) self.value = value;141 return callback(err, self);142 });...
1073.js
Source:1073.js
1var att = require('./att');2var btle = require('./btle');3var EventEmitter = require('events').EventEmitter;4var gatt = require('./gatt');5var util = require('util');6var UUID = require('./uuid');7// Characteristic Property bit field8module.exports.Properties = Properties = {9 BROADCAST : 0x01,10 READ : 0x02,11 WRITE_WITHOUT_RESP : 0x04,12 WRITE : 0x08,13 NOTIFY : 0x10,14 INDICATE : 0x20,15 AUTH : 0x40,16 EXT_PROPER : 0x8017}18function Characteristic(handle, properties, uuid, value, descriptors) {19 EventEmitter.call(this);20 if (!properties) throw new TypeError('Properties must be specified');21 if (!uuid) throw new TypeError('UUID must be specified');22 if (handle) this.endHandle = handle + 1 + (descriptors ? descriptors.length : 0);23 // Construct the value for the declaration24 uuid = UUID.getUUID(uuid);25 var declValue = new Buffer(uuid.length() + 3);26 declValue[0] = properties;27 if (handle) declValue.writeUInt16LE(handle+1, 1);28 uuid.toBuffer().copy(declValue, 3);29 this.attributes = [];30 this.properties = properties;31 // The declaration32 var declaration = att.createAttribute(handle, gatt.AttributeTypes.CHARACTERISTIC, declValue, this.endHandle);33 declaration.properties = Properties.READ;34 this.attributes.push(declaration);35 // The value36 var valAttr = att.createAttribute(handle && handle+1, uuid, value);37 valAttr.properties = properties;38 valAttr.on('valueChanged', function(attrib) {39 this.emit('valueChanged', attrib);40 });41 this.attributes.push(valAttr);42 // Set a write callback so we can emit a 'write' event43 // when this characteristic value is written44 if (properties & (Properties.WRITE | Properties.WRITE_WITHOUT_RESP)) {45 var self = this;46 this.attributes[1].writeCallback = function() {47 console.log(self.listeners('write'));48 self.emit('write', self);49 }50 }51 // The descriptors52 if (descriptors) {53 for (var i = 0; i < descriptors.length; ++i) {54 descriptors[i].handle = handle && handle+2+i;55 descriptors[i].properties = Properties.READ;56 this.attributes.push(descriptors[i]);57 }58 }59}60util.inherits(Characteristic, EventEmitter);61Object.defineProperty(Characteristic.prototype, 'value', {62 get: function() {63 return this.attributes[1].value;64 },65 set: function(value) {66 this.attributes[1].value = value;67 }68});69Object.defineProperty(Characteristic.prototype, 'uuid', {70 get: function() {71 return this.attributes[1].type;72 },73 set: function(value) {74 this.attributes[1].type = UUID.getUUID(value);75 }76});77module.exports.create = function(handle, properties, uuid, value, descriptors) {78 return new Characteristic(handle, properties, uuid, value, descriptors);79}80Characteristic.prototype.setHandle = function(handle) {81 // Write the handle value to the declaration82 this.attributes[0].value.writeUInt16LE(handle+1, 1);83 for (var i = 0; i < this.attributes.length; ++i) {84 this.attributes[i].handle = handle+i;85 }86 this.endHandle = this.attributes[0].endHandle = handle + this.attributes.length - 1;87}88// Populate the value field89Characteristic.prototype.readValue = function(callback) {90 var self = this;91 // Only attempt to read if the read property is set92 if (this.properties & Properties.READ) {93 this.service.device.readHandle(this.declaration.valueHandle, function(err, value) {94 try {95 if (!err) {96 self.value.value = value;97 }98 return callback(err, self);99 } catch (e) {100 return callback(e, null);101 }102 });103 } else {104 return callback(new Error('Characteristic is not readable'), this);105 }106}107Characteristic.prototype.writeValue = function(buffer, callback) {108 if (this.properties & Properties.WRITE_WITHOUT_RESP ||109 this.properties & Properties.WRITE) {110 this.service.device.writeCommand(this.valueHandle, buffer, callback);111 } else {112 return callback(new Error('Characteristic is not writable'));113 }114}115// Get the descriptors116Characteristic.prototype.readDescriptors = function(callback) {117 var self = this;118 if (this.endHandle > this.valueHandle) {119 this.service.device.findInformation(this.valueHandle+1, this.endHandle, function(err, list) {120 try {121 if (err) return callback(err, null);122 self.descriptors = [];123 var item = list.shift();124 while (item) {125 self.descriptors.push(new Descriptor(self.service, item.handle, item.type));126 item = list.shift();127 }128 return callback(err, self);129 } catch (e) {130 return callback(e, null);131 }132 });133 } else {134 return callback(null, self);135 }136}137Characteristic.prototype.listenForNotifications = function(callback) {138 var self = this;139 this.service.device.addNotificationListener(this.valueHandle, function(err, value) {140 if (!err) self.value = value;141 return callback(err, self);142 });...
1075.js
Source:1075.js
1var att = require('./att');2var btle = require('./btle');3var EventEmitter = require('events').EventEmitter;4var gatt = require('./gatt');5var util = require('util');6var UUID = require('./uuid');7// Characteristic Property bit field8module.exports.Properties = Properties = {9 BROADCAST : 0x01,10 READ : 0x02,11 WRITE_WITHOUT_RESP : 0x04,12 WRITE : 0x08,13 NOTIFY : 0x10,14 INDICATE : 0x20,15 AUTH : 0x40,16 EXT_PROPER : 0x8017}18function Characteristic(handle, properties, uuid, value, descriptors) {19 EventEmitter.call(this);20 if (!properties) throw new TypeError('Properties must be specified');21 if (!uuid) throw new TypeError('UUID must be specified');22 if (handle) this.endHandle = handle + 1 + (descriptors ? descriptors.length : 0);23 // Construct the value for the declaration24 uuid = UUID.getUUID(uuid);25 var declValue = new Buffer(uuid.length() + 3);26 declValue[0] = properties;27 if (handle) declValue.writeUInt16LE(handle+1, 1);28 uuid.toBuffer().copy(declValue, 3);29 this.attributes = [];30 this.properties = properties;31 // The declaration32 var declaration = att.createAttribute(handle, gatt.AttributeTypes.CHARACTERISTIC, declValue, this.endHandle);33 declaration.properties = Properties.READ;34 this.attributes.push(declaration);35 // The value36 var valAttr = att.createAttribute(handle && handle+1, uuid, value);37 valAttr.properties = properties;38 valAttr.on('valueChanged', function(attrib) {39 this.emit('valueChanged', attrib);40 });41 this.attributes.push(valAttr);42 // Set a write callback so we can emit a 'write' event43 // when this characteristic value is written44 if (properties & (Properties.WRITE | Properties.WRITE_WITHOUT_RESP)) {45 var self = this;46 this.attributes[1].writeCallback = function() {47 console.log(self.listeners('write'));48 self.emit('write', self);49 }50 }51 // The descriptors52 if (descriptors) {53 for (var i = 0; i < descriptors.length; ++i) {54 descriptors[i].handle = handle && handle+2+i;55 descriptors[i].properties = Properties.READ;56 this.attributes.push(descriptors[i]);57 }58 }59}60util.inherits(Characteristic, EventEmitter);61Object.defineProperty(Characteristic.prototype, 'value', {62 get: function() {63 return this.attributes[1].value;64 },65 set: function(value) {66 this.attributes[1].value = value;67 }68});69Object.defineProperty(Characteristic.prototype, 'uuid', {70 get: function() {71 return this.attributes[1].type;72 },73 set: function(value) {74 this.attributes[1].type = UUID.getUUID(value);75 }76});77module.exports.create = function(handle, properties, uuid, value, descriptors) {78 return new Characteristic(handle, properties, uuid, value, descriptors);79}80Characteristic.prototype.setHandle = function(handle) {81 // Write the handle value to the declaration82 this.attributes[0].value.writeUInt16LE(handle+1, 1);83 for (var i = 0; i < this.attributes.length; ++i) {84 this.attributes[i].handle = handle+i;85 }86 this.endHandle = this.attributes[0].endHandle = handle + this.attributes.length - 1;87}88// Populate the value field89Characteristic.prototype.readValue = function(callback) {90 var self = this;91 // Only attempt to read if the read property is set92 if (this.properties & Properties.READ) {93 this.service.device.readHandle(this.declaration.valueHandle, function(err, value) {94 try {95 if (!err) {96 self.value.value = value;97 }98 return callback(err, self);99 } catch (e) {100 return callback(e, null);101 }102 });103 } else {104 return callback(new Error('Characteristic is not readable'), this);105 }106}107Characteristic.prototype.writeValue = function(buffer, callback) {108 if (this.properties & Properties.WRITE_WITHOUT_RESP ||109 this.properties & Properties.WRITE) {110 this.service.device.writeCommand(this.valueHandle, buffer, callback);111 } else {112 return callback(new Error('Characteristic is not writable'));113 }114}115// Get the descriptors116Characteristic.prototype.readDescriptors = function(callback) {117 var self = this;118 if (this.endHandle > this.valueHandle) {119 this.service.device.findInformation(this.valueHandle+1, this.endHandle, function(err, list) {120 try {121 if (err) return callback(err, null);122 self.descriptors = [];123 var item = list.shift();124 while (item) {125 self.descriptors.push(new Descriptor(self.service, item.handle, item.type));126 item = list.shift();127 }128 return callback(err, self);129 } catch (e) {130 return callback(e, null);131 }132 });133 } else {134 return callback(null, self);135 }136}137Characteristic.prototype.listenForNotifications = function(callback) {138 var self = this;139 this.service.device.addNotificationListener(this.valueHandle, function(err, value) {140 if (!err) self.value = value;141 return callback(err, self);142 });...
1076.js
Source:1076.js
1var att = require('./att');2var btle = require('./btle');3var EventEmitter = require('events').EventEmitter;4var gatt = require('./gatt');5var util = require('util');6var UUID = require('./uuid');7// Characteristic Property bit field8module.exports.Properties = Properties = {9 BROADCAST : 0x01,10 READ : 0x02,11 WRITE_WITHOUT_RESP : 0x04,12 WRITE : 0x08,13 NOTIFY : 0x10,14 INDICATE : 0x20,15 AUTH : 0x40,16 EXT_PROPER : 0x8017}18function Characteristic(handle, properties, uuid, value, descriptors) {19 EventEmitter.call(this);20 if (!properties) throw new TypeError('Properties must be specified');21 if (!uuid) throw new TypeError('UUID must be specified');22 if (handle) this.endHandle = handle + 1 + (descriptors ? descriptors.length : 0);23 // Construct the value for the declaration24 uuid = UUID.getUUID(uuid);25 var declValue = new Buffer(uuid.length() + 3);26 declValue[0] = properties;27 if (handle) declValue.writeUInt16LE(handle+1, 1);28 uuid.toBuffer().copy(declValue, 3);29 this.attributes = [];30 this.properties = properties;31 // The declaration32 var declaration = att.createAttribute(handle, gatt.AttributeTypes.CHARACTERISTIC, declValue, this.endHandle);33 declaration.properties = Properties.READ;34 this.attributes.push(declaration);35 // The value36 var valAttr = att.createAttribute(handle && handle+1, uuid, value);37 valAttr.properties = properties;38 valAttr.on('valueChanged', function(attrib) {39 this.emit('valueChanged', attrib);40 });41 this.attributes.push(valAttr);42 // Set a write callback so we can emit a 'write' event43 // when this characteristic value is written44 if (properties & (Properties.WRITE | Properties.WRITE_WITHOUT_RESP)) {45 var self = this;46 this.attributes[1].writeCallback = function() {47 console.log(self.listeners('write'));48 self.emit('write', self);49 }50 }51 // The descriptors52 if (descriptors) {53 for (var i = 0; i < descriptors.length; ++i) {54 descriptors[i].handle = handle && handle+2+i;55 descriptors[i].properties = Properties.READ;56 this.attributes.push(descriptors[i]);57 }58 }59}60util.inherits(Characteristic, EventEmitter);61Object.defineProperty(Characteristic.prototype, 'value', {62 get: function() {63 return this.attributes[1].value;64 },65 set: function(value) {66 this.attributes[1].value = value;67 }68});69Object.defineProperty(Characteristic.prototype, 'uuid', {70 get: function() {71 return this.attributes[1].type;72 },73 set: function(value) {74 this.attributes[1].type = UUID.getUUID(value);75 }76});77module.exports.create = function(handle, properties, uuid, value, descriptors) {78 return new Characteristic(handle, properties, uuid, value, descriptors);79}80Characteristic.prototype.setHandle = function(handle) {81 // Write the handle value to the declaration82 this.attributes[0].value.writeUInt16LE(handle+1, 1);83 for (var i = 0; i < this.attributes.length; ++i) {84 this.attributes[i].handle = handle+i;85 }86 this.endHandle = this.attributes[0].endHandle = handle + this.attributes.length - 1;87}88// Populate the value field89Characteristic.prototype.readValue = function(callback) {90 var self = this;91 // Only attempt to read if the read property is set92 if (this.properties & Properties.READ) {93 this.service.device.readHandle(this.declaration.valueHandle, function(err, value) {94 try {95 if (!err) {96 self.value.value = value;97 }98 return callback(err, self);99 } catch (e) {100 return callback(e, null);101 }102 });103 } else {104 return callback(new Error('Characteristic is not readable'), this);105 }106}107Characteristic.prototype.writeValue = function(buffer, callback) {108 if (this.properties & Properties.WRITE_WITHOUT_RESP ||109 this.properties & Properties.WRITE) {110 this.service.device.writeCommand(this.valueHandle, buffer, callback);111 } else {112 return callback(new Error('Characteristic is not writable'));113 }114}115// Get the descriptors116Characteristic.prototype.readDescriptors = function(callback) {117 var self = this;118 if (this.endHandle > this.valueHandle) {119 this.service.device.findInformation(this.valueHandle+1, this.endHandle, function(err, list) {120 try {121 if (err) return callback(err, null);122 self.descriptors = [];123 var item = list.shift();124 while (item) {125 self.descriptors.push(new Descriptor(self.service, item.handle, item.type));126 item = list.shift();127 }128 return callback(err, self);129 } catch (e) {130 return callback(e, null);131 }132 });133 } else {134 return callback(null, self);135 }136}137Characteristic.prototype.listenForNotifications = function(callback) {138 var self = this;139 this.service.device.addNotificationListener(this.valueHandle, function(err, value) {140 if (!err) self.value = value;141 return callback(err, self);142 });...
Using AI Code Generation
1const {readDescriptors} = require('playwright/lib/server/frames');2const {chromium} = require('playwright');3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 const descriptors = await readDescriptors(page.mainFrame());8 console.log(descriptors);9 await browser.close();10})();11[ { name: 'main',12 children: [] } ]
Using AI Code Generation
1const { readDescriptors } = require('playwright/lib/server/playwright.js');2const { chromium } = require('playwright');3const browser = await chromium.launch();4const context = await browser.newContext();5const page = await context.newPage();6const descriptors = readDescriptors();7console.log(descriptors);8await browser.close();9 {10 { name: 'launch', type: 'function' },11 { name: 'launchPersistentContext', type: 'function' },12 { name: 'connectOverCDP', type: 'function' },13 { name: 'connect', type: 'function' },14 { name: 'name', type: 'string' },15 { name: 'executablePath', type: 'string' },16 { name: 'defaultArgs', type: 'function' },17 { name: 'defaultViewport', type: 'null' },18 { name: 'deviceDescriptors', type: 'object' },19 { name: 'isChromium', type: 'boolean' },20 { name: 'isFirefox', type: 'boolean' },21 { name: 'isWebKit', type: 'boolean' },22 { name: 'newContext', type: 'function' },23 { name: 'launchServer', type: 'function' },24 { name: 'connectOverCDP', type: 'function' },25 { name: 'connect', type: 'function' }26 },27 {28 { name: 'newContext', type: 'function' },29 { name: 'contexts', type: 'array' },30 { name: 'defaultContext', type: 'object' },31 { name: 'version', type: 'string' },32 { name: 'wsEndpoint', type: 'string' },33 { name: 'isChromium', type: 'boolean' },34 { name: 'isFirefox', type: 'boolean' },35 { name: 'isWebKit', type: 'boolean' },36 { name: 'close', type: 'function' },37 { name: 'newPage', type: 'function' },38 { name: 'waitForTarget', type: 'function' },39 { name: 'targets', type: 'array'
Using AI Code Generation
1const { readDescriptors } = require('playwright/lib/server/chromium/crPage');2const descriptors = readDescriptors();3console.log(descriptors);4const { readDescriptors } = require('playwright/lib/server/chromium/crPage');5const descriptors = readDescriptors();6console.log(descriptors);
Using AI Code Generation
1const { readDescriptors } = require('playwright/lib/server/chromium/crBrowser');2const descriptors = await readDescriptors('/path/to/chrome');3console.log(descriptors);4const { writeDescriptors } = require('playwright/lib/server/chromium/crBrowser');5await writeDescriptors(descriptors, '/path/to/chrome');6const { createBrowserFetcher } = require('playwright/lib/server/browserFetcher');7const browserFetcher = await createBrowserFetcher('/path/to/chrome');8const revisionInfo = await browserFetcher.download(revision);9const { getBrowserPath } = require('playwright/lib/server/browserFetcher');10const browserPath = await getBrowserPath('/path/to/chrome', revision);11const { getExecutablePath } = require('playwright/lib/server/browserFetcher');12const executablePath = await getExecutablePath('/path/to/chrome', revision);13const { getBrowserEnv } = require('playwright/lib/server/browserFetcher');14const browserEnv = await getBrowserEnv('/path/to/chrome', revision);15const { getBrowserEnv } = require('playwright/lib/server/browserFetcher');16const browserEnv = await getBrowserEnv('/path/to/chrome', revision);17const { getBrowserEnv } = require('playwright/lib/server/browserFetcher');18const browserEnv = await getBrowserEnv('/path/to/chrome', revision);19const { getBrowserEnv } = require('playwright/lib/server/browserFetcher');20const browserEnv = await getBrowserEnv('/path/to/chrome', revision);21const { getBrowserEnv } = require('playwright/lib/server/browserFetcher');22const browserEnv = await getBrowserEnv('/path/to/chrome', revision);23const { getBrowserEnv } = require('playwright/lib/server/browserFetcher');24const browserEnv = await getBrowserEnv('/path/to/ch
Using AI Code Generation
1const { readDescriptors } = require('@playwright/test/lib/server/trace/recorder/descriptors');2const descriptors = readDescriptors('trace.json');3console.log(descriptors);4const { readDescriptors } = require('@playwright/test/lib/server/trace/recorder/descriptors');5const descriptors = readDescriptors('trace.json');6console.log(descriptors);7const { readDescriptors } = require('@playwright/test/lib/server/trace/recorder/descriptors');8const descriptors = readDescriptors('trace.json');9console.log(descriptors);10const { readDescriptors } = require('@playwright/test/lib/server/trace/recorder/descriptors');11const descriptors = readDescriptors('trace.json');12console.log(descriptors);13const { readDescriptors } = require('@playwright/test/lib/server/trace/recorder/descriptors');14const descriptors = readDescriptors('trace.json');15console.log(descriptors);16const { readDescriptors } = require('@playwright/test/lib/server/trace/recorder/descriptors');17const descriptors = readDescriptors('trace.json');18console.log(descriptors);19const { readDescriptors } = require('@playwright/test/lib/server/trace/recorder/descriptors');20const descriptors = readDescriptors('trace.json');21console.log(descriptors);22const { readDescriptors } = require('@playwright/test/lib/server/trace/recorder/descriptors');23const descriptors = readDescriptors('trace.json');24console.log(descriptors);25const { readDescriptors } = require('@playwright/test/lib/server/trace/recorder/descriptors');26const descriptors = readDescriptors('trace.json');27console.log(descriptors);28const {
Using AI Code Generation
1const internal = require('@playwright/test/lib/test').test.internal;2(async () => {3 const descriptors = await internal.readDescriptors();4 console.log(descriptors);5})();6[ {7 location: { line: 5, column: 1 },8 annotations: {},9 parameterValues: {}10} ]
Using AI Code Generation
1const { readDescriptors } = require('playwright/lib/server/trace/recorder/recorderApp');2const { descriptors } = readDescriptors();3console.log(descriptors);4const { readDescriptors } = require('playwright/lib/server/trace/recorder/recorderApp');5const { descriptors } = readDescriptors();6console.log(descriptors);7const { readDescriptors } = require('playwright/lib/server/trace/recorder/recorderApp');8const { descriptors } = readDescriptors();9console.log(descriptors);10const { readDescriptors } = require('playwright/lib/server/trace/recorder/recorderApp');11const { descriptors } = readDescriptors();12console.log(descriptors);13const { readDescriptors } = require('playwright/lib/server/trace/recorder/recorderApp');14const { descriptors } = readDescriptors();15console.log(descriptors);16const { readDescriptors } = require('playwright/lib/server/trace/recorder/recorderApp');17const { descriptors } = readDescriptors();18console.log(descriptors);19const { readDescriptors } = require('playwright/lib/server/trace/recorder/recorderApp');20const { descriptors } = readDescriptors();21console.log(descriptors);22const { readDescriptors } = require('playwright/lib/server/trace/recorder/recorderApp');23const { descriptors } = readDescriptors();24console.log(descriptors);25const { readDescriptors } = require('playwright/lib/server/trace/recorder/recorderApp');26const { descriptors } = readDescriptors();27console.log(descriptors);28const { readDescriptors } = require('playwright/lib/server/trace/recorder/recorderApp');29const { descriptors } = readDescriptors();30console.log(descriptors);31const { readDescriptors } = require
LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.
Get 100 minutes of automation test minutes FREE!!