How to use readDescriptors method in Playwright Internal

Best JavaScript code snippet using playwright-internal

BluetoothPluginIOSDiscoverServices.js

Source:BluetoothPluginIOSDiscoverServices.js Github

copy

Full Screen

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;...

Full Screen

Full Screen

1109.js

Source:1109.js Github

copy

Full Screen

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 });...

Full Screen

Full Screen

1074.js

Source:1074.js Github

copy

Full Screen

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 });...

Full Screen

Full Screen

1108.js

Source:1108.js Github

copy

Full Screen

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 });...

Full Screen

Full Screen

1106.js

Source:1106.js Github

copy

Full Screen

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 });...

Full Screen

Full Screen

1073.js

Source:1073.js Github

copy

Full Screen

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 });...

Full Screen

Full Screen

1075.js

Source:1075.js Github

copy

Full Screen

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 });...

Full Screen

Full Screen

1076.js

Source:1076.js Github

copy

Full Screen

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 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

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: [] } ]

Full Screen

Using AI Code Generation

copy

Full Screen

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'

Full Screen

Using AI Code Generation

copy

Full Screen

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);

Full Screen

Using AI Code Generation

copy

Full Screen

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

Full Screen

Using AI Code Generation

copy

Full Screen

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 {

Full Screen

Using AI Code Generation

copy

Full Screen

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} ]

Full Screen

Using AI Code Generation

copy

Full Screen

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

Full Screen

Using AI Code Generation

copy

Full Screen

1const { readDescriptors } = require('playwright/lib/utils/registry');2const descriptors = readDescriptors();3console.log(descriptors);4[ { name: 'chromium',5 isTrusted: true },6 { name: 'firefox',7 isTrusted: true },8 { name: 'webkit',9 isTrusted: true } ]

Full Screen

Playwright tutorial

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.

Chapters:

  1. What is Playwright : Playwright is comparatively new but has gained good popularity. Get to know some history of the Playwright with some interesting facts connected with it.
  2. How To Install Playwright : Learn in detail about what basic configuration and dependencies are required for installing Playwright and run a test. Get a step-by-step direction for installing the Playwright automation framework.
  3. Playwright Futuristic Features: Launched in 2020, Playwright gained huge popularity quickly because of some obliging features such as Playwright Test Generator and Inspector, Playwright Reporter, Playwright auto-waiting mechanism and etc. Read up on those features to master Playwright testing.
  4. What is Component Testing: Component testing in Playwright is a unique feature that allows a tester to test a single component of a web application without integrating them with other elements. Learn how to perform Component testing on the Playwright automation framework.
  5. Inputs And Buttons In Playwright: Every website has Input boxes and buttons; learn about testing inputs and buttons with different scenarios and examples.
  6. Functions and Selectors in Playwright: Learn how to launch the Chromium browser with Playwright. Also, gain a better understanding of some important functions like “BrowserContext,” which allows you to run multiple browser sessions, and “newPage” which interacts with a page.
  7. Handling Alerts and Dropdowns in Playwright : Playwright interact with different types of alerts and pop-ups, such as simple, confirmation, and prompt, and different types of dropdowns, such as single selector and multi-selector get your hands-on with handling alerts and dropdown in Playright testing.
  8. Playwright vs Puppeteer: Get to know about the difference between two testing frameworks and how they are different than one another, which browsers they support, and what features they provide.
  9. Run Playwright Tests on LambdaTest: Playwright testing with LambdaTest leverages test performance to the utmost. You can run multiple Playwright tests in Parallel with the LammbdaTest test cloud. Get a step-by-step guide to run your Playwright test on the LambdaTest platform.
  10. Playwright Python Tutorial: Playwright automation framework support all major languages such as Python, JavaScript, TypeScript, .NET and etc. However, there are various advantages to Python end-to-end testing with Playwright because of its versatile utility. Get the hang of Playwright python testing with this chapter.
  11. Playwright End To End Testing Tutorial: Get your hands on with Playwright end-to-end testing and learn to use some exciting features such as TraceViewer, Debugging, Networking, Component testing, Visual testing, and many more.
  12. Playwright Video Tutorial: Watch the video tutorials on Playwright testing from experts and get a consecutive in-depth explanation of Playwright automation testing.

Run Playwright Internal automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful