webbluetooth
Advanced tools
Comparing version 2.0.1-next.e654729.0 to 2.0.1
@@ -1,2 +0,2 @@ | ||
import{on as e,state as t,once as i,stopScanning as r,startScanning as n}from"@abandonware/noble";var s,a,c;function o(){}function d(){d.init.call(this)}function h(e){return void 0===e._maxListeners?d.defaultMaxListeners:e._maxListeners}function _(e,t,i){if(t)e.call(i);else for(var r=e.length,n=w(e,r),s=0;s<r;++s)n[s].call(i)}function l(e,t,i,r){if(t)e.call(i,r);else for(var n=e.length,s=w(e,n),a=0;a<n;++a)s[a].call(i,r)}function u(e,t,i,r,n){if(t)e.call(i,r,n);else for(var s=e.length,a=w(e,s),c=0;c<s;++c)a[c].call(i,r,n)}function v(e,t,i,r,n,s){if(t)e.call(i,r,n,s);else for(var a=e.length,c=w(e,a),o=0;o<a;++o)c[o].call(i,r,n,s)}function m(e,t,i,r){if(t)e.apply(i,r);else for(var n=e.length,s=w(e,n),a=0;a<n;++a)s[a].apply(i,r)}function f(e,t,i,r){var n,s,a,c;if("function"!=typeof i)throw new TypeError('"listener" argument must be a function');if((s=e._events)?(s.newListener&&(e.emit("newListener",t,i.listener?i.listener:i),s=e._events),a=s[t]):(s=e._events=new o,e._eventsCount=0),a){if("function"==typeof a?a=s[t]=r?[i,a]:[a,i]:r?a.unshift(i):a.push(i),!a.warned&&(n=h(e))&&n>0&&a.length>n){a.warned=!0;var d=new Error("Possible EventEmitter memory leak detected. "+a.length+" "+t+" listeners added. Use emitter.setMaxListeners() to increase limit");d.name="MaxListenersExceededWarning",d.emitter=e,d.type=t,d.count=a.length,c=d,"function"==typeof console.warn?console.warn(c):console.log(c)}}else a=s[t]=i,++e._eventsCount;return e}function p(e,t,i){var r=!1;function n(){e.removeListener(t,n),r||(r=!0,i.apply(e,arguments))}return n.listener=i,n}function g(e){var t=this._events;if(t){var i=t[e];if("function"==typeof i)return 1;if(i)return i.length}return 0}function w(e,t){for(var i=new Array(t);t--;)i[t]=e[t];return i}o.prototype=Object.create(null),d.EventEmitter=d,d.usingDomains=!1,d.prototype.domain=void 0,d.prototype._events=void 0,d.prototype._maxListeners=void 0,d.defaultMaxListeners=10,d.init=function(){this.domain=null,d.usingDomains&&(void 0).active&&(void 0).Domain,this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=new o,this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},d.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||isNaN(e))throw new TypeError('"n" argument must be a positive number');return this._maxListeners=e,this},d.prototype.getMaxListeners=function(){return h(this)},d.prototype.emit=function(e){var t,i,r,n,s,a,c,o="error"===e;if(a=this._events)o=o&&null==a.error;else if(!o)return!1;if(c=this.domain,o){if(t=arguments[1],!c){if(t instanceof Error)throw t;var d=new Error('Uncaught, unspecified "error" event. ('+t+")");throw d.context=t,d}return t||(t=new Error('Uncaught, unspecified "error" event')),t.domainEmitter=this,t.domain=c,t.domainThrown=!1,c.emit("error",t),!1}if(!(i=a[e]))return!1;var h="function"==typeof i;switch(r=arguments.length){case 1:_(i,h,this);break;case 2:l(i,h,this,arguments[1]);break;case 3:u(i,h,this,arguments[1],arguments[2]);break;case 4:v(i,h,this,arguments[1],arguments[2],arguments[3]);break;default:for(n=new Array(r-1),s=1;s<r;s++)n[s-1]=arguments[s];m(i,h,this,n)}return!0},d.prototype.addListener=function(e,t){return f(this,e,t,!1)},d.prototype.on=d.prototype.addListener,d.prototype.prependListener=function(e,t){return f(this,e,t,!0)},d.prototype.once=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.on(e,p(this,e,t)),this},d.prototype.prependOnceListener=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.prependListener(e,p(this,e,t)),this},d.prototype.removeListener=function(e,t){var i,r,n,s,a;if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');if(!(r=this._events))return this;if(!(i=r[e]))return this;if(i===t||i.listener&&i.listener===t)0==--this._eventsCount?this._events=new o:(delete r[e],r.removeListener&&this.emit("removeListener",e,i.listener||t));else if("function"!=typeof i){for(n=-1,s=i.length;s-- >0;)if(i[s]===t||i[s].listener&&i[s].listener===t){a=i[s].listener,n=s;break}if(n<0)return this;if(1===i.length){if(i[0]=void 0,0==--this._eventsCount)return this._events=new o,this;delete r[e]}else!function(e,t){for(var i=t,r=i+1,n=e.length;r<n;i+=1,r+=1)e[i]=e[r];e.pop()}(i,n);r.removeListener&&this.emit("removeListener",e,a||t)}return this},d.prototype.removeAllListeners=function(e){var t,i;if(!(i=this._events))return this;if(!i.removeListener)return 0===arguments.length?(this._events=new o,this._eventsCount=0):i[e]&&(0==--this._eventsCount?this._events=new o:delete i[e]),this;if(0===arguments.length){for(var r,n=Object.keys(i),s=0;s<n.length;++s)"removeListener"!==(r=n[s])&&this.removeAllListeners(r);return this.removeAllListeners("removeListener"),this._events=new o,this._eventsCount=0,this}if("function"==typeof(t=i[e]))this.removeListener(e,t);else if(t)do{this.removeListener(e,t[t.length-1])}while(t[0]);return this},d.prototype.listeners=function(e){var t,i=this._events;return i&&(t=i[e])?"function"==typeof t?[t.listener||t]:function(e){for(var t=new Array(e.length),i=0;i<t.length;++i)t[i]=e[i].listener||e[i];return t}(t):[]},d.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):g.call(e,t)},d.prototype.listenerCount=g,d.prototype.eventNames=function(){return this._eventsCount>0?Reflect.ownKeys(this._events):[]};class b extends d{constructor(){super(...arguments),this.isEventListenerObject=e=>void 0!==e.handleEvent}addEventListener(e,t){if(t){const i=this.isEventListenerObject(t)?t.handleEvent:t;super.addListener(e,i)}}removeEventListener(e,t){if(t){const i=this.isEventListenerObject(t)?t.handleEvent:t;super.removeListener(e,i)}}dispatchEvent(e){return super.emit(e.type,e)}}function y(e){return"number"==typeof e&&(e=e.toString(16)),(e=e.toLowerCase()).length<=8&&(e=("00000000"+e).slice(-8)+"-0000-1000-8000-00805f9b34fb"),32===e.length&&(e=e.match(/^([0-9a-f]{8})([0-9a-f]{4})([0-9a-f]{4})([0-9a-f]{4})([0-9a-f]{12})$/).splice(1).join("-")),e}function E(e){return"string"==typeof e&&s[e]&&(e=s[e]),y(e)}function x(e){return"string"==typeof e&&a[e]&&(e=a[e]),y(e)}function L(e){return"string"==typeof e&&c[e]&&(e=c[e]),y(e)}!function(e){e[e.alert_notification=6161]="alert_notification",e[e.automation_io=6165]="automation_io",e[e.battery_service=6159]="battery_service",e[e.blood_pressure=6160]="blood_pressure",e[e.body_composition=6171]="body_composition",e[e.bond_management=6174]="bond_management",e[e.continuous_glucose_monitoring=6175]="continuous_glucose_monitoring",e[e.current_time=6149]="current_time",e[e.cycling_power=6168]="cycling_power",e[e.cycling_speed_and_cadence=6166]="cycling_speed_and_cadence",e[e.device_information=6154]="device_information",e[e.environmental_sensing=6170]="environmental_sensing",e[e.generic_access=6144]="generic_access",e[e.generic_attribute=6145]="generic_attribute",e[e.glucose=6152]="glucose",e[e.health_thermometer=6153]="health_thermometer",e[e.heart_rate=6157]="heart_rate",e[e.human_interface_device=6162]="human_interface_device",e[e.immediate_alert=6146]="immediate_alert",e[e.indoor_positioning=6177]="indoor_positioning",e[e.internet_protocol_support=6176]="internet_protocol_support",e[e.link_loss=6147]="link_loss",e[e.location_and_navigation=6169]="location_and_navigation",e[e.next_dst_change=6151]="next_dst_change",e[e.phone_alert_status=6158]="phone_alert_status",e[e.pulse_oximeter=6178]="pulse_oximeter",e[e.reference_time_update=6150]="reference_time_update",e[e.running_speed_and_cadence=6164]="running_speed_and_cadence",e[e.scan_parameters=6163]="scan_parameters",e[e.tx_power=6148]="tx_power",e[e.user_data=6172]="user_data",e[e.weight_scale=6173]="weight_scale"}(s||(s={})),function(e){e[e.aerobic_heart_rate_lower_limit=10878]="aerobic_heart_rate_lower_limit",e[e.aerobic_heart_rate_upper_limit=10884]="aerobic_heart_rate_upper_limit",e[e.aerobic_threshold=10879]="aerobic_threshold",e[e.age=10880]="age",e[e.aggregate=10842]="aggregate",e[e.alert_category_id=10819]="alert_category_id",e[e.alert_category_id_bit_mask=10818]="alert_category_id_bit_mask",e[e.alert_level=10758]="alert_level",e[e.alert_notification_control_point=10820]="alert_notification_control_point",e[e.alert_status=10815]="alert_status",e[e.altitude=10931]="altitude",e[e.anaerobic_heart_rate_lower_limit=10881]="anaerobic_heart_rate_lower_limit",e[e.anaerobic_heart_rate_upper_limit=10882]="anaerobic_heart_rate_upper_limit",e[e.anaerobic_threshold=10883]="anaerobic_threshold",e[e.analog=10840]="analog",e[e.apparent_wind_direction=10867]="apparent_wind_direction",e[e.apparent_wind_speed=10866]="apparent_wind_speed",e[e["gap.appearance"]=10753]="gap.appearance",e[e.barometric_pressure_trend=10915]="barometric_pressure_trend",e[e.battery_level=10777]="battery_level",e[e.blood_pressure_feature=10825]="blood_pressure_feature",e[e.blood_pressure_measurement=10805]="blood_pressure_measurement",e[e.body_composition_feature=10907]="body_composition_feature",e[e.body_composition_measurement=10908]="body_composition_measurement",e[e.body_sensor_location=10808]="body_sensor_location",e[e.bond_management_control_point=10916]="bond_management_control_point",e[e.bond_management_feature=10917]="bond_management_feature",e[e.boot_keyboard_input_report=10786]="boot_keyboard_input_report",e[e.boot_keyboard_output_report=10802]="boot_keyboard_output_report",e[e.boot_mouse_input_report=10803]="boot_mouse_input_report",e[e["gap.central_address_resolution_support"]=10918]="gap.central_address_resolution_support",e[e.cgm_feature=10920]="cgm_feature",e[e.cgm_measurement=10919]="cgm_measurement",e[e.cgm_session_run_time=10923]="cgm_session_run_time",e[e.cgm_session_start_time=10922]="cgm_session_start_time",e[e.cgm_specific_ops_control_point=10924]="cgm_specific_ops_control_point",e[e.cgm_status=10921]="cgm_status",e[e.csc_feature=10844]="csc_feature",e[e.csc_measurement=10843]="csc_measurement",e[e.current_time=10795]="current_time",e[e.cycling_power_control_point=10854]="cycling_power_control_point",e[e.cycling_power_feature=10853]="cycling_power_feature",e[e.cycling_power_measurement=10851]="cycling_power_measurement",e[e.cycling_power_vector=10852]="cycling_power_vector",e[e.database_change_increment=10905]="database_change_increment",e[e.date_of_birth=10885]="date_of_birth",e[e.date_of_threshold_assessment=10886]="date_of_threshold_assessment",e[e.date_time=10760]="date_time",e[e.day_date_time=10762]="day_date_time",e[e.day_of_week=10761]="day_of_week",e[e.descriptor_value_changed=10877]="descriptor_value_changed",e[e["gap.device_name"]=10752]="gap.device_name",e[e.dew_point=10875]="dew_point",e[e.digital=10838]="digital",e[e.dst_offset=10765]="dst_offset",e[e.elevation=10860]="elevation",e[e.email_address=10887]="email_address",e[e.exact_time_256=10764]="exact_time_256",e[e.fat_burn_heart_rate_lower_limit=10888]="fat_burn_heart_rate_lower_limit",e[e.fat_burn_heart_rate_upper_limit=10889]="fat_burn_heart_rate_upper_limit",e[e.firmware_revision_string=10790]="firmware_revision_string",e[e.first_name=10890]="first_name",e[e.five_zone_heart_rate_limits=10891]="five_zone_heart_rate_limits",e[e.floor_number=10930]="floor_number",e[e.gender=10892]="gender",e[e.glucose_feature=10833]="glucose_feature",e[e.glucose_measurement=10776]="glucose_measurement",e[e.glucose_measurement_context=10804]="glucose_measurement_context",e[e.gust_factor=10868]="gust_factor",e[e.hardware_revision_string=10791]="hardware_revision_string",e[e.heart_rate_control_point=10809]="heart_rate_control_point",e[e.heart_rate_max=10893]="heart_rate_max",e[e.heart_rate_measurement=10807]="heart_rate_measurement",e[e.heat_index=10874]="heat_index",e[e.height=10894]="height",e[e.hid_control_point=10828]="hid_control_point",e[e.hid_information=10826]="hid_information",e[e.hip_circumference=10895]="hip_circumference",e[e.humidity=10863]="humidity",e[e["ieee_11073-20601_regulatory_certification_data_list"]=10794]="ieee_11073-20601_regulatory_certification_data_list",e[e.indoor_positioning_configuration=10925]="indoor_positioning_configuration",e[e.intermediate_blood_pressure=10806]="intermediate_blood_pressure",e[e.intermediate_temperature=10782]="intermediate_temperature",e[e.irradiance=10871]="irradiance",e[e.language=10914]="language",e[e.last_name=10896]="last_name",e[e.latitude=10926]="latitude",e[e.ln_control_point=10859]="ln_control_point",e[e.ln_feature=10858]="ln_feature",e[e["local_east_coordinate.xml"]=10929]="local_east_coordinate.xml",e[e.local_north_coordinate=10928]="local_north_coordinate",e[e.local_time_information=10767]="local_time_information",e[e.location_and_speed=10855]="location_and_speed",e[e.location_name=10933]="location_name",e[e.longitude=10927]="longitude",e[e.magnetic_declination=10796]="magnetic_declination",e[e.magnetic_flux_density_2D=10912]="magnetic_flux_density_2D",e[e.magnetic_flux_density_3D=10913]="magnetic_flux_density_3D",e[e.manufacturer_name_string=10793]="manufacturer_name_string",e[e.maximum_recommended_heart_rate=10897]="maximum_recommended_heart_rate",e[e.measurement_interval=10785]="measurement_interval",e[e.model_number_string=10788]="model_number_string",e[e.navigation=10856]="navigation",e[e.new_alert=10822]="new_alert",e[e["gap.peripheral_preferred_connection_parameters"]=10756]="gap.peripheral_preferred_connection_parameters",e[e["gap.peripheral_privacy_flag"]=10754]="gap.peripheral_privacy_flag",e[e.plx_continuous_measurement=10847]="plx_continuous_measurement",e[e.plx_features=10848]="plx_features",e[e.plx_spot_check_measurement=10846]="plx_spot_check_measurement",e[e.pnp_id=10832]="pnp_id",e[e.pollen_concentration=10869]="pollen_concentration",e[e.position_quality=10857]="position_quality",e[e.pressure=10861]="pressure",e[e.protocol_mode=10830]="protocol_mode",e[e.rainfall=10872]="rainfall",e[e["gap.reconnection_address"]=10755]="gap.reconnection_address",e[e.record_access_control_point=10834]="record_access_control_point",e[e.reference_time_information=10772]="reference_time_information",e[e.report=10829]="report",e[e.report_map=10827]="report_map",e[e.resting_heart_rate=10898]="resting_heart_rate",e[e.ringer_control_point=10816]="ringer_control_point",e[e.ringer_setting=10817]="ringer_setting",e[e.rsc_feature=10836]="rsc_feature",e[e.rsc_measurement=10835]="rsc_measurement",e[e.sc_control_point=10837]="sc_control_point",e[e.scan_interval_window=10831]="scan_interval_window",e[e.scan_refresh=10801]="scan_refresh",e[e.sensor_location=10845]="sensor_location",e[e.serial_number_string=10789]="serial_number_string",e[e["gatt.service_changed"]=10757]="gatt.service_changed",e[e.software_revision_string=10792]="software_revision_string",e[e.sport_type_for_aerobic_and_anaerobic_thresholds=10899]="sport_type_for_aerobic_and_anaerobic_thresholds",e[e.supported_new_alert_category=10823]="supported_new_alert_category",e[e.supported_unread_alert_category=10824]="supported_unread_alert_category",e[e.system_id=10787]="system_id",e[e.temperature=10862]="temperature",e[e.temperature_measurement=10780]="temperature_measurement",e[e.temperature_type=10781]="temperature_type",e[e.three_zone_heart_rate_limits=10900]="three_zone_heart_rate_limits",e[e.time_accuracy=10770]="time_accuracy",e[e.time_source=10771]="time_source",e[e.time_update_control_point=10774]="time_update_control_point",e[e.time_update_state=10775]="time_update_state",e[e.time_with_dst=10769]="time_with_dst",e[e.time_zone=10766]="time_zone",e[e.true_wind_direction=10865]="true_wind_direction",e[e.true_wind_speed=10864]="true_wind_speed",e[e.two_zone_heart_rate_limit=10901]="two_zone_heart_rate_limit",e[e.tx_power_level=10759]="tx_power_level",e[e.uncertainty=10932]="uncertainty",e[e.unread_alert_status=10821]="unread_alert_status",e[e.user_control_point=10911]="user_control_point",e[e.user_index=10906]="user_index",e[e.uv_index=10870]="uv_index",e[e.vo2_max=10902]="vo2_max",e[e.waist_circumference=10903]="waist_circumference",e[e.weight=10904]="weight",e[e.weight_measurement=10909]="weight_measurement",e[e.weight_scale_feature=10910]="weight_scale_feature",e[e.wind_chill=10873]="wind_chill"}(a||(a={})),function(e){e[e["gatt.characteristic_extended_properties"]=10496]="gatt.characteristic_extended_properties",e[e["gatt.characteristic_user_description"]=10497]="gatt.characteristic_user_description",e[e["gatt.client_characteristic_configuration"]=10498]="gatt.client_characteristic_configuration",e[e["gatt.server_characteristic_configuration"]=10499]="gatt.server_characteristic_configuration",e[e["gatt.characteristic_presentation_format"]=10500]="gatt.characteristic_presentation_format",e[e["gatt.characteristic_aggregate_format"]=10501]="gatt.characteristic_aggregate_format",e[e.valid_range=10502]="valid_range",e[e.external_report_reference=10503]="external_report_reference",e[e.report_reference=10504]="report_reference",e[e.number_of_digitals=10505]="number_of_digitals",e[e.value_trigger_setting=10506]="value_trigger_setting",e[e.es_configuration=10507]="es_configuration",e[e.es_measurement=10508]="es_measurement",e[e.es_trigger_setting=10509]="es_trigger_setting",e[e.time_trigger_setting=10510]="time_trigger_setting"}(c||(c={}));class D extends d{constructor(){super(),this.deviceHandles={},this.serviceHandles={},this.characteristicHandles={},this.descriptorHandles={},this.charNotifies={},this.discoverFn=null,this.initialised=!1,this.enabled=!1,this.os="browser",this.enabled=this.state,e("stateChange",()=>{this.enabled!==this.state&&(this.enabled=this.state,this.emit(D.EVENT_ENABLED,this.enabled))})}get state(){return"poweredOn"===t}init(t){if(this.initialised)return t();e("discover",e=>{this.discoverFn&&this.discoverFn(e)}),this.initialised=!0,t()}checkForError(e,t,i){return function(r){if(r)e(r);else if("function"==typeof t){const e=[].slice.call(arguments,1);null===i?t.apply(this,e):setTimeout(()=>t.apply(this,e),i)}}}bufferToDataView(e){const t=new Uint8Array(e).buffer;return new DataView(t)}dataViewToBuffer(e){const t=new Uint8Array(e.buffer);return new Buffer(t)}validDevice(e,t){if(0===t.length)return!0;if(!e.advertisement.serviceUuids)return!1;const i=e.advertisement.serviceUuids.map(e=>y(e));return t.some(e=>i.indexOf(e)>=0)}deviceToBluetoothDevice(e){const t=e.address&&"unknown"!==e.address?e.address:e.id,i=[];e.advertisement.serviceUuids&&e.advertisement.serviceUuids.forEach(e=>{i.push(y(e))});const r=new Map;if(e.advertisement.manufacturerData){const t=e.advertisement.manufacturerData.readUInt16LE(0),i=e.advertisement.manufacturerData.slice(2);r.set(("0000"+t.toString(16)).slice(-4),this.bufferToDataView(i))}const n=new Map;return e.advertisement.serviceData&&e.advertisement.serviceData.forEach(e=>{n.set(y(e.uuid),this.bufferToDataView(e.data))}),{id:t,name:e.advertisement.localName,_serviceUUIDs:i,adData:{rssi:e.rssi,txPower:e.advertisement.txPowerLevel,serviceData:n,manufacturerData:r}}}getEnabled(e){function r(){e(this.state)}"unknown"===t||"poweredOff"===t?i("stateChange",r.bind(this)):r.call(this)}startScan(e,r,s,a){this.discoverFn=t=>{if(this.validDevice(t,e)){const e=this.deviceToBluetoothDevice(t);this.deviceHandles[e.id]||(this.deviceHandles[e.id]=t,r(e))}},this.init(()=>{function e(){!0===this.state?n([],!0,this.checkForError(a,s)):a("adapter not enabled")}this.deviceHandles={},"unknown"===t||"poweredOff"===t?i("stateChange",e.bind(this)):e.call(this)})}stopScan(e){this.discoverFn=null,r()}connect(e,t,i,r){const n=this.deviceHandles[e];n.removeAllListeners("connect"),n.removeAllListeners("disconnect"),n.once("connect",t),n.once("disconnect",()=>{this.serviceHandles={},this.characteristicHandles={},this.descriptorHandles={},this.charNotifies={},i()}),n.connect(this.checkForError(r))}disconnect(e,t){this.deviceHandles[e].disconnect(this.checkForError(t))}discoverServices(e,t,i,r){this.deviceHandles[e].discoverServices([],this.checkForError(r,e=>{const r=[];e.forEach(e=>{const i=y(e.uuid);(0===t.length||t.indexOf(i)>=0)&&(this.serviceHandles[i]||(this.serviceHandles[i]=e),r.push({uuid:i,primary:!0}))}),i(r)}))}discoverIncludedServices(e,t,i,r){this.serviceHandles[e].discoverIncludedServices([],this.checkForError(r,e=>{const r=[];e.forEach(e=>{const i=y(e.uuid);(0===t.length||t.indexOf(i)>=0)&&(this.serviceHandles[i]||(this.serviceHandles[i]=e),r.push({uuid:i,primary:!1}))},this),i(r)}))}discoverCharacteristics(e,t,i,r){this.serviceHandles[e].discoverCharacteristics([],this.checkForError(r,e=>{const r=[];e.forEach(e=>{const i=y(e.uuid);(0===t.length||t.indexOf(i)>=0)&&(this.characteristicHandles[i]||(this.characteristicHandles[i]=e),r.push({uuid:i,properties:{broadcast:e.properties.indexOf("broadcast")>=0,read:e.properties.indexOf("read")>=0,writeWithoutResponse:e.properties.indexOf("writeWithoutResponse")>=0,write:e.properties.indexOf("write")>=0,notify:e.properties.indexOf("notify")>=0,indicate:e.properties.indexOf("indicate")>=0,authenticatedSignedWrites:e.properties.indexOf("authenticatedSignedWrites")>=0,reliableWrite:e.properties.indexOf("reliableWrite")>=0,writableAuxiliaries:e.properties.indexOf("writableAuxiliaries")>=0}}),e.on("data",(e,t)=>{if(!0===t&&"function"==typeof this.charNotifies[i]){const t=this.bufferToDataView(e);this.charNotifies[i](t)}}))},this),i(r)}))}discoverDescriptors(e,t,i,r){const n=this.characteristicHandles[e];n.discoverDescriptors(this.checkForError(r,e=>{const r=[];e.forEach(e=>{const i=y(e.uuid);if(0===t.length||t.indexOf(i)>=0){const t=n.uuid+"-"+e.uuid;this.descriptorHandles[t]||(this.descriptorHandles[t]=e),r.push({uuid:i})}},this),i(r)}))}readCharacteristic(e,t,i){this.characteristicHandles[e].read(this.checkForError(i,e=>{const i=this.bufferToDataView(e);t(i)}))}writeCharacteristic(e,t,i,r){const n=this.dataViewToBuffer(t),s=this.characteristicHandles[e],a=s.properties.indexOf("writeWithoutResponse")>=0||s.properties.indexOf("authenticatedSignedWrites")>=0,c="darwin"!==this.os&&a?25:null;s.write(n,a,this.checkForError(r,i,c))}enableNotify(e,t,i,r){if(this.charNotifies[e])return this.charNotifies[e]=t,i();this.characteristicHandles[e].once("notify",n=>{if(!0!==n)return r("notify failed to enable");this.charNotifies[e]=t,i()}),this.characteristicHandles[e].notify(!0,this.checkForError(r))}disableNotify(e,t,i){if(!this.charNotifies[e])return t();this.characteristicHandles[e].once("notify",r=>{if(!1!==r)return i("notify failed to disable");this.charNotifies[e]&&delete this.charNotifies[e],t()}),this.characteristicHandles[e].notify(!1,this.checkForError(i))}readDescriptor(e,t,i){this.descriptorHandles[e].readValue(this.checkForError(i,e=>{const i=this.bufferToDataView(e);t(i)}))}writeDescriptor(e,t,i,r){const n=this.dataViewToBuffer(t);this.descriptorHandles[e].writeValue(n,this.checkForError(r,i))}}D.EVENT_ENABLED="enabledchanged";const P=new D;class S{constructor(e){this.characteristic=null,this.uuid=null,this._value=null,this.handle=null,this.characteristic=e.characteristic,this.uuid=e.uuid,this._value=e.value,this.handle=`${this.characteristic.uuid}-${this.uuid}`}get value(){return this._value}readValue(){return new Promise((e,t)=>{if(!this.characteristic.service.device.gatt.connected)return t("readValue error: device not connected");P.readDescriptor(this.handle,t=>{this._value=t,e(t)},e=>{t(`readValue error: ${e}`)})})}writeValue(e){return new Promise((t,i)=>{if(!this.characteristic.service.device.gatt.connected)return i("writeValue error: device not connected");const r=function(e){return void 0!==e.buffer}(e)?e.buffer:e,n=new DataView(r);P.writeDescriptor(this.handle,n,()=>{this._value=n,t()},e=>{i(`writeValue error: ${e}`)})})}}class k{constructor(e,t){this.bubbles=!0,this.cancelable=!1,this.cancelBubble=!1,this.composed=!1,this.defaultPrevented=!1,this.eventPhase=0,this.isTrusted=!0,this.returnValue=!0,this.target=e,this.srcElement=e,this.currentTarget=e,this.type=t}composedPath(){return[]}initEvent(e,t,i){this.type=e,this.bubbles=t,this.cancelable=i}preventDefault(){this.defaultPrevented=!0}stopImmediatePropagation(){}stopPropagation(){}}class O extends b{constructor(e){super(),this.service=null,this.uuid=null,this._value=null,this.handle=null,this.descriptors=null,this.service=e.service,this.uuid=e.uuid,this.properties=e.properties,this._value=e.value,this.handle=this.uuid}get value(){return this._value}set oncharacteristicvaluechanged(e){this._oncharacteristicvaluechanged&&this.removeEventListener("characteristicvaluechanged",this._oncharacteristicvaluechanged),this._oncharacteristicvaluechanged=e,this.addEventListener("characteristicvaluechanged",this._oncharacteristicvaluechanged)}setValue(e,t){this._value=e,t&&(this.dispatchEvent(new k(this,"characteristicvaluechanged")),this.service.dispatchEvent(new k(this,"characteristicvaluechanged")),this.service.device.dispatchEvent(new k(this,"characteristicvaluechanged")),this.service.device._bluetooth.dispatchEvent(new k(this,"characteristicvaluechanged")))}getDescriptor(e){return new Promise((t,i)=>this.service.device.gatt.connected?e?void this.getDescriptors(e).then(e=>{if(1!==e.length)return i("getDescriptor error: descriptor not found");t(e[0])}).catch(e=>{i(`getDescriptor error: ${e}`)}):i("getDescriptor error: no descriptor specified"):i("getDescriptor error: device not connected"))}getDescriptors(e){return new Promise((t,i)=>{if(!this.service.device.gatt.connected)return i("getDescriptors error: device not connected");function r(){if(!e)return t(this.descriptors);const r=this.descriptors.filter(t=>t.uuid===L(e));if(1!==r.length)return i("getDescriptors error: descriptor not found");t(r)}if(this.descriptors)return r.call(this);P.discoverDescriptors(this.handle,[],e=>{this.descriptors=e.map(e=>(Object.assign(e,{characteristic:this}),new S(e))),r.call(this)},e=>{i(`getDescriptors error: ${e}`)})})}readValue(){return new Promise((e,t)=>{if(!this.service.device.gatt.connected)return t("readValue error: device not connected");P.readCharacteristic(this.handle,t=>{this.setValue(t,!0),e(t)},e=>{t(`readValue error: ${e}`)})})}writeValue(e){return new Promise((t,i)=>{if(!this.service.device.gatt.connected)return i("writeValue error: device not connected");const r=function(e){return void 0!==e.buffer}(e)?e.buffer:e,n=new DataView(r);P.writeCharacteristic(this.handle,n,()=>{this.setValue(n),t()},e=>{i(`writeValue error: ${e}`)})})}startNotifications(){return new Promise((e,t)=>{if(!this.service.device.gatt.connected)return t("startNotifications error: device not connected");P.enableNotify(this.handle,e=>{this.setValue(e,!0)},()=>{e(this)},e=>{t(`startNotifications error: ${e}`)})})}stopNotifications(){return new Promise((e,t)=>{if(!this.service.device.gatt.connected)return t("stopNotifications error: device not connected");P.disableNotify(this.handle,()=>{e(this)},e=>{t(`stopNotifications error: ${e}`)})})}}class T extends b{constructor(e){super(),this.device=null,this.uuid=null,this.isPrimary=!1,this.handle=null,this.services=null,this.characteristics=null,this.device=e.device,this.uuid=e.uuid,this.isPrimary=e.isPrimary,this.handle=this.uuid,this.dispatchEvent(new k(this,"serviceadded")),this.device.dispatchEvent(new k(this,"serviceadded")),this.device._bluetooth.dispatchEvent(new k(this,"serviceadded"))}set oncharacteristicvaluechanged(e){this._oncharacteristicvaluechanged&&this.removeEventListener("characteristicvaluechanged",this._oncharacteristicvaluechanged),this._oncharacteristicvaluechanged=e,this.addEventListener("characteristicvaluechanged",this._oncharacteristicvaluechanged)}set onserviceadded(e){this._onserviceadded&&this.removeEventListener("serviceadded",this._onserviceadded),this._onserviceadded=e,this.addEventListener("serviceadded",this._onserviceadded)}set onservicechanged(e){this._onservicechanged&&this.removeEventListener("servicechanged",this._onservicechanged),this._onservicechanged=e,this.addEventListener("servicechanged",this._onservicechanged)}set onserviceremoved(e){this._onserviceremoved&&this.removeEventListener("serviceremoved",this._onserviceremoved),this._onserviceremoved=e,this.addEventListener("serviceremoved",this._onserviceremoved)}getCharacteristic(e){return new Promise((t,i)=>this.device.gatt.connected?e?void this.getCharacteristics(e).then(e=>{if(1!==e.length)return i("getCharacteristic error: characteristic not found");t(e[0])}).catch(e=>{i(`getCharacteristic error: ${e}`)}):i("getCharacteristic error: no characteristic specified"):i("getCharacteristic error: device not connected"))}getCharacteristics(e){return new Promise((t,i)=>{if(!this.device.gatt.connected)return i("getCharacteristics error: device not connected");function r(){if(!e)return t(this.characteristics);e=x(e);const r=this.characteristics.filter(t=>t.uuid===e);if(1!==r.length)return i("getCharacteristics error: characteristic not found");t(r)}if(this.characteristics)return r.call(this);P.discoverCharacteristics(this.handle,[],e=>{this.characteristics=e.map(e=>(Object.assign(e,{service:this}),new O(e))),r.call(this)},e=>{i(`getCharacteristics error: ${e}`)})})}getIncludedService(e){return new Promise((t,i)=>this.device.gatt.connected?e?void this.getIncludedServices(e).then(e=>{if(1!==e.length)return i("getIncludedService error: service not found");t(e[0])}).catch(e=>{i(`getIncludedService error: ${e}`)}):i("getIncludedService error: no service specified"):i("getIncludedService error: device not connected"))}getIncludedServices(e){return new Promise((t,i)=>{if(!this.device.gatt.connected)return i("getIncludedServices error: device not connected");function r(){if(!e)return t(this.services);const r=this.services.filter(t=>t.uuid===E(e));if(1!==r.length)return i("getIncludedServices error: service not found");t(r)}if(this.services)return r.call(this);P.discoverIncludedServices(this.handle,this.device._allowedServices,e=>{this.services=e.map(e=>(Object.assign(e,{device:this.device}),new T(e))),r.call(this)},e=>{i(`getIncludedServices error: ${e}`)})})}}class V{constructor(e){this.device=null,this._connected=!1,this.handle=null,this.services=null,this.device=e,this.handle=this.device.id}get connected(){return this._connected}connect(){return new Promise((e,t)=>{if(this.connected)return t("connect error: device already connected");P.connect(this.handle,()=>{this._connected=!0,e(this)},()=>{this.services=null,this._connected=!1,this.device.dispatchEvent(new k(this.device,"gattserverdisconnected")),this.device._bluetooth.dispatchEvent(new k(this.device,"gattserverdisconnected"))},e=>{t(`connect Error: ${e}`)})})}disconnect(){P.disconnect(this.handle),this._connected=!1}getPrimaryService(e){return new Promise((t,i)=>this.connected?e?void this.getPrimaryServices(e).then(e=>{if(1!==e.length)return i("getPrimaryService error: service not found");t(e[0])}).catch(e=>{i(`getPrimaryService error: ${e}`)}):i("getPrimaryService error: no service specified"):i("getPrimaryService error: device not connected"))}getPrimaryServices(e){return new Promise((t,i)=>{if(!this.connected)return i("getPrimaryServices error: device not connected");function r(){if(!e)return t(this.services);const r=this.services.filter(t=>t.uuid===E(e));if(1!==r.length)return i("getPrimaryServices error: service not found");t(r)}if(this.services)return r.call(this);P.discoverServices(this.handle,this.device._allowedServices,e=>{this.services=e.map(e=>(Object.assign(e,{device:this.device}),new T(e))),r.call(this)},e=>{i(`getPrimaryServices error: ${e}`)})})}}class C extends b{constructor(e){super(),this.id=null,this.name=null,this.gatt=null,this.watchingAdvertisements=!1,this._bluetooth=null,this._allowedServices=[],this._serviceUUIDs=[],this.id=e.id,this.name=e.name,this.gatt=e.gatt,this.watchAdvertisements=e.watchAdvertisements,this.adData=e.adData,this._bluetooth=e._bluetooth,this._allowedServices=e._allowedServices,this._serviceUUIDs=e._serviceUUIDs,this.name||(this.name=`Unknown or Unsupported Device (${this.id})`),this.gatt||(this.gatt=new V(this))}set oncharacteristicvaluechanged(e){this._oncharacteristicvaluechanged&&this.removeEventListener("characteristicvaluechanged",this._oncharacteristicvaluechanged),this._oncharacteristicvaluechanged=e,this.addEventListener("characteristicvaluechanged",this._oncharacteristicvaluechanged)}set onserviceadded(e){this._onserviceadded&&this.removeEventListener("serviceadded",this._onserviceadded),this._onserviceadded=e,this.addEventListener("serviceadded",this._onserviceadded)}set onservicechanged(e){this._onservicechanged&&this.removeEventListener("servicechanged",this._onservicechanged),this._onservicechanged=e,this.addEventListener("servicechanged",this._onservicechanged)}set onserviceremoved(e){this._onserviceremoved&&this.removeEventListener("serviceremoved",this._onserviceremoved),this._onserviceremoved=e,this.addEventListener("serviceremoved",this._onserviceremoved)}set ongattserverdisconnected(e){this._ongattserverdisconnected&&this.removeEventListener("gattserverdisconnected",this._ongattserverdisconnected),this._ongattserverdisconnected=e,this.addEventListener("gattserverdisconnected",this._ongattserverdisconnected)}set onadvertisementreceived(e){this._onadvertisementreceived&&this.removeEventListener("advertisementreceived",this._onadvertisementreceived),this._onadvertisementreceived=e,this.addEventListener("advertisementreceived",this._onadvertisementreceived)}watchAdvertisements(){return new Promise((e,t)=>{t("watchAdvertisements error: method not implemented")})}unwatchAdvertisements(){return new Promise((e,t)=>{t("unwatchAdvertisements error: method not implemented")})}}class H extends b{constructor(e){super(),this.deviceFound=null,this.scanTime=10240,this.scanner=null,e=e||{},this.referringDevice=e.referringDevice,this.deviceFound=e.deviceFound,e.scanTime&&(this.scanTime=1e3*e.scanTime),P.on(D.EVENT_ENABLED,e=>{this.dispatchEvent(new k(this,"availabilitychanged"))})}set oncharacteristicvaluechanged(e){this._oncharacteristicvaluechanged&&this.removeEventListener("characteristicvaluechanged",this._oncharacteristicvaluechanged),this._oncharacteristicvaluechanged=e,this.addEventListener("characteristicvaluechanged",this._oncharacteristicvaluechanged)}set onserviceadded(e){this._onserviceadded&&this.removeEventListener("serviceadded",this._onserviceadded),this._onserviceadded=e,this.addEventListener("serviceadded",this._onserviceadded)}set onservicechanged(e){this._onservicechanged&&this.removeEventListener("servicechanged",this._onservicechanged),this._onservicechanged=e,this.addEventListener("servicechanged",this._onservicechanged)}set onserviceremoved(e){this._onserviceremoved&&this.removeEventListener("serviceremoved",this._onserviceremoved),this._onserviceremoved=e,this.addEventListener("serviceremoved",this._onserviceremoved)}set ongattserverdisconnected(e){this._ongattserverdisconnected&&this.removeEventListener("gattserverdisconnected",this._ongattserverdisconnected),this._ongattserverdisconnected=e,this.addEventListener("gattserverdisconnected",this._ongattserverdisconnected)}set onadvertisementreceived(e){this._onadvertisementreceived&&this.removeEventListener("advertisementreceived",this._onadvertisementreceived),this._onadvertisementreceived=e,this.addEventListener("advertisementreceived",this._onadvertisementreceived)}set onavailabilitychanged(e){this._onavailabilitychanged&&this.removeEventListener("availabilitychanged",this._onavailabilitychanged),this._onavailabilitychanged=e,this.addEventListener("availabilitychanged",this._onavailabilitychanged)}filterDevice(e,t,i){let r=!1;return e.forEach(e=>{if(!e.name||e.name===t.name){if(e.namePrefix){if(!t.name||e.namePrefix.length>t.name.length)return;if(e.namePrefix!==t.name.substr(0,e.namePrefix.length))return}if(e.services){const r=e.services.map(E);if(!r.every(e=>t._serviceUUIDs.indexOf(e)>-1))return;i=i.concat(r)}r=!0}}),!!r&&t}getAvailability(){return new Promise((e,t)=>{P.getEnabled(t=>{e(t)})})}requestDevice(e={filters:[]}){return new Promise((t,i)=>{if(null!==this.scanner)return i("requestDevice error: request in progress");const r=e=>void 0!==e.filters;let n=[];if(r(e)){if(0===e.filters.length)return i(new TypeError("requestDevice error: no filters specified"));if(e.filters.some(e=>0===Object.keys(e).length))return i(new TypeError("requestDevice error: empty filter specified"));if(e.filters.some(e=>void 0!==e.namePrefix&&""===e.namePrefix))return i(new TypeError("requestDevice error: empty namePrefix specified"));e.filters.forEach(e=>{e.services&&(n=n.concat(e.services.map(E))),n=n.filter((e,t,i)=>i.indexOf(e)===t)})}else if(!(e=>!0===e.acceptAllDevices)(e))return i(new TypeError("requestDevice error: specify filters or acceptAllDevices"));let s=!1;P.startScan(n,i=>{let n=[];function a(e){this.cancelRequest().then(()=>{t(e)})}if(r(e)&&(i=this.filterDevice(e.filters,i,n)),i){s=!0,e.optionalServices&&(n=n.concat(e.optionalServices.map(E)));const t=n.filter((e,t,i)=>i.indexOf(e)===t);Object.assign(i,{_bluetooth:this,_allowedServices:t});const r=new C(i);function c(){a.call(this,r)}this.deviceFound&&!0!==this.deviceFound(r,c.bind(this))||a.call(this,r)}},()=>{this.scanner=setTimeout(()=>{this.cancelRequest().then(()=>{s||i("requestDevice error: no devices found")})},this.scanTime)},e=>i(`requestDevice error: ${e}`))})}cancelRequest(){return new Promise((e,t)=>{this.scanner&&(clearTimeout(this.scanner),this.scanner=null,P.stopScan()),e()})}}H.EVENT_AVAILABILITY="availabilitychanged";const N=new H;export{H as Bluetooth,N as bluetooth,a as bluetoothCharacteristics,c as bluetoothDescriptors,s as bluetoothServices,y as getCanonicalUUID,x as getCharacteristicUUID,L as getDescriptorUUID,E as getServiceUUID}; | ||
import{on as e,state as t,once as i,stopScanning as r,startScanning as n}from"@abandonware/noble";var s,a,c;function o(){}function d(){d.init.call(this)}function h(e){return void 0===e._maxListeners?d.defaultMaxListeners:e._maxListeners}function _(e,t,i){if(t)e.call(i);else for(var r=e.length,n=w(e,r),s=0;s<r;++s)n[s].call(i)}function l(e,t,i,r){if(t)e.call(i,r);else for(var n=e.length,s=w(e,n),a=0;a<n;++a)s[a].call(i,r)}function u(e,t,i,r,n){if(t)e.call(i,r,n);else for(var s=e.length,a=w(e,s),c=0;c<s;++c)a[c].call(i,r,n)}function v(e,t,i,r,n,s){if(t)e.call(i,r,n,s);else for(var a=e.length,c=w(e,a),o=0;o<a;++o)c[o].call(i,r,n,s)}function m(e,t,i,r){if(t)e.apply(i,r);else for(var n=e.length,s=w(e,n),a=0;a<n;++a)s[a].apply(i,r)}function f(e,t,i,r){var n,s,a,c;if("function"!=typeof i)throw new TypeError('"listener" argument must be a function');if((s=e._events)?(s.newListener&&(e.emit("newListener",t,i.listener?i.listener:i),s=e._events),a=s[t]):(s=e._events=new o,e._eventsCount=0),a){if("function"==typeof a?a=s[t]=r?[i,a]:[a,i]:r?a.unshift(i):a.push(i),!a.warned&&(n=h(e))&&n>0&&a.length>n){a.warned=!0;var d=new Error("Possible EventEmitter memory leak detected. "+a.length+" "+t+" listeners added. Use emitter.setMaxListeners() to increase limit");d.name="MaxListenersExceededWarning",d.emitter=e,d.type=t,d.count=a.length,c=d,"function"==typeof console.warn?console.warn(c):console.log(c)}}else a=s[t]=i,++e._eventsCount;return e}function p(e,t,i){var r=!1;function n(){e.removeListener(t,n),r||(r=!0,i.apply(e,arguments))}return n.listener=i,n}function g(e){var t=this._events;if(t){var i=t[e];if("function"==typeof i)return 1;if(i)return i.length}return 0}function w(e,t){for(var i=new Array(t);t--;)i[t]=e[t];return i}o.prototype=Object.create(null),d.EventEmitter=d,d.usingDomains=!1,d.prototype.domain=void 0,d.prototype._events=void 0,d.prototype._maxListeners=void 0,d.defaultMaxListeners=10,d.init=function(){this.domain=null,d.usingDomains&&(void 0).active,this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=new o,this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},d.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||isNaN(e))throw new TypeError('"n" argument must be a positive number');return this._maxListeners=e,this},d.prototype.getMaxListeners=function(){return h(this)},d.prototype.emit=function(e){var t,i,r,n,s,a,c,o="error"===e;if(a=this._events)o=o&&null==a.error;else if(!o)return!1;if(c=this.domain,o){if(t=arguments[1],!c){if(t instanceof Error)throw t;var d=new Error('Uncaught, unspecified "error" event. ('+t+")");throw d.context=t,d}return t||(t=new Error('Uncaught, unspecified "error" event')),t.domainEmitter=this,t.domain=c,t.domainThrown=!1,c.emit("error",t),!1}if(!(i=a[e]))return!1;var h="function"==typeof i;switch(r=arguments.length){case 1:_(i,h,this);break;case 2:l(i,h,this,arguments[1]);break;case 3:u(i,h,this,arguments[1],arguments[2]);break;case 4:v(i,h,this,arguments[1],arguments[2],arguments[3]);break;default:for(n=new Array(r-1),s=1;s<r;s++)n[s-1]=arguments[s];m(i,h,this,n)}return!0},d.prototype.addListener=function(e,t){return f(this,e,t,!1)},d.prototype.on=d.prototype.addListener,d.prototype.prependListener=function(e,t){return f(this,e,t,!0)},d.prototype.once=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.on(e,p(this,e,t)),this},d.prototype.prependOnceListener=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.prependListener(e,p(this,e,t)),this},d.prototype.removeListener=function(e,t){var i,r,n,s,a;if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');if(!(r=this._events))return this;if(!(i=r[e]))return this;if(i===t||i.listener&&i.listener===t)0==--this._eventsCount?this._events=new o:(delete r[e],r.removeListener&&this.emit("removeListener",e,i.listener||t));else if("function"!=typeof i){for(n=-1,s=i.length;s-- >0;)if(i[s]===t||i[s].listener&&i[s].listener===t){a=i[s].listener,n=s;break}if(n<0)return this;if(1===i.length){if(i[0]=void 0,0==--this._eventsCount)return this._events=new o,this;delete r[e]}else!function(e,t){for(var i=t,r=i+1,n=e.length;r<n;i+=1,r+=1)e[i]=e[r];e.pop()}(i,n);r.removeListener&&this.emit("removeListener",e,a||t)}return this},d.prototype.removeAllListeners=function(e){var t,i;if(!(i=this._events))return this;if(!i.removeListener)return 0===arguments.length?(this._events=new o,this._eventsCount=0):i[e]&&(0==--this._eventsCount?this._events=new o:delete i[e]),this;if(0===arguments.length){for(var r,n=Object.keys(i),s=0;s<n.length;++s)"removeListener"!==(r=n[s])&&this.removeAllListeners(r);return this.removeAllListeners("removeListener"),this._events=new o,this._eventsCount=0,this}if("function"==typeof(t=i[e]))this.removeListener(e,t);else if(t)do{this.removeListener(e,t[t.length-1])}while(t[0]);return this},d.prototype.listeners=function(e){var t,i=this._events;return i&&(t=i[e])?"function"==typeof t?[t.listener||t]:function(e){for(var t=new Array(e.length),i=0;i<t.length;++i)t[i]=e[i].listener||e[i];return t}(t):[]},d.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):g.call(e,t)},d.prototype.listenerCount=g,d.prototype.eventNames=function(){return this._eventsCount>0?Reflect.ownKeys(this._events):[]};class b extends d{constructor(){super(...arguments),this.isEventListenerObject=e=>void 0!==e.handleEvent}addEventListener(e,t){if(t){const i=this.isEventListenerObject(t)?t.handleEvent:t;super.addListener(e,i)}}removeEventListener(e,t){if(t){const i=this.isEventListenerObject(t)?t.handleEvent:t;super.removeListener(e,i)}}dispatchEvent(e){return super.emit(e.type,e)}}function y(e){return"number"==typeof e&&(e=e.toString(16)),(e=e.toLowerCase()).length<=8&&(e=("00000000"+e).slice(-8)+"-0000-1000-8000-00805f9b34fb"),32===e.length&&(e=e.match(/^([0-9a-f]{8})([0-9a-f]{4})([0-9a-f]{4})([0-9a-f]{4})([0-9a-f]{12})$/).splice(1).join("-")),e}function E(e){return"string"==typeof e&&s[e]&&(e=s[e]),y(e)}function x(e){return"string"==typeof e&&a[e]&&(e=a[e]),y(e)}function L(e){return"string"==typeof e&&c[e]&&(e=c[e]),y(e)}!function(e){e[e.alert_notification=6161]="alert_notification",e[e.automation_io=6165]="automation_io",e[e.battery_service=6159]="battery_service",e[e.blood_pressure=6160]="blood_pressure",e[e.body_composition=6171]="body_composition",e[e.bond_management=6174]="bond_management",e[e.continuous_glucose_monitoring=6175]="continuous_glucose_monitoring",e[e.current_time=6149]="current_time",e[e.cycling_power=6168]="cycling_power",e[e.cycling_speed_and_cadence=6166]="cycling_speed_and_cadence",e[e.device_information=6154]="device_information",e[e.environmental_sensing=6170]="environmental_sensing",e[e.generic_access=6144]="generic_access",e[e.generic_attribute=6145]="generic_attribute",e[e.glucose=6152]="glucose",e[e.health_thermometer=6153]="health_thermometer",e[e.heart_rate=6157]="heart_rate",e[e.human_interface_device=6162]="human_interface_device",e[e.immediate_alert=6146]="immediate_alert",e[e.indoor_positioning=6177]="indoor_positioning",e[e.internet_protocol_support=6176]="internet_protocol_support",e[e.link_loss=6147]="link_loss",e[e.location_and_navigation=6169]="location_and_navigation",e[e.next_dst_change=6151]="next_dst_change",e[e.phone_alert_status=6158]="phone_alert_status",e[e.pulse_oximeter=6178]="pulse_oximeter",e[e.reference_time_update=6150]="reference_time_update",e[e.running_speed_and_cadence=6164]="running_speed_and_cadence",e[e.scan_parameters=6163]="scan_parameters",e[e.tx_power=6148]="tx_power",e[e.user_data=6172]="user_data",e[e.weight_scale=6173]="weight_scale"}(s||(s={})),function(e){e[e.aerobic_heart_rate_lower_limit=10878]="aerobic_heart_rate_lower_limit",e[e.aerobic_heart_rate_upper_limit=10884]="aerobic_heart_rate_upper_limit",e[e.aerobic_threshold=10879]="aerobic_threshold",e[e.age=10880]="age",e[e.aggregate=10842]="aggregate",e[e.alert_category_id=10819]="alert_category_id",e[e.alert_category_id_bit_mask=10818]="alert_category_id_bit_mask",e[e.alert_level=10758]="alert_level",e[e.alert_notification_control_point=10820]="alert_notification_control_point",e[e.alert_status=10815]="alert_status",e[e.altitude=10931]="altitude",e[e.anaerobic_heart_rate_lower_limit=10881]="anaerobic_heart_rate_lower_limit",e[e.anaerobic_heart_rate_upper_limit=10882]="anaerobic_heart_rate_upper_limit",e[e.anaerobic_threshold=10883]="anaerobic_threshold",e[e.analog=10840]="analog",e[e.apparent_wind_direction=10867]="apparent_wind_direction",e[e.apparent_wind_speed=10866]="apparent_wind_speed",e[e["gap.appearance"]=10753]="gap.appearance",e[e.barometric_pressure_trend=10915]="barometric_pressure_trend",e[e.battery_level=10777]="battery_level",e[e.blood_pressure_feature=10825]="blood_pressure_feature",e[e.blood_pressure_measurement=10805]="blood_pressure_measurement",e[e.body_composition_feature=10907]="body_composition_feature",e[e.body_composition_measurement=10908]="body_composition_measurement",e[e.body_sensor_location=10808]="body_sensor_location",e[e.bond_management_control_point=10916]="bond_management_control_point",e[e.bond_management_feature=10917]="bond_management_feature",e[e.boot_keyboard_input_report=10786]="boot_keyboard_input_report",e[e.boot_keyboard_output_report=10802]="boot_keyboard_output_report",e[e.boot_mouse_input_report=10803]="boot_mouse_input_report",e[e["gap.central_address_resolution_support"]=10918]="gap.central_address_resolution_support",e[e.cgm_feature=10920]="cgm_feature",e[e.cgm_measurement=10919]="cgm_measurement",e[e.cgm_session_run_time=10923]="cgm_session_run_time",e[e.cgm_session_start_time=10922]="cgm_session_start_time",e[e.cgm_specific_ops_control_point=10924]="cgm_specific_ops_control_point",e[e.cgm_status=10921]="cgm_status",e[e.csc_feature=10844]="csc_feature",e[e.csc_measurement=10843]="csc_measurement",e[e.current_time=10795]="current_time",e[e.cycling_power_control_point=10854]="cycling_power_control_point",e[e.cycling_power_feature=10853]="cycling_power_feature",e[e.cycling_power_measurement=10851]="cycling_power_measurement",e[e.cycling_power_vector=10852]="cycling_power_vector",e[e.database_change_increment=10905]="database_change_increment",e[e.date_of_birth=10885]="date_of_birth",e[e.date_of_threshold_assessment=10886]="date_of_threshold_assessment",e[e.date_time=10760]="date_time",e[e.day_date_time=10762]="day_date_time",e[e.day_of_week=10761]="day_of_week",e[e.descriptor_value_changed=10877]="descriptor_value_changed",e[e["gap.device_name"]=10752]="gap.device_name",e[e.dew_point=10875]="dew_point",e[e.digital=10838]="digital",e[e.dst_offset=10765]="dst_offset",e[e.elevation=10860]="elevation",e[e.email_address=10887]="email_address",e[e.exact_time_256=10764]="exact_time_256",e[e.fat_burn_heart_rate_lower_limit=10888]="fat_burn_heart_rate_lower_limit",e[e.fat_burn_heart_rate_upper_limit=10889]="fat_burn_heart_rate_upper_limit",e[e.firmware_revision_string=10790]="firmware_revision_string",e[e.first_name=10890]="first_name",e[e.five_zone_heart_rate_limits=10891]="five_zone_heart_rate_limits",e[e.floor_number=10930]="floor_number",e[e.gender=10892]="gender",e[e.glucose_feature=10833]="glucose_feature",e[e.glucose_measurement=10776]="glucose_measurement",e[e.glucose_measurement_context=10804]="glucose_measurement_context",e[e.gust_factor=10868]="gust_factor",e[e.hardware_revision_string=10791]="hardware_revision_string",e[e.heart_rate_control_point=10809]="heart_rate_control_point",e[e.heart_rate_max=10893]="heart_rate_max",e[e.heart_rate_measurement=10807]="heart_rate_measurement",e[e.heat_index=10874]="heat_index",e[e.height=10894]="height",e[e.hid_control_point=10828]="hid_control_point",e[e.hid_information=10826]="hid_information",e[e.hip_circumference=10895]="hip_circumference",e[e.humidity=10863]="humidity",e[e["ieee_11073-20601_regulatory_certification_data_list"]=10794]="ieee_11073-20601_regulatory_certification_data_list",e[e.indoor_positioning_configuration=10925]="indoor_positioning_configuration",e[e.intermediate_blood_pressure=10806]="intermediate_blood_pressure",e[e.intermediate_temperature=10782]="intermediate_temperature",e[e.irradiance=10871]="irradiance",e[e.language=10914]="language",e[e.last_name=10896]="last_name",e[e.latitude=10926]="latitude",e[e.ln_control_point=10859]="ln_control_point",e[e.ln_feature=10858]="ln_feature",e[e["local_east_coordinate.xml"]=10929]="local_east_coordinate.xml",e[e.local_north_coordinate=10928]="local_north_coordinate",e[e.local_time_information=10767]="local_time_information",e[e.location_and_speed=10855]="location_and_speed",e[e.location_name=10933]="location_name",e[e.longitude=10927]="longitude",e[e.magnetic_declination=10796]="magnetic_declination",e[e.magnetic_flux_density_2D=10912]="magnetic_flux_density_2D",e[e.magnetic_flux_density_3D=10913]="magnetic_flux_density_3D",e[e.manufacturer_name_string=10793]="manufacturer_name_string",e[e.maximum_recommended_heart_rate=10897]="maximum_recommended_heart_rate",e[e.measurement_interval=10785]="measurement_interval",e[e.model_number_string=10788]="model_number_string",e[e.navigation=10856]="navigation",e[e.new_alert=10822]="new_alert",e[e["gap.peripheral_preferred_connection_parameters"]=10756]="gap.peripheral_preferred_connection_parameters",e[e["gap.peripheral_privacy_flag"]=10754]="gap.peripheral_privacy_flag",e[e.plx_continuous_measurement=10847]="plx_continuous_measurement",e[e.plx_features=10848]="plx_features",e[e.plx_spot_check_measurement=10846]="plx_spot_check_measurement",e[e.pnp_id=10832]="pnp_id",e[e.pollen_concentration=10869]="pollen_concentration",e[e.position_quality=10857]="position_quality",e[e.pressure=10861]="pressure",e[e.protocol_mode=10830]="protocol_mode",e[e.rainfall=10872]="rainfall",e[e["gap.reconnection_address"]=10755]="gap.reconnection_address",e[e.record_access_control_point=10834]="record_access_control_point",e[e.reference_time_information=10772]="reference_time_information",e[e.report=10829]="report",e[e.report_map=10827]="report_map",e[e.resting_heart_rate=10898]="resting_heart_rate",e[e.ringer_control_point=10816]="ringer_control_point",e[e.ringer_setting=10817]="ringer_setting",e[e.rsc_feature=10836]="rsc_feature",e[e.rsc_measurement=10835]="rsc_measurement",e[e.sc_control_point=10837]="sc_control_point",e[e.scan_interval_window=10831]="scan_interval_window",e[e.scan_refresh=10801]="scan_refresh",e[e.sensor_location=10845]="sensor_location",e[e.serial_number_string=10789]="serial_number_string",e[e["gatt.service_changed"]=10757]="gatt.service_changed",e[e.software_revision_string=10792]="software_revision_string",e[e.sport_type_for_aerobic_and_anaerobic_thresholds=10899]="sport_type_for_aerobic_and_anaerobic_thresholds",e[e.supported_new_alert_category=10823]="supported_new_alert_category",e[e.supported_unread_alert_category=10824]="supported_unread_alert_category",e[e.system_id=10787]="system_id",e[e.temperature=10862]="temperature",e[e.temperature_measurement=10780]="temperature_measurement",e[e.temperature_type=10781]="temperature_type",e[e.three_zone_heart_rate_limits=10900]="three_zone_heart_rate_limits",e[e.time_accuracy=10770]="time_accuracy",e[e.time_source=10771]="time_source",e[e.time_update_control_point=10774]="time_update_control_point",e[e.time_update_state=10775]="time_update_state",e[e.time_with_dst=10769]="time_with_dst",e[e.time_zone=10766]="time_zone",e[e.true_wind_direction=10865]="true_wind_direction",e[e.true_wind_speed=10864]="true_wind_speed",e[e.two_zone_heart_rate_limit=10901]="two_zone_heart_rate_limit",e[e.tx_power_level=10759]="tx_power_level",e[e.uncertainty=10932]="uncertainty",e[e.unread_alert_status=10821]="unread_alert_status",e[e.user_control_point=10911]="user_control_point",e[e.user_index=10906]="user_index",e[e.uv_index=10870]="uv_index",e[e.vo2_max=10902]="vo2_max",e[e.waist_circumference=10903]="waist_circumference",e[e.weight=10904]="weight",e[e.weight_measurement=10909]="weight_measurement",e[e.weight_scale_feature=10910]="weight_scale_feature",e[e.wind_chill=10873]="wind_chill"}(a||(a={})),function(e){e[e["gatt.characteristic_extended_properties"]=10496]="gatt.characteristic_extended_properties",e[e["gatt.characteristic_user_description"]=10497]="gatt.characteristic_user_description",e[e["gatt.client_characteristic_configuration"]=10498]="gatt.client_characteristic_configuration",e[e["gatt.server_characteristic_configuration"]=10499]="gatt.server_characteristic_configuration",e[e["gatt.characteristic_presentation_format"]=10500]="gatt.characteristic_presentation_format",e[e["gatt.characteristic_aggregate_format"]=10501]="gatt.characteristic_aggregate_format",e[e.valid_range=10502]="valid_range",e[e.external_report_reference=10503]="external_report_reference",e[e.report_reference=10504]="report_reference",e[e.number_of_digitals=10505]="number_of_digitals",e[e.value_trigger_setting=10506]="value_trigger_setting",e[e.es_configuration=10507]="es_configuration",e[e.es_measurement=10508]="es_measurement",e[e.es_trigger_setting=10509]="es_trigger_setting",e[e.time_trigger_setting=10510]="time_trigger_setting"}(c||(c={}));class D extends d{constructor(){super(),this.deviceHandles={},this.serviceHandles={},this.characteristicHandles={},this.descriptorHandles={},this.charNotifies={},this.discoverFn=null,this.initialised=!1,this.enabled=!1,this.os="browser",this.enabled=this.state,e("stateChange",()=>{this.enabled!==this.state&&(this.enabled=this.state,this.emit(D.EVENT_ENABLED,this.enabled))})}get state(){return"poweredOn"===t}init(t){if(this.initialised)return t();e("discover",e=>{this.discoverFn&&this.discoverFn(e)}),this.initialised=!0,t()}checkForError(e,t,i){return function(r){if(r)e(r);else if("function"==typeof t){const e=[].slice.call(arguments,1);null===i?t.apply(this,e):setTimeout(()=>t.apply(this,e),i)}}}bufferToDataView(e){const t=new Uint8Array(e).buffer;return new DataView(t)}dataViewToBuffer(e){const t=new Uint8Array(e.buffer);return new Buffer(t)}validDevice(e,t){if(0===t.length)return!0;if(!e.advertisement.serviceUuids)return!1;const i=e.advertisement.serviceUuids.map(e=>y(e));return t.some(e=>i.indexOf(e)>=0)}deviceToBluetoothDevice(e){const t=e.address&&"unknown"!==e.address?e.address:e.id,i=[];e.advertisement.serviceUuids&&e.advertisement.serviceUuids.forEach(e=>{i.push(y(e))});const r=new Map;if(e.advertisement.manufacturerData){const t=e.advertisement.manufacturerData.readUInt16LE(0),i=e.advertisement.manufacturerData.slice(2);r.set(("0000"+t.toString(16)).slice(-4),this.bufferToDataView(i))}const n=new Map;return e.advertisement.serviceData&&e.advertisement.serviceData.forEach(e=>{n.set(y(e.uuid),this.bufferToDataView(e.data))}),{id:t,name:e.advertisement.localName,_serviceUUIDs:i,adData:{rssi:e.rssi,txPower:e.advertisement.txPowerLevel,serviceData:n,manufacturerData:r}}}getEnabled(e){function r(){e(this.state)}"unknown"===t||"poweredOff"===t?i("stateChange",r.bind(this)):r.call(this)}startScan(e,r,s,a){this.discoverFn=t=>{if(this.validDevice(t,e)){const e=this.deviceToBluetoothDevice(t);this.deviceHandles[e.id]||(this.deviceHandles[e.id]=t,r(e))}},this.init(()=>{function e(){!0===this.state?n([],!0,this.checkForError(a,s)):a("adapter not enabled")}this.deviceHandles={},"unknown"===t||"poweredOff"===t?i("stateChange",e.bind(this)):e.call(this)})}stopScan(e){this.discoverFn=null,r()}connect(e,t,i,r){const n=this.deviceHandles[e];n.removeAllListeners("connect"),n.removeAllListeners("disconnect"),n.once("connect",t),n.once("disconnect",()=>{this.serviceHandles={},this.characteristicHandles={},this.descriptorHandles={},this.charNotifies={},i()}),n.connect(this.checkForError(r))}disconnect(e,t){this.deviceHandles[e].disconnect(this.checkForError(t))}discoverServices(e,t,i,r){this.deviceHandles[e].discoverServices([],this.checkForError(r,e=>{const r=[];e.forEach(e=>{const i=y(e.uuid);(0===t.length||t.indexOf(i)>=0)&&(this.serviceHandles[i]||(this.serviceHandles[i]=e),r.push({uuid:i,primary:!0}))}),i(r)}))}discoverIncludedServices(e,t,i,r){this.serviceHandles[e].discoverIncludedServices([],this.checkForError(r,e=>{const r=[];e.forEach(e=>{const i=y(e.uuid);(0===t.length||t.indexOf(i)>=0)&&(this.serviceHandles[i]||(this.serviceHandles[i]=e),r.push({uuid:i,primary:!1}))},this),i(r)}))}discoverCharacteristics(e,t,i,r){this.serviceHandles[e].discoverCharacteristics([],this.checkForError(r,e=>{const r=[];e.forEach(e=>{const i=y(e.uuid);(0===t.length||t.indexOf(i)>=0)&&(this.characteristicHandles[i]||(this.characteristicHandles[i]=e),r.push({uuid:i,properties:{broadcast:e.properties.indexOf("broadcast")>=0,read:e.properties.indexOf("read")>=0,writeWithoutResponse:e.properties.indexOf("writeWithoutResponse")>=0,write:e.properties.indexOf("write")>=0,notify:e.properties.indexOf("notify")>=0,indicate:e.properties.indexOf("indicate")>=0,authenticatedSignedWrites:e.properties.indexOf("authenticatedSignedWrites")>=0,reliableWrite:e.properties.indexOf("reliableWrite")>=0,writableAuxiliaries:e.properties.indexOf("writableAuxiliaries")>=0}}),e.on("data",(e,t)=>{if(!0===t&&"function"==typeof this.charNotifies[i]){const t=this.bufferToDataView(e);this.charNotifies[i](t)}}))},this),i(r)}))}discoverDescriptors(e,t,i,r){const n=this.characteristicHandles[e];n.discoverDescriptors(this.checkForError(r,e=>{const r=[];e.forEach(e=>{const i=y(e.uuid);if(0===t.length||t.indexOf(i)>=0){const t=n.uuid+"-"+e.uuid;this.descriptorHandles[t]||(this.descriptorHandles[t]=e),r.push({uuid:i})}},this),i(r)}))}readCharacteristic(e,t,i){this.characteristicHandles[e].read(this.checkForError(i,e=>{const i=this.bufferToDataView(e);t(i)}))}writeCharacteristic(e,t,i,r){const n=this.dataViewToBuffer(t),s=this.characteristicHandles[e],a=s.properties.indexOf("writeWithoutResponse")>=0||s.properties.indexOf("authenticatedSignedWrites")>=0,c="darwin"!==this.os&&a?25:null;s.write(n,a,this.checkForError(r,i,c))}enableNotify(e,t,i,r){if(this.charNotifies[e])return this.charNotifies[e]=t,i();this.characteristicHandles[e].once("notify",n=>{if(!0!==n)return r("notify failed to enable");this.charNotifies[e]=t,i()}),this.characteristicHandles[e].notify(!0,this.checkForError(r))}disableNotify(e,t,i){if(!this.charNotifies[e])return t();this.characteristicHandles[e].once("notify",r=>{if(!1!==r)return i("notify failed to disable");this.charNotifies[e]&&delete this.charNotifies[e],t()}),this.characteristicHandles[e].notify(!1,this.checkForError(i))}readDescriptor(e,t,i){this.descriptorHandles[e].readValue(this.checkForError(i,e=>{const i=this.bufferToDataView(e);t(i)}))}writeDescriptor(e,t,i,r){const n=this.dataViewToBuffer(t);this.descriptorHandles[e].writeValue(n,this.checkForError(r,i))}}D.EVENT_ENABLED="enabledchanged";const P=new D;class S{constructor(e){this.characteristic=null,this.uuid=null,this._value=null,this.handle=null,this.characteristic=e.characteristic,this.uuid=e.uuid,this._value=e.value,this.handle=`${this.characteristic.uuid}-${this.uuid}`}get value(){return this._value}readValue(){return new Promise((e,t)=>{if(!this.characteristic.service.device.gatt.connected)return t("readValue error: device not connected");P.readDescriptor(this.handle,t=>{this._value=t,e(t)},e=>{t("readValue error: "+e)})})}writeValue(e){return new Promise((t,i)=>{if(!this.characteristic.service.device.gatt.connected)return i("writeValue error: device not connected");const r=void 0!==e.buffer?e.buffer:e;const n=new DataView(r);P.writeDescriptor(this.handle,n,()=>{this._value=n,t()},e=>{i("writeValue error: "+e)})})}}class k{constructor(e,t){this.bubbles=!0,this.cancelable=!1,this.cancelBubble=!1,this.composed=!1,this.defaultPrevented=!1,this.eventPhase=0,this.isTrusted=!0,this.returnValue=!0,this.target=e,this.srcElement=e,this.currentTarget=e,this.type=t}composedPath(){return[]}initEvent(e,t,i){this.type=e,this.bubbles=t,this.cancelable=i}preventDefault(){this.defaultPrevented=!0}stopImmediatePropagation(){}stopPropagation(){}}class O extends b{constructor(e){super(),this.service=null,this.uuid=null,this._value=null,this.handle=null,this.descriptors=null,this.service=e.service,this.uuid=e.uuid,this.properties=e.properties,this._value=e.value,this.handle=this.uuid}get value(){return this._value}set oncharacteristicvaluechanged(e){this._oncharacteristicvaluechanged&&this.removeEventListener("characteristicvaluechanged",this._oncharacteristicvaluechanged),this._oncharacteristicvaluechanged=e,this.addEventListener("characteristicvaluechanged",this._oncharacteristicvaluechanged)}setValue(e,t){this._value=e,t&&(this.dispatchEvent(new k(this,"characteristicvaluechanged")),this.service.dispatchEvent(new k(this,"characteristicvaluechanged")),this.service.device.dispatchEvent(new k(this,"characteristicvaluechanged")),this.service.device._bluetooth.dispatchEvent(new k(this,"characteristicvaluechanged")))}getDescriptor(e){return new Promise((t,i)=>this.service.device.gatt.connected?e?void this.getDescriptors(e).then(e=>{if(1!==e.length)return i("getDescriptor error: descriptor not found");t(e[0])}).catch(e=>{i("getDescriptor error: "+e)}):i("getDescriptor error: no descriptor specified"):i("getDescriptor error: device not connected"))}getDescriptors(e){return new Promise((t,i)=>{if(!this.service.device.gatt.connected)return i("getDescriptors error: device not connected");function r(){if(!e)return t(this.descriptors);const r=this.descriptors.filter(t=>t.uuid===L(e));if(1!==r.length)return i("getDescriptors error: descriptor not found");t(r)}if(this.descriptors)return r.call(this);P.discoverDescriptors(this.handle,[],e=>{this.descriptors=e.map(e=>(Object.assign(e,{characteristic:this}),new S(e))),r.call(this)},e=>{i("getDescriptors error: "+e)})})}readValue(){return new Promise((e,t)=>{if(!this.service.device.gatt.connected)return t("readValue error: device not connected");P.readCharacteristic(this.handle,t=>{this.setValue(t,!0),e(t)},e=>{t("readValue error: "+e)})})}writeValue(e){return new Promise((t,i)=>{if(!this.service.device.gatt.connected)return i("writeValue error: device not connected");const r=void 0!==e.buffer?e.buffer:e;const n=new DataView(r);P.writeCharacteristic(this.handle,n,()=>{this.setValue(n),t()},e=>{i("writeValue error: "+e)})})}startNotifications(){return new Promise((e,t)=>{if(!this.service.device.gatt.connected)return t("startNotifications error: device not connected");P.enableNotify(this.handle,e=>{this.setValue(e,!0)},()=>{e(this)},e=>{t("startNotifications error: "+e)})})}stopNotifications(){return new Promise((e,t)=>{if(!this.service.device.gatt.connected)return t("stopNotifications error: device not connected");P.disableNotify(this.handle,()=>{e(this)},e=>{t("stopNotifications error: "+e)})})}}class T extends b{constructor(e){super(),this.device=null,this.uuid=null,this.isPrimary=!1,this.handle=null,this.services=null,this.characteristics=null,this.device=e.device,this.uuid=e.uuid,this.isPrimary=e.isPrimary,this.handle=this.uuid,this.dispatchEvent(new k(this,"serviceadded")),this.device.dispatchEvent(new k(this,"serviceadded")),this.device._bluetooth.dispatchEvent(new k(this,"serviceadded"))}set oncharacteristicvaluechanged(e){this._oncharacteristicvaluechanged&&this.removeEventListener("characteristicvaluechanged",this._oncharacteristicvaluechanged),this._oncharacteristicvaluechanged=e,this.addEventListener("characteristicvaluechanged",this._oncharacteristicvaluechanged)}set onserviceadded(e){this._onserviceadded&&this.removeEventListener("serviceadded",this._onserviceadded),this._onserviceadded=e,this.addEventListener("serviceadded",this._onserviceadded)}set onservicechanged(e){this._onservicechanged&&this.removeEventListener("servicechanged",this._onservicechanged),this._onservicechanged=e,this.addEventListener("servicechanged",this._onservicechanged)}set onserviceremoved(e){this._onserviceremoved&&this.removeEventListener("serviceremoved",this._onserviceremoved),this._onserviceremoved=e,this.addEventListener("serviceremoved",this._onserviceremoved)}getCharacteristic(e){return new Promise((t,i)=>this.device.gatt.connected?e?void this.getCharacteristics(e).then(e=>{if(1!==e.length)return i("getCharacteristic error: characteristic not found");t(e[0])}).catch(e=>{i("getCharacteristic error: "+e)}):i("getCharacteristic error: no characteristic specified"):i("getCharacteristic error: device not connected"))}getCharacteristics(e){return new Promise((t,i)=>{if(!this.device.gatt.connected)return i("getCharacteristics error: device not connected");function r(){if(!e)return t(this.characteristics);e=x(e);const r=this.characteristics.filter(t=>t.uuid===e);if(1!==r.length)return i("getCharacteristics error: characteristic not found");t(r)}if(this.characteristics)return r.call(this);P.discoverCharacteristics(this.handle,[],e=>{this.characteristics=e.map(e=>(Object.assign(e,{service:this}),new O(e))),r.call(this)},e=>{i("getCharacteristics error: "+e)})})}getIncludedService(e){return new Promise((t,i)=>this.device.gatt.connected?e?void this.getIncludedServices(e).then(e=>{if(1!==e.length)return i("getIncludedService error: service not found");t(e[0])}).catch(e=>{i("getIncludedService error: "+e)}):i("getIncludedService error: no service specified"):i("getIncludedService error: device not connected"))}getIncludedServices(e){return new Promise((t,i)=>{if(!this.device.gatt.connected)return i("getIncludedServices error: device not connected");function r(){if(!e)return t(this.services);const r=this.services.filter(t=>t.uuid===E(e));if(1!==r.length)return i("getIncludedServices error: service not found");t(r)}if(this.services)return r.call(this);P.discoverIncludedServices(this.handle,this.device._allowedServices,e=>{this.services=e.map(e=>(Object.assign(e,{device:this.device}),new T(e))),r.call(this)},e=>{i("getIncludedServices error: "+e)})})}}class V{constructor(e){this.device=null,this._connected=!1,this.handle=null,this.services=null,this.device=e,this.handle=this.device.id}get connected(){return this._connected}connect(){return new Promise((e,t)=>{if(this.connected)return t("connect error: device already connected");P.connect(this.handle,()=>{this._connected=!0,e(this)},()=>{this.services=null,this._connected=!1,this.device.dispatchEvent(new k(this.device,"gattserverdisconnected")),this.device._bluetooth.dispatchEvent(new k(this.device,"gattserverdisconnected"))},e=>{t("connect Error: "+e)})})}disconnect(){P.disconnect(this.handle),this._connected=!1}getPrimaryService(e){return new Promise((t,i)=>this.connected?e?void this.getPrimaryServices(e).then(e=>{if(1!==e.length)return i("getPrimaryService error: service not found");t(e[0])}).catch(e=>{i("getPrimaryService error: "+e)}):i("getPrimaryService error: no service specified"):i("getPrimaryService error: device not connected"))}getPrimaryServices(e){return new Promise((t,i)=>{if(!this.connected)return i("getPrimaryServices error: device not connected");function r(){if(!e)return t(this.services);const r=this.services.filter(t=>t.uuid===E(e));if(1!==r.length)return i("getPrimaryServices error: service not found");t(r)}if(this.services)return r.call(this);P.discoverServices(this.handle,this.device._allowedServices,e=>{this.services=e.map(e=>(Object.assign(e,{device:this.device}),new T(e))),r.call(this)},e=>{i("getPrimaryServices error: "+e)})})}}class C extends b{constructor(e){super(),this.id=null,this.name=null,this.gatt=null,this.watchingAdvertisements=!1,this._bluetooth=null,this._allowedServices=[],this._serviceUUIDs=[],this.id=e.id,this.name=e.name,this.gatt=e.gatt,this.watchAdvertisements=e.watchAdvertisements,this.adData=e.adData,this._bluetooth=e._bluetooth,this._allowedServices=e._allowedServices,this._serviceUUIDs=e._serviceUUIDs,this.name||(this.name=`Unknown or Unsupported Device (${this.id})`),this.gatt||(this.gatt=new V(this))}set oncharacteristicvaluechanged(e){this._oncharacteristicvaluechanged&&this.removeEventListener("characteristicvaluechanged",this._oncharacteristicvaluechanged),this._oncharacteristicvaluechanged=e,this.addEventListener("characteristicvaluechanged",this._oncharacteristicvaluechanged)}set onserviceadded(e){this._onserviceadded&&this.removeEventListener("serviceadded",this._onserviceadded),this._onserviceadded=e,this.addEventListener("serviceadded",this._onserviceadded)}set onservicechanged(e){this._onservicechanged&&this.removeEventListener("servicechanged",this._onservicechanged),this._onservicechanged=e,this.addEventListener("servicechanged",this._onservicechanged)}set onserviceremoved(e){this._onserviceremoved&&this.removeEventListener("serviceremoved",this._onserviceremoved),this._onserviceremoved=e,this.addEventListener("serviceremoved",this._onserviceremoved)}set ongattserverdisconnected(e){this._ongattserverdisconnected&&this.removeEventListener("gattserverdisconnected",this._ongattserverdisconnected),this._ongattserverdisconnected=e,this.addEventListener("gattserverdisconnected",this._ongattserverdisconnected)}set onadvertisementreceived(e){this._onadvertisementreceived&&this.removeEventListener("advertisementreceived",this._onadvertisementreceived),this._onadvertisementreceived=e,this.addEventListener("advertisementreceived",this._onadvertisementreceived)}watchAdvertisements(){return new Promise((e,t)=>{t("watchAdvertisements error: method not implemented")})}unwatchAdvertisements(){return new Promise((e,t)=>{t("unwatchAdvertisements error: method not implemented")})}}class H extends b{constructor(e){super(),this.deviceFound=null,this.scanTime=10240,this.scanner=null,e=e||{},this.referringDevice=e.referringDevice,this.deviceFound=e.deviceFound,e.scanTime&&(this.scanTime=1e3*e.scanTime),P.on(D.EVENT_ENABLED,e=>{this.dispatchEvent(new k(this,"availabilitychanged"))})}set oncharacteristicvaluechanged(e){this._oncharacteristicvaluechanged&&this.removeEventListener("characteristicvaluechanged",this._oncharacteristicvaluechanged),this._oncharacteristicvaluechanged=e,this.addEventListener("characteristicvaluechanged",this._oncharacteristicvaluechanged)}set onserviceadded(e){this._onserviceadded&&this.removeEventListener("serviceadded",this._onserviceadded),this._onserviceadded=e,this.addEventListener("serviceadded",this._onserviceadded)}set onservicechanged(e){this._onservicechanged&&this.removeEventListener("servicechanged",this._onservicechanged),this._onservicechanged=e,this.addEventListener("servicechanged",this._onservicechanged)}set onserviceremoved(e){this._onserviceremoved&&this.removeEventListener("serviceremoved",this._onserviceremoved),this._onserviceremoved=e,this.addEventListener("serviceremoved",this._onserviceremoved)}set ongattserverdisconnected(e){this._ongattserverdisconnected&&this.removeEventListener("gattserverdisconnected",this._ongattserverdisconnected),this._ongattserverdisconnected=e,this.addEventListener("gattserverdisconnected",this._ongattserverdisconnected)}set onadvertisementreceived(e){this._onadvertisementreceived&&this.removeEventListener("advertisementreceived",this._onadvertisementreceived),this._onadvertisementreceived=e,this.addEventListener("advertisementreceived",this._onadvertisementreceived)}set onavailabilitychanged(e){this._onavailabilitychanged&&this.removeEventListener("availabilitychanged",this._onavailabilitychanged),this._onavailabilitychanged=e,this.addEventListener("availabilitychanged",this._onavailabilitychanged)}filterDevice(e,t,i){let r=!1;return e.forEach(e=>{if(!e.name||e.name===t.name){if(e.namePrefix){if(!t.name||e.namePrefix.length>t.name.length)return;if(e.namePrefix!==t.name.substr(0,e.namePrefix.length))return}if(e.services){const r=e.services.map(E);if(!r.every(e=>t._serviceUUIDs.indexOf(e)>-1))return;i=i.concat(r)}r=!0}}),!!r&&t}getAvailability(){return new Promise((e,t)=>{P.getEnabled(t=>{e(t)})})}requestDevice(e={filters:[]}){return new Promise((t,i)=>{if(null!==this.scanner)return i("requestDevice error: request in progress");const r=e=>void 0!==e.filters;let n=[];if(r(e)){if(0===e.filters.length)return i(new TypeError("requestDevice error: no filters specified"));if(e.filters.some(e=>0===Object.keys(e).length))return i(new TypeError("requestDevice error: empty filter specified"));if(e.filters.some(e=>void 0!==e.namePrefix&&""===e.namePrefix))return i(new TypeError("requestDevice error: empty namePrefix specified"));e.filters.forEach(e=>{e.services&&(n=n.concat(e.services.map(E))),n=n.filter((e,t,i)=>i.indexOf(e)===t)})}else if(!0!==e.acceptAllDevices)return i(new TypeError("requestDevice error: specify filters or acceptAllDevices"));let s=!1;P.startScan(n,i=>{let n=[];function a(e){this.cancelRequest().then(()=>{t(e)})}if(r(e)&&(i=this.filterDevice(e.filters,i,n)),i){s=!0,e.optionalServices&&(n=n.concat(e.optionalServices.map(E)));const t=n.filter((e,t,i)=>i.indexOf(e)===t);Object.assign(i,{_bluetooth:this,_allowedServices:t});const r=new C(i);this.deviceFound&&!0!==this.deviceFound(r,function(){a.call(this,r)}.bind(this))||a.call(this,r)}},()=>{this.scanner=setTimeout(()=>{this.cancelRequest().then(()=>{s||i("requestDevice error: no devices found")})},this.scanTime)},e=>i("requestDevice error: "+e))})}cancelRequest(){return new Promise((e,t)=>{this.scanner&&(clearTimeout(this.scanner),this.scanner=null,P.stopScan()),e()})}}H.EVENT_AVAILABILITY="availabilitychanged";const N=new H;export{H as Bluetooth,N as bluetooth,a as bluetoothCharacteristics,c as bluetoothDescriptors,s as bluetoothServices,y as getCanonicalUUID,x as getCharacteristicUUID,L as getDescriptorUUID,E as getServiceUUID}; | ||
//# sourceMappingURL=webbluetooth.esm.js.map |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@abandonware/noble")):"function"==typeof define&&define.amd?define(["exports","@abandonware/noble"],t):t((e=e||self).webbluetooth={},e.noble)}(this,(function(e,t){"use strict";var i,r,n;function s(){}function a(){a.init.call(this)}function c(e){return void 0===e._maxListeners?a.defaultMaxListeners:e._maxListeners}function o(e,t,i){if(t)e.call(i);else for(var r=e.length,n=p(e,r),s=0;s<r;++s)n[s].call(i)}function d(e,t,i,r){if(t)e.call(i,r);else for(var n=e.length,s=p(e,n),a=0;a<n;++a)s[a].call(i,r)}function h(e,t,i,r,n){if(t)e.call(i,r,n);else for(var s=e.length,a=p(e,s),c=0;c<s;++c)a[c].call(i,r,n)}function _(e,t,i,r,n,s){if(t)e.call(i,r,n,s);else for(var a=e.length,c=p(e,a),o=0;o<a;++o)c[o].call(i,r,n,s)}function l(e,t,i,r){if(t)e.apply(i,r);else for(var n=e.length,s=p(e,n),a=0;a<n;++a)s[a].apply(i,r)}function u(e,t,i,r){var n,a,o,d;if("function"!=typeof i)throw new TypeError('"listener" argument must be a function');if((a=e._events)?(a.newListener&&(e.emit("newListener",t,i.listener?i.listener:i),a=e._events),o=a[t]):(a=e._events=new s,e._eventsCount=0),o){if("function"==typeof o?o=a[t]=r?[i,o]:[o,i]:r?o.unshift(i):o.push(i),!o.warned&&(n=c(e))&&n>0&&o.length>n){o.warned=!0;var h=new Error("Possible EventEmitter memory leak detected. "+o.length+" "+t+" listeners added. Use emitter.setMaxListeners() to increase limit");h.name="MaxListenersExceededWarning",h.emitter=e,h.type=t,h.count=o.length,d=h,"function"==typeof console.warn?console.warn(d):console.log(d)}}else o=a[t]=i,++e._eventsCount;return e}function v(e,t,i){var r=!1;function n(){e.removeListener(t,n),r||(r=!0,i.apply(e,arguments))}return n.listener=i,n}function m(e){var t=this._events;if(t){var i=t[e];if("function"==typeof i)return 1;if(i)return i.length}return 0}function p(e,t){for(var i=new Array(t);t--;)i[t]=e[t];return i}s.prototype=Object.create(null),a.EventEmitter=a,a.usingDomains=!1,a.prototype.domain=void 0,a.prototype._events=void 0,a.prototype._maxListeners=void 0,a.defaultMaxListeners=10,a.init=function(){this.domain=null,a.usingDomains&&(void 0).active&&(void 0).Domain,this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=new s,this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},a.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||isNaN(e))throw new TypeError('"n" argument must be a positive number');return this._maxListeners=e,this},a.prototype.getMaxListeners=function(){return c(this)},a.prototype.emit=function(e){var t,i,r,n,s,a,c,u="error"===e;if(a=this._events)u=u&&null==a.error;else if(!u)return!1;if(c=this.domain,u){if(t=arguments[1],!c){if(t instanceof Error)throw t;var v=new Error('Uncaught, unspecified "error" event. ('+t+")");throw v.context=t,v}return t||(t=new Error('Uncaught, unspecified "error" event')),t.domainEmitter=this,t.domain=c,t.domainThrown=!1,c.emit("error",t),!1}if(!(i=a[e]))return!1;var m="function"==typeof i;switch(r=arguments.length){case 1:o(i,m,this);break;case 2:d(i,m,this,arguments[1]);break;case 3:h(i,m,this,arguments[1],arguments[2]);break;case 4:_(i,m,this,arguments[1],arguments[2],arguments[3]);break;default:for(n=new Array(r-1),s=1;s<r;s++)n[s-1]=arguments[s];l(i,m,this,n)}return!0},a.prototype.addListener=function(e,t){return u(this,e,t,!1)},a.prototype.on=a.prototype.addListener,a.prototype.prependListener=function(e,t){return u(this,e,t,!0)},a.prototype.once=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.on(e,v(this,e,t)),this},a.prototype.prependOnceListener=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.prependListener(e,v(this,e,t)),this},a.prototype.removeListener=function(e,t){var i,r,n,a,c;if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');if(!(r=this._events))return this;if(!(i=r[e]))return this;if(i===t||i.listener&&i.listener===t)0==--this._eventsCount?this._events=new s:(delete r[e],r.removeListener&&this.emit("removeListener",e,i.listener||t));else if("function"!=typeof i){for(n=-1,a=i.length;a-- >0;)if(i[a]===t||i[a].listener&&i[a].listener===t){c=i[a].listener,n=a;break}if(n<0)return this;if(1===i.length){if(i[0]=void 0,0==--this._eventsCount)return this._events=new s,this;delete r[e]}else!function(e,t){for(var i=t,r=i+1,n=e.length;r<n;i+=1,r+=1)e[i]=e[r];e.pop()}(i,n);r.removeListener&&this.emit("removeListener",e,c||t)}return this},a.prototype.removeAllListeners=function(e){var t,i;if(!(i=this._events))return this;if(!i.removeListener)return 0===arguments.length?(this._events=new s,this._eventsCount=0):i[e]&&(0==--this._eventsCount?this._events=new s:delete i[e]),this;if(0===arguments.length){for(var r,n=Object.keys(i),a=0;a<n.length;++a)"removeListener"!==(r=n[a])&&this.removeAllListeners(r);return this.removeAllListeners("removeListener"),this._events=new s,this._eventsCount=0,this}if("function"==typeof(t=i[e]))this.removeListener(e,t);else if(t)do{this.removeListener(e,t[t.length-1])}while(t[0]);return this},a.prototype.listeners=function(e){var t,i=this._events;return i&&(t=i[e])?"function"==typeof t?[t.listener||t]:function(e){for(var t=new Array(e.length),i=0;i<t.length;++i)t[i]=e[i].listener||e[i];return t}(t):[]},a.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):m.call(e,t)},a.prototype.listenerCount=m,a.prototype.eventNames=function(){return this._eventsCount>0?Reflect.ownKeys(this._events):[]};class f extends a{constructor(){super(...arguments),this.isEventListenerObject=e=>void 0!==e.handleEvent}addEventListener(e,t){if(t){const i=this.isEventListenerObject(t)?t.handleEvent:t;super.addListener(e,i)}}removeEventListener(e,t){if(t){const i=this.isEventListenerObject(t)?t.handleEvent:t;super.removeListener(e,i)}}dispatchEvent(e){return super.emit(e.type,e)}}function g(e){return"number"==typeof e&&(e=e.toString(16)),(e=e.toLowerCase()).length<=8&&(e=("00000000"+e).slice(-8)+"-0000-1000-8000-00805f9b34fb"),32===e.length&&(e=e.match(/^([0-9a-f]{8})([0-9a-f]{4})([0-9a-f]{4})([0-9a-f]{4})([0-9a-f]{12})$/).splice(1).join("-")),e}function w(t){return"string"==typeof t&&e.bluetoothServices[t]&&(t=e.bluetoothServices[t]),g(t)}function b(t){return"string"==typeof t&&e.bluetoothCharacteristics[t]&&(t=e.bluetoothCharacteristics[t]),g(t)}function y(t){return"string"==typeof t&&e.bluetoothDescriptors[t]&&(t=e.bluetoothDescriptors[t]),g(t)}(i=e.bluetoothServices||(e.bluetoothServices={}))[i.alert_notification=6161]="alert_notification",i[i.automation_io=6165]="automation_io",i[i.battery_service=6159]="battery_service",i[i.blood_pressure=6160]="blood_pressure",i[i.body_composition=6171]="body_composition",i[i.bond_management=6174]="bond_management",i[i.continuous_glucose_monitoring=6175]="continuous_glucose_monitoring",i[i.current_time=6149]="current_time",i[i.cycling_power=6168]="cycling_power",i[i.cycling_speed_and_cadence=6166]="cycling_speed_and_cadence",i[i.device_information=6154]="device_information",i[i.environmental_sensing=6170]="environmental_sensing",i[i.generic_access=6144]="generic_access",i[i.generic_attribute=6145]="generic_attribute",i[i.glucose=6152]="glucose",i[i.health_thermometer=6153]="health_thermometer",i[i.heart_rate=6157]="heart_rate",i[i.human_interface_device=6162]="human_interface_device",i[i.immediate_alert=6146]="immediate_alert",i[i.indoor_positioning=6177]="indoor_positioning",i[i.internet_protocol_support=6176]="internet_protocol_support",i[i.link_loss=6147]="link_loss",i[i.location_and_navigation=6169]="location_and_navigation",i[i.next_dst_change=6151]="next_dst_change",i[i.phone_alert_status=6158]="phone_alert_status",i[i.pulse_oximeter=6178]="pulse_oximeter",i[i.reference_time_update=6150]="reference_time_update",i[i.running_speed_and_cadence=6164]="running_speed_and_cadence",i[i.scan_parameters=6163]="scan_parameters",i[i.tx_power=6148]="tx_power",i[i.user_data=6172]="user_data",i[i.weight_scale=6173]="weight_scale",(r=e.bluetoothCharacteristics||(e.bluetoothCharacteristics={}))[r.aerobic_heart_rate_lower_limit=10878]="aerobic_heart_rate_lower_limit",r[r.aerobic_heart_rate_upper_limit=10884]="aerobic_heart_rate_upper_limit",r[r.aerobic_threshold=10879]="aerobic_threshold",r[r.age=10880]="age",r[r.aggregate=10842]="aggregate",r[r.alert_category_id=10819]="alert_category_id",r[r.alert_category_id_bit_mask=10818]="alert_category_id_bit_mask",r[r.alert_level=10758]="alert_level",r[r.alert_notification_control_point=10820]="alert_notification_control_point",r[r.alert_status=10815]="alert_status",r[r.altitude=10931]="altitude",r[r.anaerobic_heart_rate_lower_limit=10881]="anaerobic_heart_rate_lower_limit",r[r.anaerobic_heart_rate_upper_limit=10882]="anaerobic_heart_rate_upper_limit",r[r.anaerobic_threshold=10883]="anaerobic_threshold",r[r.analog=10840]="analog",r[r.apparent_wind_direction=10867]="apparent_wind_direction",r[r.apparent_wind_speed=10866]="apparent_wind_speed",r[r["gap.appearance"]=10753]="gap.appearance",r[r.barometric_pressure_trend=10915]="barometric_pressure_trend",r[r.battery_level=10777]="battery_level",r[r.blood_pressure_feature=10825]="blood_pressure_feature",r[r.blood_pressure_measurement=10805]="blood_pressure_measurement",r[r.body_composition_feature=10907]="body_composition_feature",r[r.body_composition_measurement=10908]="body_composition_measurement",r[r.body_sensor_location=10808]="body_sensor_location",r[r.bond_management_control_point=10916]="bond_management_control_point",r[r.bond_management_feature=10917]="bond_management_feature",r[r.boot_keyboard_input_report=10786]="boot_keyboard_input_report",r[r.boot_keyboard_output_report=10802]="boot_keyboard_output_report",r[r.boot_mouse_input_report=10803]="boot_mouse_input_report",r[r["gap.central_address_resolution_support"]=10918]="gap.central_address_resolution_support",r[r.cgm_feature=10920]="cgm_feature",r[r.cgm_measurement=10919]="cgm_measurement",r[r.cgm_session_run_time=10923]="cgm_session_run_time",r[r.cgm_session_start_time=10922]="cgm_session_start_time",r[r.cgm_specific_ops_control_point=10924]="cgm_specific_ops_control_point",r[r.cgm_status=10921]="cgm_status",r[r.csc_feature=10844]="csc_feature",r[r.csc_measurement=10843]="csc_measurement",r[r.current_time=10795]="current_time",r[r.cycling_power_control_point=10854]="cycling_power_control_point",r[r.cycling_power_feature=10853]="cycling_power_feature",r[r.cycling_power_measurement=10851]="cycling_power_measurement",r[r.cycling_power_vector=10852]="cycling_power_vector",r[r.database_change_increment=10905]="database_change_increment",r[r.date_of_birth=10885]="date_of_birth",r[r.date_of_threshold_assessment=10886]="date_of_threshold_assessment",r[r.date_time=10760]="date_time",r[r.day_date_time=10762]="day_date_time",r[r.day_of_week=10761]="day_of_week",r[r.descriptor_value_changed=10877]="descriptor_value_changed",r[r["gap.device_name"]=10752]="gap.device_name",r[r.dew_point=10875]="dew_point",r[r.digital=10838]="digital",r[r.dst_offset=10765]="dst_offset",r[r.elevation=10860]="elevation",r[r.email_address=10887]="email_address",r[r.exact_time_256=10764]="exact_time_256",r[r.fat_burn_heart_rate_lower_limit=10888]="fat_burn_heart_rate_lower_limit",r[r.fat_burn_heart_rate_upper_limit=10889]="fat_burn_heart_rate_upper_limit",r[r.firmware_revision_string=10790]="firmware_revision_string",r[r.first_name=10890]="first_name",r[r.five_zone_heart_rate_limits=10891]="five_zone_heart_rate_limits",r[r.floor_number=10930]="floor_number",r[r.gender=10892]="gender",r[r.glucose_feature=10833]="glucose_feature",r[r.glucose_measurement=10776]="glucose_measurement",r[r.glucose_measurement_context=10804]="glucose_measurement_context",r[r.gust_factor=10868]="gust_factor",r[r.hardware_revision_string=10791]="hardware_revision_string",r[r.heart_rate_control_point=10809]="heart_rate_control_point",r[r.heart_rate_max=10893]="heart_rate_max",r[r.heart_rate_measurement=10807]="heart_rate_measurement",r[r.heat_index=10874]="heat_index",r[r.height=10894]="height",r[r.hid_control_point=10828]="hid_control_point",r[r.hid_information=10826]="hid_information",r[r.hip_circumference=10895]="hip_circumference",r[r.humidity=10863]="humidity",r[r["ieee_11073-20601_regulatory_certification_data_list"]=10794]="ieee_11073-20601_regulatory_certification_data_list",r[r.indoor_positioning_configuration=10925]="indoor_positioning_configuration",r[r.intermediate_blood_pressure=10806]="intermediate_blood_pressure",r[r.intermediate_temperature=10782]="intermediate_temperature",r[r.irradiance=10871]="irradiance",r[r.language=10914]="language",r[r.last_name=10896]="last_name",r[r.latitude=10926]="latitude",r[r.ln_control_point=10859]="ln_control_point",r[r.ln_feature=10858]="ln_feature",r[r["local_east_coordinate.xml"]=10929]="local_east_coordinate.xml",r[r.local_north_coordinate=10928]="local_north_coordinate",r[r.local_time_information=10767]="local_time_information",r[r.location_and_speed=10855]="location_and_speed",r[r.location_name=10933]="location_name",r[r.longitude=10927]="longitude",r[r.magnetic_declination=10796]="magnetic_declination",r[r.magnetic_flux_density_2D=10912]="magnetic_flux_density_2D",r[r.magnetic_flux_density_3D=10913]="magnetic_flux_density_3D",r[r.manufacturer_name_string=10793]="manufacturer_name_string",r[r.maximum_recommended_heart_rate=10897]="maximum_recommended_heart_rate",r[r.measurement_interval=10785]="measurement_interval",r[r.model_number_string=10788]="model_number_string",r[r.navigation=10856]="navigation",r[r.new_alert=10822]="new_alert",r[r["gap.peripheral_preferred_connection_parameters"]=10756]="gap.peripheral_preferred_connection_parameters",r[r["gap.peripheral_privacy_flag"]=10754]="gap.peripheral_privacy_flag",r[r.plx_continuous_measurement=10847]="plx_continuous_measurement",r[r.plx_features=10848]="plx_features",r[r.plx_spot_check_measurement=10846]="plx_spot_check_measurement",r[r.pnp_id=10832]="pnp_id",r[r.pollen_concentration=10869]="pollen_concentration",r[r.position_quality=10857]="position_quality",r[r.pressure=10861]="pressure",r[r.protocol_mode=10830]="protocol_mode",r[r.rainfall=10872]="rainfall",r[r["gap.reconnection_address"]=10755]="gap.reconnection_address",r[r.record_access_control_point=10834]="record_access_control_point",r[r.reference_time_information=10772]="reference_time_information",r[r.report=10829]="report",r[r.report_map=10827]="report_map",r[r.resting_heart_rate=10898]="resting_heart_rate",r[r.ringer_control_point=10816]="ringer_control_point",r[r.ringer_setting=10817]="ringer_setting",r[r.rsc_feature=10836]="rsc_feature",r[r.rsc_measurement=10835]="rsc_measurement",r[r.sc_control_point=10837]="sc_control_point",r[r.scan_interval_window=10831]="scan_interval_window",r[r.scan_refresh=10801]="scan_refresh",r[r.sensor_location=10845]="sensor_location",r[r.serial_number_string=10789]="serial_number_string",r[r["gatt.service_changed"]=10757]="gatt.service_changed",r[r.software_revision_string=10792]="software_revision_string",r[r.sport_type_for_aerobic_and_anaerobic_thresholds=10899]="sport_type_for_aerobic_and_anaerobic_thresholds",r[r.supported_new_alert_category=10823]="supported_new_alert_category",r[r.supported_unread_alert_category=10824]="supported_unread_alert_category",r[r.system_id=10787]="system_id",r[r.temperature=10862]="temperature",r[r.temperature_measurement=10780]="temperature_measurement",r[r.temperature_type=10781]="temperature_type",r[r.three_zone_heart_rate_limits=10900]="three_zone_heart_rate_limits",r[r.time_accuracy=10770]="time_accuracy",r[r.time_source=10771]="time_source",r[r.time_update_control_point=10774]="time_update_control_point",r[r.time_update_state=10775]="time_update_state",r[r.time_with_dst=10769]="time_with_dst",r[r.time_zone=10766]="time_zone",r[r.true_wind_direction=10865]="true_wind_direction",r[r.true_wind_speed=10864]="true_wind_speed",r[r.two_zone_heart_rate_limit=10901]="two_zone_heart_rate_limit",r[r.tx_power_level=10759]="tx_power_level",r[r.uncertainty=10932]="uncertainty",r[r.unread_alert_status=10821]="unread_alert_status",r[r.user_control_point=10911]="user_control_point",r[r.user_index=10906]="user_index",r[r.uv_index=10870]="uv_index",r[r.vo2_max=10902]="vo2_max",r[r.waist_circumference=10903]="waist_circumference",r[r.weight=10904]="weight",r[r.weight_measurement=10909]="weight_measurement",r[r.weight_scale_feature=10910]="weight_scale_feature",r[r.wind_chill=10873]="wind_chill",(n=e.bluetoothDescriptors||(e.bluetoothDescriptors={}))[n["gatt.characteristic_extended_properties"]=10496]="gatt.characteristic_extended_properties",n[n["gatt.characteristic_user_description"]=10497]="gatt.characteristic_user_description",n[n["gatt.client_characteristic_configuration"]=10498]="gatt.client_characteristic_configuration",n[n["gatt.server_characteristic_configuration"]=10499]="gatt.server_characteristic_configuration",n[n["gatt.characteristic_presentation_format"]=10500]="gatt.characteristic_presentation_format",n[n["gatt.characteristic_aggregate_format"]=10501]="gatt.characteristic_aggregate_format",n[n.valid_range=10502]="valid_range",n[n.external_report_reference=10503]="external_report_reference",n[n.report_reference=10504]="report_reference",n[n.number_of_digitals=10505]="number_of_digitals",n[n.value_trigger_setting=10506]="value_trigger_setting",n[n.es_configuration=10507]="es_configuration",n[n.es_measurement=10508]="es_measurement",n[n.es_trigger_setting=10509]="es_trigger_setting",n[n.time_trigger_setting=10510]="time_trigger_setting";class E extends a{constructor(){super(),this.deviceHandles={},this.serviceHandles={},this.characteristicHandles={},this.descriptorHandles={},this.charNotifies={},this.discoverFn=null,this.initialised=!1,this.enabled=!1,this.os="browser",this.enabled=this.state,t.on("stateChange",()=>{this.enabled!==this.state&&(this.enabled=this.state,this.emit(E.EVENT_ENABLED,this.enabled))})}get state(){return"poweredOn"===t.state}init(e){if(this.initialised)return e();t.on("discover",e=>{this.discoverFn&&this.discoverFn(e)}),this.initialised=!0,e()}checkForError(e,t,i){return function(r){if(r)e(r);else if("function"==typeof t){const e=[].slice.call(arguments,1);null===i?t.apply(this,e):setTimeout(()=>t.apply(this,e),i)}}}bufferToDataView(e){const t=new Uint8Array(e).buffer;return new DataView(t)}dataViewToBuffer(e){const t=new Uint8Array(e.buffer);return new Buffer(t)}validDevice(e,t){if(0===t.length)return!0;if(!e.advertisement.serviceUuids)return!1;const i=e.advertisement.serviceUuids.map(e=>g(e));return t.some(e=>i.indexOf(e)>=0)}deviceToBluetoothDevice(e){const t=e.address&&"unknown"!==e.address?e.address:e.id,i=[];e.advertisement.serviceUuids&&e.advertisement.serviceUuids.forEach(e=>{i.push(g(e))});const r=new Map;if(e.advertisement.manufacturerData){const t=e.advertisement.manufacturerData.readUInt16LE(0),i=e.advertisement.manufacturerData.slice(2);r.set(("0000"+t.toString(16)).slice(-4),this.bufferToDataView(i))}const n=new Map;return e.advertisement.serviceData&&e.advertisement.serviceData.forEach(e=>{n.set(g(e.uuid),this.bufferToDataView(e.data))}),{id:t,name:e.advertisement.localName,_serviceUUIDs:i,adData:{rssi:e.rssi,txPower:e.advertisement.txPowerLevel,serviceData:n,manufacturerData:r}}}getEnabled(e){function i(){e(this.state)}"unknown"===t.state||"poweredOff"===t.state?t.once("stateChange",i.bind(this)):i.call(this)}startScan(e,i,r,n){this.discoverFn=t=>{if(this.validDevice(t,e)){const e=this.deviceToBluetoothDevice(t);this.deviceHandles[e.id]||(this.deviceHandles[e.id]=t,i(e))}},this.init(()=>{function e(){!0===this.state?t.startScanning([],!0,this.checkForError(n,r)):n("adapter not enabled")}this.deviceHandles={},"unknown"===t.state||"poweredOff"===t.state?t.once("stateChange",e.bind(this)):e.call(this)})}stopScan(e){this.discoverFn=null,t.stopScanning()}connect(e,t,i,r){const n=this.deviceHandles[e];n.removeAllListeners("connect"),n.removeAllListeners("disconnect"),n.once("connect",t),n.once("disconnect",()=>{this.serviceHandles={},this.characteristicHandles={},this.descriptorHandles={},this.charNotifies={},i()}),n.connect(this.checkForError(r))}disconnect(e,t){this.deviceHandles[e].disconnect(this.checkForError(t))}discoverServices(e,t,i,r){this.deviceHandles[e].discoverServices([],this.checkForError(r,e=>{const r=[];e.forEach(e=>{const i=g(e.uuid);(0===t.length||t.indexOf(i)>=0)&&(this.serviceHandles[i]||(this.serviceHandles[i]=e),r.push({uuid:i,primary:!0}))}),i(r)}))}discoverIncludedServices(e,t,i,r){this.serviceHandles[e].discoverIncludedServices([],this.checkForError(r,e=>{const r=[];e.forEach(e=>{const i=g(e.uuid);(0===t.length||t.indexOf(i)>=0)&&(this.serviceHandles[i]||(this.serviceHandles[i]=e),r.push({uuid:i,primary:!1}))},this),i(r)}))}discoverCharacteristics(e,t,i,r){this.serviceHandles[e].discoverCharacteristics([],this.checkForError(r,e=>{const r=[];e.forEach(e=>{const i=g(e.uuid);(0===t.length||t.indexOf(i)>=0)&&(this.characteristicHandles[i]||(this.characteristicHandles[i]=e),r.push({uuid:i,properties:{broadcast:e.properties.indexOf("broadcast")>=0,read:e.properties.indexOf("read")>=0,writeWithoutResponse:e.properties.indexOf("writeWithoutResponse")>=0,write:e.properties.indexOf("write")>=0,notify:e.properties.indexOf("notify")>=0,indicate:e.properties.indexOf("indicate")>=0,authenticatedSignedWrites:e.properties.indexOf("authenticatedSignedWrites")>=0,reliableWrite:e.properties.indexOf("reliableWrite")>=0,writableAuxiliaries:e.properties.indexOf("writableAuxiliaries")>=0}}),e.on("data",(e,t)=>{if(!0===t&&"function"==typeof this.charNotifies[i]){const t=this.bufferToDataView(e);this.charNotifies[i](t)}}))},this),i(r)}))}discoverDescriptors(e,t,i,r){const n=this.characteristicHandles[e];n.discoverDescriptors(this.checkForError(r,e=>{const r=[];e.forEach(e=>{const i=g(e.uuid);if(0===t.length||t.indexOf(i)>=0){const t=n.uuid+"-"+e.uuid;this.descriptorHandles[t]||(this.descriptorHandles[t]=e),r.push({uuid:i})}},this),i(r)}))}readCharacteristic(e,t,i){this.characteristicHandles[e].read(this.checkForError(i,e=>{const i=this.bufferToDataView(e);t(i)}))}writeCharacteristic(e,t,i,r){const n=this.dataViewToBuffer(t),s=this.characteristicHandles[e],a=s.properties.indexOf("writeWithoutResponse")>=0||s.properties.indexOf("authenticatedSignedWrites")>=0,c="darwin"!==this.os&&a?25:null;s.write(n,a,this.checkForError(r,i,c))}enableNotify(e,t,i,r){if(this.charNotifies[e])return this.charNotifies[e]=t,i();this.characteristicHandles[e].once("notify",n=>{if(!0!==n)return r("notify failed to enable");this.charNotifies[e]=t,i()}),this.characteristicHandles[e].notify(!0,this.checkForError(r))}disableNotify(e,t,i){if(!this.charNotifies[e])return t();this.characteristicHandles[e].once("notify",r=>{if(!1!==r)return i("notify failed to disable");this.charNotifies[e]&&delete this.charNotifies[e],t()}),this.characteristicHandles[e].notify(!1,this.checkForError(i))}readDescriptor(e,t,i){this.descriptorHandles[e].readValue(this.checkForError(i,e=>{const i=this.bufferToDataView(e);t(i)}))}writeDescriptor(e,t,i,r){const n=this.dataViewToBuffer(t);this.descriptorHandles[e].writeValue(n,this.checkForError(r,i))}}E.EVENT_ENABLED="enabledchanged";const x=new E;class L{constructor(e){this.characteristic=null,this.uuid=null,this._value=null,this.handle=null,this.characteristic=e.characteristic,this.uuid=e.uuid,this._value=e.value,this.handle=`${this.characteristic.uuid}-${this.uuid}`}get value(){return this._value}readValue(){return new Promise((e,t)=>{if(!this.characteristic.service.device.gatt.connected)return t("readValue error: device not connected");x.readDescriptor(this.handle,t=>{this._value=t,e(t)},e=>{t(`readValue error: ${e}`)})})}writeValue(e){return new Promise((t,i)=>{if(!this.characteristic.service.device.gatt.connected)return i("writeValue error: device not connected");const r=function(e){return void 0!==e.buffer}(e)?e.buffer:e,n=new DataView(r);x.writeDescriptor(this.handle,n,()=>{this._value=n,t()},e=>{i(`writeValue error: ${e}`)})})}}class D{constructor(e,t){this.bubbles=!0,this.cancelable=!1,this.cancelBubble=!1,this.composed=!1,this.defaultPrevented=!1,this.eventPhase=0,this.isTrusted=!0,this.returnValue=!0,this.target=e,this.srcElement=e,this.currentTarget=e,this.type=t}composedPath(){return[]}initEvent(e,t,i){this.type=e,this.bubbles=t,this.cancelable=i}preventDefault(){this.defaultPrevented=!0}stopImmediatePropagation(){}stopPropagation(){}}class P extends f{constructor(e){super(),this.service=null,this.uuid=null,this._value=null,this.handle=null,this.descriptors=null,this.service=e.service,this.uuid=e.uuid,this.properties=e.properties,this._value=e.value,this.handle=this.uuid}get value(){return this._value}set oncharacteristicvaluechanged(e){this._oncharacteristicvaluechanged&&this.removeEventListener("characteristicvaluechanged",this._oncharacteristicvaluechanged),this._oncharacteristicvaluechanged=e,this.addEventListener("characteristicvaluechanged",this._oncharacteristicvaluechanged)}setValue(e,t){this._value=e,t&&(this.dispatchEvent(new D(this,"characteristicvaluechanged")),this.service.dispatchEvent(new D(this,"characteristicvaluechanged")),this.service.device.dispatchEvent(new D(this,"characteristicvaluechanged")),this.service.device._bluetooth.dispatchEvent(new D(this,"characteristicvaluechanged")))}getDescriptor(e){return new Promise((t,i)=>this.service.device.gatt.connected?e?void this.getDescriptors(e).then(e=>{if(1!==e.length)return i("getDescriptor error: descriptor not found");t(e[0])}).catch(e=>{i(`getDescriptor error: ${e}`)}):i("getDescriptor error: no descriptor specified"):i("getDescriptor error: device not connected"))}getDescriptors(e){return new Promise((t,i)=>{if(!this.service.device.gatt.connected)return i("getDescriptors error: device not connected");function r(){if(!e)return t(this.descriptors);const r=this.descriptors.filter(t=>t.uuid===y(e));if(1!==r.length)return i("getDescriptors error: descriptor not found");t(r)}if(this.descriptors)return r.call(this);x.discoverDescriptors(this.handle,[],e=>{this.descriptors=e.map(e=>(Object.assign(e,{characteristic:this}),new L(e))),r.call(this)},e=>{i(`getDescriptors error: ${e}`)})})}readValue(){return new Promise((e,t)=>{if(!this.service.device.gatt.connected)return t("readValue error: device not connected");x.readCharacteristic(this.handle,t=>{this.setValue(t,!0),e(t)},e=>{t(`readValue error: ${e}`)})})}writeValue(e){return new Promise((t,i)=>{if(!this.service.device.gatt.connected)return i("writeValue error: device not connected");const r=function(e){return void 0!==e.buffer}(e)?e.buffer:e,n=new DataView(r);x.writeCharacteristic(this.handle,n,()=>{this.setValue(n),t()},e=>{i(`writeValue error: ${e}`)})})}startNotifications(){return new Promise((e,t)=>{if(!this.service.device.gatt.connected)return t("startNotifications error: device not connected");x.enableNotify(this.handle,e=>{this.setValue(e,!0)},()=>{e(this)},e=>{t(`startNotifications error: ${e}`)})})}stopNotifications(){return new Promise((e,t)=>{if(!this.service.device.gatt.connected)return t("stopNotifications error: device not connected");x.disableNotify(this.handle,()=>{e(this)},e=>{t(`stopNotifications error: ${e}`)})})}}class S extends f{constructor(e){super(),this.device=null,this.uuid=null,this.isPrimary=!1,this.handle=null,this.services=null,this.characteristics=null,this.device=e.device,this.uuid=e.uuid,this.isPrimary=e.isPrimary,this.handle=this.uuid,this.dispatchEvent(new D(this,"serviceadded")),this.device.dispatchEvent(new D(this,"serviceadded")),this.device._bluetooth.dispatchEvent(new D(this,"serviceadded"))}set oncharacteristicvaluechanged(e){this._oncharacteristicvaluechanged&&this.removeEventListener("characteristicvaluechanged",this._oncharacteristicvaluechanged),this._oncharacteristicvaluechanged=e,this.addEventListener("characteristicvaluechanged",this._oncharacteristicvaluechanged)}set onserviceadded(e){this._onserviceadded&&this.removeEventListener("serviceadded",this._onserviceadded),this._onserviceadded=e,this.addEventListener("serviceadded",this._onserviceadded)}set onservicechanged(e){this._onservicechanged&&this.removeEventListener("servicechanged",this._onservicechanged),this._onservicechanged=e,this.addEventListener("servicechanged",this._onservicechanged)}set onserviceremoved(e){this._onserviceremoved&&this.removeEventListener("serviceremoved",this._onserviceremoved),this._onserviceremoved=e,this.addEventListener("serviceremoved",this._onserviceremoved)}getCharacteristic(e){return new Promise((t,i)=>this.device.gatt.connected?e?void this.getCharacteristics(e).then(e=>{if(1!==e.length)return i("getCharacteristic error: characteristic not found");t(e[0])}).catch(e=>{i(`getCharacteristic error: ${e}`)}):i("getCharacteristic error: no characteristic specified"):i("getCharacteristic error: device not connected"))}getCharacteristics(e){return new Promise((t,i)=>{if(!this.device.gatt.connected)return i("getCharacteristics error: device not connected");function r(){if(!e)return t(this.characteristics);e=b(e);const r=this.characteristics.filter(t=>t.uuid===e);if(1!==r.length)return i("getCharacteristics error: characteristic not found");t(r)}if(this.characteristics)return r.call(this);x.discoverCharacteristics(this.handle,[],e=>{this.characteristics=e.map(e=>(Object.assign(e,{service:this}),new P(e))),r.call(this)},e=>{i(`getCharacteristics error: ${e}`)})})}getIncludedService(e){return new Promise((t,i)=>this.device.gatt.connected?e?void this.getIncludedServices(e).then(e=>{if(1!==e.length)return i("getIncludedService error: service not found");t(e[0])}).catch(e=>{i(`getIncludedService error: ${e}`)}):i("getIncludedService error: no service specified"):i("getIncludedService error: device not connected"))}getIncludedServices(e){return new Promise((t,i)=>{if(!this.device.gatt.connected)return i("getIncludedServices error: device not connected");function r(){if(!e)return t(this.services);const r=this.services.filter(t=>t.uuid===w(e));if(1!==r.length)return i("getIncludedServices error: service not found");t(r)}if(this.services)return r.call(this);x.discoverIncludedServices(this.handle,this.device._allowedServices,e=>{this.services=e.map(e=>(Object.assign(e,{device:this.device}),new S(e))),r.call(this)},e=>{i(`getIncludedServices error: ${e}`)})})}}class C{constructor(e){this.device=null,this._connected=!1,this.handle=null,this.services=null,this.device=e,this.handle=this.device.id}get connected(){return this._connected}connect(){return new Promise((e,t)=>{if(this.connected)return t("connect error: device already connected");x.connect(this.handle,()=>{this._connected=!0,e(this)},()=>{this.services=null,this._connected=!1,this.device.dispatchEvent(new D(this.device,"gattserverdisconnected")),this.device._bluetooth.dispatchEvent(new D(this.device,"gattserverdisconnected"))},e=>{t(`connect Error: ${e}`)})})}disconnect(){x.disconnect(this.handle),this._connected=!1}getPrimaryService(e){return new Promise((t,i)=>this.connected?e?void this.getPrimaryServices(e).then(e=>{if(1!==e.length)return i("getPrimaryService error: service not found");t(e[0])}).catch(e=>{i(`getPrimaryService error: ${e}`)}):i("getPrimaryService error: no service specified"):i("getPrimaryService error: device not connected"))}getPrimaryServices(e){return new Promise((t,i)=>{if(!this.connected)return i("getPrimaryServices error: device not connected");function r(){if(!e)return t(this.services);const r=this.services.filter(t=>t.uuid===w(e));if(1!==r.length)return i("getPrimaryServices error: service not found");t(r)}if(this.services)return r.call(this);x.discoverServices(this.handle,this.device._allowedServices,e=>{this.services=e.map(e=>(Object.assign(e,{device:this.device}),new S(e))),r.call(this)},e=>{i(`getPrimaryServices error: ${e}`)})})}}class k extends f{constructor(e){super(),this.id=null,this.name=null,this.gatt=null,this.watchingAdvertisements=!1,this._bluetooth=null,this._allowedServices=[],this._serviceUUIDs=[],this.id=e.id,this.name=e.name,this.gatt=e.gatt,this.watchAdvertisements=e.watchAdvertisements,this.adData=e.adData,this._bluetooth=e._bluetooth,this._allowedServices=e._allowedServices,this._serviceUUIDs=e._serviceUUIDs,this.name||(this.name=`Unknown or Unsupported Device (${this.id})`),this.gatt||(this.gatt=new C(this))}set oncharacteristicvaluechanged(e){this._oncharacteristicvaluechanged&&this.removeEventListener("characteristicvaluechanged",this._oncharacteristicvaluechanged),this._oncharacteristicvaluechanged=e,this.addEventListener("characteristicvaluechanged",this._oncharacteristicvaluechanged)}set onserviceadded(e){this._onserviceadded&&this.removeEventListener("serviceadded",this._onserviceadded),this._onserviceadded=e,this.addEventListener("serviceadded",this._onserviceadded)}set onservicechanged(e){this._onservicechanged&&this.removeEventListener("servicechanged",this._onservicechanged),this._onservicechanged=e,this.addEventListener("servicechanged",this._onservicechanged)}set onserviceremoved(e){this._onserviceremoved&&this.removeEventListener("serviceremoved",this._onserviceremoved),this._onserviceremoved=e,this.addEventListener("serviceremoved",this._onserviceremoved)}set ongattserverdisconnected(e){this._ongattserverdisconnected&&this.removeEventListener("gattserverdisconnected",this._ongattserverdisconnected),this._ongattserverdisconnected=e,this.addEventListener("gattserverdisconnected",this._ongattserverdisconnected)}set onadvertisementreceived(e){this._onadvertisementreceived&&this.removeEventListener("advertisementreceived",this._onadvertisementreceived),this._onadvertisementreceived=e,this.addEventListener("advertisementreceived",this._onadvertisementreceived)}watchAdvertisements(){return new Promise((e,t)=>{t("watchAdvertisements error: method not implemented")})}unwatchAdvertisements(){return new Promise((e,t)=>{t("unwatchAdvertisements error: method not implemented")})}}class O extends f{constructor(e){super(),this.deviceFound=null,this.scanTime=10240,this.scanner=null,e=e||{},this.referringDevice=e.referringDevice,this.deviceFound=e.deviceFound,e.scanTime&&(this.scanTime=1e3*e.scanTime),x.on(E.EVENT_ENABLED,e=>{this.dispatchEvent(new D(this,"availabilitychanged"))})}set oncharacteristicvaluechanged(e){this._oncharacteristicvaluechanged&&this.removeEventListener("characteristicvaluechanged",this._oncharacteristicvaluechanged),this._oncharacteristicvaluechanged=e,this.addEventListener("characteristicvaluechanged",this._oncharacteristicvaluechanged)}set onserviceadded(e){this._onserviceadded&&this.removeEventListener("serviceadded",this._onserviceadded),this._onserviceadded=e,this.addEventListener("serviceadded",this._onserviceadded)}set onservicechanged(e){this._onservicechanged&&this.removeEventListener("servicechanged",this._onservicechanged),this._onservicechanged=e,this.addEventListener("servicechanged",this._onservicechanged)}set onserviceremoved(e){this._onserviceremoved&&this.removeEventListener("serviceremoved",this._onserviceremoved),this._onserviceremoved=e,this.addEventListener("serviceremoved",this._onserviceremoved)}set ongattserverdisconnected(e){this._ongattserverdisconnected&&this.removeEventListener("gattserverdisconnected",this._ongattserverdisconnected),this._ongattserverdisconnected=e,this.addEventListener("gattserverdisconnected",this._ongattserverdisconnected)}set onadvertisementreceived(e){this._onadvertisementreceived&&this.removeEventListener("advertisementreceived",this._onadvertisementreceived),this._onadvertisementreceived=e,this.addEventListener("advertisementreceived",this._onadvertisementreceived)}set onavailabilitychanged(e){this._onavailabilitychanged&&this.removeEventListener("availabilitychanged",this._onavailabilitychanged),this._onavailabilitychanged=e,this.addEventListener("availabilitychanged",this._onavailabilitychanged)}filterDevice(e,t,i){let r=!1;return e.forEach(e=>{if(!e.name||e.name===t.name){if(e.namePrefix){if(!t.name||e.namePrefix.length>t.name.length)return;if(e.namePrefix!==t.name.substr(0,e.namePrefix.length))return}if(e.services){const r=e.services.map(w);if(!r.every(e=>t._serviceUUIDs.indexOf(e)>-1))return;i=i.concat(r)}r=!0}}),!!r&&t}getAvailability(){return new Promise((e,t)=>{x.getEnabled(t=>{e(t)})})}requestDevice(e={filters:[]}){return new Promise((t,i)=>{if(null!==this.scanner)return i("requestDevice error: request in progress");const r=e=>void 0!==e.filters;let n=[];if(r(e)){if(0===e.filters.length)return i(new TypeError("requestDevice error: no filters specified"));if(e.filters.some(e=>0===Object.keys(e).length))return i(new TypeError("requestDevice error: empty filter specified"));if(e.filters.some(e=>void 0!==e.namePrefix&&""===e.namePrefix))return i(new TypeError("requestDevice error: empty namePrefix specified"));e.filters.forEach(e=>{e.services&&(n=n.concat(e.services.map(w))),n=n.filter((e,t,i)=>i.indexOf(e)===t)})}else if(!(e=>!0===e.acceptAllDevices)(e))return i(new TypeError("requestDevice error: specify filters or acceptAllDevices"));let s=!1;x.startScan(n,i=>{let n=[];function a(e){this.cancelRequest().then(()=>{t(e)})}if(r(e)&&(i=this.filterDevice(e.filters,i,n)),i){s=!0,e.optionalServices&&(n=n.concat(e.optionalServices.map(w)));const t=n.filter((e,t,i)=>i.indexOf(e)===t);Object.assign(i,{_bluetooth:this,_allowedServices:t});const r=new k(i);function c(){a.call(this,r)}this.deviceFound&&!0!==this.deviceFound(r,c.bind(this))||a.call(this,r)}},()=>{this.scanner=setTimeout(()=>{this.cancelRequest().then(()=>{s||i("requestDevice error: no devices found")})},this.scanTime)},e=>i(`requestDevice error: ${e}`))})}cancelRequest(){return new Promise((e,t)=>{this.scanner&&(clearTimeout(this.scanner),this.scanner=null,x.stopScan()),e()})}}O.EVENT_AVAILABILITY="availabilitychanged";const T=new O;e.Bluetooth=O,e.bluetooth=T,e.getCanonicalUUID=g,e.getCharacteristicUUID=b,e.getDescriptorUUID=y,e.getServiceUUID=w,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@abandonware/noble")):"function"==typeof define&&define.amd?define(["exports","@abandonware/noble"],t):t((e=e||self).webbluetooth={},e.noble)}(this,(function(e,t){"use strict";var i,r,n;function s(){}function a(){a.init.call(this)}function c(e){return void 0===e._maxListeners?a.defaultMaxListeners:e._maxListeners}function o(e,t,i){if(t)e.call(i);else for(var r=e.length,n=p(e,r),s=0;s<r;++s)n[s].call(i)}function d(e,t,i,r){if(t)e.call(i,r);else for(var n=e.length,s=p(e,n),a=0;a<n;++a)s[a].call(i,r)}function h(e,t,i,r,n){if(t)e.call(i,r,n);else for(var s=e.length,a=p(e,s),c=0;c<s;++c)a[c].call(i,r,n)}function _(e,t,i,r,n,s){if(t)e.call(i,r,n,s);else for(var a=e.length,c=p(e,a),o=0;o<a;++o)c[o].call(i,r,n,s)}function l(e,t,i,r){if(t)e.apply(i,r);else for(var n=e.length,s=p(e,n),a=0;a<n;++a)s[a].apply(i,r)}function u(e,t,i,r){var n,a,o,d;if("function"!=typeof i)throw new TypeError('"listener" argument must be a function');if((a=e._events)?(a.newListener&&(e.emit("newListener",t,i.listener?i.listener:i),a=e._events),o=a[t]):(a=e._events=new s,e._eventsCount=0),o){if("function"==typeof o?o=a[t]=r?[i,o]:[o,i]:r?o.unshift(i):o.push(i),!o.warned&&(n=c(e))&&n>0&&o.length>n){o.warned=!0;var h=new Error("Possible EventEmitter memory leak detected. "+o.length+" "+t+" listeners added. Use emitter.setMaxListeners() to increase limit");h.name="MaxListenersExceededWarning",h.emitter=e,h.type=t,h.count=o.length,d=h,"function"==typeof console.warn?console.warn(d):console.log(d)}}else o=a[t]=i,++e._eventsCount;return e}function v(e,t,i){var r=!1;function n(){e.removeListener(t,n),r||(r=!0,i.apply(e,arguments))}return n.listener=i,n}function m(e){var t=this._events;if(t){var i=t[e];if("function"==typeof i)return 1;if(i)return i.length}return 0}function p(e,t){for(var i=new Array(t);t--;)i[t]=e[t];return i}s.prototype=Object.create(null),a.EventEmitter=a,a.usingDomains=!1,a.prototype.domain=void 0,a.prototype._events=void 0,a.prototype._maxListeners=void 0,a.defaultMaxListeners=10,a.init=function(){this.domain=null,a.usingDomains&&(void 0).active,this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=new s,this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},a.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||isNaN(e))throw new TypeError('"n" argument must be a positive number');return this._maxListeners=e,this},a.prototype.getMaxListeners=function(){return c(this)},a.prototype.emit=function(e){var t,i,r,n,s,a,c,u="error"===e;if(a=this._events)u=u&&null==a.error;else if(!u)return!1;if(c=this.domain,u){if(t=arguments[1],!c){if(t instanceof Error)throw t;var v=new Error('Uncaught, unspecified "error" event. ('+t+")");throw v.context=t,v}return t||(t=new Error('Uncaught, unspecified "error" event')),t.domainEmitter=this,t.domain=c,t.domainThrown=!1,c.emit("error",t),!1}if(!(i=a[e]))return!1;var m="function"==typeof i;switch(r=arguments.length){case 1:o(i,m,this);break;case 2:d(i,m,this,arguments[1]);break;case 3:h(i,m,this,arguments[1],arguments[2]);break;case 4:_(i,m,this,arguments[1],arguments[2],arguments[3]);break;default:for(n=new Array(r-1),s=1;s<r;s++)n[s-1]=arguments[s];l(i,m,this,n)}return!0},a.prototype.addListener=function(e,t){return u(this,e,t,!1)},a.prototype.on=a.prototype.addListener,a.prototype.prependListener=function(e,t){return u(this,e,t,!0)},a.prototype.once=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.on(e,v(this,e,t)),this},a.prototype.prependOnceListener=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.prependListener(e,v(this,e,t)),this},a.prototype.removeListener=function(e,t){var i,r,n,a,c;if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');if(!(r=this._events))return this;if(!(i=r[e]))return this;if(i===t||i.listener&&i.listener===t)0==--this._eventsCount?this._events=new s:(delete r[e],r.removeListener&&this.emit("removeListener",e,i.listener||t));else if("function"!=typeof i){for(n=-1,a=i.length;a-- >0;)if(i[a]===t||i[a].listener&&i[a].listener===t){c=i[a].listener,n=a;break}if(n<0)return this;if(1===i.length){if(i[0]=void 0,0==--this._eventsCount)return this._events=new s,this;delete r[e]}else!function(e,t){for(var i=t,r=i+1,n=e.length;r<n;i+=1,r+=1)e[i]=e[r];e.pop()}(i,n);r.removeListener&&this.emit("removeListener",e,c||t)}return this},a.prototype.removeAllListeners=function(e){var t,i;if(!(i=this._events))return this;if(!i.removeListener)return 0===arguments.length?(this._events=new s,this._eventsCount=0):i[e]&&(0==--this._eventsCount?this._events=new s:delete i[e]),this;if(0===arguments.length){for(var r,n=Object.keys(i),a=0;a<n.length;++a)"removeListener"!==(r=n[a])&&this.removeAllListeners(r);return this.removeAllListeners("removeListener"),this._events=new s,this._eventsCount=0,this}if("function"==typeof(t=i[e]))this.removeListener(e,t);else if(t)do{this.removeListener(e,t[t.length-1])}while(t[0]);return this},a.prototype.listeners=function(e){var t,i=this._events;return i&&(t=i[e])?"function"==typeof t?[t.listener||t]:function(e){for(var t=new Array(e.length),i=0;i<t.length;++i)t[i]=e[i].listener||e[i];return t}(t):[]},a.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):m.call(e,t)},a.prototype.listenerCount=m,a.prototype.eventNames=function(){return this._eventsCount>0?Reflect.ownKeys(this._events):[]};class f extends a{constructor(){super(...arguments),this.isEventListenerObject=e=>void 0!==e.handleEvent}addEventListener(e,t){if(t){const i=this.isEventListenerObject(t)?t.handleEvent:t;super.addListener(e,i)}}removeEventListener(e,t){if(t){const i=this.isEventListenerObject(t)?t.handleEvent:t;super.removeListener(e,i)}}dispatchEvent(e){return super.emit(e.type,e)}}function g(e){return"number"==typeof e&&(e=e.toString(16)),(e=e.toLowerCase()).length<=8&&(e=("00000000"+e).slice(-8)+"-0000-1000-8000-00805f9b34fb"),32===e.length&&(e=e.match(/^([0-9a-f]{8})([0-9a-f]{4})([0-9a-f]{4})([0-9a-f]{4})([0-9a-f]{12})$/).splice(1).join("-")),e}function w(t){return"string"==typeof t&&e.bluetoothServices[t]&&(t=e.bluetoothServices[t]),g(t)}function b(t){return"string"==typeof t&&e.bluetoothCharacteristics[t]&&(t=e.bluetoothCharacteristics[t]),g(t)}function y(t){return"string"==typeof t&&e.bluetoothDescriptors[t]&&(t=e.bluetoothDescriptors[t]),g(t)}(i=e.bluetoothServices||(e.bluetoothServices={}))[i.alert_notification=6161]="alert_notification",i[i.automation_io=6165]="automation_io",i[i.battery_service=6159]="battery_service",i[i.blood_pressure=6160]="blood_pressure",i[i.body_composition=6171]="body_composition",i[i.bond_management=6174]="bond_management",i[i.continuous_glucose_monitoring=6175]="continuous_glucose_monitoring",i[i.current_time=6149]="current_time",i[i.cycling_power=6168]="cycling_power",i[i.cycling_speed_and_cadence=6166]="cycling_speed_and_cadence",i[i.device_information=6154]="device_information",i[i.environmental_sensing=6170]="environmental_sensing",i[i.generic_access=6144]="generic_access",i[i.generic_attribute=6145]="generic_attribute",i[i.glucose=6152]="glucose",i[i.health_thermometer=6153]="health_thermometer",i[i.heart_rate=6157]="heart_rate",i[i.human_interface_device=6162]="human_interface_device",i[i.immediate_alert=6146]="immediate_alert",i[i.indoor_positioning=6177]="indoor_positioning",i[i.internet_protocol_support=6176]="internet_protocol_support",i[i.link_loss=6147]="link_loss",i[i.location_and_navigation=6169]="location_and_navigation",i[i.next_dst_change=6151]="next_dst_change",i[i.phone_alert_status=6158]="phone_alert_status",i[i.pulse_oximeter=6178]="pulse_oximeter",i[i.reference_time_update=6150]="reference_time_update",i[i.running_speed_and_cadence=6164]="running_speed_and_cadence",i[i.scan_parameters=6163]="scan_parameters",i[i.tx_power=6148]="tx_power",i[i.user_data=6172]="user_data",i[i.weight_scale=6173]="weight_scale",(r=e.bluetoothCharacteristics||(e.bluetoothCharacteristics={}))[r.aerobic_heart_rate_lower_limit=10878]="aerobic_heart_rate_lower_limit",r[r.aerobic_heart_rate_upper_limit=10884]="aerobic_heart_rate_upper_limit",r[r.aerobic_threshold=10879]="aerobic_threshold",r[r.age=10880]="age",r[r.aggregate=10842]="aggregate",r[r.alert_category_id=10819]="alert_category_id",r[r.alert_category_id_bit_mask=10818]="alert_category_id_bit_mask",r[r.alert_level=10758]="alert_level",r[r.alert_notification_control_point=10820]="alert_notification_control_point",r[r.alert_status=10815]="alert_status",r[r.altitude=10931]="altitude",r[r.anaerobic_heart_rate_lower_limit=10881]="anaerobic_heart_rate_lower_limit",r[r.anaerobic_heart_rate_upper_limit=10882]="anaerobic_heart_rate_upper_limit",r[r.anaerobic_threshold=10883]="anaerobic_threshold",r[r.analog=10840]="analog",r[r.apparent_wind_direction=10867]="apparent_wind_direction",r[r.apparent_wind_speed=10866]="apparent_wind_speed",r[r["gap.appearance"]=10753]="gap.appearance",r[r.barometric_pressure_trend=10915]="barometric_pressure_trend",r[r.battery_level=10777]="battery_level",r[r.blood_pressure_feature=10825]="blood_pressure_feature",r[r.blood_pressure_measurement=10805]="blood_pressure_measurement",r[r.body_composition_feature=10907]="body_composition_feature",r[r.body_composition_measurement=10908]="body_composition_measurement",r[r.body_sensor_location=10808]="body_sensor_location",r[r.bond_management_control_point=10916]="bond_management_control_point",r[r.bond_management_feature=10917]="bond_management_feature",r[r.boot_keyboard_input_report=10786]="boot_keyboard_input_report",r[r.boot_keyboard_output_report=10802]="boot_keyboard_output_report",r[r.boot_mouse_input_report=10803]="boot_mouse_input_report",r[r["gap.central_address_resolution_support"]=10918]="gap.central_address_resolution_support",r[r.cgm_feature=10920]="cgm_feature",r[r.cgm_measurement=10919]="cgm_measurement",r[r.cgm_session_run_time=10923]="cgm_session_run_time",r[r.cgm_session_start_time=10922]="cgm_session_start_time",r[r.cgm_specific_ops_control_point=10924]="cgm_specific_ops_control_point",r[r.cgm_status=10921]="cgm_status",r[r.csc_feature=10844]="csc_feature",r[r.csc_measurement=10843]="csc_measurement",r[r.current_time=10795]="current_time",r[r.cycling_power_control_point=10854]="cycling_power_control_point",r[r.cycling_power_feature=10853]="cycling_power_feature",r[r.cycling_power_measurement=10851]="cycling_power_measurement",r[r.cycling_power_vector=10852]="cycling_power_vector",r[r.database_change_increment=10905]="database_change_increment",r[r.date_of_birth=10885]="date_of_birth",r[r.date_of_threshold_assessment=10886]="date_of_threshold_assessment",r[r.date_time=10760]="date_time",r[r.day_date_time=10762]="day_date_time",r[r.day_of_week=10761]="day_of_week",r[r.descriptor_value_changed=10877]="descriptor_value_changed",r[r["gap.device_name"]=10752]="gap.device_name",r[r.dew_point=10875]="dew_point",r[r.digital=10838]="digital",r[r.dst_offset=10765]="dst_offset",r[r.elevation=10860]="elevation",r[r.email_address=10887]="email_address",r[r.exact_time_256=10764]="exact_time_256",r[r.fat_burn_heart_rate_lower_limit=10888]="fat_burn_heart_rate_lower_limit",r[r.fat_burn_heart_rate_upper_limit=10889]="fat_burn_heart_rate_upper_limit",r[r.firmware_revision_string=10790]="firmware_revision_string",r[r.first_name=10890]="first_name",r[r.five_zone_heart_rate_limits=10891]="five_zone_heart_rate_limits",r[r.floor_number=10930]="floor_number",r[r.gender=10892]="gender",r[r.glucose_feature=10833]="glucose_feature",r[r.glucose_measurement=10776]="glucose_measurement",r[r.glucose_measurement_context=10804]="glucose_measurement_context",r[r.gust_factor=10868]="gust_factor",r[r.hardware_revision_string=10791]="hardware_revision_string",r[r.heart_rate_control_point=10809]="heart_rate_control_point",r[r.heart_rate_max=10893]="heart_rate_max",r[r.heart_rate_measurement=10807]="heart_rate_measurement",r[r.heat_index=10874]="heat_index",r[r.height=10894]="height",r[r.hid_control_point=10828]="hid_control_point",r[r.hid_information=10826]="hid_information",r[r.hip_circumference=10895]="hip_circumference",r[r.humidity=10863]="humidity",r[r["ieee_11073-20601_regulatory_certification_data_list"]=10794]="ieee_11073-20601_regulatory_certification_data_list",r[r.indoor_positioning_configuration=10925]="indoor_positioning_configuration",r[r.intermediate_blood_pressure=10806]="intermediate_blood_pressure",r[r.intermediate_temperature=10782]="intermediate_temperature",r[r.irradiance=10871]="irradiance",r[r.language=10914]="language",r[r.last_name=10896]="last_name",r[r.latitude=10926]="latitude",r[r.ln_control_point=10859]="ln_control_point",r[r.ln_feature=10858]="ln_feature",r[r["local_east_coordinate.xml"]=10929]="local_east_coordinate.xml",r[r.local_north_coordinate=10928]="local_north_coordinate",r[r.local_time_information=10767]="local_time_information",r[r.location_and_speed=10855]="location_and_speed",r[r.location_name=10933]="location_name",r[r.longitude=10927]="longitude",r[r.magnetic_declination=10796]="magnetic_declination",r[r.magnetic_flux_density_2D=10912]="magnetic_flux_density_2D",r[r.magnetic_flux_density_3D=10913]="magnetic_flux_density_3D",r[r.manufacturer_name_string=10793]="manufacturer_name_string",r[r.maximum_recommended_heart_rate=10897]="maximum_recommended_heart_rate",r[r.measurement_interval=10785]="measurement_interval",r[r.model_number_string=10788]="model_number_string",r[r.navigation=10856]="navigation",r[r.new_alert=10822]="new_alert",r[r["gap.peripheral_preferred_connection_parameters"]=10756]="gap.peripheral_preferred_connection_parameters",r[r["gap.peripheral_privacy_flag"]=10754]="gap.peripheral_privacy_flag",r[r.plx_continuous_measurement=10847]="plx_continuous_measurement",r[r.plx_features=10848]="plx_features",r[r.plx_spot_check_measurement=10846]="plx_spot_check_measurement",r[r.pnp_id=10832]="pnp_id",r[r.pollen_concentration=10869]="pollen_concentration",r[r.position_quality=10857]="position_quality",r[r.pressure=10861]="pressure",r[r.protocol_mode=10830]="protocol_mode",r[r.rainfall=10872]="rainfall",r[r["gap.reconnection_address"]=10755]="gap.reconnection_address",r[r.record_access_control_point=10834]="record_access_control_point",r[r.reference_time_information=10772]="reference_time_information",r[r.report=10829]="report",r[r.report_map=10827]="report_map",r[r.resting_heart_rate=10898]="resting_heart_rate",r[r.ringer_control_point=10816]="ringer_control_point",r[r.ringer_setting=10817]="ringer_setting",r[r.rsc_feature=10836]="rsc_feature",r[r.rsc_measurement=10835]="rsc_measurement",r[r.sc_control_point=10837]="sc_control_point",r[r.scan_interval_window=10831]="scan_interval_window",r[r.scan_refresh=10801]="scan_refresh",r[r.sensor_location=10845]="sensor_location",r[r.serial_number_string=10789]="serial_number_string",r[r["gatt.service_changed"]=10757]="gatt.service_changed",r[r.software_revision_string=10792]="software_revision_string",r[r.sport_type_for_aerobic_and_anaerobic_thresholds=10899]="sport_type_for_aerobic_and_anaerobic_thresholds",r[r.supported_new_alert_category=10823]="supported_new_alert_category",r[r.supported_unread_alert_category=10824]="supported_unread_alert_category",r[r.system_id=10787]="system_id",r[r.temperature=10862]="temperature",r[r.temperature_measurement=10780]="temperature_measurement",r[r.temperature_type=10781]="temperature_type",r[r.three_zone_heart_rate_limits=10900]="three_zone_heart_rate_limits",r[r.time_accuracy=10770]="time_accuracy",r[r.time_source=10771]="time_source",r[r.time_update_control_point=10774]="time_update_control_point",r[r.time_update_state=10775]="time_update_state",r[r.time_with_dst=10769]="time_with_dst",r[r.time_zone=10766]="time_zone",r[r.true_wind_direction=10865]="true_wind_direction",r[r.true_wind_speed=10864]="true_wind_speed",r[r.two_zone_heart_rate_limit=10901]="two_zone_heart_rate_limit",r[r.tx_power_level=10759]="tx_power_level",r[r.uncertainty=10932]="uncertainty",r[r.unread_alert_status=10821]="unread_alert_status",r[r.user_control_point=10911]="user_control_point",r[r.user_index=10906]="user_index",r[r.uv_index=10870]="uv_index",r[r.vo2_max=10902]="vo2_max",r[r.waist_circumference=10903]="waist_circumference",r[r.weight=10904]="weight",r[r.weight_measurement=10909]="weight_measurement",r[r.weight_scale_feature=10910]="weight_scale_feature",r[r.wind_chill=10873]="wind_chill",(n=e.bluetoothDescriptors||(e.bluetoothDescriptors={}))[n["gatt.characteristic_extended_properties"]=10496]="gatt.characteristic_extended_properties",n[n["gatt.characteristic_user_description"]=10497]="gatt.characteristic_user_description",n[n["gatt.client_characteristic_configuration"]=10498]="gatt.client_characteristic_configuration",n[n["gatt.server_characteristic_configuration"]=10499]="gatt.server_characteristic_configuration",n[n["gatt.characteristic_presentation_format"]=10500]="gatt.characteristic_presentation_format",n[n["gatt.characteristic_aggregate_format"]=10501]="gatt.characteristic_aggregate_format",n[n.valid_range=10502]="valid_range",n[n.external_report_reference=10503]="external_report_reference",n[n.report_reference=10504]="report_reference",n[n.number_of_digitals=10505]="number_of_digitals",n[n.value_trigger_setting=10506]="value_trigger_setting",n[n.es_configuration=10507]="es_configuration",n[n.es_measurement=10508]="es_measurement",n[n.es_trigger_setting=10509]="es_trigger_setting",n[n.time_trigger_setting=10510]="time_trigger_setting";class E extends a{constructor(){super(),this.deviceHandles={},this.serviceHandles={},this.characteristicHandles={},this.descriptorHandles={},this.charNotifies={},this.discoverFn=null,this.initialised=!1,this.enabled=!1,this.os="browser",this.enabled=this.state,t.on("stateChange",()=>{this.enabled!==this.state&&(this.enabled=this.state,this.emit(E.EVENT_ENABLED,this.enabled))})}get state(){return"poweredOn"===t.state}init(e){if(this.initialised)return e();t.on("discover",e=>{this.discoverFn&&this.discoverFn(e)}),this.initialised=!0,e()}checkForError(e,t,i){return function(r){if(r)e(r);else if("function"==typeof t){const e=[].slice.call(arguments,1);null===i?t.apply(this,e):setTimeout(()=>t.apply(this,e),i)}}}bufferToDataView(e){const t=new Uint8Array(e).buffer;return new DataView(t)}dataViewToBuffer(e){const t=new Uint8Array(e.buffer);return new Buffer(t)}validDevice(e,t){if(0===t.length)return!0;if(!e.advertisement.serviceUuids)return!1;const i=e.advertisement.serviceUuids.map(e=>g(e));return t.some(e=>i.indexOf(e)>=0)}deviceToBluetoothDevice(e){const t=e.address&&"unknown"!==e.address?e.address:e.id,i=[];e.advertisement.serviceUuids&&e.advertisement.serviceUuids.forEach(e=>{i.push(g(e))});const r=new Map;if(e.advertisement.manufacturerData){const t=e.advertisement.manufacturerData.readUInt16LE(0),i=e.advertisement.manufacturerData.slice(2);r.set(("0000"+t.toString(16)).slice(-4),this.bufferToDataView(i))}const n=new Map;return e.advertisement.serviceData&&e.advertisement.serviceData.forEach(e=>{n.set(g(e.uuid),this.bufferToDataView(e.data))}),{id:t,name:e.advertisement.localName,_serviceUUIDs:i,adData:{rssi:e.rssi,txPower:e.advertisement.txPowerLevel,serviceData:n,manufacturerData:r}}}getEnabled(e){function i(){e(this.state)}"unknown"===t.state||"poweredOff"===t.state?t.once("stateChange",i.bind(this)):i.call(this)}startScan(e,i,r,n){this.discoverFn=t=>{if(this.validDevice(t,e)){const e=this.deviceToBluetoothDevice(t);this.deviceHandles[e.id]||(this.deviceHandles[e.id]=t,i(e))}},this.init(()=>{function e(){!0===this.state?t.startScanning([],!0,this.checkForError(n,r)):n("adapter not enabled")}this.deviceHandles={},"unknown"===t.state||"poweredOff"===t.state?t.once("stateChange",e.bind(this)):e.call(this)})}stopScan(e){this.discoverFn=null,t.stopScanning()}connect(e,t,i,r){const n=this.deviceHandles[e];n.removeAllListeners("connect"),n.removeAllListeners("disconnect"),n.once("connect",t),n.once("disconnect",()=>{this.serviceHandles={},this.characteristicHandles={},this.descriptorHandles={},this.charNotifies={},i()}),n.connect(this.checkForError(r))}disconnect(e,t){this.deviceHandles[e].disconnect(this.checkForError(t))}discoverServices(e,t,i,r){this.deviceHandles[e].discoverServices([],this.checkForError(r,e=>{const r=[];e.forEach(e=>{const i=g(e.uuid);(0===t.length||t.indexOf(i)>=0)&&(this.serviceHandles[i]||(this.serviceHandles[i]=e),r.push({uuid:i,primary:!0}))}),i(r)}))}discoverIncludedServices(e,t,i,r){this.serviceHandles[e].discoverIncludedServices([],this.checkForError(r,e=>{const r=[];e.forEach(e=>{const i=g(e.uuid);(0===t.length||t.indexOf(i)>=0)&&(this.serviceHandles[i]||(this.serviceHandles[i]=e),r.push({uuid:i,primary:!1}))},this),i(r)}))}discoverCharacteristics(e,t,i,r){this.serviceHandles[e].discoverCharacteristics([],this.checkForError(r,e=>{const r=[];e.forEach(e=>{const i=g(e.uuid);(0===t.length||t.indexOf(i)>=0)&&(this.characteristicHandles[i]||(this.characteristicHandles[i]=e),r.push({uuid:i,properties:{broadcast:e.properties.indexOf("broadcast")>=0,read:e.properties.indexOf("read")>=0,writeWithoutResponse:e.properties.indexOf("writeWithoutResponse")>=0,write:e.properties.indexOf("write")>=0,notify:e.properties.indexOf("notify")>=0,indicate:e.properties.indexOf("indicate")>=0,authenticatedSignedWrites:e.properties.indexOf("authenticatedSignedWrites")>=0,reliableWrite:e.properties.indexOf("reliableWrite")>=0,writableAuxiliaries:e.properties.indexOf("writableAuxiliaries")>=0}}),e.on("data",(e,t)=>{if(!0===t&&"function"==typeof this.charNotifies[i]){const t=this.bufferToDataView(e);this.charNotifies[i](t)}}))},this),i(r)}))}discoverDescriptors(e,t,i,r){const n=this.characteristicHandles[e];n.discoverDescriptors(this.checkForError(r,e=>{const r=[];e.forEach(e=>{const i=g(e.uuid);if(0===t.length||t.indexOf(i)>=0){const t=n.uuid+"-"+e.uuid;this.descriptorHandles[t]||(this.descriptorHandles[t]=e),r.push({uuid:i})}},this),i(r)}))}readCharacteristic(e,t,i){this.characteristicHandles[e].read(this.checkForError(i,e=>{const i=this.bufferToDataView(e);t(i)}))}writeCharacteristic(e,t,i,r){const n=this.dataViewToBuffer(t),s=this.characteristicHandles[e],a=s.properties.indexOf("writeWithoutResponse")>=0||s.properties.indexOf("authenticatedSignedWrites")>=0,c="darwin"!==this.os&&a?25:null;s.write(n,a,this.checkForError(r,i,c))}enableNotify(e,t,i,r){if(this.charNotifies[e])return this.charNotifies[e]=t,i();this.characteristicHandles[e].once("notify",n=>{if(!0!==n)return r("notify failed to enable");this.charNotifies[e]=t,i()}),this.characteristicHandles[e].notify(!0,this.checkForError(r))}disableNotify(e,t,i){if(!this.charNotifies[e])return t();this.characteristicHandles[e].once("notify",r=>{if(!1!==r)return i("notify failed to disable");this.charNotifies[e]&&delete this.charNotifies[e],t()}),this.characteristicHandles[e].notify(!1,this.checkForError(i))}readDescriptor(e,t,i){this.descriptorHandles[e].readValue(this.checkForError(i,e=>{const i=this.bufferToDataView(e);t(i)}))}writeDescriptor(e,t,i,r){const n=this.dataViewToBuffer(t);this.descriptorHandles[e].writeValue(n,this.checkForError(r,i))}}E.EVENT_ENABLED="enabledchanged";const x=new E;class L{constructor(e){this.characteristic=null,this.uuid=null,this._value=null,this.handle=null,this.characteristic=e.characteristic,this.uuid=e.uuid,this._value=e.value,this.handle=`${this.characteristic.uuid}-${this.uuid}`}get value(){return this._value}readValue(){return new Promise((e,t)=>{if(!this.characteristic.service.device.gatt.connected)return t("readValue error: device not connected");x.readDescriptor(this.handle,t=>{this._value=t,e(t)},e=>{t("readValue error: "+e)})})}writeValue(e){return new Promise((t,i)=>{if(!this.characteristic.service.device.gatt.connected)return i("writeValue error: device not connected");const r=void 0!==e.buffer?e.buffer:e;const n=new DataView(r);x.writeDescriptor(this.handle,n,()=>{this._value=n,t()},e=>{i("writeValue error: "+e)})})}}class D{constructor(e,t){this.bubbles=!0,this.cancelable=!1,this.cancelBubble=!1,this.composed=!1,this.defaultPrevented=!1,this.eventPhase=0,this.isTrusted=!0,this.returnValue=!0,this.target=e,this.srcElement=e,this.currentTarget=e,this.type=t}composedPath(){return[]}initEvent(e,t,i){this.type=e,this.bubbles=t,this.cancelable=i}preventDefault(){this.defaultPrevented=!0}stopImmediatePropagation(){}stopPropagation(){}}class P extends f{constructor(e){super(),this.service=null,this.uuid=null,this._value=null,this.handle=null,this.descriptors=null,this.service=e.service,this.uuid=e.uuid,this.properties=e.properties,this._value=e.value,this.handle=this.uuid}get value(){return this._value}set oncharacteristicvaluechanged(e){this._oncharacteristicvaluechanged&&this.removeEventListener("characteristicvaluechanged",this._oncharacteristicvaluechanged),this._oncharacteristicvaluechanged=e,this.addEventListener("characteristicvaluechanged",this._oncharacteristicvaluechanged)}setValue(e,t){this._value=e,t&&(this.dispatchEvent(new D(this,"characteristicvaluechanged")),this.service.dispatchEvent(new D(this,"characteristicvaluechanged")),this.service.device.dispatchEvent(new D(this,"characteristicvaluechanged")),this.service.device._bluetooth.dispatchEvent(new D(this,"characteristicvaluechanged")))}getDescriptor(e){return new Promise((t,i)=>this.service.device.gatt.connected?e?void this.getDescriptors(e).then(e=>{if(1!==e.length)return i("getDescriptor error: descriptor not found");t(e[0])}).catch(e=>{i("getDescriptor error: "+e)}):i("getDescriptor error: no descriptor specified"):i("getDescriptor error: device not connected"))}getDescriptors(e){return new Promise((t,i)=>{if(!this.service.device.gatt.connected)return i("getDescriptors error: device not connected");function r(){if(!e)return t(this.descriptors);const r=this.descriptors.filter(t=>t.uuid===y(e));if(1!==r.length)return i("getDescriptors error: descriptor not found");t(r)}if(this.descriptors)return r.call(this);x.discoverDescriptors(this.handle,[],e=>{this.descriptors=e.map(e=>(Object.assign(e,{characteristic:this}),new L(e))),r.call(this)},e=>{i("getDescriptors error: "+e)})})}readValue(){return new Promise((e,t)=>{if(!this.service.device.gatt.connected)return t("readValue error: device not connected");x.readCharacteristic(this.handle,t=>{this.setValue(t,!0),e(t)},e=>{t("readValue error: "+e)})})}writeValue(e){return new Promise((t,i)=>{if(!this.service.device.gatt.connected)return i("writeValue error: device not connected");const r=void 0!==e.buffer?e.buffer:e;const n=new DataView(r);x.writeCharacteristic(this.handle,n,()=>{this.setValue(n),t()},e=>{i("writeValue error: "+e)})})}startNotifications(){return new Promise((e,t)=>{if(!this.service.device.gatt.connected)return t("startNotifications error: device not connected");x.enableNotify(this.handle,e=>{this.setValue(e,!0)},()=>{e(this)},e=>{t("startNotifications error: "+e)})})}stopNotifications(){return new Promise((e,t)=>{if(!this.service.device.gatt.connected)return t("stopNotifications error: device not connected");x.disableNotify(this.handle,()=>{e(this)},e=>{t("stopNotifications error: "+e)})})}}class S extends f{constructor(e){super(),this.device=null,this.uuid=null,this.isPrimary=!1,this.handle=null,this.services=null,this.characteristics=null,this.device=e.device,this.uuid=e.uuid,this.isPrimary=e.isPrimary,this.handle=this.uuid,this.dispatchEvent(new D(this,"serviceadded")),this.device.dispatchEvent(new D(this,"serviceadded")),this.device._bluetooth.dispatchEvent(new D(this,"serviceadded"))}set oncharacteristicvaluechanged(e){this._oncharacteristicvaluechanged&&this.removeEventListener("characteristicvaluechanged",this._oncharacteristicvaluechanged),this._oncharacteristicvaluechanged=e,this.addEventListener("characteristicvaluechanged",this._oncharacteristicvaluechanged)}set onserviceadded(e){this._onserviceadded&&this.removeEventListener("serviceadded",this._onserviceadded),this._onserviceadded=e,this.addEventListener("serviceadded",this._onserviceadded)}set onservicechanged(e){this._onservicechanged&&this.removeEventListener("servicechanged",this._onservicechanged),this._onservicechanged=e,this.addEventListener("servicechanged",this._onservicechanged)}set onserviceremoved(e){this._onserviceremoved&&this.removeEventListener("serviceremoved",this._onserviceremoved),this._onserviceremoved=e,this.addEventListener("serviceremoved",this._onserviceremoved)}getCharacteristic(e){return new Promise((t,i)=>this.device.gatt.connected?e?void this.getCharacteristics(e).then(e=>{if(1!==e.length)return i("getCharacteristic error: characteristic not found");t(e[0])}).catch(e=>{i("getCharacteristic error: "+e)}):i("getCharacteristic error: no characteristic specified"):i("getCharacteristic error: device not connected"))}getCharacteristics(e){return new Promise((t,i)=>{if(!this.device.gatt.connected)return i("getCharacteristics error: device not connected");function r(){if(!e)return t(this.characteristics);e=b(e);const r=this.characteristics.filter(t=>t.uuid===e);if(1!==r.length)return i("getCharacteristics error: characteristic not found");t(r)}if(this.characteristics)return r.call(this);x.discoverCharacteristics(this.handle,[],e=>{this.characteristics=e.map(e=>(Object.assign(e,{service:this}),new P(e))),r.call(this)},e=>{i("getCharacteristics error: "+e)})})}getIncludedService(e){return new Promise((t,i)=>this.device.gatt.connected?e?void this.getIncludedServices(e).then(e=>{if(1!==e.length)return i("getIncludedService error: service not found");t(e[0])}).catch(e=>{i("getIncludedService error: "+e)}):i("getIncludedService error: no service specified"):i("getIncludedService error: device not connected"))}getIncludedServices(e){return new Promise((t,i)=>{if(!this.device.gatt.connected)return i("getIncludedServices error: device not connected");function r(){if(!e)return t(this.services);const r=this.services.filter(t=>t.uuid===w(e));if(1!==r.length)return i("getIncludedServices error: service not found");t(r)}if(this.services)return r.call(this);x.discoverIncludedServices(this.handle,this.device._allowedServices,e=>{this.services=e.map(e=>(Object.assign(e,{device:this.device}),new S(e))),r.call(this)},e=>{i("getIncludedServices error: "+e)})})}}class C{constructor(e){this.device=null,this._connected=!1,this.handle=null,this.services=null,this.device=e,this.handle=this.device.id}get connected(){return this._connected}connect(){return new Promise((e,t)=>{if(this.connected)return t("connect error: device already connected");x.connect(this.handle,()=>{this._connected=!0,e(this)},()=>{this.services=null,this._connected=!1,this.device.dispatchEvent(new D(this.device,"gattserverdisconnected")),this.device._bluetooth.dispatchEvent(new D(this.device,"gattserverdisconnected"))},e=>{t("connect Error: "+e)})})}disconnect(){x.disconnect(this.handle),this._connected=!1}getPrimaryService(e){return new Promise((t,i)=>this.connected?e?void this.getPrimaryServices(e).then(e=>{if(1!==e.length)return i("getPrimaryService error: service not found");t(e[0])}).catch(e=>{i("getPrimaryService error: "+e)}):i("getPrimaryService error: no service specified"):i("getPrimaryService error: device not connected"))}getPrimaryServices(e){return new Promise((t,i)=>{if(!this.connected)return i("getPrimaryServices error: device not connected");function r(){if(!e)return t(this.services);const r=this.services.filter(t=>t.uuid===w(e));if(1!==r.length)return i("getPrimaryServices error: service not found");t(r)}if(this.services)return r.call(this);x.discoverServices(this.handle,this.device._allowedServices,e=>{this.services=e.map(e=>(Object.assign(e,{device:this.device}),new S(e))),r.call(this)},e=>{i("getPrimaryServices error: "+e)})})}}class k extends f{constructor(e){super(),this.id=null,this.name=null,this.gatt=null,this.watchingAdvertisements=!1,this._bluetooth=null,this._allowedServices=[],this._serviceUUIDs=[],this.id=e.id,this.name=e.name,this.gatt=e.gatt,this.watchAdvertisements=e.watchAdvertisements,this.adData=e.adData,this._bluetooth=e._bluetooth,this._allowedServices=e._allowedServices,this._serviceUUIDs=e._serviceUUIDs,this.name||(this.name=`Unknown or Unsupported Device (${this.id})`),this.gatt||(this.gatt=new C(this))}set oncharacteristicvaluechanged(e){this._oncharacteristicvaluechanged&&this.removeEventListener("characteristicvaluechanged",this._oncharacteristicvaluechanged),this._oncharacteristicvaluechanged=e,this.addEventListener("characteristicvaluechanged",this._oncharacteristicvaluechanged)}set onserviceadded(e){this._onserviceadded&&this.removeEventListener("serviceadded",this._onserviceadded),this._onserviceadded=e,this.addEventListener("serviceadded",this._onserviceadded)}set onservicechanged(e){this._onservicechanged&&this.removeEventListener("servicechanged",this._onservicechanged),this._onservicechanged=e,this.addEventListener("servicechanged",this._onservicechanged)}set onserviceremoved(e){this._onserviceremoved&&this.removeEventListener("serviceremoved",this._onserviceremoved),this._onserviceremoved=e,this.addEventListener("serviceremoved",this._onserviceremoved)}set ongattserverdisconnected(e){this._ongattserverdisconnected&&this.removeEventListener("gattserverdisconnected",this._ongattserverdisconnected),this._ongattserverdisconnected=e,this.addEventListener("gattserverdisconnected",this._ongattserverdisconnected)}set onadvertisementreceived(e){this._onadvertisementreceived&&this.removeEventListener("advertisementreceived",this._onadvertisementreceived),this._onadvertisementreceived=e,this.addEventListener("advertisementreceived",this._onadvertisementreceived)}watchAdvertisements(){return new Promise((e,t)=>{t("watchAdvertisements error: method not implemented")})}unwatchAdvertisements(){return new Promise((e,t)=>{t("unwatchAdvertisements error: method not implemented")})}}class O extends f{constructor(e){super(),this.deviceFound=null,this.scanTime=10240,this.scanner=null,e=e||{},this.referringDevice=e.referringDevice,this.deviceFound=e.deviceFound,e.scanTime&&(this.scanTime=1e3*e.scanTime),x.on(E.EVENT_ENABLED,e=>{this.dispatchEvent(new D(this,"availabilitychanged"))})}set oncharacteristicvaluechanged(e){this._oncharacteristicvaluechanged&&this.removeEventListener("characteristicvaluechanged",this._oncharacteristicvaluechanged),this._oncharacteristicvaluechanged=e,this.addEventListener("characteristicvaluechanged",this._oncharacteristicvaluechanged)}set onserviceadded(e){this._onserviceadded&&this.removeEventListener("serviceadded",this._onserviceadded),this._onserviceadded=e,this.addEventListener("serviceadded",this._onserviceadded)}set onservicechanged(e){this._onservicechanged&&this.removeEventListener("servicechanged",this._onservicechanged),this._onservicechanged=e,this.addEventListener("servicechanged",this._onservicechanged)}set onserviceremoved(e){this._onserviceremoved&&this.removeEventListener("serviceremoved",this._onserviceremoved),this._onserviceremoved=e,this.addEventListener("serviceremoved",this._onserviceremoved)}set ongattserverdisconnected(e){this._ongattserverdisconnected&&this.removeEventListener("gattserverdisconnected",this._ongattserverdisconnected),this._ongattserverdisconnected=e,this.addEventListener("gattserverdisconnected",this._ongattserverdisconnected)}set onadvertisementreceived(e){this._onadvertisementreceived&&this.removeEventListener("advertisementreceived",this._onadvertisementreceived),this._onadvertisementreceived=e,this.addEventListener("advertisementreceived",this._onadvertisementreceived)}set onavailabilitychanged(e){this._onavailabilitychanged&&this.removeEventListener("availabilitychanged",this._onavailabilitychanged),this._onavailabilitychanged=e,this.addEventListener("availabilitychanged",this._onavailabilitychanged)}filterDevice(e,t,i){let r=!1;return e.forEach(e=>{if(!e.name||e.name===t.name){if(e.namePrefix){if(!t.name||e.namePrefix.length>t.name.length)return;if(e.namePrefix!==t.name.substr(0,e.namePrefix.length))return}if(e.services){const r=e.services.map(w);if(!r.every(e=>t._serviceUUIDs.indexOf(e)>-1))return;i=i.concat(r)}r=!0}}),!!r&&t}getAvailability(){return new Promise((e,t)=>{x.getEnabled(t=>{e(t)})})}requestDevice(e={filters:[]}){return new Promise((t,i)=>{if(null!==this.scanner)return i("requestDevice error: request in progress");const r=e=>void 0!==e.filters;let n=[];if(r(e)){if(0===e.filters.length)return i(new TypeError("requestDevice error: no filters specified"));if(e.filters.some(e=>0===Object.keys(e).length))return i(new TypeError("requestDevice error: empty filter specified"));if(e.filters.some(e=>void 0!==e.namePrefix&&""===e.namePrefix))return i(new TypeError("requestDevice error: empty namePrefix specified"));e.filters.forEach(e=>{e.services&&(n=n.concat(e.services.map(w))),n=n.filter((e,t,i)=>i.indexOf(e)===t)})}else if(!0!==e.acceptAllDevices)return i(new TypeError("requestDevice error: specify filters or acceptAllDevices"));let s=!1;x.startScan(n,i=>{let n=[];function a(e){this.cancelRequest().then(()=>{t(e)})}if(r(e)&&(i=this.filterDevice(e.filters,i,n)),i){s=!0,e.optionalServices&&(n=n.concat(e.optionalServices.map(w)));const t=n.filter((e,t,i)=>i.indexOf(e)===t);Object.assign(i,{_bluetooth:this,_allowedServices:t});const r=new k(i);this.deviceFound&&!0!==this.deviceFound(r,function(){a.call(this,r)}.bind(this))||a.call(this,r)}},()=>{this.scanner=setTimeout(()=>{this.cancelRequest().then(()=>{s||i("requestDevice error: no devices found")})},this.scanTime)},e=>i("requestDevice error: "+e))})}cancelRequest(){return new Promise((e,t)=>{this.scanner&&(clearTimeout(this.scanner),this.scanner=null,x.stopScan()),e()})}}O.EVENT_AVAILABILITY="availabilitychanged";const T=new O;e.Bluetooth=O,e.bluetooth=T,e.getCanonicalUUID=g,e.getCharacteristicUUID=b,e.getDescriptorUUID=y,e.getServiceUUID=w,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=webbluetooth.umd.js.map |
{ | ||
"name": "webbluetooth", | ||
"version": "2.0.1-next.e654729.0", | ||
"version": "2.0.1", | ||
"description": "Node.js implementation of the Web Bluetooth Specification", | ||
@@ -35,12 +35,12 @@ "homepage": "https://github.com/thegecko/webbluetooth", | ||
"rollup-plugin-typescript2": "^0.21.0", | ||
"tslint": "^5.16.0", | ||
"tslint": "^6.1.1", | ||
"tslint-eslint-rules": "^5.4.0", | ||
"typedoc": "^0.15.0", | ||
"typescript": "^3.4.5" | ||
"typedoc": "^0.17.4", | ||
"typescript": "^3.8.3" | ||
}, | ||
"dependencies": { | ||
"@types/node": "^8.0.54", | ||
"@types/web-bluetooth": "^0.0.5", | ||
"@abandonware/noble": "abandonware/noble" | ||
"@abandonware/noble": "1.9.2-7", | ||
"@types/node": "^8.10.60", | ||
"@types/web-bluetooth": "^0.0.5" | ||
} | ||
} |
@@ -42,3 +42,3 @@ /// <reference types="node" /> | ||
constructor(); | ||
private readonly state; | ||
private get state(); | ||
private init; | ||
@@ -45,0 +45,0 @@ private checkForError; |
@@ -49,15 +49,15 @@ /// <reference types="web-bluetooth" /> | ||
private _oncharacteristicvaluechanged; | ||
oncharacteristicvaluechanged: (ev: Event) => void; | ||
set oncharacteristicvaluechanged(fn: (ev: Event) => void); | ||
private _onserviceadded; | ||
onserviceadded: (ev: Event) => void; | ||
set onserviceadded(fn: (ev: Event) => void); | ||
private _onservicechanged; | ||
onservicechanged: (ev: Event) => void; | ||
set onservicechanged(fn: (ev: Event) => void); | ||
private _onserviceremoved; | ||
onserviceremoved: (ev: Event) => void; | ||
set onserviceremoved(fn: (ev: Event) => void); | ||
private _ongattserverdisconnected; | ||
ongattserverdisconnected: (ev: Event) => void; | ||
set ongattserverdisconnected(fn: (ev: Event) => void); | ||
private _onadvertisementreceived; | ||
onadvertisementreceived: (ev: Event) => void; | ||
set onadvertisementreceived(fn: (ev: Event) => void); | ||
private _onavailabilitychanged; | ||
onavailabilitychanged: (ev: Event) => void; | ||
set onavailabilitychanged(fn: (ev: Event) => void); | ||
/** | ||
@@ -64,0 +64,0 @@ * Bluetooth constructor |
@@ -36,7 +36,7 @@ /// <reference types="web-bluetooth" /> | ||
*/ | ||
readonly value: DataView; | ||
get value(): DataView; | ||
private handle; | ||
private descriptors; | ||
private _oncharacteristicvaluechanged; | ||
oncharacteristicvaluechanged: (ev: Event) => void; | ||
set oncharacteristicvaluechanged(fn: (ev: Event) => void); | ||
/** | ||
@@ -43,0 +43,0 @@ * Characteristic constructor |
@@ -19,3 +19,3 @@ /// <reference types="web-bluetooth" /> | ||
*/ | ||
readonly value: DataView; | ||
get value(): DataView; | ||
private handle; | ||
@@ -22,0 +22,0 @@ /** |
@@ -62,13 +62,13 @@ import { TypedDispatcher } from "./dispatcher"; | ||
private _oncharacteristicvaluechanged; | ||
oncharacteristicvaluechanged: (ev: Event) => void; | ||
set oncharacteristicvaluechanged(fn: (ev: Event) => void); | ||
private _onserviceadded; | ||
onserviceadded: (ev: Event) => void; | ||
set onserviceadded(fn: (ev: Event) => void); | ||
private _onservicechanged; | ||
onservicechanged: (ev: Event) => void; | ||
set onservicechanged(fn: (ev: Event) => void); | ||
private _onserviceremoved; | ||
onserviceremoved: (ev: Event) => void; | ||
set onserviceremoved(fn: (ev: Event) => void); | ||
private _ongattserverdisconnected; | ||
ongattserverdisconnected: (ev: Event) => void; | ||
set ongattserverdisconnected(fn: (ev: Event) => void); | ||
private _onadvertisementreceived; | ||
onadvertisementreceived: (ev: Event) => void; | ||
set onadvertisementreceived(fn: (ev: Event) => void); | ||
/** | ||
@@ -86,4 +86,4 @@ * Device constructor | ||
*/ | ||
unwatchAdvertisements(): Promise<{}>; | ||
unwatchAdvertisements(): Promise<unknown>; | ||
} | ||
export {}; |
@@ -16,3 +16,3 @@ import { BluetoothDevice } from "./device"; | ||
*/ | ||
readonly connected: boolean; | ||
get connected(): boolean; | ||
private handle; | ||
@@ -19,0 +19,0 @@ private services; |
@@ -43,9 +43,9 @@ import { TypedDispatcher } from "./dispatcher"; | ||
private _oncharacteristicvaluechanged; | ||
oncharacteristicvaluechanged: (ev: Event) => void; | ||
set oncharacteristicvaluechanged(fn: (ev: Event) => void); | ||
private _onserviceadded; | ||
onserviceadded: (ev: Event) => void; | ||
set onserviceadded(fn: (ev: Event) => void); | ||
private _onservicechanged; | ||
onservicechanged: (ev: Event) => void; | ||
set onservicechanged(fn: (ev: Event) => void); | ||
private _onserviceremoved; | ||
onserviceremoved: (ev: Event) => void; | ||
set onserviceremoved(fn: (ev: Event) => void); | ||
/** | ||
@@ -52,0 +52,0 @@ * Service constructor |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
GitHub dependency
Supply chain riskContains a dependency which resolves to a GitHub URL. Dependencies fetched from GitHub specifiers are not immutable can be used to inject untrusted code or reduce the likelihood of a reproducible install.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses eval() which is a dangerous function. This prevents the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 2 instances in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
6147
1
0
1
1388065
+ Added@abandonware/bluetooth-hci-socket@0.5.3-12(transitive)
+ Added@abandonware/noble@1.9.2-7(transitive)
+ Added@isaacs/cliui@8.0.2(transitive)
+ Added@mapbox/node-pre-gyp@1.0.11(transitive)
+ Added@npmcli/agent@2.2.2(transitive)
+ Added@npmcli/fs@3.1.1(transitive)
+ Added@pkgjs/parseargs@0.11.0(transitive)
+ Added@types/w3c-web-usb@1.0.10(transitive)
+ Addedabbrev@1.1.12.0.0(transitive)
+ Addedagent-base@6.0.27.1.1(transitive)
+ Addedaggregate-error@3.1.0(transitive)
+ Addedansi-regex@5.0.16.0.1(transitive)
+ Addedansi-styles@4.3.06.2.1(transitive)
+ Addedaproba@2.0.0(transitive)
+ Addedare-we-there-yet@2.0.0(transitive)
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbrace-expansion@1.1.112.0.1(transitive)
+ Addedcacache@18.0.3(transitive)
+ Addedchownr@2.0.0(transitive)
+ Addedclean-stack@2.2.0(transitive)
+ Addedcolor-convert@2.0.1(transitive)
+ Addedcolor-name@1.1.4(transitive)
+ Addedcolor-support@1.1.3(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addedconsole-control-strings@1.1.0(transitive)
+ Addedcross-spawn@7.0.3(transitive)
+ Addeddebug@4.3.5(transitive)
+ Addeddelegates@1.0.0(transitive)
+ Addeddetect-libc@2.0.3(transitive)
+ Addedeastasianwidth@0.2.0(transitive)
+ Addedemoji-regex@8.0.09.2.2(transitive)
+ Addedencoding@0.1.13(transitive)
+ Addedenv-paths@2.2.1(transitive)
+ Addederr-code@2.0.3(transitive)
+ Addedexponential-backoff@3.1.1(transitive)
+ Addedforeground-child@3.2.0(transitive)
+ Addedfs-minipass@2.1.03.0.3(transitive)
+ Addedfs.realpath@1.0.0(transitive)
+ Addedgauge@3.0.2(transitive)
+ Addedglob@10.4.17.2.3(transitive)
+ Addedgraceful-fs@4.2.11(transitive)
+ Addedhas-unicode@2.0.1(transitive)
+ Addedhttp-cache-semantics@4.1.1(transitive)
+ Addedhttp-proxy-agent@7.0.2(transitive)
+ Addedhttps-proxy-agent@5.0.17.0.4(transitive)
+ Addediconv-lite@0.6.3(transitive)
+ Addedimurmurhash@0.1.4(transitive)
+ Addedindent-string@4.0.0(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedip-address@9.0.5(transitive)
+ Addedis-fullwidth-code-point@3.0.0(transitive)
+ Addedis-lambda@1.0.1(transitive)
+ Addedisexe@2.0.03.1.1(transitive)
+ Addedjackspeak@3.4.0(transitive)
+ Addedjsbn@1.1.0(transitive)
+ Addedlru-cache@10.2.2(transitive)
+ Addedmake-dir@3.1.0(transitive)
+ Addedmake-fetch-happen@13.0.1(transitive)
+ Addedminimatch@3.1.29.0.4(transitive)
+ Addedminipass@3.3.65.0.07.1.2(transitive)
+ Addedminipass-collect@2.0.1(transitive)
+ Addedminipass-fetch@3.0.5(transitive)
+ Addedminipass-flush@1.0.5(transitive)
+ Addedminipass-pipeline@1.2.4(transitive)
+ Addedminipass-sized@1.0.3(transitive)
+ Addedminizlib@2.1.2(transitive)
+ Addedmkdirp@1.0.4(transitive)
+ Addedms@2.1.2(transitive)
+ Addednan@2.19.0(transitive)
+ Addednapi-thread-safe-callback@0.0.6(transitive)
+ Addednegotiator@0.6.3(transitive)
+ Addednode-addon-api@2.0.28.0.0(transitive)
+ Addednode-fetch@2.7.0(transitive)
+ Addednode-gyp@10.1.0(transitive)
+ Addednode-gyp-build@4.8.1(transitive)
+ Addednopt@5.0.07.2.1(transitive)
+ Addednpmlog@5.0.1(transitive)
+ Addedobject-assign@4.1.1(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedp-map@4.0.0(transitive)
+ Addedpath-is-absolute@1.0.1(transitive)
+ Addedpath-key@3.1.1(transitive)
+ Addedpath-scurry@1.11.1(transitive)
+ Addedproc-log@3.0.04.2.0(transitive)
+ Addedpromise-retry@2.0.1(transitive)
+ Addedreadable-stream@3.6.2(transitive)
+ Addedretry@0.12.0(transitive)
+ Addedrimraf@3.0.2(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedsafer-buffer@2.1.2(transitive)
+ Addedsemver@6.3.17.6.2(transitive)
+ Addedset-blocking@2.0.0(transitive)
+ Addedshebang-command@2.0.0(transitive)
+ Addedshebang-regex@3.0.0(transitive)
+ Addedsignal-exit@3.0.74.1.0(transitive)
+ Addedsmart-buffer@4.2.0(transitive)
+ Addedsocks@2.8.3(transitive)
+ Addedsocks-proxy-agent@8.0.3(transitive)
+ Addedsprintf-js@1.1.3(transitive)
+ Addedssri@10.0.6(transitive)
+ Addedstring-width@4.2.35.1.2(transitive)
+ Addedstring_decoder@1.3.0(transitive)
+ Addedstrip-ansi@6.0.17.1.0(transitive)
+ Addedtar@6.2.1(transitive)
+ Addedtr46@0.0.3(transitive)
+ Addedunique-filename@3.0.0(transitive)
+ Addedunique-slug@4.0.0(transitive)
+ Addedusb@2.13.0(transitive)
+ Addedutil-deprecate@1.0.2(transitive)
+ Addedwebidl-conversions@3.0.1(transitive)
+ Addedwhatwg-url@5.0.0(transitive)
+ Addedwhich@2.0.24.0.0(transitive)
+ Addedwide-align@1.1.5(transitive)
+ Addedwrap-ansi@7.0.08.1.0(transitive)
+ Addedwrappy@1.0.2(transitive)
+ Addedyallist@4.0.0(transitive)
Updated@abandonware/noble@1.9.2-7
Updated@types/node@^8.10.60