diff --git a/blueapp.io.min.js b/blueapp.io.min.js index c95cd56..b10792a 100644 --- a/blueapp.io.min.js +++ b/blueapp.io.min.js @@ -1,7 +1,7 @@ /* blueapp.io v0.0.1 */ -require=function e(r,t,i){function n(s,o){if(!t[s]){if(!r[s]){var c="function"==typeof require&&require;if(!o&&c)return c(s,!0);if(a)return a(s,!0);var u=new Error("Cannot find module '"+s+"'");throw u.code="MODULE_NOT_FOUND",u}var l=t[s]={exports:{}};r[s][0].call(l.exports,function(e){var t=r[s][1][e];return n(t?t:e)},l,l.exports,e,r,t,i)}return t[s].exports}for(var a="function"==typeof require&&require,s=0;sreq:"),i.send(JSON.stringify(s))},this.respond=function(e,r){var t=d.wrapResponse(e,r);m.traceMessage(t,">rsp:"),i.send(JSON.stringify(t))},this.sendIndications=function(e,r){var t={params:r,jsonrpc:"2.0"};t.result=e,t.params=r,m.traceMessage(t,">rsp:"),i.send(JSON.stringify(t))},this.sendError=function(e){e.jsonrpc="2.0",m.traceMessage(e,">rsp:"),i.send(JSON.stringify(e))}}var n=e("./lib/event-emitter"),a=e("./errors").InternalError,s=e("./errors").ApplicationError,o=e("./errors").GatewayError,c=e("./lib/message-handler").MessageHandler,u=e("./lib/message-processor").MessageProcessor,l=e("./gateway").Gateway,p=(e("./lib/message-helper"),e("./lib/server-message-handler").ServerMessageHandler),f={keepalive:!0,dropConnectionOnKeepaliveTimeout:!0,keepaliveInterval:1e4,keepaliveGracePeriod:1e4};n.makeEmitter(i),r.exports.GATTIP=i},{"./errors":3,"./gateway":4,"./lib/event-emitter":7,"./lib/message-handler":10,"./lib/message-helper":11,"./lib/message-processor":12,"./lib/server-message-handler":13,websocket:17}],6:[function(e,r,t){var i={DEFAULT_MESSAGE_TIMEOUT_MS:61e3,MAX_PENDING_MESSAGES:200,NUM_CONNECT_ATTEMPTS:3,kMessageId:"id",kSessionId:"session_id",kAuthenticate:"aut",kOpen:"opn",kDeviceAccessToken:"dat",kGetVersionInfo:"vif",kError:"error",kCode:"code",kMessageField:"message",kMethod:"method",kResult:"result",kIdField:"id",kConfigure:"aa",kScanForPeripherals:"ab",kStopScanning:"ac",kConnect:"ad",kDisconnect:"ae",kCentralState:"af",kGetConnectedPeripherals:"ag",kGetPerhipheralsWithServices:"ah",kGetPerhipheralsWithIdentifiers:"ai",kGetServices:"ak",kGetIncludedServices:"al",kGetCharacteristics:"am",kGetDescriptors:"an",kGetCharacteristicValue:"ao",kGetDescriptorValue:"ap",kWriteCharacteristicValue:"aq",kWriteDescriptorValue:"ar",kSetValueNotification:"as",kGetPeripheralState:"at",kGetRSSI:"au",kInvalidatedServices:"av",kPeripheralNameUpdate:"aw",kMessage:"zz",kCentralUUID:"ba",kPeripheralUUID:"bb",kPeripheralName:"bc",kPeripheralUUIDs:"bd",kServiceUUID:"be",kServiceUUIDs:"bf",kPeripherals:"bg",kIncludedServiceUUIDs:"bh",kCharacteristicUUID:"bi",kCharacteristicUUIDs:"bj",kDescriptorUUID:"bk",kServices:"bl",kCharacteristics:"bm",kDescriptors:"bn",kProperties:"bo",kValue:"bp",kState:"bq",kStateInfo:"br",kStateField:"bs",kWriteType:"bt",kRSSIkey:"bu",kIsPrimaryKey:"bv",kIsBroadcasted:"bw",kIsNotifying:"bx",kShowPowerAlert:"by",kIdentifierKey:"bz",kScanOptionAllowDuplicatesKey:"b0",kScanOptionSolicitedServiceUUIDs:"b1",kAdvertisementDataKey:"b2",kCBAdvertisementDataManufacturerDataKey:"mfr",kCBAdvertisementDataServiceUUIDsKey:"suu",kCBAdvertisementDataServiceDataKey:"sdt",kCBAdvertisementDataOverflowServiceUUIDsKey:"b6",kCBAdvertisementDataSolicitedServiceUUIDsKey:"b7",kCBAdvertisementDataIsConnectable:"b8",kCBAdvertisementDataTxPowerLevel:"txp",kPeripheralBtAddress:"c1",kRawAdvertisementData:"c2",kScanRecord:"c3",kCBCentralManagerRestoredStatePeripheralsKey:"da",kCBCentralManagerRestoredStateScanServicesKey:"db",kWriteWithResponse:"cc",kWriteWithoutResponse:"cd",kNotifyOnConnection:"ce",kNotifyOnDisconnection:"cf",kNotifyOnNotification:"cg",kDisconnected:"ch",kConnecting:"ci",kConnected:"cj",kUnknown:"ck",kResetting:"cl",kUnsupported:"cm",kUnauthorized:"cn",kPoweredOff:"co",kPoweredOn:"cp",kErrorPeripheralNotFound:"-32001",kErrorServiceNotFound:"-32002",kErrorCharacteristicNotFound:"-32003",kErrorDescriptorNotFound:"-32004",kErrorPeripheralStateIsNotValid:"-32005",kErrorNoServiceSpecified:"-32006",kErrorNoPeripheralIdentiferSpecified:"-32007",kErrorStateRestorationNotValid:"-32008",kInvalidRequest:"-32600",kMethodNotFound:"-32601",kInvalidParams:"-32602",kError32603:"-32603",kParseError:"-32700",kGAP_ADTYPE_FLAGS:"01",kGAP_ADTYPE_INCOMPLETE_16BIT_SERVICEUUID:"02",kGAP_ADTYPE_COMPLETE_16BIT_SERVICEUUID:"03",kGAP_ADTYPE_INCOMPLETE_32BIT_SERVICEUUID:"04",kGAP_ADTYPE_COMPLETE_32BIT_SERVICEUUID:"05",kGAP_ADTYPE_INCOMPLETE_128BIT_SERVICEUUID:"06",kGAP_ADTYPE_COMPLETE_128BIT_SERVICEUUID:"07",kGAP_ADTYPE_POWER_LEVEL:"0A",kGAP_ADTYPE_MANUFACTURER_SPECIFIC:"FF",kGAP_ADTYPE_16BIT_SERVICE_DATA:"16",id:1,authenticate:"authenticate",AllProperties:["Broadcast","Read","WriteWithoutResponse","Write","Notify","Indicate","AuthenticatedSignedWrites","ExtendedProperties","NotifyEncryptionRequired","IndicateEncryptionRequired"]};r.exports.C=i},{}],7:[function(e,r,t){var i=e("events"),n=e("util");r.exports.makeEmitter=function(e){n.inherits(e,i)},r.exports.instantiateEmitter=function(e){i.call(e)}},{events:18,util:22}],8:[function(e,r,t){function i(){function r(e,r){var t=r?"0x":"";for(var i in e){var n=(255&e[i]).toString(16);1==n.length&&(n="0"+n),t+=n}return t}function t(e){for(var r in e)if(e.hasOwnProperty(r))return!1;return JSON.stringify(e)===JSON.stringify({})}function i(e){var r={};if(e&&e.getAllServices())for(var t in e.getAllServices()){var i={};i[n.kServiceUUID]=t,i[n.kIsPrimaryKey]=e.findService(t).isPrimary,i[n.kCharacteristics]=o(e.findService(t)),r[t]=i}return r}function o(e){var r={};if(e&&e.getAllCharacteristics())for(var t in e.getAllCharacteristics()){var i={};i[n.kCharacteristicUUID]=t,i[n.kValue]=e.findCharacteristic(t).value,i[n.kProperties]=e.findCharacteristic(t).allProperties(),i[n.kIsNotifying]=e.findCharacteristic(t).isNotifying,i[n.kDescriptors]=c(e.findCharacteristic(t)),r[t]=i}return r}function c(e){var r={};if(e&&e.getAllDescriptors())for(var t in e.getAllDescriptors()){var i={};i[n.kDescriptorUUID]=t,i[n.kValue]=e.findDescriptor(t).value,i[n.kProperties]=e.findDescriptor(t).properties,i[n.kIsNotifying]=e.findDescriptor(t).isNotifying,r[t]=i}return r}s.instantiateEmitter(this);var u,l=this;this.peripherals={},this.init=function(r,t){t&&(this.oninit=t),"object"!=typeof window&&(WebSocket=e("websocket").w3cwebsocket),l.socket=new WebSocket(r),l.socket.onopen=function(){l.initWithServer(l.socket),l.oninit&&l.oninit()}},this.initWithServer=function(e){if(u=e,!u.send)throw new Error("server must implement the send method");u.onmessage=l.processMessage,u.onclose||(u.onclose=function(){}),u.onerror||(u.onerror=function(e){}),u.error||(u.onerror=function(e){})},this.processMessage=function(e){function r(e){var r=p[n.kPeripheralUUID],i={};if(i.peripheral=l.peripherals[r],i.peripheral&&i.peripheral.uuid){if("p"===e)return i;var a=p[n.kServiceUUID];if(i.service=i.peripheral.findService(a),i.service&&i.service.uuid){if("s"===e)return i;var s=p[n.kCharacteristicUUID];if(i.characteristic=i.service.findCharacteristic(s),i.characteristic&&i.characteristic.uuid){if("c"===e)return i;var o=p[n.kDescriptorUUID];if(i.descriptor=i.characteristic.findDescriptor(o),i.descriptor&&i.descriptor.uuid)return i;throw l.sendErrorResponse(t.method,n.kErrorDescriptorNotFound,"Descriptor not found in the service database"),new Error("Descriptor not found")}throw l.sendErrorResponse(t.method,n.kErrorCharacteristicNotFound,"Characteristic not found in the service database"),new Error("Characteristic not found")}throw l.sendErrorResponse(t.method,n.kErrorServiceNotFound,"Service not found in the service database"),new Error("Service not found")}throw l.sendErrorResponse(t.method,n.kErrorPeripheralNotFound,"Peripheral not found in the service database"),new Error("Peripheral not found")}try{var t=JSON.parse(e.data)}catch(i){}if("undefined"!=typeof t&&t&&!t.error){var a;if(t.result&&(t.result==n.kMessage||t.result==n.kAuthenticate)){var s=!1;return t.error||"object"!=typeof t.params||t.params[n.kAuthenticate]!==!0||(s=!0),void l.emit("authenticated",s)}if(t.method&&t.method==n.kAuthenticate){var o={};o[n.kAuthenticate]=!0;var c={};return c.result=n.kAuthenticate,c.params=o,c[n.kIdField]=t[n.kIdField],c=JSON.stringify(c),void l.send(c)}var u={id:t.id,session_id:t.session_id,method:t.method},p=t.params;switch(t.method){case n.kConfigure:l.emit("configure",u,p[n.kShowPowerAlert],p[n.kIdentifierKey]);break;case n.kScanForPeripherals:l.emit("scan",u,p[n.kScanOptionAllowDuplicatesKey],p[n.kServiceUUIDs]);break;case n.kStopScanning:l.emit("stopScan",u);break;case n.kCentralState:l.emit("getCentralState",u);break;case n.kConnect:try{a=r("p"),l.emit("connect",u,a.peripheral.uuid)}catch(f){}break;case n.kDisconnect:try{a=r("p"),l.emit("disconnect",u,a.peripheral.uuid)}catch(f){}break;case n.kGetCharacteristicValue:try{a=r("c",u),l.emit("readCharacteristic",u,a.peripheral.uuid,a.service.uuid,a.characteristic.uuid)}catch(f){}break;case n.kWriteCharacteristicValue:try{a=r("c",u),l.emit("writeCharacteristic",u,a.peripheral.uuid,a.service.uuid,a.characteristic.uuid,t.params[n.kValue])}catch(f){}break;case n.kSetValueNotification:try{a=r("c",u),a.characteristic.isNotifying=t.params[n.kValue],l.emit("enableNotifications",u,a.peripheral.uuid,a.service.uuid,a.characteristic.uuid,t.params[n.kIsNotifying])}catch(f){}break;case n.kGetDescriptorValue:try{a=r("d",u),l.emit("readDescriptor",u,a.peripheral.uuid,a.service.uuid,a.characteristic.uuid,a.descriptor.uuid)}catch(f){}break;case n.kWriteDescriptorValue:try{a=r("d",u),l.emit("writeDescriptor",u,a.peripheral.uuid,a.service.uuid,a.characteristic.uuid,a.descriptor.uuid,t.params[n.kValue])}catch(f){}break;default:return void l.sendErrorResponse(u,t.method,n.kInvalidRequest,"Request not handled by server")}}},this.sendErrorResponse=function(e,r,t,i){var a={};params={},a[n.kCode]=t,a[n.kMessageField]=i,params[n.kError]=a,l.write(r,void 0,e,a)},this.authenticate=function(e,r){params={},params[n.kDeviceAccessToken]=e,params[n.kGetVersionInfo]=r;var t={};t.method=n.kAuthenticate,t.params=params,t.id=n.id.toString(),n.id+=1,this.send(JSON.stringify(t))},this.configureResponse=function(e,r){r?l.sendErrorResponse(e,n.kConfigure,void 0):l.write(n.kConfigure,void 0,e)},this.centralStateResponse=function(e,r,t){t?l.sendErrorResponse(e,n.kCentralState,void 0):(params={},params[n.kState]=r,l.write(n.kCentralState,params,e))},this.scanResponse=function(e,i,a,s,o,c,u,p){params={};var f,h;if(!t(u)){f={};for(var d in u){var v=d.toUpperCase();f[v]=r(u[d]).toUpperCase()}}if(!t(p)){h={};for(var k in p){var m=k.toUpperCase();h[m]=r(p[k]).toUpperCase()}}params[n.kPeripheralName]=a,params[n.kPeripheralUUID]=i,params[n.kRSSIkey]=s,params[n.kCBAdvertisementDataTxPowerLevel]=o,params[n.kCBAdvertisementDataServiceUUIDsKey]=c&&c.length>0?c:void 0,params[n.kCBAdvertisementDataManufacturerDataKey]=f,params[n.kCBAdvertisementDataServiceDataKey]=h,l.write(n.kScanForPeripherals,params,e)},this.stopScanResponse=function(e,r){r?this.sendErrorResponse(e,n.kStopScanning,r):l.write(n.kStopScanning,void 0,e)},this.connectResponse=function(e,r,t){var a={};a[n.kPeripheralUUID]=r.uuid,a[n.kPeripheralName]=r.name;var s={};s=i(r),a[n.kServices]=s,t?l.sendErrorResponse(e,n.kConnect,t):l.write(n.kConnect,a,e)},this.disconnectResponse=function(e,r,t){t?l.sendErrorResponse(e,n.kDisconnect,t):(params={},params[n.kPeripheralUUID]=r.uuid,params[n.kPeripheralName]=r.name,l.write(n.kDisconnect,params))},this.write=function(e,r,t,i){var n={};n.jsonrpc="2.0",n.result=e,n.params=r,n.error=i,t&&(n.id=t.id,n.session_id=t.session_id),l.send(JSON.stringify(n))},this.send=function(e){return u?void(1===u.readyState&&u.send(e)):void l.onerror("not connected")},this.close=function(e){u&&u.close()},this.addPeripheral=function(e,r,t,i,n){var s=new a(this,e,r,t,i,n);return l.peripherals[s.uuid]=s,s},this.GATM_SECURITY_PROPERTIES_NO_SECURITY=0,this.GATM_SECURITY_PROPERTIES_UNAUTHENTICATED_ENCRYPTION_WRITE=1,this.GATM_SECURITY_PROPERTIES_AUTHENTICATED_ENCRYPTION_WRITE=2,this.GATM_SECURITY_PROPERTIES_UNAUTHENTICATED_ENCRYPTION_READ=4,this.GATM_SECURITY_PROPERTIES_AUTHENTICATED_ENCRYPTION_READ=8,this.GATM_SECURITY_PROPERTIES_UNAUTHENTICATED_SIGNED_WRITES=16,this.GATM_SECURITY_PROPERTIES_AUTHENTICATED_SIGNED_WRITES=32,this.GATM_CHARACTERISTIC_PROPERTIES_BROADCAST=1,this.GATM_CHARACTERISTIC_PROPERTIES_READ=2,this.GATM_CHARACTERISTIC_PROPERTIES_WRITE_WO_RESP=4,this.GATM_CHARACTERISTIC_PROPERTIES_WRITE=8,this.GATM_CHARACTERISTIC_PROPERTIES_NOTIFY=16,this.GATM_CHARACTERISTIC_PROPERTIES_INDICATE=32,this.GATM_CHARACTERISTIC_PROPERTIES_AUTHENTICATED_SIGNED_WRITES=64,this.GATM_CHARACTERISTIC_PROPERTIES_EXT_PROPERTIES=128,this.GATM_DESCRIPTOR_PROPERTIES_READ=1,this.GATM_DESCRIPTOR_PROPERTIES_WRITE=2}var n=e("./constants.js").C,a=e("../peripheral.js").Peripheral,s=e("./event-emitter");s.makeEmitter(i),r.exports.GattIpServer=i},{"../peripheral.js":15,"./constants.js":6,"./event-emitter":7,websocket:17}],9:[function(e,r,t){function i(e,r){var t=parseInt(r[0],16);parseInt(r[2],16)>=1?e.discoverable="true":e.discoverable="false",r.splice(0,t+1)}function n(e,r){var t=parseInt(r[0],16);e.txPowerLevel=parseInt(r[2]),r.splice(0,t+1)}function a(e,r){var t=parseInt(r[0],16);if(t>2){for(var i=r[3]+r[2],n="",a=4;a<=t;a++)n+=r[a];e.manufacturerData[i]=n}r.splice(0,t+1)}function s(e,r){for(var t=parseInt(r[0],16),i="",n=t;n>=2;n--)i+=r[n];e.serviceUUIDs=i,r.splice(0,t+1)}function o(e,r){for(var t=parseInt(r[0],16),i="",n=t;n>=2;n--)i+=r[n],14!=n&&12!=n&&10!=n&&8!=n||(i+="-");e.serviceUUIDs=i,r.splice(0,t+1)}function c(e,r){for(var t=parseInt(r[0],16),i="",n=3;n>=2;n--)i+=r[n];"FEAA"==i&&(0===parseInt(r[4],16)?u(e):16==parseInt(r[4],16)?l(e):32==parseInt(r[4],16)&&p(e)),r.splice(0,t+1)}function u(e,r){e.frameType="UID",e.nameSpace="",e.instanceID="",e.txPowerLevel=parseInt(r[5],16);for(var t=6;t<16;t++)e.nameSpace+=r[t];for(var i=16;i<22;i++)e.instanceID+=r[i];e.reserved=r[22],e.reserved+=r[23]}function l(e,r){e.frameType="URL",e.txPowerLevel=parseInt(r[5]);for(var t in f.AllProtocols)r[6]==t&&(e.url=f.AllProtocols[t]);for(var i=7;i2?e.temperature+=i.toString().substring(0,2):e.temperature+=i;for(var n=10;n<14;n++)e.advPacketCount+=r[n];e.advPacketCount=parseInt(e.advPacketCount,16);for(var a=14;a<18;a++)e.timeInterval+=r[a];if(e.timeInterval=Math.ceil(.1*parseInt(e.timeInterval,16)),e.timePeriod="",e.timeInterval>=60){var s=Math.floor(e.timeInterval/86400);s>0&&(e.timePeriod+=s<10?s+"day ":s+"days ",e.timeInterval-=24*s*60*60);var o=Math.floor(e.timeInterval/3600);o>0?(e.timePeriod+=o<10?"0"+o+":":o+":",e.timeInterval-=60*o*60):e.timePeriod+="00:";var c=Math.floor(e.timeInterval/60);c>0?(e.timePeriod+=c<10?"0"+c+":":c+":",e.timeInterval-=60*c,e.timePeriod+=e.timeInterval<10?"0"+e.timeInterval:e.timeInterval,e.timePeriod+=" secs",e.timeInterval=0):(e.timePeriod+="00:"+e.timeInterval,e.timeInterval=0)}else e.timeInterval>0&&e.timeInterval<60&&(e.timePeriod+=e.timeInterval<10?"00:00:0"+e.timeInterval:"00:00:"+e.timeInterval,e.timePeriod+=" secs")}var f=e("./constants").C;r.exports.parseAdvArray=function(e,r){e.advdata||(e.advdata={});var t=e.advdata;if(t.manufacturerData||(t.manufacturerData={}),t.serviceUUIDs||(t.serviceUUIDs=[]),!r)return[];var u=[];if(r.length%2===0)for(var l=0;ls.MAX_PENDING_MESSAGES)throw new o("Message queue is full",t);var c=new i(e,t,n,a);return r[c.id]=c,c.msg},this.hasMessage=function(e){var t=r[""+e];return!!t},this.onMessageReceived=function(t){var i;if(t.params&&t.params.id&&(t.id=t.params.id),t.id&&(i=r[""+t.id]),!i){if(t.id)return t.result==s.kScanForPeripherals&&t.params&&t.params.bb?(l||(l=!0),void e.emit("indication",t)):void e.emit("request",t);if(t.result!=s.kMessage)return void e.emit("indication",t);u||(u=!0),t.id="1",i=r[1]}i.timeout&&clearTimeout(i.timeout),delete r[t.id],e.emit("response",t,i.userContext,i.msg)}}var a=e("./event-emitter"),s=e("./constants").C,o=e("./../errors").ApplicationError,c=1,u=!1,l=!1;a.makeEmitter(n),r.exports.MessageProcessor=n},{"./../errors":3,"./constants":6,"./event-emitter":7}],13:[function(e,r,t){function i(e,r){function t(e,r){var t=r?"0x":"";for(var i in e){var n=(255&e[i]).toString(16);1==n.length&&(n="0"+n),t+=n}return t}function i(e){for(var r in e)if(e.hasOwnProperty(r))return!1;return JSON.stringify(e)===JSON.stringify({})}function s(e,r){var t=r.params,i=e.original.params[n.kPeripheralUUID],a=e.original.params[n.kServiceUUID];i&&(t[n.kPeripheralUUID]=i), -a&&(t[n.kServiceUUID]=a)}a.instantiateEmitter(this);var o=this;this.processMessage=function(e){function t(t){var i=l[n.kPeripheralUUID],a={};if(a.peripheral=r.getPeripheral(i),a.peripheral&&a.peripheral.uuid){if("p"===t)return a;var s=l[n.kServiceUUID];if(a.service=a.peripheral.findService(s),a.service&&a.service.uuid){if("s"===t)return a;var c=l[n.kCharacteristicUUID];if(a.characteristic=a.service.findCharacteristic(c),a.characteristic&&a.characteristic.uuid){if("c"===t)return a;var u=l[n.kDescriptorUUID];if(a.descriptor=a.characteristic.findDescriptor(u),a.descriptor&&a.descriptor.uuid)return a;throw o.sendErrorResponse(e.method,n.kErrorDescriptorNotFound,"Descriptor not found in the service database"),new Error("Descriptor not found")}throw o.sendErrorResponse(e.method,n.kErrorCharacteristicNotFound,"Characteristic not found in the service database"),new Error("Characteristic not found")}throw o.sendErrorResponse(e.method,n.kErrorServiceNotFound,"Service not found in the service database"),new Error("Service not found")}throw o.sendErrorResponse(e.method,n.kErrorPeripheralNotFound,"Peripheral not found in the service database"),new Error("Peripheral not found")}var i;if("undefined"!=typeof e&&e&&!e.error){if(e.result&&(e.result==n.kMessage||e.result==n.kAuthenticate)){var a=!1;return e.error||"object"!=typeof e.params||e.params[n.kAuthenticate]!==!0||(a=!0),void o.emit("authenticated",a)}if(e.method&&e.method==n.kAuthenticate){var s={};s[n.kAuthenticate]=!0;var c={};return c.result=n.kAuthenticate,c.params=s,c[n.kIdField]=e[n.kIdField],c=JSON.stringify(c),void o.send(c)}var u={original:e},l=e.params;switch(e.method){case n.kConfigure:o.emit("configure",u,l[n.kShowPowerAlert],l[n.kIdentifierKey]);break;case n.kScanForPeripherals:o.emit("scan",u,l[n.kScanOptionAllowDuplicatesKey],l[n.kServiceUUIDs]);break;case n.kStopScanning:o.emit("stopScan",u);break;case n.kCentralState:o.emit("getCentralState",u);break;case n.kConnect:try{i=t("p"),o.emit("connect",u,i.peripheral.uuid)}catch(p){}break;case n.kDisconnect:try{i=t("p"),o.emit("disconnect",u,i.peripheral.uuid)}catch(p){}break;case n.kGetCharacteristicValue:try{i=t("c",u),o.emit("readCharacteristic",u,i.peripheral.uuid,i.service.uuid,i.characteristic.uuid)}catch(p){}break;case n.kWriteCharacteristicValue:try{i=t("c",u),o.emit("writeCharacteristic",u,i.peripheral.uuid,i.service.uuid,i.characteristic.uuid,e.params[n.kValue])}catch(p){}break;case n.kSetValueNotification:try{i=t("c",u),o.emit("enableNotifications",u,i.peripheral.uuid,i.service.uuid,i.characteristic.uuid,e.params[n.kIsNotifying])}catch(p){}break;case n.kGetDescriptorValue:try{i=t("d",u),o.emit("readDescriptor",u,i.peripheral.uuid,i.service.uuid,i.characteristic.uuid,i.descriptor.uuid)}catch(p){}break;case n.kWriteDescriptorValue:try{i=t("d",u),o.emit("writeDescriptor",u,i.peripheral.uuid,i.service.uuid,i.characteristic.uuid,i.descriptor.uuid,e.params[n.kValue])}catch(p){}break;default:return void o.sendErrorResponse(u,e.method,n.kInvalidRequest,"Request not handled by server")}}},o.sendErrorResponse=function(r,t,i,a){var s={},o={};o[n.kCode]=i,o[n.kMessageField]=a,s[n.kError]=o,s.result=t,r&&r.original&&(s[n.kMessageId]=r.original.id,s[n.kSessionId]=r.original.session_id),e.sendError(s)},o.configureResponse=function(r){r.result=n.kConfigure,e.respond(r,{})},o.centralStateResponse=function(r,t,i){var a={};a[n.kState]=t,r.result=n.kCentralState,e.respond(r,a)},o.stopScanResponse=function(r){r.result=n.kStopScanning,e.respond(r,{})},o.disconnectResponse=function(r,t){var i={};i[n.kPeripheralUUID]=t.uuid,i[n.kPeripheralName]=t.name,null!=r?e.respond(r,i):e.sendIndications(n.kDisconnect,i)},o.scanResponse=function(r,a,s,o,c,u,l,p){if(r)return r.result=n.kScanForPeripherals,void e.respond(r,{});var f,h,d={};if(!i(l)){f={};for(var v in l){var k=v.toUpperCase();f[k]=t(l[v]).toUpperCase()}}if(!i(p)){h={};for(var m in p){var E=m.toUpperCase();h[E]=t(p[m]).toUpperCase()}}d[n.kPeripheralName]=s,d[n.kPeripheralUUID]=a,d[n.kRSSIkey]=o,d[n.kCBAdvertisementDataTxPowerLevel]=c,d[n.kCBAdvertisementDataServiceUUIDsKey]=u&&u.length>0?u:void 0,d[n.kCBAdvertisementDataManufacturerDataKey]=f,d[n.kCBAdvertisementDataServiceDataKey]=h,e.sendIndications(n.kScanForPeripherals,d)},o.addPeripheral=function(e,r,t,i,n){var a=new Peripheral(this,e,r,t,i,n);return o.peripherals[a.uuid]=a,a},this.respondToConnect=function(r){var t={};s(r,t),e.respond(r,t)}}var n=e("./constants.js").C,a=e("./event-emitter");this.GATM_SECURITY_PROPERTIES_NO_SECURITY=0,this.GATM_SECURITY_PROPERTIES_UNAUTHENTICATED_ENCRYPTION_WRITE=1,this.GATM_SECURITY_PROPERTIES_AUTHENTICATED_ENCRYPTION_WRITE=2,this.GATM_SECURITY_PROPERTIES_UNAUTHENTICATED_ENCRYPTION_READ=4,this.GATM_SECURITY_PROPERTIES_AUTHENTICATED_ENCRYPTION_READ=8,this.GATM_SECURITY_PROPERTIES_UNAUTHENTICATED_SIGNED_WRITES=16,this.GATM_SECURITY_PROPERTIES_AUTHENTICATED_SIGNED_WRITES=32,this.GATM_CHARACTERISTIC_PROPERTIES_BROADCAST=1,this.GATM_CHARACTERISTIC_PROPERTIES_READ=2,this.GATM_CHARACTERISTIC_PROPERTIES_WRITE_WO_RESP=4,this.GATM_CHARACTERISTIC_PROPERTIES_WRITE=8,this.GATM_CHARACTERISTIC_PROPERTIES_NOTIFY=16,this.GATM_CHARACTERISTIC_PROPERTIES_INDICATE=32,this.GATM_CHARACTERISTIC_PROPERTIES_AUTHENTICATED_SIGNED_WRITES=64,this.GATM_CHARACTERISTIC_PROPERTIES_EXT_PROPERTIES=128,this.GATM_DESCRIPTOR_PROPERTIES_READ=1,this.GATM_DESCRIPTOR_PROPERTIES_WRITE=2,a.makeEmitter(i),r.exports.ServerMessageHandler=i},{"./constants.js":6,"./event-emitter":7}],14:[function(e,r,t){function i(e,r){var t=r[c.kDescriptorUUID],i=e.findDescriptor(t);i||(i=new p(e,t),e.addDescriptor(i)),i.value=r[c.kValue]}function n(e,r){var t=r[c.kCharacteristicUUID],n=e.findCharacteristic(t);n||(n=new l(e,t),e.addCharacteristic(n)),n.value=r[c.kValue];var a=r[c.kProperties];if("object"==typeof a)for(var s in a)n.setProperty(s,{enabled:a[s].enabled,name:a[s].name});else for(var o in c.AllProperties)n.setProperty([c.AllProperties[o]],{enabled:a>>o&1,name:c.AllProperties[o]});n.isNotifying=!1;var u=r[c.kDescriptors];if(u)for(var p in u){var f=u[p];i(n,f)}}function a(e,r){var t=r[c.kServiceUUID],i=e.findService(t);i||(i=new u(e,t),e.addService(i));var a=r[c.kCharacteristics];if(a)for(var s in a){var o=a[s];n(i,o)}}function s(e){var r={};if(e&&e.getAllDescriptors())for(var t in e.getAllDescriptors()){var i={};i[c.kDescriptorUUID]=t,i[c.kValue]=e.findDescriptor(t).value,i[c.kProperties]=e.findDescriptor(t).properties,i[c.kIsNotifying]=e.findDescriptor(t).isNotifying,r[t]=i}return r}function o(e){var r={};if(e&&e.getAllCharacteristics())for(var t in e.getAllCharacteristics()){var i={};i[c.kCharacteristicUUID]=t,i[c.kValue]=e.findCharacteristic(t).value,i[c.kProperties]=e.findCharacteristic(t).allProperties(),i[c.kIsNotifying]=e.findCharacteristic(t).isNotifying,i[c.kDescriptors]=s(e.findCharacteristic(t)),r[t]=i}return r}var c=e("./constants").C,u=e("./../service").Service,l=e("./../characteristic").Characteristic,p=e("./../descriptor").Descriptor;r.exports.parseServiceRecord=function(e,r){var t=r[c.kServices];if(t)for(var i in t){var n=t[i];a(e,n)}},r.exports.getServiceJsonFromPeripheralObject=function(e){var r={};if(e&&e.getAllServices())for(var t in e.getAllServices()){var i={};i[c.kServiceUUID]=t,i[c.kIsPrimaryKey]=e.findService(t).isPrimary,i[c.kCharacteristics]=o(e.findService(t)),r[t]=i}return r}},{"./../characteristic":1,"./../descriptor":2,"./../service":16,"./constants":6}],15:[function(e,r,t){function i(e,r){return e.indexOf(r)==-1&&(e.push(r),!0)}function n(e,r,t,n,p,f){c.instantiateEmitter(this);var h=this;this.type="p",this.uuid=r,this.isConnected=!1;var d={},v={},k={},m=[];this._updateFromScanData=function(e,r,t,n,a,s,c,u){this.name=e,this.rssi=r,this.txPowerLevel=t;if(a)for(var l in a)v[l]=a[l];if(k)for(var p in s)k[p]=s[p];if(n)for(var f=0;f=0},this.getAllServices=function(){return d},this.getAllMfrData=function(){return v},this.getAllSvcData=function(){return k},this.getAllAdvertisedServiceUUIDs=function(){return m},this.addServiceWithUUID=function(e){var r=new l(h,e);return d[e]=r},this.addService=function(e){return d[e.uuid]=e},this.gattip=function(){return e},this.connectOnce=function(r){var t=s.populateParams(h);e.request(a.kConnect,t,r,function(t){u.parseServiceRecord(h,t),h.isConnected=!0,e.fulfill(r,h)})},this.connect=function(r,t){function i(t){s++,s<=a.NUM_CONNECT_ATTEMPTS?h.connectOnce({fulfill:n,reject:i}):e.reject(r,t)}var n="object"==typeof r?r.fulfill:r,s=0;t&&"number"==typeof t.numConnectAttempts&&(s=t.numConnectAttempts),i()},this.disconnect=function(r){var t=s.populateParams(h);e.request(a.kDisconnect,t,r,function(t){h.isConnected=!1,e.fulfill(r,h)})},this.respondToConnectRequest=function(r){var t={};t[a.kPeripheralUUID]=this.uuid,t[a.kPeripheralName]=this.name;var i;i=u.getServiceJsonFromPeripheralObject(this),t[a.kServices]=i,r.result=a.kConnect,e.respond(r,t)},this.handleDisconnectIndication=function(){h.isConnected=!1,h.emit("disconnected",h)},this._updateFromScanData(t,n,p,f)}var a=e("./lib/constants.js").C,s=e("./lib/message-helper"),o=e("./lib/message-advdata-parser"),c=e("./lib/event-emitter"),u=e("./lib/service-table"),l=e("./service").Service;c.makeEmitter(n),r.exports.Peripheral=n},{"./lib/constants.js":6,"./lib/event-emitter":7,"./lib/message-advdata-parser":9,"./lib/message-helper":11,"./lib/service-table":14,"./service":16}],16:[function(e,r,t){function i(e,r){var t=this,i=e.gattip(),s={};n.requireUUID("Service","uuid",r),this.uuid=r,this.type="s",this.isPrimary=!0,this.peripheral=function(){return e},this.gattip=function(){return i},this.getAllCharacteristics=function(){return s},this.findCharacteristic=function(e){return s[e]},this.addCharacteristicWithUUID=function(e,r){var i=new a(t,e,r);return s[e]=i},this.addCharacteristic=function(e){s[e.uuid]=e}}var n=e("./lib/message-helper"),a=e("./characteristic").Characteristic;t.Service=i},{"./characteristic":1,"./lib/message-helper":11}],17:[function(e,r,t){},{}],18:[function(e,r,t){function i(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function n(e){return"function"==typeof e}function a(e){return"number"==typeof e}function s(e){return"object"==typeof e&&null!==e}function o(e){return void 0===e}r.exports=i,i.EventEmitter=i,i.prototype._events=void 0,i.prototype._maxListeners=void 0,i.defaultMaxListeners=10,i.prototype.setMaxListeners=function(e){if(!a(e)||e<0||isNaN(e))throw TypeError("n must be a positive number");return this._maxListeners=e,this},i.prototype.emit=function(e){var r,t,i,a,c,u;if(this._events||(this._events={}),"error"===e&&(!this._events.error||s(this._events.error)&&!this._events.error.length)){if(r=arguments[1],r instanceof Error)throw r;throw TypeError('Uncaught, unspecified "error" event.')}if(t=this._events[e],o(t))return!1;if(n(t))switch(arguments.length){case 1:t.call(this);break;case 2:t.call(this,arguments[1]);break;case 3:t.call(this,arguments[1],arguments[2]);break;default:a=Array.prototype.slice.call(arguments,1),t.apply(this,a)}else if(s(t))for(a=Array.prototype.slice.call(arguments,1),u=t.slice(),i=u.length,c=0;c0&&this._events[e].length>t&&(this._events[e].warned=!0,"function"==typeof console.trace)),this},i.prototype.on=i.prototype.addListener,i.prototype.once=function(e,r){function t(){this.removeListener(e,t),i||(i=!0,r.apply(this,arguments))}if(!n(r))throw TypeError("listener must be a function");var i=!1;return t.listener=r,this.on(e,t),this},i.prototype.removeListener=function(e,r){var t,i,a,o;if(!n(r))throw TypeError("listener must be a function");if(!this._events||!this._events[e])return this;if(t=this._events[e],a=t.length,i=-1,t===r||n(t.listener)&&t.listener===r)delete this._events[e],this._events.removeListener&&this.emit("removeListener",e,r);else if(s(t)){for(o=a;o-- >0;)if(t[o]===r||t[o].listener&&t[o].listener===r){i=o;break}if(i<0)return this;1===t.length?(t.length=0,delete this._events[e]):t.splice(i,1),this._events.removeListener&&this.emit("removeListener",e,r)}return this},i.prototype.removeAllListeners=function(e){var r,t;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[e]&&delete this._events[e],this;if(0===arguments.length){for(r in this._events)"removeListener"!==r&&this.removeAllListeners(r);return this.removeAllListeners("removeListener"),this._events={},this}if(t=this._events[e],n(t))this.removeListener(e,t);else if(t)for(;t.length;)this.removeListener(e,t[t.length-1]);return delete this._events[e],this},i.prototype.listeners=function(e){var r;return r=this._events&&this._events[e]?n(this._events[e])?[this._events[e]]:this._events[e].slice():[]},i.prototype.listenerCount=function(e){if(this._events){var r=this._events[e];if(n(r))return 1;if(r)return r.length}return 0},i.listenerCount=function(e,r){return e.listenerCount(r)}},{}],19:[function(e,r,t){"function"==typeof Object.create?r.exports=function(e,r){e.super_=r,e.prototype=Object.create(r.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}})}:r.exports=function(e,r){e.super_=r;var t=function(){};t.prototype=r.prototype,e.prototype=new t,e.prototype.constructor=e}},{}],20:[function(e,r,t){function i(){l=!1,o.length?u=o.concat(u):p=-1,u.length&&n()}function n(){if(!l){var e=setTimeout(i);l=!0;for(var r=u.length;r;){for(o=u,u=[];++p1)for(var t=1;t=3&&(i.depth=arguments[2]),arguments.length>=4&&(i.colors=arguments[3]),v(r)?i.showHidden=r:r&&t._extend(i,r),S(i.showHidden)&&(i.showHidden=!1),S(i.depth)&&(i.depth=2),S(i.colors)&&(i.colors=!1),S(i.customInspect)&&(i.customInspect=!0),i.colors&&(i.stylize=a),c(i,e,i.depth)}function a(e,r){var t=n.styles[r];return t?"["+n.colors[t][0]+"m"+e+"["+n.colors[t][1]+"m":e}function s(e,r){return e}function o(e){var r={};return e.forEach(function(e,t){r[e]=!0}),r}function c(e,r,i){if(e.customInspect&&r&&C(r.inspect)&&r.inspect!==t.inspect&&(!r.constructor||r.constructor.prototype!==r)){var n=r.inspect(i,e);return I(n)||(n=c(e,n,i)),n}var a=u(e,r);if(a)return a;var s=Object.keys(r),v=o(s);if(e.showHidden&&(s=Object.getOwnPropertyNames(r)),T(r)&&(s.indexOf("message")>=0||s.indexOf("description")>=0))return l(r);if(0===s.length){if(C(r)){var k=r.name?": "+r.name:"";return e.stylize("[Function"+k+"]","special")}if(P(r))return e.stylize(RegExp.prototype.toString.call(r),"regexp");if(A(r))return e.stylize(Date.prototype.toString.call(r),"date");if(T(r))return l(r)}var m="",E=!1,g=["{","}"];if(d(r)&&(E=!0,g=["[","]"]),C(r)){var S=r.name?": "+r.name:"";m=" [Function"+S+"]"}if(P(r)&&(m=" "+RegExp.prototype.toString.call(r)),A(r)&&(m=" "+Date.prototype.toUTCString.call(r)),T(r)&&(m=" "+l(r)),0===s.length&&(!E||0==r.length))return g[0]+m+g[1];if(i<0)return P(r)?e.stylize(RegExp.prototype.toString.call(r),"regexp"):e.stylize("[Object]","special");e.seen.push(r);var y;return y=E?p(e,r,i,v,s):s.map(function(t){return f(e,r,i,v,t,E)}),e.seen.pop(),h(y,m,g)}function u(e,r){if(S(r))return e.stylize("undefined","undefined");if(I(r)){var t="'"+JSON.stringify(r).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return e.stylize(t,"string")}return E(r)?e.stylize(""+r,"number"):v(r)?e.stylize(""+r,"boolean"):k(r)?e.stylize("null","null"):void 0}function l(e){return"["+Error.prototype.toString.call(e)+"]"}function p(e,r,t,i,n){for(var a=[],s=0,o=r.length;s-1&&(o=a?o.split("\n").map(function(e){return" "+e}).join("\n").substr(2):"\n"+o.split("\n").map(function(e){return" "+e}).join("\n"))):o=e.stylize("[Circular]","special")),S(s)){if(a&&n.match(/^\d+$/))return o;s=JSON.stringify(""+n),s.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)?(s=s.substr(1,s.length-2),s=e.stylize(s,"name")):(s=s.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'"),s=e.stylize(s,"string"))}return s+": "+o}function h(e,r,t){var i=0,n=e.reduce(function(e,r){return i++,r.indexOf("\n")>=0&&i++,e+r.replace(/\u001b\[\d\d?m/g,"").length+1},0);return n>60?t[0]+(""===r?"":r+"\n ")+" "+e.join(",\n ")+" "+t[1]:t[0]+r+" "+e.join(", ")+" "+t[1]}function d(e){return Array.isArray(e)}function v(e){return"boolean"==typeof e}function k(e){return null===e}function m(e){return null==e}function E(e){return"number"==typeof e}function I(e){return"string"==typeof e}function g(e){return"symbol"==typeof e}function S(e){return void 0===e}function P(e){return y(e)&&"[object RegExp]"===_(e)}function y(e){return"object"==typeof e&&null!==e}function A(e){return y(e)&&"[object Date]"===_(e)}function T(e){return y(e)&&("[object Error]"===_(e)||e instanceof Error)}function C(e){return"function"==typeof e}function D(e){return null===e||"boolean"==typeof e||"number"==typeof e||"string"==typeof e||"symbol"==typeof e||"undefined"==typeof e}function _(e){return Object.prototype.toString.call(e)}function R(e,r){return Object.prototype.hasOwnProperty.call(e,r)}var U=/%[sdj%]/g;t.format=function(e){if(!I(e)){for(var r=[],t=0;t=a)return e;switch(e){case"%s":return String(i[t++]);case"%d":return Number(i[t++]);case"%j":try{return JSON.stringify(i[t++])}catch(r){return"[Circular]"}default:return e}}),o=i[t];treq:"),i.send(JSON.stringify(s))},this.respond=function(e,t){var r=d.wrapResponse(e,t);k.traceMessage(r,">rsp:"),i.send(JSON.stringify(r))},this.sendIndications=function(e,t){var r={params:t,jsonrpc:"2.0"};r.result=e,r.params=t,k.traceMessage(r,">rsp:"),i.send(JSON.stringify(r))},this.sendError=function(e){e.jsonrpc="2.0",k.traceMessage(e,">rsp:"),i.send(JSON.stringify(e))}}var n=e("./lib/event-emitter"),a=e("./errors").InternalError,s=e("./errors").ApplicationError,o=e("./errors").GatewayError,c=e("./lib/message-handler").MessageHandler,u=e("./lib/message-processor").MessageProcessor,l=e("./gateway").Gateway,f=(e("./lib/message-helper"),e("./lib/server-message-handler").ServerMessageHandler),p={keepalive:!0,dropConnectionOnKeepaliveTimeout:!0,keepaliveInterval:1e4,keepaliveGracePeriod:1e4};n.makeEmitter(i),t.exports.GATTIP=i},{"./errors":3,"./gateway":4,"./lib/event-emitter":7,"./lib/message-handler":9,"./lib/message-helper":10,"./lib/message-processor":11,"./lib/server-message-handler":12,websocket:16}],6:[function(e,t,r){var i={DEFAULT_MESSAGE_TIMEOUT_MS:61e3,MAX_PENDING_MESSAGES:200,NUM_CONNECT_ATTEMPTS:3,kMessageId:"id",kSessionId:"session_id",kAuthenticate:"aut",kOpen:"opn",kDeviceAccessToken:"dat",kGetVersionInfo:"vif",kError:"error",kCode:"code",kMessageField:"message",kMethod:"method",kResult:"result",kIdField:"id",kConfigure:"aa",kScanForPeripherals:"ab",kStopScanning:"ac",kConnect:"ad",kDisconnect:"ae",kCentralState:"af",kGetConnectedPeripherals:"ag",kGetPerhipheralsWithServices:"ah",kGetPerhipheralsWithIdentifiers:"ai",kGetServices:"ak",kGetIncludedServices:"al",kGetCharacteristics:"am",kGetDescriptors:"an",kGetCharacteristicValue:"ao",kGetDescriptorValue:"ap",kWriteCharacteristicValue:"aq",kWriteDescriptorValue:"ar",kSetValueNotification:"as",kGetPeripheralState:"at",kGetRSSI:"au",kInvalidatedServices:"av",kPeripheralNameUpdate:"aw",kMessage:"zz",kCentralUUID:"ba",kPeripheralUUID:"bb",kPeripheralName:"bc",kPeripheralUUIDs:"bd",kServiceUUID:"be",kServiceUUIDs:"bf",kPeripherals:"bg",kIncludedServiceUUIDs:"bh",kCharacteristicUUID:"bi",kCharacteristicUUIDs:"bj",kDescriptorUUID:"bk",kServices:"bl",kCharacteristics:"bm",kDescriptors:"bn",kProperties:"bo",kValue:"bp",kState:"bq",kStateInfo:"br",kStateField:"bs",kWriteType:"bt",kRSSIkey:"bu",kIsPrimaryKey:"bv",kIsBroadcasted:"bw",kIsNotifying:"bx",kShowPowerAlert:"by",kIdentifierKey:"bz",kScanOptionAllowDuplicatesKey:"b0",kScanOptionSolicitedServiceUUIDs:"b1",kAdvertisementDataKey:"b2",kCBAdvertisementDataManufacturerDataKey:"mfr",kCBAdvertisementDataServiceUUIDsKey:"suu",kCBAdvertisementDataServiceDataKey:"sdt",kCBAdvertisementDataOverflowServiceUUIDsKey:"b6",kCBAdvertisementDataSolicitedServiceUUIDsKey:"b7",kCBAdvertisementDataIsConnectable:"b8",kCBAdvertisementDataTxPowerLevel:"txp",kPeripheralBtAddress:"c1",kRawAdvertisementData:"c2",kScanRecord:"c3",kCBCentralManagerRestoredStatePeripheralsKey:"da",kCBCentralManagerRestoredStateScanServicesKey:"db",kWriteWithResponse:"cc",kWriteWithoutResponse:"cd",kNotifyOnConnection:"ce",kNotifyOnDisconnection:"cf",kNotifyOnNotification:"cg",kDisconnected:"ch",kConnecting:"ci",kConnected:"cj",kUnknown:"ck",kResetting:"cl",kUnsupported:"cm",kUnauthorized:"cn",kPoweredOff:"co",kPoweredOn:"cp",kErrorPeripheralNotFound:"-32001",kErrorServiceNotFound:"-32002",kErrorCharacteristicNotFound:"-32003",kErrorDescriptorNotFound:"-32004",kErrorPeripheralStateIsNotValid:"-32005",kErrorNoServiceSpecified:"-32006",kErrorNoPeripheralIdentiferSpecified:"-32007",kErrorStateRestorationNotValid:"-32008",kInvalidRequest:"-32600",kMethodNotFound:"-32601",kInvalidParams:"-32602",kError32603:"-32603",kParseError:"-32700",kGAP_ADTYPE_FLAGS:"01",kGAP_ADTYPE_INCOMPLETE_16BIT_SERVICEUUID:"02",kGAP_ADTYPE_COMPLETE_16BIT_SERVICEUUID:"03",kGAP_ADTYPE_INCOMPLETE_32BIT_SERVICEUUID:"04",kGAP_ADTYPE_COMPLETE_32BIT_SERVICEUUID:"05",kGAP_ADTYPE_INCOMPLETE_128BIT_SERVICEUUID:"06",kGAP_ADTYPE_COMPLETE_128BIT_SERVICEUUID:"07",kGAP_ADTYPE_POWER_LEVEL:"0A",kGAP_ADTYPE_MANUFACTURER_SPECIFIC:"FF",kGAP_ADTYPE_16BIT_SERVICE_DATA:"16",id:1,authenticate:"authenticate",AllProperties:["Broadcast","Read","WriteWithoutResponse","Write","Notify","Indicate","AuthenticatedSignedWrites","ExtendedProperties","NotifyEncryptionRequired","IndicateEncryptionRequired"]};t.exports.C=i},{}],7:[function(e,t,r){var i=e("events"),n=e("util");t.exports.makeEmitter=function(e){n.inherits(e,i)},t.exports.instantiateEmitter=function(e){i.call(e)}},{events:17,util:21}],8:[function(e,t,r){function i(e,t){var r=parseInt(t[0],16);parseInt(t[2],16)>=1?e.discoverable="true":e.discoverable="false",t.splice(0,r+1)}function n(e,t){var r=parseInt(t[0],16);e.txPowerLevel=parseInt(t[2]),t.splice(0,r+1)}function a(e,t){var r=parseInt(t[0],16);if(r>2){for(var i=t[3]+t[2],n="",a=4;a<=r;a++)n+=t[a];e.manufacturerData[i]=n}t.splice(0,r+1)}function s(e,t){for(var r=parseInt(t[0],16),i="",n=r;n>=2;n--)i+=t[n];e.serviceUUIDs=i,t.splice(0,r+1)}function o(e,t){for(var r=parseInt(t[0],16),i="",n=r;n>=2;n--)i+=t[n],14!=n&&12!=n&&10!=n&&8!=n||(i+="-");e.serviceUUIDs=i,t.splice(0,r+1)}function c(e,t){for(var r=parseInt(t[0],16),i="",n=3;n>=2;n--)i+=t[n];"FEAA"==i&&(0===parseInt(t[4],16)?u(e):16==parseInt(t[4],16)?l(e):32==parseInt(t[4],16)&&f(e)),t.splice(0,r+1)}function u(e,t){e.frameType="UID",e.nameSpace="",e.instanceID="",e.txPowerLevel=parseInt(t[5],16);for(var r=6;r<16;r++)e.nameSpace+=t[r];for(var i=16;i<22;i++)e.instanceID+=t[i];e.reserved=t[22],e.reserved+=t[23]}function l(e,t){e.frameType="URL",e.txPowerLevel=parseInt(t[5]);for(var r in p.AllProtocols)t[6]==r&&(e.url=p.AllProtocols[r]);for(var i=7;i2?e.temperature+=i.toString().substring(0,2):e.temperature+=i;for(var n=10;n<14;n++)e.advPacketCount+=t[n];e.advPacketCount=parseInt(e.advPacketCount,16);for(var a=14;a<18;a++)e.timeInterval+=t[a];if(e.timeInterval=Math.ceil(.1*parseInt(e.timeInterval,16)),e.timePeriod="",e.timeInterval>=60){var s=Math.floor(e.timeInterval/86400);s>0&&(e.timePeriod+=s<10?s+"day ":s+"days ",e.timeInterval-=24*s*60*60);var o=Math.floor(e.timeInterval/3600);o>0?(e.timePeriod+=o<10?"0"+o+":":o+":",e.timeInterval-=60*o*60):e.timePeriod+="00:";var c=Math.floor(e.timeInterval/60);c>0?(e.timePeriod+=c<10?"0"+c+":":c+":",e.timeInterval-=60*c,e.timePeriod+=e.timeInterval<10?"0"+e.timeInterval:e.timeInterval,e.timePeriod+=" secs",e.timeInterval=0):(e.timePeriod+="00:"+e.timeInterval,e.timeInterval=0)}else e.timeInterval>0&&e.timeInterval<60&&(e.timePeriod+=e.timeInterval<10?"00:00:0"+e.timeInterval:"00:00:"+e.timeInterval,e.timePeriod+=" secs")}var p=e("./constants").C;t.exports.parseAdvArray=function(e,t){e.advdata||(e.advdata={});var r=e.advdata;if(r.manufacturerData||(r.manufacturerData={}),r.serviceUUIDs||(r.serviceUUIDs=[]),!t)return[];var u=[];if(t.length%2===0)for(var l=0;ls.MAX_PENDING_MESSAGES)throw new o("Message queue is full",r);var c=new i(e,r,n,a);return t[c.id]=c,c.msg},this.hasMessage=function(e){var r=t[""+e];return!!r},this.onMessageReceived=function(r){var i;if(r.params&&r.params.id&&(r.id=r.params.id),r.id&&(i=t[""+r.id]),!i){if(r.id)return r.result==s.kScanForPeripherals&&r.params&&r.params.bb?(l||(l=!0),void e.emit("indication",r)):void e.emit("request",r);if(r.result!=s.kMessage)return void e.emit("indication",r);u||(u=!0),r.id="1",i=t[1]}i.timeout&&clearTimeout(i.timeout),delete t[r.id],e.emit("response",r,i.userContext,i.msg)}}var a=e("./event-emitter"),s=e("./constants").C,o=e("./../errors").ApplicationError,c=1,u=!1,l=!1;a.makeEmitter(n),t.exports.MessageProcessor=n},{"./../errors":3,"./constants":6,"./event-emitter":7}],12:[function(e,t,r){function i(e,t){function r(e,t){var r=t?"0x":"";for(var i in e){var n=(255&e[i]).toString(16);1==n.length&&(n="0"+n),r+=n}return r}function i(e){for(var t in e)if(e.hasOwnProperty(t))return!1;return JSON.stringify(e)===JSON.stringify({})}a.instantiateEmitter(this);var s=this;this.processMessage=function(e){function r(r){var i=l[n.kPeripheralUUID],a={};if(a.peripheral=t.getPeripheral(i),a.peripheral&&a.peripheral.uuid){if("p"===r)return a;var o=l[n.kServiceUUID];if(a.service=a.peripheral.findService(o),a.service&&a.service.uuid){if("s"===r)return a;var c=l[n.kCharacteristicUUID];if(a.characteristic=a.service.findCharacteristic(c),a.characteristic&&a.characteristic.uuid){if("c"===r)return a;var u=l[n.kDescriptorUUID];if(a.descriptor=a.characteristic.findDescriptor(u),a.descriptor&&a.descriptor.uuid)return a;throw s.sendErrorResponse(e.method,n.kErrorDescriptorNotFound,"Descriptor not found in the service database"),new Error("Descriptor not found")}throw s.sendErrorResponse(e.method,n.kErrorCharacteristicNotFound,"Characteristic not found in the service database"),new Error("Characteristic not found")}throw s.sendErrorResponse(e.method,n.kErrorServiceNotFound,"Service not found in the service database"),new Error("Service not found")}throw s.sendErrorResponse(e.method,n.kErrorPeripheralNotFound,"Peripheral not found in the service database"),new Error("Peripheral not found")}var i;if("undefined"!=typeof e&&e&&!e.error){if(e.result&&(e.result==n.kMessage||e.result==n.kAuthenticate)){var a=!1;return e.error||"object"!=typeof e.params||e.params[n.kAuthenticate]!==!0||(a=!0),void s.emit("authenticated",a)}if(e.method&&e.method==n.kAuthenticate){var o={};o[n.kAuthenticate]=!0;var c={};return c.result=n.kAuthenticate,c.params=o,c[n.kIdField]=e[n.kIdField],c=JSON.stringify(c),void s.send(c)}var u={original:e},l=e.params;switch(e.method){case n.kConfigure:s.emit("configure",u,l[n.kShowPowerAlert],l[n.kIdentifierKey]);break;case n.kScanForPeripherals:s.emit("scan",u,l[n.kScanOptionAllowDuplicatesKey],l[n.kServiceUUIDs]);break;case n.kStopScanning:s.emit("stopScan",u);break;case n.kCentralState:s.emit("getCentralState",u);break;case n.kConnect:try{i=r("p"),s.emit("connect",u,i.peripheral.uuid)}catch(f){}break;case n.kDisconnect:try{i=r("p"),s.emit("disconnect",u,i.peripheral.uuid)}catch(f){}break;case n.kGetCharacteristicValue:try{i=r("c",u),s.emit("readCharacteristic",u,i.peripheral.uuid,i.service.uuid,i.characteristic.uuid)}catch(f){}break;case n.kWriteCharacteristicValue:try{i=r("c",u),s.emit("writeCharacteristic",u,i.peripheral.uuid,i.service.uuid,i.characteristic.uuid,e.params[n.kValue])}catch(f){}break;case n.kSetValueNotification:try{i=r("c",u),s.emit("enableNotifications",u,i.peripheral.uuid,i.service.uuid,i.characteristic.uuid,e.params[n.kIsNotifying])}catch(f){}break;case n.kGetDescriptorValue:try{i=r("d",u),s.emit("readDescriptor",u,i.peripheral.uuid,i.service.uuid,i.characteristic.uuid,i.descriptor.uuid)}catch(f){}break;case n.kWriteDescriptorValue:try{i=r("d",u),s.emit("writeDescriptor",u,i.peripheral.uuid,i.service.uuid,i.characteristic.uuid,i.descriptor.uuid,e.params[n.kValue])}catch(f){}break;default:return void s.sendErrorResponse(u,e.method,n.kInvalidRequest,"Request not handled by server")}}},s.sendErrorResponse=function(t,r,i,a){var s={},o={};o[n.kCode]=i,o[n.kMessageField]=a,s[n.kError]=o,s.result=r,t&&t.original&&(s[n.kMessageId]=t.original.id,s[n.kSessionId]=t.original.session_id),e.sendError(s)},s.configureResponse=function(t){t.result=n.kConfigure,e.respond(t,{})},s.centralStateResponse=function(t,r,i){var a={};a[n.kState]=r,t.result=n.kCentralState,e.respond(t,a)},s.stopScanResponse=function(t){t.result=n.kStopScanning,e.respond(t,{})},s.disconnectResponse=function(t,r){var i={};i[n.kPeripheralUUID]=r.uuid,i[n.kPeripheralName]=r.name,null!=t?e.respond(t,i):e.sendIndications(n.kDisconnect,i)},s.scanResponse=function(t,a,s,o,c,u,l,f){if(t)return t.result=n.kScanForPeripherals,void e.respond(t,{});var p,h,d={};if(!i(l)){p={};for(var v in l){var m=v.toUpperCase();p[m]=r(l[v]).toUpperCase()}}if(!i(f)){h={};for(var k in f){var g=k.toUpperCase();h[g]=r(f[k]).toUpperCase()}}d[n.kPeripheralName]=s,d[n.kPeripheralUUID]=a,d[n.kRSSIkey]=o,d[n.kCBAdvertisementDataTxPowerLevel]=c,d[n.kCBAdvertisementDataServiceUUIDsKey]=u&&u.length>0?u:void 0,d[n.kCBAdvertisementDataManufacturerDataKey]=p,d[n.kCBAdvertisementDataServiceDataKey]=h,e.sendIndications(n.kScanForPeripherals,d)},s.addPeripheral=function(e,t,r,i,n){var a=new Peripheral(this,e,t,r,i,n);return s.peripherals[a.uuid]=a,a}}var n=e("./constants.js").C,a=e("./event-emitter");this.GATM_SECURITY_PROPERTIES_NO_SECURITY=0,this.GATM_SECURITY_PROPERTIES_UNAUTHENTICATED_ENCRYPTION_WRITE=1,this.GATM_SECURITY_PROPERTIES_AUTHENTICATED_ENCRYPTION_WRITE=2,this.GATM_SECURITY_PROPERTIES_UNAUTHENTICATED_ENCRYPTION_READ=4,this.GATM_SECURITY_PROPERTIES_AUTHENTICATED_ENCRYPTION_READ=8,this.GATM_SECURITY_PROPERTIES_UNAUTHENTICATED_SIGNED_WRITES=16,this.GATM_SECURITY_PROPERTIES_AUTHENTICATED_SIGNED_WRITES=32,this.GATM_CHARACTERISTIC_PROPERTIES_BROADCAST=1,this.GATM_CHARACTERISTIC_PROPERTIES_READ=2,this.GATM_CHARACTERISTIC_PROPERTIES_WRITE_WO_RESP=4,this.GATM_CHARACTERISTIC_PROPERTIES_WRITE=8,this.GATM_CHARACTERISTIC_PROPERTIES_NOTIFY=16,this.GATM_CHARACTERISTIC_PROPERTIES_INDICATE=32,this.GATM_CHARACTERISTIC_PROPERTIES_AUTHENTICATED_SIGNED_WRITES=64,this.GATM_CHARACTERISTIC_PROPERTIES_EXT_PROPERTIES=128,this.GATM_DESCRIPTOR_PROPERTIES_READ=1,this.GATM_DESCRIPTOR_PROPERTIES_WRITE=2,a.makeEmitter(i),t.exports.ServerMessageHandler=i},{"./constants.js":6,"./event-emitter":7}],13:[function(e,t,r){function i(e,t){var r=t[c.kDescriptorUUID],i=e.findDescriptor(r);i||(i=new f(e,r),e.addDescriptor(i)),i.value=t[c.kValue]}function n(e,t){var r=t[c.kCharacteristicUUID],n=e.findCharacteristic(r);n||(n=new l(e,r),e.addCharacteristic(n)),n.value=t[c.kValue];var a=t[c.kProperties];if("object"==typeof a)for(var s in a)n.setProperty(s,{enabled:a[s].enabled,name:a[s].name});else for(var o in c.AllProperties)n.setProperty([c.AllProperties[o]],{enabled:a>>o&1,name:c.AllProperties[o]});n.isNotifying=!1;var u=t[c.kDescriptors];if(u)for(var f in u){var p=u[f];i(n,p)}}function a(e,t){var r=t[c.kServiceUUID],i=e.findService(r);i||(i=new u(e,r),e.addService(i));var a=t[c.kCharacteristics];if(a)for(var s in a){var o=a[s];n(i,o)}}function s(e){var t={};if(e&&e.getAllDescriptors())for(var r in e.getAllDescriptors()){var i={};i[c.kDescriptorUUID]=r,i[c.kValue]=e.findDescriptor(r).value,i[c.kProperties]=e.findDescriptor(r).properties,i[c.kIsNotifying]=e.findDescriptor(r).isNotifying,t[r]=i}return t}function o(e){var t={};if(e&&e.getAllCharacteristics())for(var r in e.getAllCharacteristics()){var i={};i[c.kCharacteristicUUID]=r,i[c.kValue]=e.findCharacteristic(r).value,i[c.kProperties]=e.findCharacteristic(r).allProperties(),i[c.kIsNotifying]=e.findCharacteristic(r).isNotifying,i[c.kDescriptors]=s(e.findCharacteristic(r)),t[r]=i}return t}var c=e("./constants").C,u=e("./../service").Service,l=e("./../characteristic").Characteristic,f=e("./../descriptor").Descriptor;t.exports.parseServiceRecord=function(e,t){var r=t[c.kServices];if(r)for(var i in r){var n=r[i];a(e,n)}},t.exports.getServiceJsonFromPeripheralObject=function(e){var t={};if(e&&e.getAllServices())for(var r in e.getAllServices()){var i={};i[c.kServiceUUID]=r,i[c.kIsPrimaryKey]=e.findService(r).isPrimary,i[c.kCharacteristics]=o(e.findService(r)),t[r]=i}return t}},{"./../characteristic":1,"./../descriptor":2,"./../service":15,"./constants":6}],14:[function(e,t,r){function i(e,t){return e.indexOf(t)==-1&&(e.push(t),!0)}function n(e,t,r,n,f,p){c.instantiateEmitter(this);var h=this;this.type="p",this.uuid=t,this.isConnected=!1;var d={},v={},m={},k=[];this._updateFromScanData=function(e,t,r,n,a,s,c,u){this.name=e,this.rssi=t,this.txPowerLevel=r;if(a)for(var l in a){var f=l.toUpperCase(),p=a[l].toUpperCase();v[f]=p}if(m)for(var d in s)m[d]=s[d];if(n)for(var g=0;g=0},this.getAllServices=function(){return d; +},this.getAllMfrData=function(){return v},this.getAllSvcData=function(){return m},this.getAllAdvertisedServiceUUIDs=function(){return k},this.addServiceWithUUID=function(e){var t=new l(h,e);return d[e]=t},this.addService=function(e){return d[e.uuid]=e},this.gattip=function(){return e},this.connectOnce=function(t){var r=s.populateParams(h);e.request(a.kConnect,r,t,function(r){u.parseServiceRecord(h,r),h.isConnected=!0,e.fulfill(t,h)})},this.connect=function(t,r){function i(r){s++,s<=a.NUM_CONNECT_ATTEMPTS?h.connectOnce({fulfill:n,reject:i}):e.reject(t,r)}var n="object"==typeof t?t.fulfill:t,s=0;r&&"number"==typeof r.numConnectAttempts&&(s=r.numConnectAttempts),i()},this.disconnect=function(t){var r=s.populateParams(h);e.request(a.kDisconnect,r,t,function(r){h.isConnected=!1,e.fulfill(t,h)})},this.respondToConnectRequest=function(t){var r={};r[a.kPeripheralUUID]=this.uuid,r[a.kPeripheralName]=this.name;var i;i=u.getServiceJsonFromPeripheralObject(this),r[a.kServices]=i,t.result=a.kConnect,e.respond(t,r)},this.handleDisconnectIndication=function(){h.isConnected=!1,h.emit("disconnected",h)},this._updateFromScanData(r,n,f,p)}var a=e("./lib/constants.js").C,s=e("./lib/message-helper"),o=e("./lib/message-advdata-parser"),c=e("./lib/event-emitter"),u=e("./lib/service-table"),l=e("./service").Service;c.makeEmitter(n),t.exports.Peripheral=n},{"./lib/constants.js":6,"./lib/event-emitter":7,"./lib/message-advdata-parser":8,"./lib/message-helper":10,"./lib/service-table":13,"./service":15}],15:[function(e,t,r){function i(e,t){var r=this,i=e.gattip(),s={};n.requireUUID("Service","uuid",t),this.uuid=t,this.type="s",this.isPrimary=!0,this.peripheral=function(){return e},this.gattip=function(){return i},this.getAllCharacteristics=function(){return s},this.findCharacteristic=function(e){return s[e]},this.addCharacteristicWithUUID=function(e,t){var i=new a(r,e,t);return s[e]=i},this.addCharacteristic=function(e){s[e.uuid]=e}}var n=e("./lib/message-helper"),a=e("./characteristic").Characteristic;r.Service=i},{"./characteristic":1,"./lib/message-helper":10}],16:[function(e,t,r){},{}],17:[function(e,t,r){function i(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function n(e){return"function"==typeof e}function a(e){return"number"==typeof e}function s(e){return"object"==typeof e&&null!==e}function o(e){return void 0===e}t.exports=i,i.EventEmitter=i,i.prototype._events=void 0,i.prototype._maxListeners=void 0,i.defaultMaxListeners=10,i.prototype.setMaxListeners=function(e){if(!a(e)||e<0||isNaN(e))throw TypeError("n must be a positive number");return this._maxListeners=e,this},i.prototype.emit=function(e){var t,r,i,a,c,u;if(this._events||(this._events={}),"error"===e&&(!this._events.error||s(this._events.error)&&!this._events.error.length)){if(t=arguments[1],t instanceof Error)throw t;throw TypeError('Uncaught, unspecified "error" event.')}if(r=this._events[e],o(r))return!1;if(n(r))switch(arguments.length){case 1:r.call(this);break;case 2:r.call(this,arguments[1]);break;case 3:r.call(this,arguments[1],arguments[2]);break;default:a=Array.prototype.slice.call(arguments,1),r.apply(this,a)}else if(s(r))for(a=Array.prototype.slice.call(arguments,1),u=r.slice(),i=u.length,c=0;c0&&this._events[e].length>r&&(this._events[e].warned=!0,"function"==typeof console.trace)),this},i.prototype.on=i.prototype.addListener,i.prototype.once=function(e,t){function r(){this.removeListener(e,r),i||(i=!0,t.apply(this,arguments))}if(!n(t))throw TypeError("listener must be a function");var i=!1;return r.listener=t,this.on(e,r),this},i.prototype.removeListener=function(e,t){var r,i,a,o;if(!n(t))throw TypeError("listener must be a function");if(!this._events||!this._events[e])return this;if(r=this._events[e],a=r.length,i=-1,r===t||n(r.listener)&&r.listener===t)delete this._events[e],this._events.removeListener&&this.emit("removeListener",e,t);else if(s(r)){for(o=a;o-- >0;)if(r[o]===t||r[o].listener&&r[o].listener===t){i=o;break}if(i<0)return this;1===r.length?(r.length=0,delete this._events[e]):r.splice(i,1),this._events.removeListener&&this.emit("removeListener",e,t)}return this},i.prototype.removeAllListeners=function(e){var t,r;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[e]&&delete this._events[e],this;if(0===arguments.length){for(t in this._events)"removeListener"!==t&&this.removeAllListeners(t);return this.removeAllListeners("removeListener"),this._events={},this}if(r=this._events[e],n(r))this.removeListener(e,r);else if(r)for(;r.length;)this.removeListener(e,r[r.length-1]);return delete this._events[e],this},i.prototype.listeners=function(e){var t;return t=this._events&&this._events[e]?n(this._events[e])?[this._events[e]]:this._events[e].slice():[]},i.prototype.listenerCount=function(e){if(this._events){var t=this._events[e];if(n(t))return 1;if(t)return t.length}return 0},i.listenerCount=function(e,t){return e.listenerCount(t)}},{}],18:[function(e,t,r){"function"==typeof Object.create?t.exports=function(e,t){e.super_=t,e.prototype=Object.create(t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}})}:t.exports=function(e,t){e.super_=t;var r=function(){};r.prototype=t.prototype,e.prototype=new r,e.prototype.constructor=e}},{}],19:[function(e,t,r){function i(){l=!1,o.length?u=o.concat(u):f=-1,u.length&&n()}function n(){if(!l){var e=setTimeout(i);l=!0;for(var t=u.length;t;){for(o=u,u=[];++f1)for(var r=1;r=3&&(i.depth=arguments[2]),arguments.length>=4&&(i.colors=arguments[3]),v(t)?i.showHidden=t:t&&r._extend(i,t),y(i.showHidden)&&(i.showHidden=!1),y(i.depth)&&(i.depth=2),y(i.colors)&&(i.colors=!1),y(i.customInspect)&&(i.customInspect=!0),i.colors&&(i.stylize=a),c(i,e,i.depth)}function a(e,t){var r=n.styles[t];return r?"["+n.colors[r][0]+"m"+e+"["+n.colors[r][1]+"m":e}function s(e,t){return e}function o(e){var t={};return e.forEach(function(e,r){t[e]=!0}),t}function c(e,t,i){if(e.customInspect&&t&&_(t.inspect)&&t.inspect!==r.inspect&&(!t.constructor||t.constructor.prototype!==t)){var n=t.inspect(i,e);return I(n)||(n=c(e,n,i)),n}var a=u(e,t);if(a)return a;var s=Object.keys(t),v=o(s);if(e.showHidden&&(s=Object.getOwnPropertyNames(t)),A(t)&&(s.indexOf("message")>=0||s.indexOf("description")>=0))return l(t);if(0===s.length){if(_(t)){var m=t.name?": "+t.name:"";return e.stylize("[Function"+m+"]","special")}if(S(t))return e.stylize(RegExp.prototype.toString.call(t),"regexp");if(D(t))return e.stylize(Date.prototype.toString.call(t),"date");if(A(t))return l(t)}var k="",g=!1,E=["{","}"];if(d(t)&&(g=!0,E=["[","]"]),_(t)){var y=t.name?": "+t.name:"";k=" [Function"+y+"]"}if(S(t)&&(k=" "+RegExp.prototype.toString.call(t)),D(t)&&(k=" "+Date.prototype.toUTCString.call(t)),A(t)&&(k=" "+l(t)),0===s.length&&(!g||0==t.length))return E[0]+k+E[1];if(i<0)return S(t)?e.stylize(RegExp.prototype.toString.call(t),"regexp"):e.stylize("[Object]","special");e.seen.push(t);var P;return P=g?f(e,t,i,v,s):s.map(function(r){return p(e,t,i,v,r,g)}),e.seen.pop(),h(P,k,E)}function u(e,t){if(y(t))return e.stylize("undefined","undefined");if(I(t)){var r="'"+JSON.stringify(t).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return e.stylize(r,"string")}return g(t)?e.stylize(""+t,"number"):v(t)?e.stylize(""+t,"boolean"):m(t)?e.stylize("null","null"):void 0}function l(e){return"["+Error.prototype.toString.call(e)+"]"}function f(e,t,r,i,n){for(var a=[],s=0,o=t.length;s-1&&(o=a?o.split("\n").map(function(e){return" "+e}).join("\n").substr(2):"\n"+o.split("\n").map(function(e){return" "+e}).join("\n"))):o=e.stylize("[Circular]","special")),y(s)){if(a&&n.match(/^\d+$/))return o;s=JSON.stringify(""+n),s.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)?(s=s.substr(1,s.length-2),s=e.stylize(s,"name")):(s=s.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'"),s=e.stylize(s,"string"))}return s+": "+o}function h(e,t,r){var i=0,n=e.reduce(function(e,t){return i++,t.indexOf("\n")>=0&&i++,e+t.replace(/\u001b\[\d\d?m/g,"").length+1},0);return n>60?r[0]+(""===t?"":t+"\n ")+" "+e.join(",\n ")+" "+r[1]:r[0]+t+" "+e.join(", ")+" "+r[1]}function d(e){return Array.isArray(e)}function v(e){return"boolean"==typeof e}function m(e){return null===e}function k(e){return null==e}function g(e){return"number"==typeof e}function I(e){return"string"==typeof e}function E(e){return"symbol"==typeof e}function y(e){return void 0===e}function S(e){return P(e)&&"[object RegExp]"===b(e)}function P(e){return"object"==typeof e&&null!==e}function D(e){return P(e)&&"[object Date]"===b(e)}function A(e){return P(e)&&("[object Error]"===b(e)||e instanceof Error)}function _(e){return"function"==typeof e}function C(e){return null===e||"boolean"==typeof e||"number"==typeof e||"string"==typeof e||"symbol"==typeof e||"undefined"==typeof e}function b(e){return Object.prototype.toString.call(e)}function w(e,t){return Object.prototype.hasOwnProperty.call(e,t)}var U=/%[sdj%]/g;r.format=function(e){if(!I(e)){for(var t=[],r=0;r=a)return e;switch(e){case"%s":return String(i[r++]);case"%d":return Number(i[r++]);case"%j":try{return JSON.stringify(i[r++])}catch(t){return"[Circular]"}default:return e}}),o=i[r];r>>=0;var t="0000000"+e.toString(16);return t=t.substr(-8),t+"-0000-1000-8000-00805f9b34fb"}function n(e){var r=t.exports.BluetoothUUID[e];return function(t){if("string"==typeof t&&(t=t.toLowerCase()),"number"==typeof t)return i(t);if(a.test(t))return t;if(r.hasOwnProperty(t))return r[t];throw new NamedError("SyntaxError",'"'+t+'" is not a known '+e+" name.")}}var a=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;t.exports.BluetoothUUID={},t.exports.BluetoothUUID.canonicalUUID=i,t.exports.BluetoothUUID.service={alert_notification:i(6161),automation_io:i(6165),battery_service:i(6159),blood_pressure:i(6160),body_composition:i(6171),bond_management:i(6174),continuous_glucose_monitoring:i(6175),current_time:i(6149),cycling_power:i(6168),cycling_speed_and_cadence:i(6166),device_information:i(6154),environmental_sensing:i(6170),generic_access:i(6144),generic_attribute:i(6145),glucose:i(6152),health_thermometer:i(6153),heart_rate:i(6157),human_interface_device:i(6162),immediate_alert:i(6146),indoor_positioning:i(6177),internet_protocol_support:i(6176),link_loss:i(6147),location_and_navigation:i(6169),next_dst_change:i(6151),phone_alert_status:i(6158),pulse_oximeter:i(6178),reference_time_update:i(6150),running_speed_and_cadence:i(6164),scan_parameters:i(6163),tx_power:i(6148),user_data:i(6172),weight_scale:i(6173)},t.exports.BluetoothUUID.characteristic={aerobic_heart_rate_lower_limit:i(10878),aerobic_heart_rate_upper_limit:i(10884),aerobic_threshold:i(10879),age:i(10880),aggregate:i(10842),alert_category_id:i(10819),alert_category_id_bit_mask:i(10818),alert_level:i(10758),alert_notification_control_point:i(10820),alert_status:i(10815),altitude:i(10931),anaerobic_heart_rate_lower_limit:i(10881),anaerobic_heart_rate_upper_limit:i(10882),anaerobic_threshold:i(10883),analog:i(10840),apparent_wind_direction:i(10867),apparent_wind_speed:i(10866),"gap.appearance":i(10753),barometric_pressure_trend:i(10915),battery_level:i(10777),blood_pressure_feature:i(10825),blood_pressure_measurement:i(10805),body_composition_feature:i(10907),body_composition_measurement:i(10908),body_sensor_location:i(10808),bond_management_control_point:i(10916),bond_management_feature:i(10917),boot_keyboard_input_report:i(10786),boot_keyboard_output_report:i(10802),boot_mouse_input_report:i(10803),"gap.central_address_resolution_support":i(10918),cgm_feature:i(10920),cgm_measurement:i(10919),cgm_session_run_time:i(10923),cgm_session_start_time:i(10922),cgm_specific_ops_control_point:i(10924),cgm_status:i(10921),csc_feature:i(10844),csc_measurement:i(10843),current_time:i(10795),cycling_power_control_point:i(10854),cycling_power_feature:i(10853),cycling_power_measurement:i(10851),cycling_power_vector:i(10852),database_change_increment:i(10905),date_of_birth:i(10885),date_of_threshold_assessment:i(10886),date_time:i(10760),day_date_time:i(10762),day_of_week:i(10761),descriptor_value_changed:i(10877),"gap.device_name":i(10752),dew_point:i(10875),digital:i(10838),dst_offset:i(10765),elevation:i(10860),email_address:i(10887),exact_time_256:i(10764),fat_burn_heart_rate_lower_limit:i(10888),fat_burn_heart_rate_upper_limit:i(10889),firmware_revision_string:i(10790),first_name:i(10890),five_zone_heart_rate_limits:i(10891),floor_number:i(10930),gender:i(10892),glucose_feature:i(10833),glucose_measurement:i(10776),glucose_measurement_context:i(10804),gust_factor:i(10868),hardware_revision_string:i(10791),heart_rate_control_point:i(10809),heart_rate_max:i(10893),heart_rate_measurement:i(10807),heat_index:i(10874),height:i(10894),hid_control_point:i(10828),hid_information:i(10826),hip_circumference:i(10895),humidity:i(10863),"ieee_11073-20601_regulatory_certification_data_list":i(10794),indoor_positioning_configuration:i(10925),intermediate_blood_pressure:i(10806),intermediate_temperature:i(10782),irradiance:i(10871),language:i(10914),last_name:i(10896),latitude:i(10926),ln_control_point:i(10859),ln_feature:i(10858),"local_east_coordinate.xml":i(10929),local_north_coordinate:i(10928),local_time_information:i(10767),location_and_speed:i(10855),location_name:i(10933),longitude:i(10927),magnetic_declination:i(10796),magnetic_flux_density_2D:i(10912),magnetic_flux_density_3D:i(10913),manufacturer_name_string:i(10793),maximum_recommended_heart_rate:i(10897),measurement_interval:i(10785),model_number_string:i(10788),navigation:i(10856),new_alert:i(10822),"gap.peripheral_preferred_connection_parameters":i(10756),"gap.peripheral_privacy_flag":i(10754),plx_continuous_measurement:i(10847),plx_features:i(10848),plx_spot_check_measurement:i(10846),pnp_id:i(10832),pollen_concentration:i(10869),position_quality:i(10857),pressure:i(10861),protocol_mode:i(10830),rainfall:i(10872),"gap.reconnection_address":i(10755),record_access_control_point:i(10834),reference_time_information:i(10772),report:i(10829),report_map:i(10827),resting_heart_rate:i(10898),ringer_control_point:i(10816),ringer_setting:i(10817),rsc_feature:i(10836),rsc_measurement:i(10835),sc_control_point:i(10837),scan_interval_window:i(10831),scan_refresh:i(10801),sensor_location:i(10845),serial_number_string:i(10789),"gatt.service_changed":i(10757),software_revision_string:i(10792),sport_type_for_aerobic_and_anaerobic_thresholds:i(10899),supported_new_alert_category:i(10823),supported_unread_alert_category:i(10824),system_id:i(10787),temperature:i(10862),temperature_measurement:i(10780),temperature_type:i(10781),three_zone_heart_rate_limits:i(10900),time_accuracy:i(10770),time_source:i(10771),time_update_control_point:i(10774),time_update_state:i(10775),time_with_dst:i(10769),time_zone:i(10766),true_wind_direction:i(10865),true_wind_speed:i(10864),two_zone_heart_rate_limit:i(10901),tx_power_level:i(10759),uncertainty:i(10932),unread_alert_status:i(10821),user_control_point:i(10911),user_index:i(10906),uv_index:i(10870),vo2_max:i(10902),waist_circumference:i(10903),weight:i(10904),weight_measurement:i(10909),weight_scale_feature:i(10910),wind_chill:i(10873)},t.exports.BluetoothUUID.descriptor={"gatt.characteristic_extended_properties":i(10496),"gatt.characteristic_user_description":i(10497),"gatt.client_characteristic_configuration":i(10498),"gatt.server_characteristic_configuration":i(10499),"gatt.characteristic_presentation_format":i(10500),"gatt.characteristic_aggregate_format":i(10501),valid_range:i(10502),external_report_reference:i(10503),report_reference:i(10504),value_trigger_setting:i(10506),es_configuration:i(10507),es_measurement:i(10508),es_trigger_setting:i(10509)},t.exports.BluetoothUUID.getService=n("service"),t.exports.BluetoothUUID.getCharacteristic=n("characteristic"),t.exports.BluetoothUUID.getDescriptor=n("descriptor")},{}],5:[function(e,t,r){function i(e){return 8==e.indexOf(n)?0==e.indexOf("0000")?e.substring(4,8):e.substring(0,8):e}var n="-0000-1000-8000-00805F9B34FB";t.exports.toVensiUUID=function(e){switch(typeof e){case"string":return i(e.toUpperCase());case"number":return Number(e).toString(16).toUpperCase();default:return}},t.exports.toWbUUID=function(e){return e&&(e=e.toLowerCase()),e},t.exports.hexAsArray=function(e){var t=[];e.length%2==1&&(e="0"+e);for(var r=0;r0&&this._events[e].length>r&&(this._events[e].warned=!0,"function"==typeof console.trace)}return this},i.prototype.on=i.prototype.addListener,i.prototype.once=function(e,t){function r(){this.removeListener(e,r),i||(i=!0,t.apply(this,arguments))}if(!n(t))throw TypeError("listener must be a function");var i=!1;return r.listener=t,this.on(e,r),this},i.prototype.removeListener=function(e,t){var r,i,a,s;if(!n(t))throw TypeError("listener must be a function");if(!this._events||!this._events[e])return this;if(r=this._events[e],a=r.length,i=-1,r===t||n(r.listener)&&r.listener===t)delete this._events[e],this._events.removeListener&&this.emit("removeListener",e,t);else if(o(r)){for(s=a;s-- >0;)if(r[s]===t||r[s].listener&&r[s].listener===t){i=s;break}if(i<0)return this;1===r.length?(r.length=0,delete this._events[e]):r.splice(i,1),this._events.removeListener&&this.emit("removeListener",e,t)}return this},i.prototype.removeAllListeners=function(e){var t,r;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[e]&&delete this._events[e],this;if(0===arguments.length){for(t in this._events)"removeListener"!==t&&this.removeAllListeners(t);return this.removeAllListeners("removeListener"),this._events={},this}if(r=this._events[e],n(r))this.removeListener(e,r);else for(;r.length;)this.removeListener(e,r[r.length-1]);return delete this._events[e],this},i.prototype.listeners=function(e){var t;return t=this._events&&this._events[e]?n(this._events[e])?[this._events[e]]:this._events[e].slice():[]},i.listenerCount=function(e,t){var r;return r=e._events&&e._events[t]?n(e._events[t])?1:e._events[t].length:0}},{}],11:[function(e,t,r){function i(e,t,r){o.instantiateEmitter(this);var i=this,c=e.peripheral(),u=c.gattip(),l={},p={};a.requireUUID("Characteristic","uuid",t),this.uuid=t,r||(r={}),p=r,this.type="c",this.isNotifying=!1,this.gattip=function(){return u},this.peripheral=function(){return c},this.service=function(){return e},this.getAllDescriptors=function(){return l},this.findDescriptor=function(e){return l[e]},this.addDescriptorWithUUID=function(e){var t=new s(i,e);return l[e]=t},this.addDescriptor=function(e){return l[e.uuid]=e},this.hasProperty=function(e){return p[e]&&p[e].enabled},this.setProperty=function(e,t){return p[e]=t},this.allProperties=function(){return p},this.readValue=function(e){var t=a.populateParams(i);u.request(n.kGetCharacteristicValue,t,e,function(t){a.requireFields("Value",t,[n.kValue],[]),i.value=t[n.kValue],u.fulfill(e,i,i.value)})},this.writeValue=function(e,t){a.requireHexValue("writeValue","value",t);var r=a.populateParams(i);r[n.kValue]=t,u.request(n.kWriteCharacteristicValue,r,e,function(r){i.value=t,u.fulfill(e,i)})},this.enableNotifications=function(e,t){a.requireBooleanValue("enableNotifications","isNotifying",t);var r=a.populateParams(i);r[n.kIsNotifying]=t,u.request(n.kSetValueNotification,r,e,function(r){i.isNotifying=t,u.fulfill(e,i,t)})},this.handleValueNotification=function(e){i.value=e[n.kValue],i.emit("valueChange",i,i.value)},this.respondToReadRequest=function(e,t){a.requireHexValue("respondToReadRequest","value",t);var r=a.populateParams(i);r[n.kValue]=t,e.result=n.kGetCharacteristicValue,u.respond(e,r)},this.respondToWriteRequest=function(e){var t=a.populateParams(i);e.result=n.kWriteCharacteristicValue,u.respond(e,t)},this.respondToChangeNotification=function(e,t){var r=a.populateParams(i);a.requireBooleanValue("respondToChangeNotification","value",t),r[n.kIsNotifying]=t,this.isNotifying=t,e.result=n.kSetValueNotification,u.respond(e,r)},this.indicateValueChange=function(e){a.requireHexValue("writeValue","value",e);var t=a.populateParams(i);t[n.kValue]=e,u.sendIndications(n.kSetValueNotification,t)}}var n=e("./lib/constants.js").C,a=e("./lib/message-helper"),o=e("./lib/event-emitter"),s=e("./descriptor").Descriptor;o.makeEmitter(i),t.exports.Characteristic=i},{"./descriptor":12,"./lib/constants.js":17,"./lib/event-emitter":18,"./lib/message-helper":22}],12:[function(e,t,r){function i(e,t){var r=this,i=e.service(),o=i.peripheral(),s=o.gattip();a.requireUUID("Descriptor","uuid",t),this.uuid=t,this.type="d",this.characteristic=function(){return e},this.service=function(){return i},this.peripheral=function(){return o},this.gattip=function(){return s},this.readValue=function(e){var t=a.populateParams(r);s.request(n.kGetDescriptorValue,t,e,function(t){a.requireFields("readValue",t,[n.kValue],[]),r.value=t[n.kValue],s.fulfill(e,r,r.value)})},this.writeValue=function(e,t){var i=a.populateParams(r);a.requireHexValue("writeValue","value",t),s.request(n.kWriteDescriptorValue,i,e,function(i){r.value=t,s.fulfill(e,r)})},this.respondToReadRequest=function(e,t){var i=a.populateParams(r);a.requireHexValue("respondToReadRequest","value",t),i[n.kValue]=t,s.respond(e,i)},this.respondToWriteRequest=function(e){var t=a.populateParams(r);s.respond(e,t)}}var n=e("./lib/constants.js").C,a=e("./lib/message-helper");t.exports.Descriptor=i},{"./lib/constants.js":17,"./lib/message-helper":22}],13:[function(e,t,r){t.exports.ApplicationError=function(e){this.message="Application Error:"+e,Error.captureStackTrace(this,t.exports.ApplicationError)},t.exports.InternalError=function(e){this.message="Application Error:"+e,Error.captureStackTrace(this,t.exports.InternalError)},t.exports.GatewayError=function(e){"object"==typeof e?(this.message="Gateway Error:",e.message&&(this.message+=" "+e.message),e.code&&(this.message+=" Code:"+e.code),0==this.message.length&&(this.message="Unknown Gateway Error")):this.message=e,Error.captureStackTrace(this,t.exports.GatewayError)}},{}],14:[function(e,t,r){function i(e,t){c.instantiateEmitter(this);var r=this,i={};this.isScanning=!1,this.isPoweredOn=function(){return r.state==n.kPoweredOn},this._authenticate=function(t,i,a){var o={};o[n.kDeviceAccessToken]=i,o[n.kGetVersionInfo]=a,e.request(n.kOpen,o,t,function(i){if(i.isAuthenticated!==!0)throw new GatewayError({error:"Auth error"});e.fulfill(t,r)})},this.scan=function(t,i){var a={};i&&("boolean"==typeof i.scanDuplicates&&(a[n.kScanOptionAllowDuplicatesKey]=i.scanDuplicates),"object"==typeof i.services&&(a[n.kServiceUUIDs]=i.services)),e.request(n.kScanForPeripherals,a,t,function(i){r.isScanning=!0,e.fulfill(t,r)})},this.stopScan=function(t){e.request(n.kStopScanning,{},t,function(i){r.isScanning=!1,e.fulfill(t,r)})},this.centralState=function(t){e.request(n.kCentralState,{},t,function(i){r.state=i[n.kState],e.fulfill(t,r)})},this.configure=function(t,i,a){var o={};"undefined"!=typeof i&&(o[n.kShowPowerAlert]=i),"undefined"!=typeof a&&(o[n.kIdentifierKey]=a),e.request(n.kConfigure,{},t,function(i){e.fulfill(t,r)})},this.handleScanIndication=function(i){var s=i[n.kPeripheralUUID];if(!s)throw new o("Peripheral UUID is not availabvle");if(t&&t.uuids)for(var c in t.uuids){var u=t.uuids[c];if(u&&u.length&&u!=s)return}var l=r.getPeripheral(s);l?l._updateFromScanData(i[n.kPeripheralName],i[n.kRSSIkey],i[n.kCBAdvertisementDataTxPowerLevel],i[n.kCBAdvertisementDataServiceUUIDsKey],i[n.kCBAdvertisementDataManufacturerDataKey],i[n.kCBAdvertisementDataServiceDataKey],i[n.kAdvertisementDataKey],i[n.kScanRecord]):l=r.addPeripheral(new a(e,s,i[n.kPeripheralName],i[n.kRSSIkey],i[n.kCBAdvertisementDataTxPowerLevel],i[n.kCBAdvertisementDataServiceUUIDsKey],i[n.kCBAdvertisementDataManufacturerDataKey],i[n.kCBAdvertisementDataServiceDataKey],i[n.kAdvertisementDataKey],i[n.kScanRecord])),r.emit("scan",l)},this.addPeripheralWithValues=function(t,n,s,c,u,l,p){if(!t)throw new o("Attempting to add an empty peripheral");var f=r.addPeripheral(new a(e,t,n,s,c,u,l,p));return i[t]=f,f},this.addPeripheral=function(e){if(!e||!e.uuid)throw new o("Attempting to add an empty peripheral");return i[e.uuid]=e,e},this.removePeripheral=function(e){if(!e||!e.uuid)throw new o("Attempting to remove an empty peripheral");delete i[e.uuid]},this.getPeripheral=function(e){return i[e]},this.getPeripheralOrDie=function(e){var t=i[e];if(!t)throw new o("Unable to find peripheral with UUID "+e);return t},this.getObjects=function(e,t,r,n,a){var c={};if(c.peripheral=i[t],c.peripheral){if("p"===e)return c;if(c.service=c.peripheral.findService(r),c.service){if("s"===e)return c;if(c.characteristic=c.service.findCharacteristic(n),c.characteristic){if("c"===e)return c;if(c.descriptor=c.characteristic.findDescriptor(a),c.descriptor){if("d"===e)return c;throw new o('_getObjects: Argument "type" is required')}throw new s('Descriptor "'+a+'" not found in the service table')}throw new s('Characteristic "'+n+'" not found in the service table')}throw new s('Service "'+r+'" not found in the service table')}throw new s("Peripheral with id "+t+" not found")},this.getObjectsFromMessage=function(e,t){if(!t)throw new o("Message parameters are missing");try{return r.getObjects(e,t[n.kPeripheralUUID],t[n.kServiceUUID],t[n.kCharacteristicUUID],t[n.kDescriptorUUID])}catch(i){throw new o(i.message,i.detail)}}}var n=e("./lib/constants").C,a=(e("./lib/message-helper"),e("./peripheral").Peripheral),o=e("./errors").InternalError,s=e("./errors").ApplicationError,c=e("./lib/event-emitter");c.makeEmitter(i),t.exports.Gateway=i},{"./errors":13,"./lib/constants":17,"./lib/event-emitter":18,"./lib/message-helper":22,"./peripheral":26}],15:[function(e,t,r){function i(){function t(e){m.emit("error",e)}function r(e,r,i){try{e&&(r=JSON.parse(r)),i(r)}catch(n){t(n)}}n.instantiateEmitter(this),this.traceEnabled=!1;var i,h,d,v,_,m=this;this.getGateway=function(){return _},this.traceMessage=function(e,t){m.traceEnabled&&"object"==typeof e&&(e=JSON.stringify(e))},this.getServerMessageHandler=function(){return v||t(new s("Server Message Handler is not Ready")),v},this.fulfill=function(e,t,r,i,n,a){"object"==typeof e&&"function"==typeof e.fulfill?e.fulfill(t,r,i,n,a):"function"==typeof e&&e(t,r,i,n,a)},this.reject=function(e,r){"object"==typeof e&&"function"==typeof e.reject?e.reject(r):t(r)},this.open=function(n){function g(e){e.isServer?(h.on("request",function(e){m.traceMessage(e,"req:"),i.send(JSON.stringify(o))},this.respond=function(e,t){var r=d.wrapResponse(e,t);m.traceMessage(r,">rsp:"),i.send(JSON.stringify(r))},this.sendIndications=function(e,t){var r={params:t,jsonrpc:"2.0"};r.result=e,r.params=t,m.traceMessage(r,">rsp:"),i.send(JSON.stringify(r))},this.sendError=function(e){e.jsonrpc="2.0",m.traceMessage(e,">rsp:"),i.send(JSON.stringify(e))}}var n=e("./lib/event-emitter"),a=e("./errors").InternalError,o=e("./errors").ApplicationError,s=e("./errors").GatewayError,c=e("./lib/message-handler").MessageHandler,u=e("./lib/message-processor").MessageProcessor,l=e("./gateway").Gateway,p=(e("./lib/message-helper"),e("./lib/server-message-handler").ServerMessageHandler),f={keepalive:!0,dropConnectionOnKeepaliveTimeout:!0,keepaliveInterval:1e4,keepaliveGracePeriod:1e4};n.makeEmitter(i),t.exports.GATTIP=i},{"./errors":13,"./gateway":14,"./lib/event-emitter":18,"./lib/message-handler":21,"./lib/message-helper":22,"./lib/message-processor":23,"./lib/server-message-handler":24,websocket:32}],16:[function(e,t,r){t.exports.GATTIP=e("./gattip").GATTIP,t.exports.GattIpServer=e("./lib/gattip-server").GattIpServer},{"./gattip":15,"./lib/gattip-server":19}],17:[function(e,t,r){var i={DEFAULT_MESSAGE_TIMEOUT_MS:61e3,MAX_PENDING_MESSAGES:200,NUM_CONNECT_ATTEMPTS:3,kMessageId:"id",kSessionId:"session_id",kAuthenticate:"aut",kOpen:"opn",kDeviceAccessToken:"dat",kGetVersionInfo:"vif",kError:"error",kCode:"code",kMessageField:"message",kMethod:"method",kResult:"result",kIdField:"id",kConfigure:"aa",kScanForPeripherals:"ab",kStopScanning:"ac",kConnect:"ad",kDisconnect:"ae",kCentralState:"af",kGetConnectedPeripherals:"ag",kGetPerhipheralsWithServices:"ah",kGetPerhipheralsWithIdentifiers:"ai",kGetServices:"ak",kGetIncludedServices:"al",kGetCharacteristics:"am",kGetDescriptors:"an",kGetCharacteristicValue:"ao",kGetDescriptorValue:"ap",kWriteCharacteristicValue:"aq",kWriteDescriptorValue:"ar",kSetValueNotification:"as",kGetPeripheralState:"at",kGetRSSI:"au",kInvalidatedServices:"av",kPeripheralNameUpdate:"aw",kMessage:"zz",kCentralUUID:"ba",kPeripheralUUID:"bb",kPeripheralName:"bc",kPeripheralUUIDs:"bd",kServiceUUID:"be",kServiceUUIDs:"bf",kPeripherals:"bg",kIncludedServiceUUIDs:"bh",kCharacteristicUUID:"bi",kCharacteristicUUIDs:"bj",kDescriptorUUID:"bk",kServices:"bl",kCharacteristics:"bm",kDescriptors:"bn",kProperties:"bo",kValue:"bp",kState:"bq",kStateInfo:"br",kStateField:"bs",kWriteType:"bt",kRSSIkey:"bu",kIsPrimaryKey:"bv",kIsBroadcasted:"bw",kIsNotifying:"bx",kShowPowerAlert:"by",kIdentifierKey:"bz",kScanOptionAllowDuplicatesKey:"b0",kScanOptionSolicitedServiceUUIDs:"b1",kAdvertisementDataKey:"b2",kCBAdvertisementDataManufacturerDataKey:"mfr",kCBAdvertisementDataServiceUUIDsKey:"suu", -kCBAdvertisementDataServiceDataKey:"sdt",kCBAdvertisementDataOverflowServiceUUIDsKey:"b6",kCBAdvertisementDataSolicitedServiceUUIDsKey:"b7",kCBAdvertisementDataIsConnectable:"b8",kCBAdvertisementDataTxPowerLevel:"txp",kPeripheralBtAddress:"c1",kRawAdvertisementData:"c2",kScanRecord:"c3",kCBCentralManagerRestoredStatePeripheralsKey:"da",kCBCentralManagerRestoredStateScanServicesKey:"db",kWriteWithResponse:"cc",kWriteWithoutResponse:"cd",kNotifyOnConnection:"ce",kNotifyOnDisconnection:"cf",kNotifyOnNotification:"cg",kDisconnected:"ch",kConnecting:"ci",kConnected:"cj",kUnknown:"ck",kResetting:"cl",kUnsupported:"cm",kUnauthorized:"cn",kPoweredOff:"co",kPoweredOn:"cp",kErrorPeripheralNotFound:"-32001",kErrorServiceNotFound:"-32002",kErrorCharacteristicNotFound:"-32003",kErrorDescriptorNotFound:"-32004",kErrorPeripheralStateIsNotValid:"-32005",kErrorNoServiceSpecified:"-32006",kErrorNoPeripheralIdentiferSpecified:"-32007",kErrorStateRestorationNotValid:"-32008",kInvalidRequest:"-32600",kMethodNotFound:"-32601",kInvalidParams:"-32602",kError32603:"-32603",kParseError:"-32700",kGAP_ADTYPE_FLAGS:"01",kGAP_ADTYPE_INCOMPLETE_16BIT_SERVICEUUID:"02",kGAP_ADTYPE_COMPLETE_16BIT_SERVICEUUID:"03",kGAP_ADTYPE_INCOMPLETE_32BIT_SERVICEUUID:"04",kGAP_ADTYPE_COMPLETE_32BIT_SERVICEUUID:"05",kGAP_ADTYPE_INCOMPLETE_128BIT_SERVICEUUID:"06",kGAP_ADTYPE_COMPLETE_128BIT_SERVICEUUID:"07",kGAP_ADTYPE_POWER_LEVEL:"0A",kGAP_ADTYPE_MANUFACTURER_SPECIFIC:"FF",kGAP_ADTYPE_16BIT_SERVICE_DATA:"16",id:1,authenticate:"authenticate",AllProperties:["Broadcast","Read","WriteWithoutResponse","Write","Notify","Indicate","AuthenticatedSignedWrites","ExtendedProperties","NotifyEncryptionRequired","IndicateEncryptionRequired"]};t.exports.C=i},{}],18:[function(e,t,r){var i=e("events"),n=e("util");t.exports.makeEmitter=function(e){n.inherits(e,i)},t.exports.instantiateEmitter=function(e){i.call(e)}},{events:10,util:31}],19:[function(e,t,r){function i(){function t(e,t){var r=t?"0x":"";for(var i in e){var n=(255&e[i]).toString(16);1==n.length&&(n="0"+n),r+=n}return r}function r(e){for(var t in e)if(e.hasOwnProperty(t))return!1;return JSON.stringify(e)===JSON.stringify({})}function i(e){var t={};if(e&&e.getAllServices())for(var r in e.getAllServices()){var i={};i[n.kServiceUUID]=r,i[n.kIsPrimaryKey]=e.findService(r).isPrimary,i[n.kCharacteristics]=s(e.findService(r)),t[r]=i}return t}function s(e){var t={};if(e&&e.getAllCharacteristics())for(var r in e.getAllCharacteristics()){var i={};i[n.kCharacteristicUUID]=r,i[n.kValue]=e.findCharacteristic(r).value,i[n.kProperties]=e.findCharacteristic(r).allProperties(),i[n.kIsNotifying]=e.findCharacteristic(r).isNotifying,i[n.kDescriptors]=c(e.findCharacteristic(r)),t[r]=i}return t}function c(e){var t={};if(e&&e.getAllDescriptors())for(var r in e.getAllDescriptors()){var i={};i[n.kDescriptorUUID]=r,i[n.kValue]=e.findDescriptor(r).value,i[n.kProperties]=e.findDescriptor(r).properties,i[n.kIsNotifying]=e.findDescriptor(r).isNotifying,t[r]=i}return t}o.instantiateEmitter(this);var u,l=this;this.peripherals={},this.init=function(t,r){r&&(this.oninit=r),"object"!=typeof window&&(WebSocket=e("websocket").w3cwebsocket),l.socket=new WebSocket(t),l.socket.onopen=function(){l.initWithServer(l.socket),l.oninit&&l.oninit()}},this.initWithServer=function(e){if(u=e,!u.send)throw new Error("server must implement the send method");u.onmessage=l.processMessage,u.onclose||(u.onclose=function(){}),u.onerror||(u.onerror=function(e){}),u.error||(u.onerror=function(e){})},this.processMessage=function(e){function t(e){var t=p[n.kPeripheralUUID],i={};if(i.peripheral=l.peripherals[t],i.peripheral&&i.peripheral.uuid){if("p"===e)return i;var a=p[n.kServiceUUID];if(i.service=i.peripheral.findService(a),i.service&&i.service.uuid){if("s"===e)return i;var o=p[n.kCharacteristicUUID];if(i.characteristic=i.service.findCharacteristic(o),i.characteristic&&i.characteristic.uuid){if("c"===e)return i;var s=p[n.kDescriptorUUID];if(i.descriptor=i.characteristic.findDescriptor(s),i.descriptor&&i.descriptor.uuid)return i;throw l.sendErrorResponse(r.method,n.kErrorDescriptorNotFound,"Descriptor not found in the service database"),new Error("Descriptor not found")}throw l.sendErrorResponse(r.method,n.kErrorCharacteristicNotFound,"Characteristic not found in the service database"),new Error("Characteristic not found")}throw l.sendErrorResponse(r.method,n.kErrorServiceNotFound,"Service not found in the service database"),new Error("Service not found")}throw l.sendErrorResponse(r.method,n.kErrorPeripheralNotFound,"Peripheral not found in the service database"),new Error("Peripheral not found")}try{var r=JSON.parse(e.data)}catch(i){}if("undefined"!=typeof r&&r&&!r.error){var a;if(r.result&&(r.result==n.kMessage||r.result==n.kAuthenticate)){var o=!1;return r.error||"object"!=typeof r.params||r.params[n.kAuthenticate]!==!0||(o=!0),void l.emit("authenticated",o)}if(r.method&&r.method==n.kAuthenticate){var s={};s[n.kAuthenticate]=!0;var c={};return c.result=n.kAuthenticate,c.params=s,c[n.kIdField]=r[n.kIdField],c=JSON.stringify(c),void l.send(c)}var u={id:r.id,session_id:r.session_id,method:r.method},p=r.params;switch(r.method){case n.kConfigure:l.emit("configure",u,p[n.kShowPowerAlert],p[n.kIdentifierKey]);break;case n.kScanForPeripherals:l.emit("scan",u,p[n.kScanOptionAllowDuplicatesKey],p[n.kServiceUUIDs]);break;case n.kStopScanning:l.emit("stopScan",u);break;case n.kCentralState:l.emit("getCentralState",u);break;case n.kConnect:try{a=t("p"),l.emit("connect",u,a.peripheral.uuid)}catch(f){}break;case n.kDisconnect:try{a=t("p"),l.emit("disconnect",u,a.peripheral.uuid)}catch(f){}break;case n.kGetCharacteristicValue:try{a=t("c",u),l.emit("readCharacteristic",u,a.peripheral.uuid,a.service.uuid,a.characteristic.uuid)}catch(f){}break;case n.kWriteCharacteristicValue:try{a=t("c",u),l.emit("writeCharacteristic",u,a.peripheral.uuid,a.service.uuid,a.characteristic.uuid,r.params[n.kValue])}catch(f){}break;case n.kSetValueNotification:try{a=t("c",u),a.characteristic.isNotifying=r.params[n.kValue],l.emit("enableNotifications",u,a.peripheral.uuid,a.service.uuid,a.characteristic.uuid,r.params[n.kIsNotifying])}catch(f){}break;case n.kGetDescriptorValue:try{a=t("d",u),l.emit("readDescriptor",u,a.peripheral.uuid,a.service.uuid,a.characteristic.uuid,a.descriptor.uuid)}catch(f){}break;case n.kWriteDescriptorValue:try{a=t("d",u),l.emit("writeDescriptor",u,a.peripheral.uuid,a.service.uuid,a.characteristic.uuid,a.descriptor.uuid,r.params[n.kValue])}catch(f){}break;default:return void l.sendErrorResponse(u,r.method,n.kInvalidRequest,"Request not handled by server")}}},this.sendErrorResponse=function(e,t,r,i){var a={};params={},a[n.kCode]=r,a[n.kMessageField]=i,params[n.kError]=a,l.write(t,void 0,e,a)},this.authenticate=function(e,t){params={},params[n.kDeviceAccessToken]=e,params[n.kGetVersionInfo]=t;var r={};r.method=n.kAuthenticate,r.params=params,r.id=n.id.toString(),n.id+=1,this.send(JSON.stringify(r))},this.configureResponse=function(e,t){t?l.sendErrorResponse(e,n.kConfigure,void 0):l.write(n.kConfigure,void 0,e)},this.centralStateResponse=function(e,t,r){r?l.sendErrorResponse(e,n.kCentralState,void 0):(params={},params[n.kState]=t,l.write(n.kCentralState,params,e))},this.scanResponse=function(e,i,a,o,s,c,u,p){params={};var f,h;if(!r(u)){f={};for(var d in u){var v=d.toUpperCase();f[v]=t(u[d]).toUpperCase()}}if(!r(p)){h={};for(var _ in p){var m=_.toUpperCase();h[m]=t(p[_]).toUpperCase()}}params[n.kPeripheralName]=a,params[n.kPeripheralUUID]=i,params[n.kRSSIkey]=o,params[n.kCBAdvertisementDataTxPowerLevel]=s,params[n.kCBAdvertisementDataServiceUUIDsKey]=c&&c.length>0?c:void 0,params[n.kCBAdvertisementDataManufacturerDataKey]=f,params[n.kCBAdvertisementDataServiceDataKey]=h,l.write(n.kScanForPeripherals,params,e)},this.stopScanResponse=function(e,t){t?this.sendErrorResponse(e,n.kStopScanning,t):l.write(n.kStopScanning,void 0,e)},this.connectResponse=function(e,t,r){var a={};a[n.kPeripheralUUID]=t.uuid,a[n.kPeripheralName]=t.name;var o={};o=i(t),a[n.kServices]=o,r?l.sendErrorResponse(e,n.kConnect,r):l.write(n.kConnect,a,e)},this.disconnectResponse=function(e,t,r){r?l.sendErrorResponse(e,n.kDisconnect,r):(params={},params[n.kPeripheralUUID]=t.uuid,params[n.kPeripheralName]=t.name,l.write(n.kDisconnect,params))},this.write=function(e,t,r,i){var n={};n.jsonrpc="2.0",n.result=e,n.params=t,n.error=i,r&&(n.id=r.id,n.session_id=r.session_id),l.send(JSON.stringify(n))},this.send=function(e){return u?void(1===u.readyState&&u.send(e)):void l.onerror("not connected")},this.close=function(e){u&&u.close()},this.addPeripheral=function(e,t,r,i,n){var o=new a(this,e,t,r,i,n);return l.peripherals[o.uuid]=o,o},this.GATM_SECURITY_PROPERTIES_NO_SECURITY=0,this.GATM_SECURITY_PROPERTIES_UNAUTHENTICATED_ENCRYPTION_WRITE=1,this.GATM_SECURITY_PROPERTIES_AUTHENTICATED_ENCRYPTION_WRITE=2,this.GATM_SECURITY_PROPERTIES_UNAUTHENTICATED_ENCRYPTION_READ=4,this.GATM_SECURITY_PROPERTIES_AUTHENTICATED_ENCRYPTION_READ=8,this.GATM_SECURITY_PROPERTIES_UNAUTHENTICATED_SIGNED_WRITES=16,this.GATM_SECURITY_PROPERTIES_AUTHENTICATED_SIGNED_WRITES=32,this.GATM_CHARACTERISTIC_PROPERTIES_BROADCAST=1,this.GATM_CHARACTERISTIC_PROPERTIES_READ=2,this.GATM_CHARACTERISTIC_PROPERTIES_WRITE_WO_RESP=4,this.GATM_CHARACTERISTIC_PROPERTIES_WRITE=8,this.GATM_CHARACTERISTIC_PROPERTIES_NOTIFY=16,this.GATM_CHARACTERISTIC_PROPERTIES_INDICATE=32,this.GATM_CHARACTERISTIC_PROPERTIES_AUTHENTICATED_SIGNED_WRITES=64,this.GATM_CHARACTERISTIC_PROPERTIES_EXT_PROPERTIES=128,this.GATM_DESCRIPTOR_PROPERTIES_READ=1,this.GATM_DESCRIPTOR_PROPERTIES_WRITE=2}var n=e("./constants.js").C,a=e("../peripheral.js").Peripheral,o=e("./event-emitter");o.makeEmitter(i),t.exports.GattIpServer=i},{"../peripheral.js":26,"./constants.js":17,"./event-emitter":18,websocket:32}],20:[function(e,t,r){function i(e,t){var r=parseInt(t[0],16);parseInt(t[2],16)>=1?e.discoverable="true":e.discoverable="false",t.splice(0,r+1)}function n(e,t){var r=parseInt(t[0],16);e.txPowerLevel=parseInt(t[2]),t.splice(0,r+1)}function a(e,t){var r=parseInt(t[0],16);if(r>2){for(var i=t[3]+t[2],n="",a=4;a<=r;a++)n+=t[a];e.manufacturerData[i]=n}t.splice(0,r+1)}function o(e,t){for(var r=parseInt(t[0],16),i="",n=r;n>=2;n--)i+=t[n];e.serviceUUIDs=i,t.splice(0,r+1)}function s(e,t){for(var r=parseInt(t[0],16),i="",n=r;n>=2;n--)i+=t[n],14!=n&&12!=n&&10!=n&&8!=n||(i+="-");e.serviceUUIDs=i,t.splice(0,r+1)}function c(e,t){for(var r=parseInt(t[0],16),i="",n=3;n>=2;n--)i+=t[n];"FEAA"==i&&(0===parseInt(t[4],16)?u(e):16==parseInt(t[4],16)?l(e):32==parseInt(t[4],16)&&p(e)),t.splice(0,r+1)}function u(e,t){e.frameType="UID",e.nameSpace="",e.instanceID="",e.txPowerLevel=parseInt(t[5],16);for(var r=6;r<16;r++)e.nameSpace+=t[r];for(var i=16;i<22;i++)e.instanceID+=t[i];e.reserved=t[22],e.reserved+=t[23]}function l(e,t){e.frameType="URL",e.txPowerLevel=parseInt(t[5]);for(var r in f.AllProtocols)t[6]==r&&(e.url=f.AllProtocols[r]);for(var i=7;i2?e.temperature+=i.toString().substring(0,2):e.temperature+=i;for(var n=10;n<14;n++)e.advPacketCount+=t[n];e.advPacketCount=parseInt(e.advPacketCount,16);for(var a=14;a<18;a++)e.timeInterval+=t[a];if(e.timeInterval=Math.ceil(.1*parseInt(e.timeInterval,16)),e.timePeriod="",e.timeInterval>=60){var o=Math.floor(e.timeInterval/86400);o>0&&(e.timePeriod+=o<10?o+"day ":o+"days ",e.timeInterval-=24*o*60*60);var s=Math.floor(e.timeInterval/3600);s>0?(e.timePeriod+=s<10?"0"+s+":":s+":",e.timeInterval-=60*s*60):e.timePeriod+="00:";var c=Math.floor(e.timeInterval/60);c>0?(e.timePeriod+=c<10?"0"+c+":":c+":",e.timeInterval-=60*c,e.timePeriod+=e.timeInterval<10?"0"+e.timeInterval:e.timeInterval,e.timePeriod+=" secs",e.timeInterval=0):(e.timePeriod+="00:"+e.timeInterval,e.timeInterval=0)}else e.timeInterval>0&&e.timeInterval<60&&(e.timePeriod+=e.timeInterval<10?"00:00:0"+e.timeInterval:"00:00:"+e.timeInterval,e.timePeriod+=" secs")}var f=e("./constants").C;t.exports.parseAdvArray=function(e,t){e.advdata||(e.advdata={});var r=e.advdata;if(r.manufacturerData||(r.manufacturerData={}),r.serviceUUIDs||(r.serviceUUIDs=[]),!t)return[];var u=[];if(t.length%2===0)for(var l=0;lo.MAX_PENDING_MESSAGES)throw new s("Message queue is full",r);var c=new i(e,r,n,a);return t[c.id]=c,c.msg},this.hasMessage=function(e){var r=t[""+e];return!!r},this.onMessageReceived=function(r){var i;if(r.params&&r.params.id&&(r.id=r.params.id),r.id&&(i=t[""+r.id]),!i){if(r.id)return r.result==o.kScanForPeripherals&&r.params&&r.params.bb?(l||(l=!0),void e.emit("indication",r)):void e.emit("request",r);if(r.result!=o.kMessage)return void e.emit("indication",r);u||(u=!0),r.id="1",i=t[1]}i.timeout&&clearTimeout(i.timeout),delete t[r.id],e.emit("response",r,i.userContext,i.msg)}}var a=e("./event-emitter"),o=e("./constants").C,s=e("./../errors").ApplicationError,c=1,u=!1,l=!1;a.makeEmitter(n),t.exports.MessageProcessor=n},{"./../errors":13,"./constants":17,"./event-emitter":18}],24:[function(e,t,r){function i(e,t){function r(e,t){var r=t?"0x":"";for(var i in e){var n=(255&e[i]).toString(16);1==n.length&&(n="0"+n),r+=n}return r}function i(e){for(var t in e)if(e.hasOwnProperty(t))return!1;return JSON.stringify(e)===JSON.stringify({})}function o(e,t){var r=t.params,i=e.original.params[n.kPeripheralUUID],a=e.original.params[n.kServiceUUID];i&&(r[n.kPeripheralUUID]=i),a&&(r[n.kServiceUUID]=a)}a.instantiateEmitter(this);var s=this;this.processMessage=function(e){function r(r){var i=l[n.kPeripheralUUID],a={};if(a.peripheral=t.getPeripheral(i),a.peripheral&&a.peripheral.uuid){if("p"===r)return a;var o=l[n.kServiceUUID];if(a.service=a.peripheral.findService(o),a.service&&a.service.uuid){if("s"===r)return a;var c=l[n.kCharacteristicUUID];if(a.characteristic=a.service.findCharacteristic(c),a.characteristic&&a.characteristic.uuid){if("c"===r)return a;var u=l[n.kDescriptorUUID];if(a.descriptor=a.characteristic.findDescriptor(u),a.descriptor&&a.descriptor.uuid)return a;throw s.sendErrorResponse(e.method,n.kErrorDescriptorNotFound,"Descriptor not found in the service database"),new Error("Descriptor not found")}throw s.sendErrorResponse(e.method,n.kErrorCharacteristicNotFound,"Characteristic not found in the service database"),new Error("Characteristic not found")}throw s.sendErrorResponse(e.method,n.kErrorServiceNotFound,"Service not found in the service database"),new Error("Service not found")}throw s.sendErrorResponse(e.method,n.kErrorPeripheralNotFound,"Peripheral not found in the service database"),new Error("Peripheral not found")}var i;if("undefined"!=typeof e&&e&&!e.error){if(e.result&&(e.result==n.kMessage||e.result==n.kAuthenticate)){var a=!1;return e.error||"object"!=typeof e.params||e.params[n.kAuthenticate]!==!0||(a=!0),void s.emit("authenticated",a)}if(e.method&&e.method==n.kAuthenticate){var o={};o[n.kAuthenticate]=!0;var c={};return c.result=n.kAuthenticate,c.params=o,c[n.kIdField]=e[n.kIdField],c=JSON.stringify(c),void s.send(c)}var u={original:e},l=e.params;switch(e.method){case n.kConfigure:s.emit("configure",u,l[n.kShowPowerAlert],l[n.kIdentifierKey]);break;case n.kScanForPeripherals:s.emit("scan",u,l[n.kScanOptionAllowDuplicatesKey],l[n.kServiceUUIDs]);break;case n.kStopScanning:s.emit("stopScan",u);break;case n.kCentralState:s.emit("getCentralState",u);break;case n.kConnect:try{i=r("p"),s.emit("connect",u,i.peripheral.uuid)}catch(p){}break;case n.kDisconnect:try{i=r("p"),s.emit("disconnect",u,i.peripheral.uuid)}catch(p){}break;case n.kGetCharacteristicValue:try{i=r("c",u),s.emit("readCharacteristic",u,i.peripheral.uuid,i.service.uuid,i.characteristic.uuid)}catch(p){}break;case n.kWriteCharacteristicValue:try{i=r("c",u),s.emit("writeCharacteristic",u,i.peripheral.uuid,i.service.uuid,i.characteristic.uuid,e.params[n.kValue])}catch(p){}break;case n.kSetValueNotification:try{i=r("c",u),s.emit("enableNotifications",u,i.peripheral.uuid,i.service.uuid,i.characteristic.uuid,e.params[n.kIsNotifying])}catch(p){}break;case n.kGetDescriptorValue:try{i=r("d",u),s.emit("readDescriptor",u,i.peripheral.uuid,i.service.uuid,i.characteristic.uuid,i.descriptor.uuid)}catch(p){}break;case n.kWriteDescriptorValue:try{i=r("d",u),s.emit("writeDescriptor",u,i.peripheral.uuid,i.service.uuid,i.characteristic.uuid,i.descriptor.uuid,e.params[n.kValue])}catch(p){}break;default:return void s.sendErrorResponse(u,e.method,n.kInvalidRequest,"Request not handled by server")}}},s.sendErrorResponse=function(t,r,i,a){var o={},s={};s[n.kCode]=i,s[n.kMessageField]=a,o[n.kError]=s,o.result=r,t&&t.original&&(o[n.kMessageId]=t.original.id,o[n.kSessionId]=t.original.session_id),e.sendError(o)},s.configureResponse=function(t){t.result=n.kConfigure,e.respond(t,{})},s.centralStateResponse=function(t,r,i){var a={};a[n.kState]=r,t.result=n.kCentralState,e.respond(t,a)},s.stopScanResponse=function(t){t.result=n.kStopScanning,e.respond(t,{})},s.disconnectResponse=function(t,r){var i={};i[n.kPeripheralUUID]=r.uuid,i[n.kPeripheralName]=r.name,null!=t?e.respond(t,i):e.sendIndications(n.kDisconnect,i)},s.scanResponse=function(t,a,o,s,c,u,l,p){if(t)return t.result=n.kScanForPeripherals,void e.respond(t,{});var f,h,d={};if(!i(l)){f={};for(var v in l){var _=v.toUpperCase();f[_]=r(l[v]).toUpperCase()}}if(!i(p)){h={};for(var m in p){var g=m.toUpperCase();h[g]=r(p[m]).toUpperCase()}}d[n.kPeripheralName]=o,d[n.kPeripheralUUID]=a,d[n.kRSSIkey]=s,d[n.kCBAdvertisementDataTxPowerLevel]=c,d[n.kCBAdvertisementDataServiceUUIDsKey]=u&&u.length>0?u:void 0,d[n.kCBAdvertisementDataManufacturerDataKey]=f,d[n.kCBAdvertisementDataServiceDataKey]=h,e.sendIndications(n.kScanForPeripherals,d)},s.addPeripheral=function(e,t,r,i,n){var a=new Peripheral(this,e,t,r,i,n);return s.peripherals[a.uuid]=a,a},this.respondToConnect=function(t){var r={};o(t,r),e.respond(t,r)}}var n=e("./constants.js").C,a=e("./event-emitter");this.GATM_SECURITY_PROPERTIES_NO_SECURITY=0,this.GATM_SECURITY_PROPERTIES_UNAUTHENTICATED_ENCRYPTION_WRITE=1,this.GATM_SECURITY_PROPERTIES_AUTHENTICATED_ENCRYPTION_WRITE=2,this.GATM_SECURITY_PROPERTIES_UNAUTHENTICATED_ENCRYPTION_READ=4,this.GATM_SECURITY_PROPERTIES_AUTHENTICATED_ENCRYPTION_READ=8,this.GATM_SECURITY_PROPERTIES_UNAUTHENTICATED_SIGNED_WRITES=16,this.GATM_SECURITY_PROPERTIES_AUTHENTICATED_SIGNED_WRITES=32,this.GATM_CHARACTERISTIC_PROPERTIES_BROADCAST=1,this.GATM_CHARACTERISTIC_PROPERTIES_READ=2,this.GATM_CHARACTERISTIC_PROPERTIES_WRITE_WO_RESP=4,this.GATM_CHARACTERISTIC_PROPERTIES_WRITE=8,this.GATM_CHARACTERISTIC_PROPERTIES_NOTIFY=16,this.GATM_CHARACTERISTIC_PROPERTIES_INDICATE=32,this.GATM_CHARACTERISTIC_PROPERTIES_AUTHENTICATED_SIGNED_WRITES=64,this.GATM_CHARACTERISTIC_PROPERTIES_EXT_PROPERTIES=128,this.GATM_DESCRIPTOR_PROPERTIES_READ=1,this.GATM_DESCRIPTOR_PROPERTIES_WRITE=2,a.makeEmitter(i),t.exports.ServerMessageHandler=i},{"./constants.js":17,"./event-emitter":18}],25:[function(e,t,r){function i(e,t){var r=t[c.kDescriptorUUID],i=e.findDescriptor(r);i||(i=new p(e,r),e.addDescriptor(i)),i.value=t[c.kValue]}function n(e,t){var r=t[c.kCharacteristicUUID],n=e.findCharacteristic(r);n||(n=new l(e,r),e.addCharacteristic(n)),n.value=t[c.kValue];var a=t[c.kProperties];if("object"==typeof a)for(var o in a)n.setProperty(o,{enabled:a[o].enabled,name:a[o].name});else for(var s in c.AllProperties)n.setProperty([c.AllProperties[s]],{enabled:a>>s&1,name:c.AllProperties[s]});n.isNotifying=!1;var u=t[c.kDescriptors];if(u)for(var p in u){var f=u[p];i(n,f)}}function a(e,t){var r=t[c.kServiceUUID],i=e.findService(r);i||(i=new u(e,r),e.addService(i));var a=t[c.kCharacteristics];if(a)for(var o in a){var s=a[o];n(i,s)}}function o(e){var t={};if(e&&e.getAllDescriptors())for(var r in e.getAllDescriptors()){var i={};i[c.kDescriptorUUID]=r,i[c.kValue]=e.findDescriptor(r).value,i[c.kProperties]=e.findDescriptor(r).properties,i[c.kIsNotifying]=e.findDescriptor(r).isNotifying,t[r]=i}return t}function s(e){var t={};if(e&&e.getAllCharacteristics())for(var r in e.getAllCharacteristics()){var i={};i[c.kCharacteristicUUID]=r,i[c.kValue]=e.findCharacteristic(r).value,i[c.kProperties]=e.findCharacteristic(r).allProperties(),i[c.kIsNotifying]=e.findCharacteristic(r).isNotifying,i[c.kDescriptors]=o(e.findCharacteristic(r)),t[r]=i}return t}var c=e("./constants").C,u=e("./../service").Service,l=e("./../characteristic").Characteristic,p=e("./../descriptor").Descriptor;t.exports.parseServiceRecord=function(e,t){var r=t[c.kServices];if(r)for(var i in r){var n=r[i];a(e,n)}},t.exports.getServiceJsonFromPeripheralObject=function(e){var t={};if(e&&e.getAllServices())for(var r in e.getAllServices()){var i={};i[c.kServiceUUID]=r,i[c.kIsPrimaryKey]=e.findService(r).isPrimary,i[c.kCharacteristics]=s(e.findService(r)),t[r]=i}return t}},{"./../characteristic":11,"./../descriptor":12,"./../service":27,"./constants":17}],26:[function(e,t,r){function i(e,t){return e.indexOf(t)==-1&&(e.push(t),!0)}function n(e,t,r,n,p,f){c.instantiateEmitter(this);var h=this;this.type="p",this.uuid=t,this.isConnected=!1;var d={},v={},_={},m=[];this._updateFromScanData=function(e,t,r,n,a,o,c,u){this.name=e,this.rssi=t,this.txPowerLevel=r;if(a)for(var l in a)v[l]=a[l];if(_)for(var p in o)_[p]=o[p];if(n)for(var f=0;f=0},this.getAllServices=function(){return d},this.getAllMfrData=function(){return v},this.getAllSvcData=function(){return _},this.getAllAdvertisedServiceUUIDs=function(){return m},this.addServiceWithUUID=function(e){var t=new l(h,e);return d[e]=t},this.addService=function(e){return d[e.uuid]=e},this.gattip=function(){return e},this.connectOnce=function(t){var r=o.populateParams(h);e.request(a.kConnect,r,t,function(r){u.parseServiceRecord(h,r),h.isConnected=!0,e.fulfill(t,h)})},this.connect=function(t,r){function i(r){o++,o<=a.NUM_CONNECT_ATTEMPTS?h.connectOnce({fulfill:n,reject:i}):e.reject(t,r)}var n="object"==typeof t?t.fulfill:t,o=0;r&&"number"==typeof r.numConnectAttempts&&(o=r.numConnectAttempts),i()},this.disconnect=function(t){var r=o.populateParams(h);e.request(a.kDisconnect,r,t,function(r){h.isConnected=!1,e.fulfill(t,h)})},this.respondToConnectRequest=function(t){var r={};r[a.kPeripheralUUID]=this.uuid,r[a.kPeripheralName]=this.name;var i;i=u.getServiceJsonFromPeripheralObject(this),r[a.kServices]=i,t.result=a.kConnect,e.respond(t,r)},this.handleDisconnectIndication=function(){h.isConnected=!1,h.emit("disconnected",h)},this._updateFromScanData(r,n,p,f)}var a=e("./lib/constants.js").C,o=e("./lib/message-helper"),s=e("./lib/message-advdata-parser"),c=e("./lib/event-emitter"),u=e("./lib/service-table"),l=e("./service").Service;c.makeEmitter(n),t.exports.Peripheral=n},{"./lib/constants.js":17,"./lib/event-emitter":18,"./lib/message-advdata-parser":20,"./lib/message-helper":22,"./lib/service-table":25,"./service":27}],27:[function(e,t,r){function i(e,t){var r=this,i=e.gattip(),o={};n.requireUUID("Service","uuid",t),this.uuid=t,this.type="s",this.isPrimary=!0,this.peripheral=function(){return e},this.gattip=function(){return i},this.getAllCharacteristics=function(){return o},this.findCharacteristic=function(e){return o[e]},this.addCharacteristicWithUUID=function(e,t){var i=new a(r,e,t);return o[e]=i},this.addCharacteristic=function(e){o[e.uuid]=e}}var n=e("./lib/message-helper"),a=e("./characteristic").Characteristic;r.Service=i},{"./characteristic":11,"./lib/message-helper":22}],28:[function(e,t,r){"function"==typeof Object.create?t.exports=function(e,t){e.super_=t,e.prototype=Object.create(t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}})}:t.exports=function(e,t){e.super_=t;var r=function(){};r.prototype=t.prototype,e.prototype=new r,e.prototype.constructor=e}},{}],29:[function(e,t,r){function i(){f&&l&&(f=!1,l.length?p=l.concat(p):h=-1,p.length&&n())}function n(){if(!f){var e=s(i);f=!0;for(var t=p.length;t;){for(l=p,p=[];++h1)for(var r=1;r=3&&(i.depth=arguments[2]),arguments.length>=4&&(i.colors=arguments[3]),v(t)?i.showHidden=t:t&&r._extend(i,t),b(i.showHidden)&&(i.showHidden=!1),b(i.depth)&&(i.depth=2),b(i.colors)&&(i.colors=!1),b(i.customInspect)&&(i.customInspect=!0),i.colors&&(i.stylize=a),c(i,e,i.depth)}function a(e,t){var r=n.styles[t];return r?"["+n.colors[r][0]+"m"+e+"["+n.colors[r][1]+"m":e}function o(e,t){return e}function s(e){var t={};return e.forEach(function(e,r){t[e]=!0}),t}function c(e,t,i){if(e.customInspect&&t&&P(t.inspect)&&t.inspect!==r.inspect&&(!t.constructor||t.constructor.prototype!==t)){var n=t.inspect(i,e);return k(n)||(n=c(e,n,i)),n}var a=u(e,t);if(a)return a;var o=Object.keys(t),v=s(o);if(e.showHidden&&(o=Object.getOwnPropertyNames(t)),S(t)&&(o.indexOf("message")>=0||o.indexOf("description")>=0))return l(t);if(0===o.length){if(P(t)){var _=t.name?": "+t.name:"";return e.stylize("[Function"+_+"]","special")}if(y(t))return e.stylize(RegExp.prototype.toString.call(t),"regexp");if(w(t))return e.stylize(Date.prototype.toString.call(t),"date");if(S(t))return l(t)}var m="",g=!1,I=["{","}"]; -if(d(t)&&(g=!0,I=["[","]"]),P(t)){var b=t.name?": "+t.name:"";m=" [Function"+b+"]"}if(y(t)&&(m=" "+RegExp.prototype.toString.call(t)),w(t)&&(m=" "+Date.prototype.toUTCString.call(t)),S(t)&&(m=" "+l(t)),0===o.length&&(!g||0==t.length))return I[0]+m+I[1];if(i<0)return y(t)?e.stylize(RegExp.prototype.toString.call(t),"regexp"):e.stylize("[Object]","special");e.seen.push(t);var E;return E=g?p(e,t,i,v,o):o.map(function(r){return f(e,t,i,v,r,g)}),e.seen.pop(),h(E,m,I)}function u(e,t){if(b(t))return e.stylize("undefined","undefined");if(k(t)){var r="'"+JSON.stringify(t).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return e.stylize(r,"string")}return g(t)?e.stylize(""+t,"number"):v(t)?e.stylize(""+t,"boolean"):_(t)?e.stylize("null","null"):void 0}function l(e){return"["+Error.prototype.toString.call(e)+"]"}function p(e,t,r,i,n){for(var a=[],o=0,s=t.length;o-1&&(s=a?s.split("\n").map(function(e){return" "+e}).join("\n").substr(2):"\n"+s.split("\n").map(function(e){return" "+e}).join("\n"))):s=e.stylize("[Circular]","special")),b(o)){if(a&&n.match(/^\d+$/))return s;o=JSON.stringify(""+n),o.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)?(o=o.substr(1,o.length-2),o=e.stylize(o,"name")):(o=o.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'"),o=e.stylize(o,"string"))}return o+": "+s}function h(e,t,r){var i=0,n=e.reduce(function(e,t){return i++,t.indexOf("\n")>=0&&i++,e+t.replace(/\u001b\[\d\d?m/g,"").length+1},0);return n>60?r[0]+(""===t?"":t+"\n ")+" "+e.join(",\n ")+" "+r[1]:r[0]+t+" "+e.join(", ")+" "+r[1]}function d(e){return Array.isArray(e)}function v(e){return"boolean"==typeof e}function _(e){return null===e}function m(e){return null==e}function g(e){return"number"==typeof e}function k(e){return"string"==typeof e}function I(e){return"symbol"==typeof e}function b(e){return void 0===e}function y(e){return E(e)&&"[object RegExp]"===A(e)}function E(e){return"object"==typeof e&&null!==e}function w(e){return E(e)&&"[object Date]"===A(e)}function S(e){return E(e)&&("[object Error]"===A(e)||e instanceof Error)}function P(e){return"function"==typeof e}function D(e){return null===e||"boolean"==typeof e||"number"==typeof e||"string"==typeof e||"symbol"==typeof e||"undefined"==typeof e}function A(e){return Object.prototype.toString.call(e)}function C(e,t){return Object.prototype.hasOwnProperty.call(e,t)}var U=/%[sdj%]/g;r.format=function(e){if(!k(e)){for(var t=[],r=0;r=a)return e;switch(e){case"%s":return String(i[r++]);case"%d":return Number(i[r++]);case"%j":try{return JSON.stringify(i[r++])}catch(t){return"[Circular]"}default:return e}}),s=i[r];r=0.8.0"},gitHead:"ba2fa7e9676c456bcfb12ad160655319af66faed",homepage:"https://github.com/theturtle32/WebSocket-Node",keywords:["websocket","websockets","socket","networking","comet","push","RFC-6455","realtime","server","client"],license:"Apache-2.0",main:"index",maintainers:[{name:"theturtle32",email:"brian@worlize.com"}],name:"websocket",optionalDependencies:{},readme:"ERROR: No README data found!",repository:{type:"git",url:"git+https://github.com/theturtle32/WebSocket-Node.git"},scripts:{gulp:"gulp",install:"(node-gyp rebuild 2> builderror.log) || (exit 0)",test:"faucet test/unit"},version:"1.0.23"}},{}]},{},[1]); \ No newline at end of file +!function e(t,r,i){function n(o,s){if(!r[o]){if(!t[o]){var c="function"==typeof require&&require;if(!s&&c)return c(o,!0);if(a)return a(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}var l=r[o]={exports:{}};t[o][0].call(l.exports,function(e){var r=t[o][1][e];return n(r?r:e)},l,l.exports,e,t,r,i)}return r[o].exports}for(var a="function"==typeof require&&require,o=0;o0?e.serviceUUIDs=e.advdata.serviceUUIDs:e.serviceUUIDs=e.getAllAdvertisedServiceUUIDs(),n.length>0&&""!==r&&"undefined"!=typeof r){if(n.length>0){for(var u=0;u0&&e.serviceUUIDs.indexOf(n[u])>-1&&c++;if(c>0&&(s=!0),s&&(e.name.toUpperCase()===r.toUpperCase()||e.name.toUpperCase().indexOf(r.toUpperCase())>-1))return e}}else{if(!(n.length>0||""!==r&&"undefined"!=typeof r))return e;if(n.length>0){for(var o=0;o0&&e.serviceUUIDs.indexOf(n[o])>-1&&c++;if(c>0&&(s=!0),s)return e}if(""!==r&&"undefined"!=typeof r&&(e.name.toUpperCase()===r.toUpperCase()||e.name.toUpperCase().indexOf(r.toUpperCase())>-1))return e}}for(var o,s=e("gatt-ip").GATTIP,c=e("./util.js"),u=e("./thirdparty"),l=e("./wb-device").BluetoothDevice,p=/\+/g,f=/([^&=]+)=?([^&]*)/g,d=function(e){return decodeURIComponent(e.replace(p," "))},h=window.location.search.substring(1),v={};o=f.exec(h);)v[d(o[1])]=d(o[2]);var g=v.app;t.exports.navigator=void 0,t.exports.window=void 0,i.prototype.requestDevice=function(e){var t=e.filters,r=this.gateway,i=[];return c.errorLoggingPromise(function(e,t){r.getGateway()?e(r.getGateway()):r.once("ready",function(t){e(t)})}).then(function(){return c.errorLoggingPromise(function(e,o){function s(o){if(clearTimeout(c),"true"==g){var p=a(o,t);if(p){i=n(i,p);for(var f='',d=0;d",f+="";document.getElementById("peripheral").innerHTML=f}}else u.stopScan(function(){u.removeListener("scan",s);var t=new l(r,o);t.gatt=t,e(t)})}var c=setTimeout(function(){o("Timed out")},3e4),u=r.getGateway();window.onPeripheralSelect=function(t){u.stopScan(function(){var n=document.getElementById("picker");n.style.display="none";for(var a=0;a.modal { display: block; position: fixed; z-index: 1; padding-top: 100px; left: 0; top: 50; width: 100%; height: 100%; overflow: auto; background-color: rgb(0, 0, 0); background-color: rgba(0, 0, 0, 0.4);}.modal-content { background-color: #fefefe; margin: auto; padding: 20px; border: 1px solid #888; width: 80%;}.spacing-table td { border-width: 3px 0; padding: 10px 10px;}.div-border { border-collapse: collapse; border: 1px solid #b5aeae;;}'),u.on("scan",s)})})})},t.exports.init=function(e){var t={};t.bluetooth={},t.BluetoothUUID=u.BluetoothUUID,e||(e={});var r=new s;r.BluetoothUUID=u.BluetoothUUID;var n={};return n.bluetooth=new i(r),e.token&&(n.bluetooth.referringDevice={dummy:"this is a dummy device",id:e.deviceUUID}),n.bluetooth.gattip=r,r.open(e),r.on("error",function(e){e.stack}),{navigator:n,window:t}}},{"./thirdparty":4,"./util.js":5,"./wb-device":8,"gatt-ip":16}],4:[function(e,t,r){function i(e){e>>>=0;var t="0000000"+e.toString(16);return t=t.substr(-8),t+"-0000-1000-8000-00805f9b34fb"}function n(e){var r=t.exports.BluetoothUUID[e];return function(t){if("string"==typeof t&&(t=t.toLowerCase()),"number"==typeof t)return i(t);if(a.test(t))return t;if(r.hasOwnProperty(t))return r[t];throw new NamedError("SyntaxError",'"'+t+'" is not a known '+e+" name.")}}var a=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;t.exports.BluetoothUUID={},t.exports.BluetoothUUID.canonicalUUID=i,t.exports.BluetoothUUID.service={alert_notification:i(6161),automation_io:i(6165),battery_service:i(6159),blood_pressure:i(6160),body_composition:i(6171),bond_management:i(6174),continuous_glucose_monitoring:i(6175),current_time:i(6149),cycling_power:i(6168),cycling_speed_and_cadence:i(6166),device_information:i(6154),environmental_sensing:i(6170),generic_access:i(6144),generic_attribute:i(6145),glucose:i(6152),health_thermometer:i(6153),heart_rate:i(6157),human_interface_device:i(6162),immediate_alert:i(6146),indoor_positioning:i(6177),internet_protocol_support:i(6176),link_loss:i(6147),location_and_navigation:i(6169),next_dst_change:i(6151),phone_alert_status:i(6158),pulse_oximeter:i(6178),reference_time_update:i(6150),running_speed_and_cadence:i(6164),scan_parameters:i(6163),tx_power:i(6148),user_data:i(6172),weight_scale:i(6173)},t.exports.BluetoothUUID.characteristic={aerobic_heart_rate_lower_limit:i(10878),aerobic_heart_rate_upper_limit:i(10884),aerobic_threshold:i(10879),age:i(10880),aggregate:i(10842),alert_category_id:i(10819),alert_category_id_bit_mask:i(10818),alert_level:i(10758),alert_notification_control_point:i(10820),alert_status:i(10815),altitude:i(10931),anaerobic_heart_rate_lower_limit:i(10881),anaerobic_heart_rate_upper_limit:i(10882),anaerobic_threshold:i(10883),analog:i(10840),apparent_wind_direction:i(10867),apparent_wind_speed:i(10866),"gap.appearance":i(10753),barometric_pressure_trend:i(10915),battery_level:i(10777),blood_pressure_feature:i(10825),blood_pressure_measurement:i(10805),body_composition_feature:i(10907),body_composition_measurement:i(10908),body_sensor_location:i(10808),bond_management_control_point:i(10916),bond_management_feature:i(10917),boot_keyboard_input_report:i(10786),boot_keyboard_output_report:i(10802),boot_mouse_input_report:i(10803),"gap.central_address_resolution_support":i(10918),cgm_feature:i(10920),cgm_measurement:i(10919),cgm_session_run_time:i(10923),cgm_session_start_time:i(10922),cgm_specific_ops_control_point:i(10924),cgm_status:i(10921),csc_feature:i(10844),csc_measurement:i(10843),current_time:i(10795),cycling_power_control_point:i(10854),cycling_power_feature:i(10853),cycling_power_measurement:i(10851),cycling_power_vector:i(10852),database_change_increment:i(10905),date_of_birth:i(10885),date_of_threshold_assessment:i(10886),date_time:i(10760),day_date_time:i(10762),day_of_week:i(10761),descriptor_value_changed:i(10877),"gap.device_name":i(10752),dew_point:i(10875),digital:i(10838),dst_offset:i(10765),elevation:i(10860),email_address:i(10887),exact_time_256:i(10764),fat_burn_heart_rate_lower_limit:i(10888),fat_burn_heart_rate_upper_limit:i(10889),firmware_revision_string:i(10790),first_name:i(10890),five_zone_heart_rate_limits:i(10891),floor_number:i(10930),gender:i(10892),glucose_feature:i(10833),glucose_measurement:i(10776),glucose_measurement_context:i(10804),gust_factor:i(10868),hardware_revision_string:i(10791),heart_rate_control_point:i(10809),heart_rate_max:i(10893),heart_rate_measurement:i(10807),heat_index:i(10874),height:i(10894),hid_control_point:i(10828),hid_information:i(10826),hip_circumference:i(10895),humidity:i(10863),"ieee_11073-20601_regulatory_certification_data_list":i(10794),indoor_positioning_configuration:i(10925),intermediate_blood_pressure:i(10806),intermediate_temperature:i(10782),irradiance:i(10871),language:i(10914),last_name:i(10896),latitude:i(10926),ln_control_point:i(10859),ln_feature:i(10858),"local_east_coordinate.xml":i(10929),local_north_coordinate:i(10928),local_time_information:i(10767),location_and_speed:i(10855),location_name:i(10933),longitude:i(10927),magnetic_declination:i(10796),magnetic_flux_density_2D:i(10912),magnetic_flux_density_3D:i(10913),manufacturer_name_string:i(10793),maximum_recommended_heart_rate:i(10897),measurement_interval:i(10785),model_number_string:i(10788),navigation:i(10856),new_alert:i(10822),"gap.peripheral_preferred_connection_parameters":i(10756),"gap.peripheral_privacy_flag":i(10754),plx_continuous_measurement:i(10847),plx_features:i(10848),plx_spot_check_measurement:i(10846),pnp_id:i(10832),pollen_concentration:i(10869),position_quality:i(10857),pressure:i(10861),protocol_mode:i(10830),rainfall:i(10872),"gap.reconnection_address":i(10755),record_access_control_point:i(10834),reference_time_information:i(10772),report:i(10829),report_map:i(10827),resting_heart_rate:i(10898),ringer_control_point:i(10816),ringer_setting:i(10817),rsc_feature:i(10836),rsc_measurement:i(10835),sc_control_point:i(10837),scan_interval_window:i(10831),scan_refresh:i(10801),sensor_location:i(10845),serial_number_string:i(10789),"gatt.service_changed":i(10757),software_revision_string:i(10792),sport_type_for_aerobic_and_anaerobic_thresholds:i(10899),supported_new_alert_category:i(10823),supported_unread_alert_category:i(10824),system_id:i(10787),temperature:i(10862),temperature_measurement:i(10780),temperature_type:i(10781),three_zone_heart_rate_limits:i(10900),time_accuracy:i(10770),time_source:i(10771),time_update_control_point:i(10774),time_update_state:i(10775),time_with_dst:i(10769),time_zone:i(10766),true_wind_direction:i(10865),true_wind_speed:i(10864),two_zone_heart_rate_limit:i(10901),tx_power_level:i(10759),uncertainty:i(10932),unread_alert_status:i(10821),user_control_point:i(10911),user_index:i(10906),uv_index:i(10870),vo2_max:i(10902),waist_circumference:i(10903),weight:i(10904),weight_measurement:i(10909),weight_scale_feature:i(10910),wind_chill:i(10873)},t.exports.BluetoothUUID.descriptor={"gatt.characteristic_extended_properties":i(10496),"gatt.characteristic_user_description":i(10497),"gatt.client_characteristic_configuration":i(10498),"gatt.server_characteristic_configuration":i(10499),"gatt.characteristic_presentation_format":i(10500),"gatt.characteristic_aggregate_format":i(10501),valid_range:i(10502),external_report_reference:i(10503),report_reference:i(10504),value_trigger_setting:i(10506),es_configuration:i(10507),es_measurement:i(10508),es_trigger_setting:i(10509)},t.exports.BluetoothUUID.getService=n("service"),t.exports.BluetoothUUID.getCharacteristic=n("characteristic"),t.exports.BluetoothUUID.getDescriptor=n("descriptor")},{}],5:[function(e,t,r){function i(e){return 8==e.indexOf(n)?0==e.indexOf("0000")?e.substring(4,8):e.substring(0,8):e}var n="-0000-1000-8000-00805F9B34FB";t.exports.toVensiUUID=function(e){switch(typeof e){case"string":return i(e.toUpperCase());case"number":return Number(e).toString(16).toUpperCase();default:return}},t.exports.toWbUUID=function(e){return e&&(e=e.toLowerCase()),e},t.exports.hexAsArray=function(e){var t=[];e.length%2==1&&(e="0"+e);for(var r=0;r0&&this._events[e].length>r&&(this._events[e].warned=!0,"function"==typeof console.trace)}return this},i.prototype.on=i.prototype.addListener,i.prototype.once=function(e,t){function r(){this.removeListener(e,r),i||(i=!0,t.apply(this,arguments))}if(!n(t))throw TypeError("listener must be a function");var i=!1;return r.listener=t,this.on(e,r),this},i.prototype.removeListener=function(e,t){var r,i,a,s;if(!n(t))throw TypeError("listener must be a function");if(!this._events||!this._events[e])return this;if(r=this._events[e],a=r.length,i=-1,r===t||n(r.listener)&&r.listener===t)delete this._events[e],this._events.removeListener&&this.emit("removeListener",e,t);else if(o(r)){for(s=a;s-- >0;)if(r[s]===t||r[s].listener&&r[s].listener===t){i=s;break}if(i<0)return this;1===r.length?(r.length=0,delete this._events[e]):r.splice(i,1),this._events.removeListener&&this.emit("removeListener",e,t)}return this},i.prototype.removeAllListeners=function(e){var t,r;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[e]&&delete this._events[e],this;if(0===arguments.length){for(t in this._events)"removeListener"!==t&&this.removeAllListeners(t);return this.removeAllListeners("removeListener"),this._events={},this}if(r=this._events[e],n(r))this.removeListener(e,r);else for(;r.length;)this.removeListener(e,r[r.length-1]);return delete this._events[e],this},i.prototype.listeners=function(e){var t;return t=this._events&&this._events[e]?n(this._events[e])?[this._events[e]]:this._events[e].slice():[]},i.listenerCount=function(e,t){var r;return r=e._events&&e._events[t]?n(e._events[t])?1:e._events[t].length:0}},{}],11:[function(e,t,r){function i(e,t,r){o.instantiateEmitter(this);var i=this,c=e.peripheral(),u=c.gattip(),l={},p={};a.requireUUID("Characteristic","uuid",t),this.uuid=t,r||(r={}),p=r,this.type="c",this.isNotifying=!1,this.gattip=function(){return u},this.peripheral=function(){return c},this.service=function(){return e},this.getAllDescriptors=function(){return l},this.findDescriptor=function(e){return l[e]},this.addDescriptorWithUUID=function(e){var t=new s(i,e);return l[e]=t},this.addDescriptor=function(e){return l[e.uuid]=e},this.hasProperty=function(e){return p[e]&&p[e].enabled},this.setProperty=function(e,t){return p[e]=t},this.allProperties=function(){return p},this.readValue=function(e){var t=a.populateParams(i);u.request(n.kGetCharacteristicValue,t,e,function(t){a.requireFields("Value",t,[n.kValue],[]),i.value=t[n.kValue],u.fulfill(e,i,i.value)})},this.writeValue=function(e,t){a.requireHexValue("writeValue","value",t);var r=a.populateParams(i);r[n.kValue]=t,u.request(n.kWriteCharacteristicValue,r,e,function(r){i.value=t,u.fulfill(e,i)})},this.enableNotifications=function(e,t){a.requireBooleanValue("enableNotifications","isNotifying",t);var r=a.populateParams(i);r[n.kIsNotifying]=t,u.request(n.kSetValueNotification,r,e,function(r){i.isNotifying=t,u.fulfill(e,i,t)})},this.handleValueNotification=function(e){i.value=e[n.kValue],i.emit("valueChange",i,i.value)},this.respondToReadRequest=function(e,t){a.requireHexValue("respondToReadRequest","value",t);var r=a.populateParams(i);r[n.kValue]=t,e.result=n.kGetCharacteristicValue,u.respond(e,r)},this.respondToWriteRequest=function(e){var t=a.populateParams(i);e.result=n.kWriteCharacteristicValue,u.respond(e,t)},this.respondToChangeNotification=function(e,t){var r=a.populateParams(i);a.requireBooleanValue("respondToChangeNotification","value",t),r[n.kIsNotifying]=t,this.isNotifying=t,e.result=n.kSetValueNotification,u.respond(e,r)},this.indicateValueChange=function(e){a.requireHexValue("writeValue","value",e);var t=a.populateParams(i);t[n.kValue]=e,u.sendIndications(n.kSetValueNotification,t)}}var n=e("./lib/constants.js").C,a=e("./lib/message-helper"),o=e("./lib/event-emitter"),s=e("./descriptor").Descriptor;o.makeEmitter(i),t.exports.Characteristic=i},{"./descriptor":12,"./lib/constants.js":17,"./lib/event-emitter":18,"./lib/message-helper":21}],12:[function(e,t,r){function i(e,t){var r=this,i=e.service(),o=i.peripheral(),s=o.gattip();a.requireUUID("Descriptor","uuid",t),this.uuid=t,this.type="d",this.characteristic=function(){return e},this.service=function(){return i},this.peripheral=function(){return o},this.gattip=function(){return s},this.readValue=function(e){var t=a.populateParams(r);s.request(n.kGetDescriptorValue,t,e,function(t){a.requireFields("readValue",t,[n.kValue],[]),r.value=t[n.kValue],s.fulfill(e,r,r.value)})},this.writeValue=function(e,t){var i=a.populateParams(r);a.requireHexValue("writeValue","value",t),s.request(n.kWriteDescriptorValue,i,e,function(i){r.value=t,s.fulfill(e,r)})},this.respondToReadRequest=function(e,t){var i=a.populateParams(r);a.requireHexValue("respondToReadRequest","value",t),i[n.kValue]=t,s.respond(e,i)},this.respondToWriteRequest=function(e){var t=a.populateParams(r);s.respond(e,t)}}var n=e("./lib/constants.js").C,a=e("./lib/message-helper");t.exports.Descriptor=i},{"./lib/constants.js":17,"./lib/message-helper":21}],13:[function(e,t,r){t.exports.ApplicationError=function(e){this.message="Application Error:"+e,Error.captureStackTrace(this,t.exports.ApplicationError)},t.exports.InternalError=function(e){this.message="Application Error:"+e,Error.captureStackTrace(this,t.exports.InternalError)},t.exports.GatewayError=function(e){"object"==typeof e?(this.message="Gateway Error:",e.message&&(this.message+=" "+e.message),e.code&&(this.message+=" Code:"+e.code),0==this.message.length&&(this.message="Unknown Gateway Error")):this.message=e,Error.captureStackTrace(this,t.exports.GatewayError)}},{}],14:[function(e,t,r){function i(e,t){c.instantiateEmitter(this);var r=this,i={};this.isScanning=!1,this.isPoweredOn=function(){return r.state==n.kPoweredOn},this._authenticate=function(t,i,a){var o={};o[n.kDeviceAccessToken]=i,o[n.kGetVersionInfo]=a,e.request(n.kOpen,o,t,function(i){if(i.isAuthenticated!==!0)throw new GatewayError({error:"Auth error"});e.fulfill(t,r)})},this.scan=function(t,i){var a={};i&&("boolean"==typeof i.scanDuplicates&&(a[n.kScanOptionAllowDuplicatesKey]=i.scanDuplicates),"object"==typeof i.services&&(a[n.kServiceUUIDs]=i.services)),e.request(n.kScanForPeripherals,a,t,function(i){r.isScanning=!0,e.fulfill(t,r)})},this.stopScan=function(t){e.request(n.kStopScanning,{},t,function(i){r.isScanning=!1,e.fulfill(t,r)})},this.centralState=function(t){e.request(n.kCentralState,{},t,function(i){r.state=i[n.kState],e.fulfill(t,r)})},this.configure=function(t,i,a){var o={};"undefined"!=typeof i&&(o[n.kShowPowerAlert]=i),"undefined"!=typeof a&&(o[n.kIdentifierKey]=a),e.request(n.kConfigure,{},t,function(i){e.fulfill(t,r)})},this.handleScanIndication=function(i){var s=i[n.kPeripheralUUID];if(!s)throw new o("Peripheral UUID is not availabvle");if(t&&t.uuids)for(var c in t.uuids){var u=t.uuids[c];if(u&&u.length&&u!=s)return}var l=r.getPeripheral(s);l?l._updateFromScanData(i[n.kPeripheralName],i[n.kRSSIkey],i[n.kCBAdvertisementDataTxPowerLevel],i[n.kCBAdvertisementDataServiceUUIDsKey],i[n.kCBAdvertisementDataManufacturerDataKey],i[n.kCBAdvertisementDataServiceDataKey],i[n.kAdvertisementDataKey],i[n.kScanRecord]):l=r.addPeripheral(new a(e,s,i[n.kPeripheralName],i[n.kRSSIkey],i[n.kCBAdvertisementDataTxPowerLevel],i[n.kCBAdvertisementDataServiceUUIDsKey],i[n.kCBAdvertisementDataManufacturerDataKey],i[n.kCBAdvertisementDataServiceDataKey],i[n.kAdvertisementDataKey],i[n.kScanRecord])),r.emit("scan",l)},this.addPeripheralWithValues=function(t,n,s,c,u,l,p){if(!t)throw new o("Attempting to add an empty peripheral");var f=r.addPeripheral(new a(e,t,n,s,c,u,l,p));return i[t]=f,f},this.addPeripheral=function(e){if(!e||!e.uuid)throw new o("Attempting to add an empty peripheral");return i[e.uuid]=e,e},this.removePeripheral=function(e){if(!e||!e.uuid)throw new o("Attempting to remove an empty peripheral");delete i[e.uuid]},this.getPeripheral=function(e){return i[e]},this.getPeripheralOrDie=function(e){var t=i[e];if(!t)throw new o("Unable to find peripheral with UUID "+e);return t},this.getObjects=function(e,t,r,n,a){var c={};if(c.peripheral=i[t],c.peripheral){if("p"===e)return c;if(c.service=c.peripheral.findService(r),c.service){if("s"===e)return c;if(c.characteristic=c.service.findCharacteristic(n),c.characteristic){if("c"===e)return c;if(c.descriptor=c.characteristic.findDescriptor(a),c.descriptor){if("d"===e)return c;throw new o('_getObjects: Argument "type" is required')}throw new s('Descriptor "'+a+'" not found in the service table')}throw new s('Characteristic "'+n+'" not found in the service table')}throw new s('Service "'+r+'" not found in the service table')}throw new s("Peripheral with id "+t+" not found")},this.getObjectsFromMessage=function(e,t){if(!t)throw new o("Message parameters are missing");try{return r.getObjects(e,t[n.kPeripheralUUID],t[n.kServiceUUID],t[n.kCharacteristicUUID],t[n.kDescriptorUUID])}catch(i){throw new o(i.message,i.detail)}}}var n=e("./lib/constants").C,a=(e("./lib/message-helper"),e("./peripheral").Peripheral),o=e("./errors").InternalError,s=e("./errors").ApplicationError,c=e("./lib/event-emitter");c.makeEmitter(i),t.exports.Gateway=i},{"./errors":13,"./lib/constants":17,"./lib/event-emitter":18,"./lib/message-helper":21,"./peripheral":25}],15:[function(e,t,r){function i(){function t(e){m.emit("error",e)}function r(e,r,i){try{e&&(r=JSON.parse(r)),i(r)}catch(n){t(n)}}n.instantiateEmitter(this),this.traceEnabled=!1;var i,d,h,v,g,m=this;this.getGateway=function(){return g},this.traceMessage=function(e,t){m.traceEnabled&&"object"==typeof e&&(e=JSON.stringify(e))},this.getServerMessageHandler=function(){return v||t(new s("Server Message Handler is not Ready")),v},this.fulfill=function(e,t,r,i,n,a){"object"==typeof e&&"function"==typeof e.fulfill?e.fulfill(t,r,i,n,a):"function"==typeof e&&e(t,r,i,n,a)},this.reject=function(e,r){"object"==typeof e&&"function"==typeof e.reject?e.reject(r):t(r)},this.open=function(n){function _(e){e.isServer?(d.on("request",function(e){m.traceMessage(e,"req:"),i.send(JSON.stringify(o))},this.respond=function(e,t){var r=h.wrapResponse(e,t);m.traceMessage(r,">rsp:"),i.send(JSON.stringify(r))},this.sendIndications=function(e,t){var r={params:t,jsonrpc:"2.0"};r.result=e,r.params=t,m.traceMessage(r,">rsp:"),i.send(JSON.stringify(r))},this.sendError=function(e){e.jsonrpc="2.0",m.traceMessage(e,">rsp:"),i.send(JSON.stringify(e))}}var n=e("./lib/event-emitter"),a=e("./errors").InternalError,o=e("./errors").ApplicationError,s=e("./errors").GatewayError,c=e("./lib/message-handler").MessageHandler,u=e("./lib/message-processor").MessageProcessor,l=e("./gateway").Gateway,p=(e("./lib/message-helper"),e("./lib/server-message-handler").ServerMessageHandler),f={keepalive:!0,dropConnectionOnKeepaliveTimeout:!0,keepaliveInterval:1e4,keepaliveGracePeriod:1e4};n.makeEmitter(i),t.exports.GATTIP=i},{"./errors":13,"./gateway":14,"./lib/event-emitter":18,"./lib/message-handler":20,"./lib/message-helper":21,"./lib/message-processor":22,"./lib/server-message-handler":23,websocket:31}],16:[function(e,t,r){t.exports.GATTIP=e("./gattip").GATTIP},{"./gattip":15}],17:[function(e,t,r){var i={DEFAULT_MESSAGE_TIMEOUT_MS:61e3,MAX_PENDING_MESSAGES:200,NUM_CONNECT_ATTEMPTS:3,kMessageId:"id",kSessionId:"session_id",kAuthenticate:"aut",kOpen:"opn",kDeviceAccessToken:"dat",kGetVersionInfo:"vif",kError:"error",kCode:"code",kMessageField:"message",kMethod:"method",kResult:"result",kIdField:"id",kConfigure:"aa",kScanForPeripherals:"ab",kStopScanning:"ac",kConnect:"ad",kDisconnect:"ae",kCentralState:"af",kGetConnectedPeripherals:"ag",kGetPerhipheralsWithServices:"ah",kGetPerhipheralsWithIdentifiers:"ai",kGetServices:"ak",kGetIncludedServices:"al",kGetCharacteristics:"am",kGetDescriptors:"an",kGetCharacteristicValue:"ao",kGetDescriptorValue:"ap",kWriteCharacteristicValue:"aq",kWriteDescriptorValue:"ar",kSetValueNotification:"as",kGetPeripheralState:"at",kGetRSSI:"au",kInvalidatedServices:"av",kPeripheralNameUpdate:"aw",kMessage:"zz",kCentralUUID:"ba",kPeripheralUUID:"bb",kPeripheralName:"bc",kPeripheralUUIDs:"bd",kServiceUUID:"be",kServiceUUIDs:"bf",kPeripherals:"bg",kIncludedServiceUUIDs:"bh",kCharacteristicUUID:"bi",kCharacteristicUUIDs:"bj",kDescriptorUUID:"bk",kServices:"bl",kCharacteristics:"bm",kDescriptors:"bn",kProperties:"bo",kValue:"bp",kState:"bq",kStateInfo:"br",kStateField:"bs",kWriteType:"bt",kRSSIkey:"bu",kIsPrimaryKey:"bv",kIsBroadcasted:"bw",kIsNotifying:"bx",kShowPowerAlert:"by",kIdentifierKey:"bz",kScanOptionAllowDuplicatesKey:"b0",kScanOptionSolicitedServiceUUIDs:"b1",kAdvertisementDataKey:"b2",kCBAdvertisementDataManufacturerDataKey:"mfr",kCBAdvertisementDataServiceUUIDsKey:"suu",kCBAdvertisementDataServiceDataKey:"sdt",kCBAdvertisementDataOverflowServiceUUIDsKey:"b6",kCBAdvertisementDataSolicitedServiceUUIDsKey:"b7",kCBAdvertisementDataIsConnectable:"b8",kCBAdvertisementDataTxPowerLevel:"txp",kPeripheralBtAddress:"c1",kRawAdvertisementData:"c2",kScanRecord:"c3",kCBCentralManagerRestoredStatePeripheralsKey:"da",kCBCentralManagerRestoredStateScanServicesKey:"db",kWriteWithResponse:"cc",kWriteWithoutResponse:"cd",kNotifyOnConnection:"ce",kNotifyOnDisconnection:"cf",kNotifyOnNotification:"cg",kDisconnected:"ch",kConnecting:"ci",kConnected:"cj",kUnknown:"ck",kResetting:"cl",kUnsupported:"cm",kUnauthorized:"cn",kPoweredOff:"co",kPoweredOn:"cp",kErrorPeripheralNotFound:"-32001",kErrorServiceNotFound:"-32002",kErrorCharacteristicNotFound:"-32003",kErrorDescriptorNotFound:"-32004",kErrorPeripheralStateIsNotValid:"-32005",kErrorNoServiceSpecified:"-32006",kErrorNoPeripheralIdentiferSpecified:"-32007",kErrorStateRestorationNotValid:"-32008",kInvalidRequest:"-32600",kMethodNotFound:"-32601",kInvalidParams:"-32602",kError32603:"-32603",kParseError:"-32700",kGAP_ADTYPE_FLAGS:"01",kGAP_ADTYPE_INCOMPLETE_16BIT_SERVICEUUID:"02",kGAP_ADTYPE_COMPLETE_16BIT_SERVICEUUID:"03",kGAP_ADTYPE_INCOMPLETE_32BIT_SERVICEUUID:"04",kGAP_ADTYPE_COMPLETE_32BIT_SERVICEUUID:"05",kGAP_ADTYPE_INCOMPLETE_128BIT_SERVICEUUID:"06",kGAP_ADTYPE_COMPLETE_128BIT_SERVICEUUID:"07",kGAP_ADTYPE_POWER_LEVEL:"0A",kGAP_ADTYPE_MANUFACTURER_SPECIFIC:"FF",kGAP_ADTYPE_16BIT_SERVICE_DATA:"16",id:1,authenticate:"authenticate",AllProperties:["Broadcast","Read","WriteWithoutResponse","Write","Notify","Indicate","AuthenticatedSignedWrites","ExtendedProperties","NotifyEncryptionRequired","IndicateEncryptionRequired"]};t.exports.C=i},{}],18:[function(e,t,r){var i=e("events"),n=e("util");t.exports.makeEmitter=function(e){n.inherits(e,i)},t.exports.instantiateEmitter=function(e){i.call(e)}},{events:10,util:30}],19:[function(e,t,r){function i(e,t){var r=parseInt(t[0],16);parseInt(t[2],16)>=1?e.discoverable="true":e.discoverable="false",t.splice(0,r+1)}function n(e,t){var r=parseInt(t[0],16);e.txPowerLevel=parseInt(t[2]),t.splice(0,r+1)}function a(e,t){var r=parseInt(t[0],16);if(r>2){for(var i=t[3]+t[2],n="",a=4;a<=r;a++)n+=t[a];e.manufacturerData[i]=n}t.splice(0,r+1)}function o(e,t){for(var r=parseInt(t[0],16),i="",n=r;n>=2;n--)i+=t[n];e.serviceUUIDs=i,t.splice(0,r+1)}function s(e,t){for(var r=parseInt(t[0],16),i="",n=r;n>=2;n--)i+=t[n],14!=n&&12!=n&&10!=n&&8!=n||(i+="-");e.serviceUUIDs=i,t.splice(0,r+1)}function c(e,t){for(var r=parseInt(t[0],16),i="",n=3;n>=2;n--)i+=t[n];"FEAA"==i&&(0===parseInt(t[4],16)?u(e):16==parseInt(t[4],16)?l(e):32==parseInt(t[4],16)&&p(e)),t.splice(0,r+1)}function u(e,t){e.frameType="UID",e.nameSpace="",e.instanceID="",e.txPowerLevel=parseInt(t[5],16);for(var r=6;r<16;r++)e.nameSpace+=t[r];for(var i=16;i<22;i++)e.instanceID+=t[i];e.reserved=t[22],e.reserved+=t[23]}function l(e,t){e.frameType="URL",e.txPowerLevel=parseInt(t[5]);for(var r in f.AllProtocols)t[6]==r&&(e.url=f.AllProtocols[r]);for(var i=7;i2?e.temperature+=i.toString().substring(0,2):e.temperature+=i;for(var n=10;n<14;n++)e.advPacketCount+=t[n];e.advPacketCount=parseInt(e.advPacketCount,16);for(var a=14;a<18;a++)e.timeInterval+=t[a];if(e.timeInterval=Math.ceil(.1*parseInt(e.timeInterval,16)),e.timePeriod="",e.timeInterval>=60){var o=Math.floor(e.timeInterval/86400);o>0&&(e.timePeriod+=o<10?o+"day ":o+"days ",e.timeInterval-=24*o*60*60);var s=Math.floor(e.timeInterval/3600);s>0?(e.timePeriod+=s<10?"0"+s+":":s+":",e.timeInterval-=60*s*60):e.timePeriod+="00:";var c=Math.floor(e.timeInterval/60);c>0?(e.timePeriod+=c<10?"0"+c+":":c+":",e.timeInterval-=60*c,e.timePeriod+=e.timeInterval<10?"0"+e.timeInterval:e.timeInterval,e.timePeriod+=" secs",e.timeInterval=0):(e.timePeriod+="00:"+e.timeInterval,e.timeInterval=0)}else e.timeInterval>0&&e.timeInterval<60&&(e.timePeriod+=e.timeInterval<10?"00:00:0"+e.timeInterval:"00:00:"+e.timeInterval,e.timePeriod+=" secs")}var f=e("./constants").C;t.exports.parseAdvArray=function(e,t){e.advdata||(e.advdata={});var r=e.advdata;if(r.manufacturerData||(r.manufacturerData={}),r.serviceUUIDs||(r.serviceUUIDs=[]),!t)return[];var u=[];if(t.length%2===0)for(var l=0;lo.MAX_PENDING_MESSAGES)throw new s("Message queue is full",r);var c=new i(e,r,n,a);return t[c.id]=c,c.msg},this.hasMessage=function(e){var r=t[""+e];return!!r},this.onMessageReceived=function(r){var i;if(r.params&&r.params.id&&(r.id=r.params.id),r.id&&(i=t[""+r.id]),!i){if(r.id)return r.result==o.kScanForPeripherals&&r.params&&r.params.bb?(l||(l=!0),void e.emit("indication",r)):void e.emit("request",r);if(r.result!=o.kMessage)return void e.emit("indication",r);u||(u=!0),r.id="1",i=t[1]}i.timeout&&clearTimeout(i.timeout),delete t[r.id],e.emit("response",r,i.userContext,i.msg)}}var a=e("./event-emitter"),o=e("./constants").C,s=e("./../errors").ApplicationError,c=1,u=!1,l=!1;a.makeEmitter(n),t.exports.MessageProcessor=n},{"./../errors":13,"./constants":17,"./event-emitter":18}],23:[function(e,t,r){function i(e,t){function r(e,t){var r=t?"0x":"";for(var i in e){var n=(255&e[i]).toString(16);1==n.length&&(n="0"+n),r+=n}return r}function i(e){for(var t in e)if(e.hasOwnProperty(t))return!1;return JSON.stringify(e)===JSON.stringify({})}a.instantiateEmitter(this);var o=this;this.processMessage=function(e){function r(r){var i=l[n.kPeripheralUUID],a={};if(a.peripheral=t.getPeripheral(i),a.peripheral&&a.peripheral.uuid){if("p"===r)return a;var s=l[n.kServiceUUID];if(a.service=a.peripheral.findService(s),a.service&&a.service.uuid){if("s"===r)return a;var c=l[n.kCharacteristicUUID];if(a.characteristic=a.service.findCharacteristic(c),a.characteristic&&a.characteristic.uuid){if("c"===r)return a;var u=l[n.kDescriptorUUID];if(a.descriptor=a.characteristic.findDescriptor(u),a.descriptor&&a.descriptor.uuid)return a;throw o.sendErrorResponse(e.method,n.kErrorDescriptorNotFound,"Descriptor not found in the service database"),new Error("Descriptor not found")}throw o.sendErrorResponse(e.method,n.kErrorCharacteristicNotFound,"Characteristic not found in the service database"),new Error("Characteristic not found")}throw o.sendErrorResponse(e.method,n.kErrorServiceNotFound,"Service not found in the service database"),new Error("Service not found")}throw o.sendErrorResponse(e.method,n.kErrorPeripheralNotFound,"Peripheral not found in the service database"),new Error("Peripheral not found")}var i;if("undefined"!=typeof e&&e&&!e.error){if(e.result&&(e.result==n.kMessage||e.result==n.kAuthenticate)){var a=!1;return e.error||"object"!=typeof e.params||e.params[n.kAuthenticate]!==!0||(a=!0),void o.emit("authenticated",a)}if(e.method&&e.method==n.kAuthenticate){var s={};s[n.kAuthenticate]=!0;var c={};return c.result=n.kAuthenticate,c.params=s,c[n.kIdField]=e[n.kIdField],c=JSON.stringify(c),void o.send(c)}var u={original:e},l=e.params;switch(e.method){case n.kConfigure:o.emit("configure",u,l[n.kShowPowerAlert],l[n.kIdentifierKey]);break;case n.kScanForPeripherals:o.emit("scan",u,l[n.kScanOptionAllowDuplicatesKey],l[n.kServiceUUIDs]);break;case n.kStopScanning:o.emit("stopScan",u);break;case n.kCentralState:o.emit("getCentralState",u);break;case n.kConnect:try{i=r("p"),o.emit("connect",u,i.peripheral.uuid)}catch(p){}break;case n.kDisconnect:try{i=r("p"),o.emit("disconnect",u,i.peripheral.uuid)}catch(p){}break;case n.kGetCharacteristicValue:try{i=r("c",u),o.emit("readCharacteristic",u,i.peripheral.uuid,i.service.uuid,i.characteristic.uuid)}catch(p){}break;case n.kWriteCharacteristicValue:try{i=r("c",u),o.emit("writeCharacteristic",u,i.peripheral.uuid,i.service.uuid,i.characteristic.uuid,e.params[n.kValue])}catch(p){}break;case n.kSetValueNotification:try{i=r("c",u),o.emit("enableNotifications",u,i.peripheral.uuid,i.service.uuid,i.characteristic.uuid,e.params[n.kIsNotifying])}catch(p){}break;case n.kGetDescriptorValue:try{i=r("d",u),o.emit("readDescriptor",u,i.peripheral.uuid,i.service.uuid,i.characteristic.uuid,i.descriptor.uuid)}catch(p){}break;case n.kWriteDescriptorValue:try{i=r("d",u),o.emit("writeDescriptor",u,i.peripheral.uuid,i.service.uuid,i.characteristic.uuid,i.descriptor.uuid,e.params[n.kValue])}catch(p){}break;default:return void o.sendErrorResponse(u,e.method,n.kInvalidRequest,"Request not handled by server")}}},o.sendErrorResponse=function(t,r,i,a){var o={},s={};s[n.kCode]=i,s[n.kMessageField]=a,o[n.kError]=s,o.result=r,t&&t.original&&(o[n.kMessageId]=t.original.id,o[n.kSessionId]=t.original.session_id),e.sendError(o)},o.configureResponse=function(t){t.result=n.kConfigure,e.respond(t,{})},o.centralStateResponse=function(t,r,i){var a={};a[n.kState]=r,t.result=n.kCentralState,e.respond(t,a)},o.stopScanResponse=function(t){t.result=n.kStopScanning,e.respond(t,{})},o.disconnectResponse=function(t,r){var i={};i[n.kPeripheralUUID]=r.uuid,i[n.kPeripheralName]=r.name,null!=t?e.respond(t,i):e.sendIndications(n.kDisconnect,i)},o.scanResponse=function(t,a,o,s,c,u,l,p){if(t)return t.result=n.kScanForPeripherals,void e.respond(t,{});var f,d,h={};if(!i(l)){f={};for(var v in l){var g=v.toUpperCase();f[g]=r(l[v]).toUpperCase()}}if(!i(p)){d={};for(var m in p){var _=m.toUpperCase();d[_]=r(p[m]).toUpperCase()}}h[n.kPeripheralName]=o,h[n.kPeripheralUUID]=a,h[n.kRSSIkey]=s,h[n.kCBAdvertisementDataTxPowerLevel]=c,h[n.kCBAdvertisementDataServiceUUIDsKey]=u&&u.length>0?u:void 0,h[n.kCBAdvertisementDataManufacturerDataKey]=f,h[n.kCBAdvertisementDataServiceDataKey]=d,e.sendIndications(n.kScanForPeripherals,h)},o.addPeripheral=function(e,t,r,i,n){var a=new Peripheral(this,e,t,r,i,n);return o.peripherals[a.uuid]=a,a}}var n=e("./constants.js").C,a=e("./event-emitter");this.GATM_SECURITY_PROPERTIES_NO_SECURITY=0,this.GATM_SECURITY_PROPERTIES_UNAUTHENTICATED_ENCRYPTION_WRITE=1,this.GATM_SECURITY_PROPERTIES_AUTHENTICATED_ENCRYPTION_WRITE=2,this.GATM_SECURITY_PROPERTIES_UNAUTHENTICATED_ENCRYPTION_READ=4,this.GATM_SECURITY_PROPERTIES_AUTHENTICATED_ENCRYPTION_READ=8,this.GATM_SECURITY_PROPERTIES_UNAUTHENTICATED_SIGNED_WRITES=16,this.GATM_SECURITY_PROPERTIES_AUTHENTICATED_SIGNED_WRITES=32,this.GATM_CHARACTERISTIC_PROPERTIES_BROADCAST=1,this.GATM_CHARACTERISTIC_PROPERTIES_READ=2,this.GATM_CHARACTERISTIC_PROPERTIES_WRITE_WO_RESP=4,this.GATM_CHARACTERISTIC_PROPERTIES_WRITE=8,this.GATM_CHARACTERISTIC_PROPERTIES_NOTIFY=16,this.GATM_CHARACTERISTIC_PROPERTIES_INDICATE=32,this.GATM_CHARACTERISTIC_PROPERTIES_AUTHENTICATED_SIGNED_WRITES=64,this.GATM_CHARACTERISTIC_PROPERTIES_EXT_PROPERTIES=128,this.GATM_DESCRIPTOR_PROPERTIES_READ=1,this.GATM_DESCRIPTOR_PROPERTIES_WRITE=2,a.makeEmitter(i),t.exports.ServerMessageHandler=i},{"./constants.js":17,"./event-emitter":18}],24:[function(e,t,r){function i(e,t){var r=t[c.kDescriptorUUID],i=e.findDescriptor(r);i||(i=new p(e,r),e.addDescriptor(i)),i.value=t[c.kValue]}function n(e,t){var r=t[c.kCharacteristicUUID],n=e.findCharacteristic(r);n||(n=new l(e,r),e.addCharacteristic(n)),n.value=t[c.kValue];var a=t[c.kProperties];if("object"==typeof a)for(var o in a)n.setProperty(o,{enabled:a[o].enabled,name:a[o].name});else for(var s in c.AllProperties)n.setProperty([c.AllProperties[s]],{enabled:a>>s&1,name:c.AllProperties[s]});n.isNotifying=!1;var u=t[c.kDescriptors];if(u)for(var p in u){var f=u[p];i(n,f)}}function a(e,t){var r=t[c.kServiceUUID],i=e.findService(r);i||(i=new u(e,r),e.addService(i));var a=t[c.kCharacteristics];if(a)for(var o in a){var s=a[o];n(i,s)}}function o(e){var t={};if(e&&e.getAllDescriptors())for(var r in e.getAllDescriptors()){var i={};i[c.kDescriptorUUID]=r,i[c.kValue]=e.findDescriptor(r).value,i[c.kProperties]=e.findDescriptor(r).properties,i[c.kIsNotifying]=e.findDescriptor(r).isNotifying,t[r]=i}return t}function s(e){var t={};if(e&&e.getAllCharacteristics())for(var r in e.getAllCharacteristics()){var i={};i[c.kCharacteristicUUID]=r,i[c.kValue]=e.findCharacteristic(r).value,i[c.kProperties]=e.findCharacteristic(r).allProperties(),i[c.kIsNotifying]=e.findCharacteristic(r).isNotifying,i[c.kDescriptors]=o(e.findCharacteristic(r)),t[r]=i}return t}var c=e("./constants").C,u=e("./../service").Service,l=e("./../characteristic").Characteristic,p=e("./../descriptor").Descriptor;t.exports.parseServiceRecord=function(e,t){var r=t[c.kServices];if(r)for(var i in r){var n=r[i];a(e,n)}},t.exports.getServiceJsonFromPeripheralObject=function(e){var t={};if(e&&e.getAllServices())for(var r in e.getAllServices()){var i={};i[c.kServiceUUID]=r,i[c.kIsPrimaryKey]=e.findService(r).isPrimary,i[c.kCharacteristics]=s(e.findService(r)),t[r]=i}return t}},{"./../characteristic":11,"./../descriptor":12,"./../service":26,"./constants":17}],25:[function(e,t,r){function i(e,t){return e.indexOf(t)==-1&&(e.push(t),!0)}function n(e,t,r,n,p,f){c.instantiateEmitter(this);var d=this;this.type="p",this.uuid=t,this.isConnected=!1;var h={},v={},g={},m=[];this._updateFromScanData=function(e,t,r,n,a,o,c,u){this.name=e,this.rssi=t,this.txPowerLevel=r;if(a)for(var l in a){var p=l.toUpperCase(),f=a[l].toUpperCase();v[p]=f}if(g)for(var h in o)g[h]=o[h];if(n)for(var _=0;_=0},this.getAllServices=function(){return h},this.getAllMfrData=function(){return v},this.getAllSvcData=function(){return g},this.getAllAdvertisedServiceUUIDs=function(){return m},this.addServiceWithUUID=function(e){var t=new l(d,e);return h[e]=t},this.addService=function(e){return h[e.uuid]=e},this.gattip=function(){return e},this.connectOnce=function(t){var r=o.populateParams(d);e.request(a.kConnect,r,t,function(r){u.parseServiceRecord(d,r),d.isConnected=!0,e.fulfill(t,d)})},this.connect=function(t,r){function i(r){o++,o<=a.NUM_CONNECT_ATTEMPTS?d.connectOnce({fulfill:n,reject:i}):e.reject(t,r)}var n="object"==typeof t?t.fulfill:t,o=0;r&&"number"==typeof r.numConnectAttempts&&(o=r.numConnectAttempts),i()},this.disconnect=function(t){var r=o.populateParams(d);e.request(a.kDisconnect,r,t,function(r){d.isConnected=!1,e.fulfill(t,d)})},this.respondToConnectRequest=function(t){var r={};r[a.kPeripheralUUID]=this.uuid,r[a.kPeripheralName]=this.name;var i;i=u.getServiceJsonFromPeripheralObject(this),r[a.kServices]=i,t.result=a.kConnect,e.respond(t,r)},this.handleDisconnectIndication=function(){d.isConnected=!1,d.emit("disconnected",d)},this._updateFromScanData(r,n,p,f)}var a=e("./lib/constants.js").C,o=e("./lib/message-helper"),s=e("./lib/message-advdata-parser"),c=e("./lib/event-emitter"),u=e("./lib/service-table"),l=e("./service").Service;c.makeEmitter(n),t.exports.Peripheral=n},{"./lib/constants.js":17,"./lib/event-emitter":18,"./lib/message-advdata-parser":19,"./lib/message-helper":21,"./lib/service-table":24,"./service":26}],26:[function(e,t,r){function i(e,t){var r=this,i=e.gattip(),o={};n.requireUUID("Service","uuid",t),this.uuid=t,this.type="s",this.isPrimary=!0,this.peripheral=function(){return e},this.gattip=function(){return i},this.getAllCharacteristics=function(){return o},this.findCharacteristic=function(e){return o[e]},this.addCharacteristicWithUUID=function(e,t){var i=new a(r,e,t);return o[e]=i},this.addCharacteristic=function(e){o[e.uuid]=e}}var n=e("./lib/message-helper"),a=e("./characteristic").Characteristic;r.Service=i},{"./characteristic":11,"./lib/message-helper":21}],27:[function(e,t,r){"function"==typeof Object.create?t.exports=function(e,t){e.super_=t,e.prototype=Object.create(t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}})}:t.exports=function(e,t){e.super_=t;var r=function(){};r.prototype=t.prototype,e.prototype=new r,e.prototype.constructor=e}},{}],28:[function(e,t,r){function i(){throw new Error("setTimeout has not been defined")}function n(){throw new Error("clearTimeout has not been defined")}function a(e){if(p===setTimeout)return setTimeout(e,0);if((p===i||!p)&&setTimeout)return p=setTimeout,setTimeout(e,0);try{return p(e,0)}catch(t){try{return p.call(null,e,0)}catch(t){return p.call(this,e,0)}}}function o(e){if(f===clearTimeout)return clearTimeout(e);if((f===n||!f)&&clearTimeout)return f=clearTimeout,clearTimeout(e);try{return f(e)}catch(t){try{return f.call(null,e)}catch(t){return f.call(this,e)}}}function s(){g&&h&&(g=!1,h.length?v=h.concat(v):m=-1,v.length&&c())}function c(){if(!g){var e=a(s);g=!0;for(var t=v.length;t;){for(h=v,v=[];++m1)for(var r=1;r=3&&(i.depth=arguments[2]),arguments.length>=4&&(i.colors=arguments[3]),v(t)?i.showHidden=t:t&&r._extend(i,t),k(i.showHidden)&&(i.showHidden=!1),k(i.depth)&&(i.depth=2),k(i.colors)&&(i.colors=!1),k(i.customInspect)&&(i.customInspect=!0),i.colors&&(i.stylize=a),c(i,e,i.depth)}function a(e,t){var r=n.styles[t];return r?"["+n.colors[r][0]+"m"+e+"["+n.colors[r][1]+"m":e}function o(e,t){return e}function s(e){var t={};return e.forEach(function(e,r){t[e]=!0}),t}function c(e,t,i){if(e.customInspect&&t&&D(t.inspect)&&t.inspect!==r.inspect&&(!t.constructor||t.constructor.prototype!==t)){var n=t.inspect(i,e);return b(n)||(n=c(e,n,i)),n}var a=u(e,t);if(a)return a;var o=Object.keys(t),v=s(o);if(e.showHidden&&(o=Object.getOwnPropertyNames(t)),U(t)&&(o.indexOf("message")>=0||o.indexOf("description")>=0))return l(t);if(0===o.length){if(D(t)){var g=t.name?": "+t.name:"";return e.stylize("[Function"+g+"]","special")}if(w(t))return e.stylize(RegExp.prototype.toString.call(t),"regexp");if(E(t))return e.stylize(Date.prototype.toString.call(t),"date");if(U(t))return l(t)}var m="",_=!1,y=["{","}"];if(h(t)&&(_=!0,y=["[","]"]),D(t)){var k=t.name?": "+t.name:"";m=" [Function"+k+"]"}if(w(t)&&(m=" "+RegExp.prototype.toString.call(t)),E(t)&&(m=" "+Date.prototype.toUTCString.call(t)),U(t)&&(m=" "+l(t)),0===o.length&&(!_||0==t.length))return y[0]+m+y[1];if(i<0)return w(t)?e.stylize(RegExp.prototype.toString.call(t),"regexp"):e.stylize("[Object]","special");e.seen.push(t);var I;return I=_?p(e,t,i,v,o):o.map(function(r){return f(e,t,i,v,r,_)}),e.seen.pop(),d(I,m,y)}function u(e,t){if(k(t))return e.stylize("undefined","undefined");if(b(t)){var r="'"+JSON.stringify(t).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return e.stylize(r,"string")}return _(t)?e.stylize(""+t,"number"):v(t)?e.stylize(""+t,"boolean"):g(t)?e.stylize("null","null"):void 0}function l(e){return"["+Error.prototype.toString.call(e)+"]"}function p(e,t,r,i,n){for(var a=[],o=0,s=t.length;o-1&&(s=a?s.split("\n").map(function(e){return" "+e}).join("\n").substr(2):"\n"+s.split("\n").map(function(e){return" "+e}).join("\n"))):s=e.stylize("[Circular]","special")),k(o)){if(a&&n.match(/^\d+$/))return s;o=JSON.stringify(""+n),o.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)?(o=o.substr(1,o.length-2),o=e.stylize(o,"name")):(o=o.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'"),o=e.stylize(o,"string"))}return o+": "+s}function d(e,t,r){var i=0,n=e.reduce(function(e,t){return i++,t.indexOf("\n")>=0&&i++,e+t.replace(/\u001b\[\d\d?m/g,"").length+1},0);return n>60?r[0]+(""===t?"":t+"\n ")+" "+e.join(",\n ")+" "+r[1]:r[0]+t+" "+e.join(", ")+" "+r[1]}function h(e){return Array.isArray(e)}function v(e){return"boolean"==typeof e}function g(e){return null===e}function m(e){return null==e}function _(e){return"number"==typeof e}function b(e){return"string"==typeof e}function y(e){return"symbol"==typeof e}function k(e){return void 0===e}function w(e){return I(e)&&"[object RegExp]"===P(e)}function I(e){return"object"==typeof e&&null!==e}function E(e){return I(e)&&"[object Date]"===P(e)}function U(e){return I(e)&&("[object Error]"===P(e)||e instanceof Error)}function D(e){return"function"==typeof e}function S(e){return null===e||"boolean"==typeof e||"number"==typeof e||"string"==typeof e||"symbol"==typeof e||"undefined"==typeof e}function P(e){return Object.prototype.toString.call(e)}function A(e,t){return Object.prototype.hasOwnProperty.call(e,t)}var C=/%[sdj%]/g;r.format=function(e){if(!b(e)){for(var t=[],r=0;r=a)return e;switch(e){case"%s":return String(i[r++]);case"%d":return Number(i[r++]);case"%j":try{return JSON.stringify(i[r++])}catch(t){return"[Circular]"}default:return e}}),s=i[r];r=0.8.0"},gitHead:"ba2fa7e9676c456bcfb12ad160655319af66faed",homepage:"https://github.com/theturtle32/WebSocket-Node",keywords:["websocket","websockets","socket","networking","comet","push","RFC-6455","realtime","server","client"],license:"Apache-2.0",main:"index",maintainers:[{name:"theturtle32",email:"brian@worlize.com"}],name:"websocket",optionalDependencies:{},readme:"ERROR: No README data found!",repository:{type:"git",url:"git+https://github.com/theturtle32/WebSocket-Node.git"},scripts:{gulp:"gulp",install:"(node-gyp rebuild 2> builderror.log) || (exit 0)",test:"faucet test/unit"},version:"1.0.23"}},{}]},{},[1]); \ No newline at end of file
"+i[d].name+"