diff --git a/1.1.2/blueapp.io.min.js b/1.1.2/blueapp.io.min.js
new file mode 100644
index 0000000..8f335cc
--- /dev/null
+++ b/1.1.2/blueapp.io.min.js
@@ -0,0 +1,7 @@
+/* blueapp.io v0.0.1 */
+require=function e(t,r,i){function n(s,o){if(!r[s]){if(!t[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=r[s]={exports:{}};t[s][0].call(l.exports,function(e){var r=t[s][1][e];return n(r?r:e)},l,l.exports,e,t,r,i)}return r[s].exports}for(var a="function"==typeof require&&require,s=0;s<i.length;s++)n(i[s]);return n}({1:[function(e,t,r){function i(e,t,r){s.instantiateEmitter(this);var i=this,c=e.peripheral(),u=c.gattip(),l={},f={};a.requireUUID("Characteristic","uuid",t),this.uuid=t,r||(r={}),f=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 o(i,e);return l[e]=t},this.addDescriptor=function(e){return l[e.uuid]=e},this.hasProperty=function(e){return f[e]&&f[e].enabled},this.setProperty=function(e,t){return f[e]=t},this.allProperties=function(){return f},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"),s=e("./lib/event-emitter"),o=e("./descriptor").Descriptor;s.makeEmitter(i),t.exports.Characteristic=i},{"./descriptor":2,"./lib/constants.js":6,"./lib/event-emitter":7,"./lib/message-helper":10}],2:[function(e,t,r){function i(e,t){var r=this,i=e.service(),s=i.peripheral(),o=s.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 s},this.gattip=function(){return o},this.readValue=function(e){var t=a.populateParams(r);o.request(n.kGetDescriptorValue,t,e,function(t){a.requireFields("readValue",t,[n.kValue],[]),r.value=t[n.kValue],o.fulfill(e,r,r.value)})},this.writeValue=function(e,t){var i=a.populateParams(r);a.requireHexValue("writeValue","value",t),o.request(n.kWriteDescriptorValue,i,e,function(i){r.value=t,o.fulfill(e,r)})},this.respondToReadRequest=function(e,t){var i=a.populateParams(r);a.requireHexValue("respondToReadRequest","value",t),i[n.kValue]=t,o.respond(e,i)},this.respondToWriteRequest=function(e){var t=a.populateParams(r);o.respond(e,t)}}var n=e("./lib/constants.js").C,a=e("./lib/message-helper");t.exports.Descriptor=i},{"./lib/constants.js":6,"./lib/message-helper":10}],3:[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)}},{}],4:[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 s={};s[n.kDeviceAccessToken]=i,s[n.kGetVersionInfo]=a,e.request(n.kOpen,s,t,function(i){if(i.isAuthenticated===!0)e.fulfill(t,r);else{if(i[n.kOpen]!==!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 s={};"undefined"!=typeof i&&(s[n.kShowPowerAlert]=i),"undefined"!=typeof a&&(s[n.kIdentifierKey]=a),e.request(n.kConfigure,{},t,function(i){e.fulfill(t,r)})},this.handleScanIndication=function(i){var o=i[n.kPeripheralUUID];if(!o)throw new s("Peripheral UUID is not availabvle");if(t&&t.uuids)for(var c=0;c<t.uuids.length;c++){var u=t.uuids[c];if(u&&u.length&&u!=o)return}var l=r.getPeripheral(o);l?l._updateFromScanData(i[n.kPeripheralName],i[n.kRSSIkey],i[n.kCBAdvertisementDataTxPowerLevel],i[n.kCBAdvertisementDataIsConnectable],i[n.kCBAdvertisementDataServiceUUIDsKey],i[n.kCBAdvertisementDataManufacturerDataKey],i[n.kCBAdvertisementDataServiceDataKey],i[n.kAdvertisementDataKey],i[n.kScanRecord]):l=r.addPeripheral(new a(e,o,i[n.kPeripheralName],i[n.kRSSIkey],i[n.kCBAdvertisementDataTxPowerLevel],i[n.kCBAdvertisementDataIsConnectable],i[n.kCBAdvertisementDataServiceUUIDsKey],i[n.kCBAdvertisementDataManufacturerDataKey],i[n.kCBAdvertisementDataServiceDataKey],i[n.kAdvertisementDataKey],i[n.kScanRecord])),r.emit("scan",l)},this.addPeripheralWithValues=function(t,n,o,c,u,l,f){if(!t)throw new s("Attempting to add an empty peripheral");var p=r.addPeripheral(new a(e,t,n,o,c,u,l,f));return i[t]=p,p},this.addPeripheral=function(e){if(!e||!e.uuid)throw new s("Attempting to add an empty peripheral");return i[e.uuid]=e,e},this.removePeripheral=function(e){if(!e||!e.uuid)throw new s("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 s("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 s('_getObjects: Argument "type" is required')}throw new o('Descriptor "'+a+'" not found in the service table')}throw new o('Characteristic "'+n+'" not found in the service table')}throw new o('Service "'+r+'" not found in the service table')}throw new o("Peripheral with id "+t+" not found")},this.getObjectsFromMessage=function(e,t){if(!t)throw new s("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 s(i.message,i.detail)}}}var n=e("./lib/constants").C,a=(e("./lib/message-helper"),e("./peripheral").Peripheral),s=e("./errors").InternalError,o=e("./errors").ApplicationError,c=e("./lib/event-emitter");c.makeEmitter(i),t.exports.Gateway=i},{"./errors":3,"./lib/constants":6,"./lib/event-emitter":7,"./lib/message-helper":10,"./peripheral":14}],5:[function(e,t,r){function i(){function t(e){k.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,k=this;this.getGateway=function(){return m},this.traceMessage=function(e,t){k.traceEnabled&&"object"==typeof e&&(e=JSON.stringify(e))},this.getServerMessageHandler=function(){return v||t(new o("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){k.traceMessage(e,"<req:"),r(!1,e,v.processMessage)}),h.on("indication",function(e){t(new s("Received an indication on a server stream:"+JSON.stringify(e)))}),m=y,k.emit("ready",y)):e.isPassThrough?I():y.configure(function(){y.centralState(function(){if(y.isPoweredOn())y.isPoweredOn()&&I();else{k.emit("state",y.isPoweredOn());var e=setInterval(function(){y.centralState(function(){y.isPoweredOn()&&(k.emit("state",y.isPoweredOn()),clearInterval(e),I())})},500)}})})}function I(){h.on("indication",function(e){k.traceMessage(e,"<ind:"),r(!1,e,d.handleIndication)}),h.on("request",function(e){t(new a("Received a request on a client stream:"+JSON.stringify(e)))}),m=y,k.emit("ready",y)}function E(e){e.token?y._authenticate(function(){g(e)},e.token,e.version):g(e)}var y=new l(this,n.scanFilters);if(h=new u(this),d=new c(this,y),v=new f(this,y),n.trace===!0&&(k.traceEnabled=!0),n.url){var S;S="object"==typeof window?window.WebSocket:e("websocket").w3cwebsocket,i=new S(n.url,(void 0),(void 0),(void 0),(void 0),p),i.onopen=function(){E(n)},i.onclose=function(e){k.emit("onclose",e)},i.onerror=function(e){k.emit("onerror",e)}}else{if(!n.stream)throw new s("URL or stream implementing a socket interface is required");i=n.stream,E(n)}i.onmessage=function(e){r(!0,e.data,h.onMessageReceived)},h.on("response",function(e,t){k.traceMessage(e,"<rsp:");try{e.error?k.reject(t.cb,new o(e.error)):t.handler?t.handler(e.params):k.fulfill(t.cb)}catch(r){k.reject(t.cb,r)}}),h.on("error",function(e){k.emit("error",e)})},this.close=function(){i&&i.close()},this.request=function(e,t,r,n){var a=d.createUserContext(e,t,r,n),s=a.originalMessage;h.register(s,a),k.traceMessage(s,">req:"),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:"cbl",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.connectable="true":e.connectable="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;i<advArrayLength;i++)e.url+=String.fromCharCode(parseInt(t[i],16));for(var n in p.AllDomains)t[advArrayLength]==n&&(e.url+=p.AllDomains[n])}function f(e,t){e.frameType="TLM",e.advPacketCount="",e.timeInterval="",e.batteryVoltage="",e.eddyVersion=parseInt(t[5],16);for(var r=6;r<8;r++)e.batteryVoltage+=t[r];e.batteryVoltage=parseInt(e.batteryVoltage,16),e.temperature=Math.ceil(parseInt(t[8],16)),e.temperature+=".";var i=Math.ceil(1/256*parseInt(t[9],16));i.length>2?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;l<t.length;l+=2)u[l/2]=t.charAt(l)+t.charAt(l+1);else for(var f=0;f<t.length;f++)u[f]=t.charAt(2*f)+t.charAt(2*f+1);for(;;){var h=u[1];if(h==p.kGAP_ADTYPE_FLAGS)i(r,u);else if(h==p.kGAP_ADTYPE_POWER_LEVEL)n(r,u);else if(h==p.kGAP_ADTYPE_INCOMPLETE_16BIT_SERVICEUUID||h==p.kGAP_ADTYPE_COMPLETE_16BIT_SERVICEUUID)s(r,u);else if(h==p.kGAP_ADTYPE_INCOMPLETE_32BIT_SERVICEUUID||h==p.kGAP_ADTYPE_COMPLETE_32BIT_SERVICEUUID)s(r,u);else if(h==p.kGAP_ADTYPE_INCOMPLETE_128BIT_SERVICEUUID||h==p.kGAP_ADTYPE_COMPLETE_128BIT_SERVICEUUID)o(r,u);else if(h==p.kGAP_ADTYPE_MANUFACTURER_SPECIFIC)a(r,u);else if(h==p.kGAP_ADTYPE_16BIT_SERVICE_DATA)c(r,u);else if("00"==h)u.splice(0,1);else{var d=parseInt(u[0],16);u.splice(0,d+1)}if(0===u.length)break}}},{"./constants":6}],9:[function(e,t,r){var i=e("./constants").C,n=e("./message-helper"),a=e("./../errors").InternalError,s=e("./../errors").ApplicationError;t.exports.MessageHandler=function(e,t){this.createUserContext=function(e,t,r,i){var n={method:e,params:t,jsonrpc:"2.0"};return{originalMessage:n,cb:r,handler:i}},this.wrapResponse=function(e,t){var r={params:t,jsonrpc:"2.0"};return n.requireAndPopulateFieldsFromCookie("wrapResponse",e,r),r},this.handleIndication=function(e){if(e.error)throw new s(JSON.stringify(e));var r=e.params;switch(e.result){case i.kScanForPeripherals:t.handleScanIndication(r);break;case i.kDisconnect:!function(){n.requireFields("Disconnect indication",r,[i.kPeripheralUUID]);var e=t.getPeripheral(r[i.kPeripheralUUID]);e&&e.handleDisconnectIndication(e)}();break;case i.kSetValueNotification:!function(){n.requireFields("Disconnect indication",r,[i.kPeripheralUUID]);var a=t.getPeripheral(r[i.kPeripheralUUID]);if(a){n.requireFields("Value notification",r,[i.kPeripheralUUID,i.kServiceUUID,i.kCharacteristicUUID,i.kValue]);var s=t.getObjectsFromMessage("c",e.params);s.characteristic.handleValueNotification(r)}}();break;default:!function(){throw new a("Unknown indication received from the gateway:",JSON.stringify(e))}()}}}},{"./../errors":3,"./constants":6,"./message-helper":10}],10:[function(e,t,r){function i(e){var t="";if("object"==typeof e){if(Array.isArray(e)){for(var r in e)0!=r&&(t+=" ,"),t+=e[r]}for(var n in e)if(e.hasOwnProperty(n)){var s=e[n],o=a[n];o||(o=n),t+="object"==typeof s?Array.isArray(s)?" "+o+":["+i(s)+"]":" "+o+":{"+i(s)+"}":" "+o+"="+s}}return t}var n=e("./constants").C,a={},s=e("./../errors").InternalError,o=e("./../errors").ApplicationError;for(var c in n){var u=n[c];0==c.indexOf("k")&&(c=c.substring(1,c.length),a[u]=c)}t.exports.isEmpty=function(e){for(var t in e)if(e.hasOwnProperty(t))return!1;return JSON.stringify(e)===JSON.stringify({})},t.exports.arrayAsHex=function(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},t.exports.toString=function(e){return i(e.params).trim()},t.exports.requireAndAssignParameters=function(e,r,i,n){t.exports.requireFields(e+" call parameters ",r,i,n)},t.exports.requireBooleanValue=function(e,t,r){if("boolean"!=typeof r)throw new o(e+" missing parameter "+t)},t.exports.requireHexValue=function(e,t,r){if("string"!=typeof r)throw new o(e+" missing parameter "+t);if(r.length>0&&(r.length%2!=0||!/^[0-9a-fA-F]+$/.test(r)))throw new o(e+" value "+t+" is not a valid hex string")},t.exports.requireUUID=function(e,t,r){if("string"!=typeof r)throw new o(e+" missing parameter "+t);if(r.length<4||!/^[0-9A-F-]+$/.test(r))throw new o(e+" value "+t+" is not a valid UUID")},t.exports.requireHexValues=function(e,t,r){var i=[];if(!Array.isArray(t)||!Array.isArray(r))throw new s("Illegal use of requireHexValues");for(var n=0;n<t.length;n++){var a=t[n],c=r[n];("string"!=typeof c||c.length<2||c.length%2!=0||!/^#[0-9A-F]$/i.test(c))&&i.push(a)}if(i)throw new o(e+" missing parameters "+i)},t.exports.requireFields=function(e,t,r,i){var n=[];if(i||(i={}),!t)throw new s(e+"Object is undefined");for(var a=0;a<r.length;a++){var o=r[a];void 0==typeof t[o]&&(void 0==typeof i[a]?n.push(r):t[o]=i[a])}if(n.length)throw new s(e+" missing "+n)},t.exports.requireAndPopulateFieldsFromCookie=function(e,t,r){if(!t)throw new o('Error: "'+e+" is missing the cookie");if(!t.original.id)throw new o('Error: "'+e+" is missing the cookie ID");if(!t.original.session_id)throw new o('Error: "'+e+" is missing the cookie session ID");if(!t.original.method)throw new o('Error: "'+e+" is missing the cookie request");r[n.kMessageId]=t.original.id,r[n.kSessionId]=t.original.session_id,r.result=t.result},t.exports.populateParams=function(e,t){function r(e,r){u--;var i=r.uuid;if(!i)throw new s('UUID for object of type "'+r.type+'" is missing');t[e]=i}if(t||(t={}),!e)throw new s("populateParams: service object is undefined");var i,a,o,c,u=23132;switch(e.type){case"d":u=4,c=e;break;case"c":u=3,o=e;break;case"s":u=2,a=e;break;case"p":u=1,i=e;break;default:throw new s('type must be one of: "s", "c" or "d"')}if(c&&(r(n.kDescriptorUUID,c),o=c.characteristic()),o&&(r(n.kCharacteristicUUID,o),a=o.service()),a&&(r(n.kServiceUUID,a),i=o.peripheral()),i&&r(n.kPeripheralUUID,i),0!=u)throw new s("Expected "+u+" more parts when constructing params of "+e.type);return t}},{"./../errors":3,"./constants":6}],11:[function(e,t,r){function i(e,t,r,i){this.msg=t,this.userContext=r,"undefined"==typeof t.id&&(t.id=Number(c++).toString()),this.id=t.id,i||(i=s.DEFAULT_MESSAGE_TIMEOUT_MS);var n=this;this.timeout=setTimeout(function(){delete n.timeout,e.emit("error",new o("Timed out : "+JSON.stringify(t)),n.userContext.cb)},i)}function n(){a.instantiateEmitter(this);var e=this,t={};this.register=function(r,n,a){if(Object.keys(t).length>s.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){a.instantiateEmitter(this);var r=this;this.processMessage=function(e){function i(i){var a=l[n.kPeripheralUUID],s={};if(s.peripheral=t.getPeripheral(a),s.peripheral&&s.peripheral.uuid){if("p"===i)return s;var o=l[n.kServiceUUID];if(s.service=s.peripheral.findService(o),s.service&&s.service.uuid){if("s"===i)return s;var c=l[n.kCharacteristicUUID];if(s.characteristic=s.service.findCharacteristic(c),s.characteristic&&s.characteristic.uuid){if("c"===i)return s;var u=l[n.kDescriptorUUID];if(s.descriptor=s.characteristic.findDescriptor(u),s.descriptor&&s.descriptor.uuid)return s;throw r.sendErrorResponse(e.method,n.kErrorDescriptorNotFound,"Descriptor not found in the service database"),new Error("Descriptor not found")}throw r.sendErrorResponse(e.method,n.kErrorCharacteristicNotFound,"Characteristic not found in the service database"),new Error("Characteristic not found")}throw r.sendErrorResponse(e.method,n.kErrorServiceNotFound,"Service not found in the service database"),new Error("Service not found")}throw r.sendErrorResponse(e.method,n.kErrorPeripheralNotFound,"Peripheral not found in the service database"),new Error("Peripheral not found")}var a;if("undefined"!=typeof e&&e&&!e.error){if(e.result&&(e.result==n.kMessage||e.result==n.kAuthenticate)){var s=!1;return e.error||"object"!=typeof e.params||e.params[n.kAuthenticate]!==!0||(s=!0),void r.emit("authenticated",s)}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 r.send(c)}var u={original:e},l=e.params;switch(e.method){case n.kConfigure:r.emit("configure",u,l[n.kShowPowerAlert],l[n.kIdentifierKey]);break;case n.kScanForPeripherals:r.emit("scan",u,l[n.kScanOptionAllowDuplicatesKey],l[n.kServiceUUIDs]);break;case n.kStopScanning:r.emit("stopScan",u);break;case n.kCentralState:r.emit("getCentralState",u);break;case n.kConnect:try{a=i("p"),r.emit("connect",u,a.peripheral.uuid)}catch(f){}break;case n.kDisconnect:try{a=i("p"),r.emit("disconnect",u,a.peripheral.uuid)}catch(f){}break;case n.kGetCharacteristicValue:try{a=i("c",u),r.emit("readCharacteristic",u,a.peripheral.uuid,a.service.uuid,a.characteristic.uuid)}catch(f){}break;case n.kWriteCharacteristicValue:try{a=i("c",u),r.emit("writeCharacteristic",u,a.peripheral.uuid,a.service.uuid,a.characteristic.uuid,e.params[n.kValue])}catch(f){}break;case n.kSetValueNotification:try{a=i("c",u),r.emit("enableNotifications",u,a.peripheral.uuid,a.service.uuid,a.characteristic.uuid,e.params[n.kIsNotifying])}catch(f){}break;case n.kGetDescriptorValue:try{a=i("d",u),r.emit("readDescriptor",u,a.peripheral.uuid,a.service.uuid,a.characteristic.uuid,a.descriptor.uuid)}catch(f){}break;case n.kWriteDescriptorValue:try{a=i("d",u),r.emit("writeDescriptor",u,a.peripheral.uuid,a.service.uuid,a.characteristic.uuid,a.descriptor.uuid,e.params[n.kValue])}catch(f){}break;default:return void r.sendErrorResponse(u,e.method,n.kInvalidRequest,"Request not handled by server")}}},r.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)},r.configureResponse=function(t){t.result=n.kConfigure,e.respond(t,{})},r.centralStateResponse=function(t,r){var i={};i[n.kState]=r,t.result=n.kCentralState,e.respond(t,i)},r.stopScanResponse=function(t){t.result=n.kStopScanning,e.respond(t,{})},r.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)},r.scanResponse=function(t,r,i,a,o,c,u,l,f){if(t)return t.result=n.kScanForPeripherals,void e.respond(t,{});var p,h,d={};if(!s.isEmpty(u)){p={};for(var v in u){var m=v.toUpperCase();p[m]=s.arrayAsHex(u[v]).toUpperCase()}}if(!s.isEmpty(l)){h={};for(var k in l){var g=k.toUpperCase();h[g]=s.arrayAsHex(l[k]).toUpperCase()}}d[n.kPeripheralName]=i,d[n.kPeripheralUUID]=r,d[n.kRSSIkey]=a,d[n.kCBAdvertisementDataTxPowerLevel]=o,d[n.kCBAdvertisementDataIsConnectable]=f,d[n.kCBAdvertisementDataServiceUUIDsKey]=c&&c.length>0?c:void 0,d[n.kCBAdvertisementDataManufacturerDataKey]=p,d[n.kCBAdvertisementDataServiceDataKey]=h,e.sendIndications(n.kScanForPeripherals,d)},r.addPeripheral=function(e,t,i,n,a){var s=new Peripheral(this,e,t,i,n,a);return r.peripherals[s.uuid]=s,s}}var n=e("./constants.js").C,a=e("./event-emitter"),s=e("./message-helper");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,"./message-helper":10}],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,c,u,l,f){this.name=e,this.rssi=t,this.txPowerLevel=r,this.connectable=n;if(c)for(var p in c){
+var d=p.toUpperCase();v[d]=c[p].toUpperCase()}if(u)for(var g in u)m[g]=u[g];if(a)for(var I=0;I<a.length;I++)i(k,a[I]);if(l){if(o.parseAdvArray(h,l.c2),h.advdata.connectable&&(h.connectable="true"===h.advdata.connectable),h.advdata.txPowerLevel&&(this.txPowerLevel=h.advdata.txPowerLevel),h.advdata.manufacturerData&&!s.isEmpty(h.advdata.manufacturerData))for(var E in h.advdata.manufacturerData){var y=E.toUpperCase();v[y]=h.advdata.manufacturerData[E].toUpperCase()}h.advdata.serviceUUIDs&&h.advdata.serviceUUIDs.length>0&&i(k,h.advdata.serviceUUIDs)}},this.findService=function(e){return d[e]},this.getMfrData=function(e){return v[e]},this.getSvcData=function(e){return m[e]},this.hasAdvertisedServiceUUID=function(e){return k.indexOf(e)>=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;c<i;c++)u[c].apply(this,a);return!0},i.prototype.addListener=function(e,t){var r;if(!n(t))throw TypeError("listener must be a function");return this._events||(this._events={}),this._events.newListener&&this.emit("newListener",e,n(t.listener)?t.listener:t),this._events[e]?s(this._events[e])?this._events[e].push(t):this._events[e]=[this._events[e],t]:this._events[e]=t,s(this._events[e])&&!this._events[e].warned&&(r=o(this._maxListeners)?i.defaultMaxListeners:this._maxListeners,r&&r>0&&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&&o&&(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=[];++f<t;)o&&o[f].run();f=-1,t=u.length}o=null,l=!1,clearTimeout(e)}}function a(e,t){this.fun=e,this.array=t}function s(){}var o,c=t.exports={},u=[],l=!1,f=-1;c.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var r=1;r<arguments.length;r++)t[r-1]=arguments[r];u.push(new a(e,t)),1!==u.length||l||setTimeout(n,0)},a.prototype.run=function(){this.fun.apply(null,this.array)},c.title="browser",c.browser=!0,c.env={},c.argv=[],c.version="",c.versions={},c.on=s,c.addListener=s,c.once=s,c.off=s,c.removeListener=s,c.removeAllListeners=s,c.emit=s,c.binding=function(e){throw new Error("process.binding is not supported")},c.cwd=function(){return"/"},c.chdir=function(e){throw new Error("process.chdir is not supported")},c.umask=function(){return 0}},{}],20:[function(e,t,r){t.exports=function(e){return e&&"object"==typeof e&&"function"==typeof e.copy&&"function"==typeof e.fill&&"function"==typeof e.readUInt8}},{}],21:[function(e,t,r){(function(t,i){function n(e,t){var i={seen:[],stylize:s};return arguments.length>=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&&C(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(C(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=["[","]"]),C(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<o;++s)U(t,String(s))?a.push(p(e,t,r,i,String(s),!0)):a.push("");return n.forEach(function(n){n.match(/^\d+$/)||a.push(p(e,t,r,i,n,!0))}),a}function p(e,t,r,i,n,a){var s,o,u;if(u=Object.getOwnPropertyDescriptor(t,n)||{value:t[n]},u.get?o=u.set?e.stylize("[Getter/Setter]","special"):e.stylize("[Getter]","special"):u.set&&(o=e.stylize("[Setter]","special")),U(i,n)||(s="["+n+"]"),o||(e.seen.indexOf(u.value)<0?(o=m(r)?c(e,u.value,null):c(e,u.value,r-1),o.indexOf("\n")>-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]"===_(e)}function P(e){return"object"==typeof e&&null!==e}function D(e){return P(e)&&"[object Date]"===_(e)}function A(e){return P(e)&&("[object Error]"===_(e)||e instanceof Error)}function C(e){return"function"==typeof e}function b(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 U(e,t){return Object.prototype.hasOwnProperty.call(e,t)}var w=/%[sdj%]/g;r.format=function(e){if(!I(e)){for(var t=[],r=0;r<arguments.length;r++)t.push(n(arguments[r]));return t.join(" ")}for(var r=1,i=arguments,a=i.length,s=String(e).replace(w,function(e){if("%%"===e)return"%";if(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<a;o=i[++r])s+=m(o)||!P(o)?" "+o:" "+n(o);return s},r.deprecate=function(e,n){function a(){if(!s){if(t.throwDeprecation)throw new Error(n);t.traceDeprecation,s=!0}return e.apply(this,arguments)}if(y(i.process))return function(){return r.deprecate(e,n).apply(this,arguments)};if(t.noDeprecation===!0)return e;var s=!1;return a};var T,R={};r.debuglog=function(e){if(y(T)&&(T=t.env.NODE_DEBUG||""),e=e.toUpperCase(),!R[e])if(new RegExp("\\b"+e+"\\b","i").test(T)){t.pid;R[e]=function(){r.format.apply(r,arguments)}}else R[e]=function(){};return R[e]},r.inspect=n,n.colors={bold:[1,22],italic:[3,23],underline:[4,24],inverse:[7,27],white:[37,39],grey:[90,39],black:[30,39],blue:[34,39],cyan:[36,39],green:[32,39],magenta:[35,39],red:[31,39],yellow:[33,39]},n.styles={special:"cyan",number:"yellow","boolean":"yellow",undefined:"grey","null":"bold",string:"green",date:"magenta",regexp:"red"},r.isArray=d,r.isBoolean=v,r.isNull=m,r.isNullOrUndefined=k,r.isNumber=g,r.isString=I,r.isSymbol=E,r.isUndefined=y,r.isRegExp=S,r.isObject=P,r.isDate=D,r.isError=A,r.isFunction=C,r.isPrimitive=b,r.isBuffer=e("./support/isBuffer");r.log=function(){},r.inherits=e("inherits"),r._extend=function(e,t){if(!t||!P(t))return e;for(var r=Object.keys(t),i=r.length;i--;)e[r[i]]=t[r[i]];return e}}).call(this,e("_process"),"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./support/isBuffer":20,_process:19,inherits:18}],"gatt-ip":[function(e,t,r){t.exports.GATTIP=e("./gattip").GATTIP,t.exports.C=e("./lib/constants").C},{"./gattip":5,"./lib/constants":6}]},{},[]);
+/* blueapp.io v0.0.1 */
+!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;o<i.length;o++)n(i[o]);return n}({1:[function(e,t,r){!function(){function t(){Object.defineProperty?Object.defineProperty(navigator,"bluetooth",{get:p}):Object.prototype.__defineGetter__&&navigator.__defineGetter__("bluetooth",p);navigator.bluetooth}for(var r,i=/\+/g,n=/([^&=]+)=?([^&]*)/g,a=function(e){return decodeURIComponent(e.replace(i," "))},o=window.location.search.substring(1),s={};r=n.exec(o);)s[a(r[1])]=a(r[2]);var c=s.token,u=s.uuid,l=s.proxyUrl;window.cordovaApp=s.app;var p=function(){if("object"==typeof window.bawb)return window.bawb;var t;if(cordovaApp){t={};var r=function(e){t.onerror&&t.onerror(e)},i=function(e){if(e&&t.onmessage){var r={data:e};t.onmessage(r)}};t.close=function(){blueappio.request("close",data,i,r)},t.send=function(e){blueappio.request("message",e,i,r)},blueappio.request("init",{},i,r)}return window.bawb=e("blueapp-wb").init({url:l,token:c,scanFilters:{uuids:[u]},stream:t}).navigator.bluetooth,window.bawb};"object"==typeof window&&"object"==typeof navigator&&(cordovaApp?document.addEventListener("deviceready",t,!1):c&&t())}()},{"blueapp-wb":3}],2:[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}],3:[function(e,t,r){"use strict";function i(e){this.gateway=e}function n(e,t){var r=!1,i=-1;if("undefined"!=typeof e){for(i=0;i<e.length;i++)if(e[i].uuid===t.uuid){r=!0;break}}else e=[];return r?(e.splice(i,1,t),e):(e.push(t),e)}function a(e,t){for(var r=void 0,i=void 0,n=[],a=0;a<t.length;a++)if(t[a].name&&(r=t[a].name),t[a].services)for(var o=0;o<t[a].services.length;o++)"number"==typeof t[a].services[o]&&(t[a].services[o]=t[a].services[o].toString(16)),i=i?i+","+t[a].services[o]:t[a].services[o]+"";if(""!==i&&"undefined"!=typeof i){n=i.trim().split(/\s*,\s*/);for(var a=0;a<n.length;a++)n[a]=n[a].toUpperCase()}var s=!1,c=0;if(e.advdata&&e.advdata.serviceUUIDs.length>0?e.serviceUUIDs=e.advdata.serviceUUIDs:e.serviceUUIDs=e.getAllAdvertisedServiceUUIDs(),n.length>0&&""!==r&&"undefined"!=typeof r){if(n.length>0){for(var u=0;u<n.length;u++)"undefined"!=typeof e.serviceUUIDs&&e.serviceUUIDs.length>0&&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;o<n.length;o++)"undefined"!=typeof e.serviceUUIDs&&e.serviceUUIDs.length>0&&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}}var o=e("gatt-ip").GATTIP,s=e("./util.js"),c=e("./thirdparty"),u=e("./wb-device").BluetoothDevice;t.exports.navigator=void 0,t.exports.window=void 0,i.prototype.requestDevice=function(e){var t=e.filters,r=this.gateway,i=[];return s.errorLoggingPromise(function(e,t){r.getGateway()?e(r.getGateway()):r.once("ready",function(t){e(t)})}).then(function(){return s.errorLoggingPromise(function(e,o){function s(o){if(clearTimeout(c),"true"==cordovaApp){var p=a(o,t);if(p){i=n(i,p);for(var f='<table cellpadding="0" cellspacing="0"><tbody><tr>',d=0;d<i.length;d++)f+="</tr><tr onclick='onPeripheralSelect(\""+i[d].uuid+"\")'>",f+="<td>"+i[d].name+"</td>";document.getElementById("peripheral").innerHTML=f}}else l.stopScan(function(){l.removeListener("scan",s);var t=new u(r,o);t.gatt=t,e(t)})}var c=setTimeout(function(){o("Timed out")},3e4),l=r.getGateway();window.onPeripheralSelect=function(t){l.stopScan(function(){var n=document.getElementById("picker");n.style.display="none";for(var a=0;a<i.length;a++)if(i[a].uuid==t){var o=new u(r,i[a]);o.gatt=o,e(o);break}})},window.onCancel=function(){l.stopScan(function(){});var t=document.getElementById("picker");t.style.display="none",e()},l.scan(function(){"true"==cordovaApp&&(document.getElementById("scanDialog").innerHTML='<style>.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;;}</style><div id= "picker" style= "z-index: 100;" class= "modal">    <div class= "modal-content">       <div style="font-size: 15px; padding-bottom: 10px; color: black"> App wants to pair with : </div>        <div class= "spacing-table div-border" style="color: black" id=\'peripheral\'>        </div>        <div style="text-align: right; margin-top: 10px; font-size: 14px;">        <button type= "button" onclick= "onCancel()" style="padding: 4px;">Cancel</button>    </div>    </div></div>'),l.on("scan",s)})})})},t.exports.init=function(e){var t={};t.bluetooth={},t.BluetoothUUID=c.BluetoothUUID,e||(e={});var r=new o;r.BluetoothUUID=c.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("state",function(e){if("true"==cordovaApp)if(e){var t=document.getElementById("BluetoothAlert");t&&(t.style.display="none")}else document.getElementById("scanDialog").innerHTML='<style>.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;;}</style><div id= "BluetoothAlert" style= "z-index: 100;" class= "modal">    <div class= "modal-content">       <div style="font-size: 15px;text-align: center; color: black"> Please turn on the Bluetooth... </div>    </div></div>'}),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;r<e.length-1;r+=2)t.push(parseInt(e.substr(r,2),16));return t},t.exports.arrayAsHex=function(e){var t="";for(var r in e){byte=e[r];var i=(255&byte).toString(16);1==i.length&&(i="0"+i),t+=i}return t.toUpperCase()},t.exports.uncaughtError=function(e){},t.exports.gattIpRequestPromise=function(e){return new Promise(function(r,i){try{e(r,i)}catch(n){throw t.exports.uncaughtError(n),n}})},t.exports.errorLoggingPromise=function(e){return new Promise(function(r,i){try{e(r,i)}catch(n){throw t.exports.uncaughtError(n),n}})}},{}],6:[function(e,t,r){function i(e,t){function r(e,t){var r=a.hexAsArray(t);i._value=new DataView(new Uint8Array(r).buffer),i.emit("characteristicvaluechanged",{target:i})}o.instantiateEmitter(this);var i=this;this._gattIp=e._gattIp,this._service=e,this._gattipCharacteristic=t,t.wbCharacteristic=this,this._properties=new n(t.allProperties()),this._value=null,Object.defineProperty(this,"uuid",{get:function(){return a.toWbUUID(i._gattipCharacteristic.uuid)}}),Object.defineProperty(this,"service",{get:function(){return i._service}}),Object.defineProperty(this,"properties",{get:function(){return i._properties}}),Object.defineProperty(this,"value",{get:function(){return i._value}}),this.getAllDescriptors=function(e){return a.errorLoggingPromise(function(e,t){t("Not implemented")})},this.getDescriptor=function(e){var t=this;return a.errorLoggingPromise(function(r,i){var n=a.toVensiUUID(t._gattIp.BluetoothUUID.getDescriptor(e));if("undefined"==typeof n)i("Unable to find descriptor with requested UUID "+e);else{var o=t._gattipCharacteristic.findDescriptor(n);o?r(new s(t,o)):i("Descriptor "+e+" not found")}})},this.readValue=function(){var e=this;return a.errorLoggingPromise(function(t,r){e._gattipCharacteristic.readValue({fulfill:function(e,r){var i=a.hexAsArray(r);t(new DataView(new Uint8Array(i).buffer))},reject:r})})},this.writeValue=function(e){var t=this;return a.errorLoggingPromise(function(r,i){t._gattipCharacteristic.writeValue({fulfill:r,reject:i},a.arrayAsHex(Array.prototype.slice.call(e)))})},this.startNotifications=function(){var e=this;return a.errorLoggingPromise(function(t,i){return e._isNotifying?void i("Already notifying"):void e._gattipCharacteristic.enableNotifications({fulfill:function(n,a){a?(e._isNotifying=!0,n.on("valueChange",r),t()):i("Did not receive expected response from the gateway")},reject:i},!0)})},this.stopNotifications=function(){var e=this;return a.errorLoggingPromise(function(t,i){return e._isNotifying?void e._gattipCharacteristic.enableNotifications({fulfill:function(n,a){a?i("Did not receive expected response from the gateway"):(e._isNotifying=!1,n.removeListener("valueChange",r),t())},reject:i},!1):void i("Was not notifying")})},this.addEventListener=function(e,t){this.on(e,t)},this.removeEventListener=function(e,t){this.removeListener(e,t)}}function n(e){function t(e){return e.charAt(0).toUpperCase()+e.slice(1)}for(var r in c){wbPropName=c[r];var i=t(wbPropName);"object"==typeof e[i]?this[wbPropName]=1==e[i].enabled:"reliableWrite"!=wbPropName&&"writableAuxiliaries"!=wbPropName||(e.ExtendedProperties&&1===e.ExtendedProperties.enabled?this[wbPropName]=!1:this[wbPropName]=!1)}}var a=e("./util.js"),o=e("./event-emitter"),s=e("./wb-descriptor").BluetoothGattDescriptor,c=["broadcast","read","writeWithoutResponse","write","notify","indicate","authenticatedSignedWrites","reliableWrite","writableAuxiliaries"];t.exports.BluetoothGattCharacteristic=i,o.makeEmitter(i)},{"./event-emitter":2,"./util.js":5,"./wb-descriptor":7}],7:[function(e,t,r){function i(e,t){this._gattIp=e._gattIp,this._characteristic=e,this._gattIpDescriptor=t,this._value=null}var n=e("./util");t.exports.BluetoothGattDescriptor=i,i.prototype={get uuid(){return n.toWbUUID(this._gattIpDescriptor.uuid)},get characteristic(){return this._characteristic},get value(){return this._value},readValue:function(){var e=this;return n.errorLoggingPromise(function(t,r){e._gattIpDescriptor.readValue({fulfill:function(e,r){var i=n.hexAsArray(r);t(new DataView(new Uint8Array(i).buffer))},reject:r})})},writeValue:function(e){var t=this;return n.errorLoggingPromise(function(r,i){t._gattIpDescriptor.writeValue({fulfill:r,reject:i},n.arrayAsHex(Array.prototype.slice.call(e)))})}}},{"./util":5}],8:[function(e,t,r){function i(e,t){this._gattIp=e,this._gattIpPeripheral=t}var n=e("./util.js"),a=e("./wb-service").BluetoothGattService;t.exports.BluetoothDevice=i,i.prototype={get name(){return this._gattIpPeripheral.name},get uuid(){return this._gattIpPeripheral.uuid},get deviceClass(){},get vendorIdSource(){},get vendorId(){},get productId(){},get productVersion(){},get paired(){return!1},get connected(){return this._gattIpPeripheral.isConnected},get uuids(){return this._gattIpPeripheral.serviceUUIDs},connect:function(){var e=this;return new Promise(function(t,r){e._gattIpPeripheral.connect({fulfill:function(r){e._gattIpPeripheral=r,t(e)},reject:r})})},disconnect:function(){var e=this;return n.errorLoggingPromise(function(t,r){e._gattIpPeripheral.disconnect({fulfill:t,reject:r})})},getAllServices:function(e){return n.errorLoggingPromise(function(e,t){t("Not implemented")})},getService:function(e){var t=this;return n.errorLoggingPromise(function(r,i){var o=n.toVensiUUID(t._gattIp.BluetoothUUID.getService(e));if("undefined"==typeof o)i("Unable to find service with requested UUID "+e);else{var s=t._gattIpPeripheral.findService(o);s?r(new a(t,s)):(s=t._gattIpPeripheral.findService(e),s?r(new a(t,s)):i("Service "+e+" not found"))}})}},i.prototype.connectGATT=i.prototype.connect,i.prototype.getPrimaryService=i.prototype.getService},{"./util.js":5,"./wb-service":9}],9:[function(e,t,r){function i(e,t){this._gattIp=e._gattIp,this._device=e,this._gattIpService=t}var n=e("./util.js"),a=e("./wb-characteristic").BluetoothGattCharacteristic;t.exports.BluetoothGattService=i,i.prototype={get uuid(){return n.toWbUUID(this._service.uuid)},get isPrimary(){return!0},get device(){return this._device},getCharacteristic:function(e){var t=this;return n.errorLoggingPromise(function(r,i){var o=n.toVensiUUID(t._gattIp.BluetoothUUID.getCharacteristic(e));if("undefined"==typeof o)i("Unable to find characteristic with requested UUID "+e);else{var s=t._gattIpService.findCharacteristic(o);s?r(new a(t,s)):(s=t._gattIpService.findCharacteristic(e),s?r(new a(t,s)):i("Characteristic "+e+" not found"))}})},getIncludedService:function(e){return n.errorLoggingPromise(function(e,t){t("Not implemented")})}}},{"./util.js":5,"./wb-characteristic":6}],10:[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 o(e){return"object"==typeof e&&null!==e}function s(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||o(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],s(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:for(i=arguments.length,a=new Array(i-1),c=1;c<i;c++)a[c-1]=arguments[c];r.apply(this,a)}else if(o(r)){for(i=arguments.length,a=new Array(i-1),c=1;c<i;c++)a[c-1]=arguments[c];for(u=r.slice(),i=u.length,c=0;c<i;c++)u[c].apply(this,a)}return!0},i.prototype.addListener=function(e,t){var r;if(!n(t))throw TypeError("listener must be a function");if(this._events||(this._events={}),this._events.newListener&&this.emit("newListener",e,n(t.listener)?t.listener:t),this._events[e]?o(this._events[e])?this._events[e].push(t):this._events[e]=[this._events[e],t]:this._events[e]=t,o(this._events[e])&&!this._events[e].warned){var r;r=s(this._maxListeners)?i.defaultMaxListeners:this._maxListeners,r&&r>0&&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)e.fulfill(t,r);else{if(i[n.kOpen]!==!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=0;c<t.uuids.length;c++){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.kCBAdvertisementDataIsConnectable],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.kCBAdvertisementDataIsConnectable],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:"),r(!1,e,v.processMessage)}),d.on("indication",function(e){t(new o("Received an indication on a server stream:"+JSON.stringify(e)))}),g=k,m.emit("ready",k)):e.isPassThrough?b():k.configure(function(){k.centralState(function(){if(k.isPoweredOn())k.isPoweredOn()&&b();else{m.emit("state",k.isPoweredOn());var e=setInterval(function(){k.centralState(function(){k.isPoweredOn()&&(m.emit("state",k.isPoweredOn()),clearInterval(e),b())})},500)}})})}function b(){d.on("indication",function(e){m.traceMessage(e,"<ind:"),r(!1,e,h.handleIndication)}),d.on("request",function(e){t(new a("Received a request on a client stream:"+JSON.stringify(e)))}),g=k,m.emit("ready",k)}function y(e){e.token?k._authenticate(function(){_(e)},e.token,e.version):_(e)}var k=new l(this,n.scanFilters);if(d=new u(this),h=new c(this,k),v=new p(this,k),n.trace===!0&&(m.traceEnabled=!0),n.url){var w;w="object"==typeof window?window.WebSocket:e("websocket").w3cwebsocket,i=new w(n.url,(void 0),(void 0),(void 0),(void 0),f),i.onopen=function(){y(n)},i.onclose=function(e){m.emit("onclose",e)},i.onerror=function(e){m.emit("onerror",e)}}else{if(!n.stream)throw new o("URL or stream implementing a socket interface is required");i=n.stream,y(n)}i.onmessage=function(e){r(!0,e.data,d.onMessageReceived)},d.on("response",function(e,t){m.traceMessage(e,"<rsp:");try{e.error?m.reject(t.cb,new s(e.error)):t.handler?t.handler(e.params):m.fulfill(t.cb)}catch(r){m.reject(t.cb,r)}}),d.on("error",function(e){m.emit("error",e)})},this.close=function(){i&&i.close()},this.request=function(e,t,r,n){var a=h.createUserContext(e,t,r,n),o=a.originalMessage;d.register(o,a),m.traceMessage(o,">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,t.exports.C=e("./lib/constants").C},{"./gattip":15,"./lib/constants":17}],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:"cbl",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.connectable="true":e.connectable="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;i<advArrayLength;i++)e.url+=String.fromCharCode(parseInt(t[i],16));for(var n in f.AllDomains)t[advArrayLength]==n&&(e.url+=f.AllDomains[n])}function p(e,t){e.frameType="TLM",e.advPacketCount="",e.timeInterval="",e.batteryVoltage="",e.eddyVersion=parseInt(t[5],16);for(var r=6;r<8;r++)e.batteryVoltage+=t[r];e.batteryVoltage=parseInt(e.batteryVoltage,16),e.temperature=Math.ceil(parseInt(t[8],16)),e.temperature+=".";var i=Math.ceil(1/256*parseInt(t[9],16));i.length>2?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;l<t.length;l+=2)u[l/2]=t.charAt(l)+t.charAt(l+1);else for(var p=0;p<t.length;p++)u[p]=t.charAt(2*p)+t.charAt(2*p+1);for(;;){var d=u[1];if(d==f.kGAP_ADTYPE_FLAGS)i(r,u);else if(d==f.kGAP_ADTYPE_POWER_LEVEL)n(r,u);else if(d==f.kGAP_ADTYPE_INCOMPLETE_16BIT_SERVICEUUID||d==f.kGAP_ADTYPE_COMPLETE_16BIT_SERVICEUUID)o(r,u);else if(d==f.kGAP_ADTYPE_INCOMPLETE_32BIT_SERVICEUUID||d==f.kGAP_ADTYPE_COMPLETE_32BIT_SERVICEUUID)o(r,u);else if(d==f.kGAP_ADTYPE_INCOMPLETE_128BIT_SERVICEUUID||d==f.kGAP_ADTYPE_COMPLETE_128BIT_SERVICEUUID)s(r,u);else if(d==f.kGAP_ADTYPE_MANUFACTURER_SPECIFIC)a(r,u);else if(d==f.kGAP_ADTYPE_16BIT_SERVICE_DATA)c(r,u);else if("00"==d)u.splice(0,1);else{var h=parseInt(u[0],16);u.splice(0,h+1)}if(0===u.length)break}}},{"./constants":17}],20:[function(e,t,r){var i=e("./constants").C,n=e("./message-helper"),a=e("./../errors").InternalError,o=e("./../errors").ApplicationError;t.exports.MessageHandler=function(e,t){this.createUserContext=function(e,t,r,i){var n={method:e,params:t,jsonrpc:"2.0"};return{originalMessage:n,cb:r,handler:i}},this.wrapResponse=function(e,t){var r={params:t,jsonrpc:"2.0"};return n.requireAndPopulateFieldsFromCookie("wrapResponse",e,r),r},this.handleIndication=function(e){if(e.error)throw new o(JSON.stringify(e));var r=e.params;switch(e.result){case i.kScanForPeripherals:t.handleScanIndication(r);break;case i.kDisconnect:!function(){n.requireFields("Disconnect indication",r,[i.kPeripheralUUID]);var e=t.getPeripheral(r[i.kPeripheralUUID]);e&&e.handleDisconnectIndication(e)}();break;case i.kSetValueNotification:!function(){n.requireFields("Disconnect indication",r,[i.kPeripheralUUID]);var a=t.getPeripheral(r[i.kPeripheralUUID]);if(a){n.requireFields("Value notification",r,[i.kPeripheralUUID,i.kServiceUUID,i.kCharacteristicUUID,i.kValue]);var o=t.getObjectsFromMessage("c",e.params);o.characteristic.handleValueNotification(r)}}();break;default:!function(){throw new a("Unknown indication received from the gateway:",JSON.stringify(e))}()}}}},{"./../errors":13,"./constants":17,"./message-helper":21}],21:[function(e,t,r){function i(e){var t="";if("object"==typeof e){if(Array.isArray(e)){for(var r in e)0!=r&&(t+=" ,"),t+=e[r]}for(var n in e)if(e.hasOwnProperty(n)){var o=e[n],s=a[n];s||(s=n),t+="object"==typeof o?Array.isArray(o)?" "+s+":["+i(o)+"]":" "+s+":{"+i(o)+"}":" "+s+"="+o}}return t}var n=e("./constants").C,a={},o=e("./../errors").InternalError,s=e("./../errors").ApplicationError;for(var c in n){var u=n[c];0==c.indexOf("k")&&(c=c.substring(1,c.length),a[u]=c)}t.exports.isEmpty=function(e){for(var t in e)if(e.hasOwnProperty(t))return!1;return JSON.stringify(e)===JSON.stringify({})},t.exports.arrayAsHex=function(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},t.exports.toString=function(e){return i(e.params).trim()},t.exports.requireAndAssignParameters=function(e,r,i,n){t.exports.requireFields(e+" call parameters ",r,i,n)},t.exports.requireBooleanValue=function(e,t,r){if("boolean"!=typeof r)throw new s(e+" missing parameter "+t)},t.exports.requireHexValue=function(e,t,r){if("string"!=typeof r)throw new s(e+" missing parameter "+t);if(r.length>0&&(r.length%2!=0||!/^[0-9a-fA-F]+$/.test(r)))throw new s(e+" value "+t+" is not a valid hex string")},t.exports.requireUUID=function(e,t,r){if("string"!=typeof r)throw new s(e+" missing parameter "+t);if(r.length<4||!/^[0-9A-F-]+$/.test(r))throw new s(e+" value "+t+" is not a valid UUID")},t.exports.requireHexValues=function(e,t,r){var i=[];if(!Array.isArray(t)||!Array.isArray(r))throw new o("Illegal use of requireHexValues");for(var n=0;n<t.length;n++){var a=t[n],c=r[n];("string"!=typeof c||c.length<2||c.length%2!=0||!/^#[0-9A-F]$/i.test(c))&&i.push(a)}if(i)throw new s(e+" missing parameters "+i)},t.exports.requireFields=function(e,t,r,i){var n=[];if(i||(i={}),!t)throw new o(e+"Object is undefined");for(var a=0;a<r.length;a++){var s=r[a];void 0==typeof t[s]&&(void 0==typeof i[a]?n.push(r):t[s]=i[a])}if(n.length)throw new o(e+" missing "+n)},t.exports.requireAndPopulateFieldsFromCookie=function(e,t,r){if(!t)throw new s('Error: "'+e+" is missing the cookie");if(!t.original.id)throw new s('Error: "'+e+" is missing the cookie ID");if(!t.original.session_id)throw new s('Error: "'+e+" is missing the cookie session ID");if(!t.original.method)throw new s('Error: "'+e+" is missing the cookie request");r[n.kMessageId]=t.original.id,r[n.kSessionId]=t.original.session_id,r.result=t.result},t.exports.populateParams=function(e,t){function r(e,r){u--;var i=r.uuid;if(!i)throw new o('UUID for object of type "'+r.type+'" is missing');t[e]=i}if(t||(t={}),!e)throw new o("populateParams: service object is undefined");var i,a,s,c,u=23132;switch(e.type){case"d":u=4,c=e;break;case"c":u=3,s=e;break;case"s":u=2,a=e;break;case"p":u=1,i=e;break;default:throw new o('type must be one of: "s", "c" or "d"')}if(c&&(r(n.kDescriptorUUID,c),s=c.characteristic()),s&&(r(n.kCharacteristicUUID,s),a=s.service()),a&&(r(n.kServiceUUID,a),i=s.peripheral()),i&&r(n.kPeripheralUUID,i),0!=u)throw new o("Expected "+u+" more parts when constructing params of "+e.type);return t}},{"./../errors":13,"./constants":17}],22:[function(e,t,r){function i(e,t,r,i){this.msg=t,this.userContext=r,"undefined"==typeof t.id&&(t.id=Number(c++).toString()),this.id=t.id,i||(i=o.DEFAULT_MESSAGE_TIMEOUT_MS);var n=this;this.timeout=setTimeout(function(){delete n.timeout,e.emit("error",new s("Timed out : "+JSON.stringify(t)),n.userContext.cb)},i)}function n(){a.instantiateEmitter(this);var e=this,t={};this.register=function(r,n,a){if(Object.keys(t).length>o.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){a.instantiateEmitter(this);var r=this;this.processMessage=function(e){function i(i){var a=l[n.kPeripheralUUID],o={};if(o.peripheral=t.getPeripheral(a),o.peripheral&&o.peripheral.uuid){if("p"===i)return o;var s=l[n.kServiceUUID];if(o.service=o.peripheral.findService(s),o.service&&o.service.uuid){if("s"===i)return o;var c=l[n.kCharacteristicUUID];if(o.characteristic=o.service.findCharacteristic(c),o.characteristic&&o.characteristic.uuid){if("c"===i)return o;var u=l[n.kDescriptorUUID];if(o.descriptor=o.characteristic.findDescriptor(u),o.descriptor&&o.descriptor.uuid)return o;throw r.sendErrorResponse(e.method,n.kErrorDescriptorNotFound,"Descriptor not found in the service database"),new Error("Descriptor not found")}throw r.sendErrorResponse(e.method,n.kErrorCharacteristicNotFound,"Characteristic not found in the service database"),new Error("Characteristic not found")}throw r.sendErrorResponse(e.method,n.kErrorServiceNotFound,"Service not found in the service database"),new Error("Service not found")}throw r.sendErrorResponse(e.method,n.kErrorPeripheralNotFound,"Peripheral not found in the service database"),new Error("Peripheral not found")}var a;if("undefined"!=typeof e&&e&&!e.error){if(e.result&&(e.result==n.kMessage||e.result==n.kAuthenticate)){var o=!1;return e.error||"object"!=typeof e.params||e.params[n.kAuthenticate]!==!0||(o=!0),void r.emit("authenticated",o)}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 r.send(c)}var u={original:e},l=e.params;switch(e.method){case n.kConfigure:r.emit("configure",u,l[n.kShowPowerAlert],l[n.kIdentifierKey]);break;case n.kScanForPeripherals:r.emit("scan",u,l[n.kScanOptionAllowDuplicatesKey],l[n.kServiceUUIDs]);break;case n.kStopScanning:r.emit("stopScan",u);break;case n.kCentralState:r.emit("getCentralState",u);break;case n.kConnect:try{a=i("p"),r.emit("connect",u,a.peripheral.uuid)}catch(p){}break;case n.kDisconnect:try{a=i("p"),r.emit("disconnect",u,a.peripheral.uuid)}catch(p){}break;case n.kGetCharacteristicValue:try{a=i("c",u),r.emit("readCharacteristic",u,a.peripheral.uuid,a.service.uuid,a.characteristic.uuid)}catch(p){}break;case n.kWriteCharacteristicValue:try{a=i("c",u),r.emit("writeCharacteristic",u,a.peripheral.uuid,a.service.uuid,a.characteristic.uuid,e.params[n.kValue])}catch(p){}break;case n.kSetValueNotification:try{a=i("c",u),r.emit("enableNotifications",u,a.peripheral.uuid,a.service.uuid,a.characteristic.uuid,e.params[n.kIsNotifying])}catch(p){}break;case n.kGetDescriptorValue:try{a=i("d",u),r.emit("readDescriptor",u,a.peripheral.uuid,a.service.uuid,a.characteristic.uuid,a.descriptor.uuid)}catch(p){}break;case n.kWriteDescriptorValue:try{a=i("d",u),r.emit("writeDescriptor",u,a.peripheral.uuid,a.service.uuid,a.characteristic.uuid,a.descriptor.uuid,e.params[n.kValue])}catch(p){}break;default:return void r.sendErrorResponse(u,e.method,n.kInvalidRequest,"Request not handled by server")}}},r.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)},r.configureResponse=function(t){t.result=n.kConfigure,e.respond(t,{})},r.centralStateResponse=function(t,r){var i={};i[n.kState]=r,t.result=n.kCentralState,e.respond(t,i)},r.stopScanResponse=function(t){t.result=n.kStopScanning,e.respond(t,{})},r.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)},r.scanResponse=function(t,r,i,a,s,c,u,l,p){if(t)return t.result=n.kScanForPeripherals,void e.respond(t,{});var f,d,h={};if(!o.isEmpty(u)){f={};for(var v in u){var g=v.toUpperCase();f[g]=o.arrayAsHex(u[v]).toUpperCase()}}if(!o.isEmpty(l)){d={};for(var m in l){var _=m.toUpperCase();d[_]=o.arrayAsHex(l[m]).toUpperCase()}}h[n.kPeripheralName]=i,h[n.kPeripheralUUID]=r,h[n.kRSSIkey]=a,h[n.kCBAdvertisementDataTxPowerLevel]=s,h[n.kCBAdvertisementDataIsConnectable]=p,h[n.kCBAdvertisementDataServiceUUIDsKey]=c&&c.length>0?c:void 0,h[n.kCBAdvertisementDataManufacturerDataKey]=f,h[n.kCBAdvertisementDataServiceDataKey]=d,e.sendIndications(n.kScanForPeripherals,h)},r.addPeripheral=function(e,t,i,n,a){var o=new Peripheral(this,e,t,i,n,a);return r.peripherals[o.uuid]=o,o}}var n=e("./constants.js").C,a=e("./event-emitter"),o=e("./message-helper");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,"./message-helper":21}],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,c,u,l,p){this.name=e,this.rssi=t,this.txPowerLevel=r,this.connectable=n;if(c)for(var f in c){var h=f.toUpperCase();v[h]=c[f].toUpperCase()}if(u)for(var _ in u)g[_]=u[_];if(a)for(var b=0;b<a.length;b++)i(m,a[b]);if(l){if(s.parseAdvArray(d,l.c2),d.advdata.connectable&&(d.connectable="true"===d.advdata.connectable),d.advdata.txPowerLevel&&(this.txPowerLevel=d.advdata.txPowerLevel),d.advdata.manufacturerData&&!o.isEmpty(d.advdata.manufacturerData))for(var y in d.advdata.manufacturerData){var k=y.toUpperCase();v[k]=d.advdata.manufacturerData[y].toUpperCase()}d.advdata.serviceUUIDs&&d.advdata.serviceUUIDs.length>0&&i(m,d.advdata.serviceUUIDs)}},this.findService=function(e){return h[e]},this.getMfrData=function(e){return v[e]},this.getSvcData=function(e){return g[e]},this.hasAdvertisedServiceUUID=function(e){return m.indexOf(e)>=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 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=[];++m<t;)h&&h[m].run();m=-1,t=v.length}h=null,g=!1,o(e)}}function u(e,t){this.fun=e,this.array=t}function l(){}var p,f,d=t.exports={};!function(){try{p="function"==typeof setTimeout?setTimeout:i}catch(e){p=i}try{f="function"==typeof clearTimeout?clearTimeout:n}catch(e){f=n}}();var h,v=[],g=!1,m=-1;d.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var r=1;r<arguments.length;r++)t[r-1]=arguments[r];v.push(new u(e,t)),1!==v.length||g||a(c)},u.prototype.run=function(){this.fun.apply(null,this.array)},d.title="browser",d.browser=!0,d.env={},d.argv=[],d.version="",d.versions={},d.on=l,d.addListener=l,d.once=l,d.off=l,d.removeListener=l,d.removeAllListeners=l,d.emit=l,d.binding=function(e){throw new Error("process.binding is not supported")},d.cwd=function(){return"/"},d.chdir=function(e){throw new Error("process.chdir is not supported")},d.umask=function(){return 0}},{}],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){t.exports=function(e){return e&&"object"==typeof e&&"function"==typeof e.copy&&"function"==typeof e.fill&&"function"==typeof e.readUInt8}},{}],30:[function(e,t,r){(function(t,i){function n(e,t){var i={seen:[],stylize:o};return arguments.length>=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<s;++o)A(t,String(o))?a.push(f(e,t,r,i,String(o),!0)):a.push("");return n.forEach(function(n){n.match(/^\d+$/)||a.push(f(e,t,r,i,n,!0))}),a}function f(e,t,r,i,n,a){var o,s,u;if(u=Object.getOwnPropertyDescriptor(t,n)||{value:t[n]},u.get?s=u.set?e.stylize("[Getter/Setter]","special"):e.stylize("[Getter]","special"):u.set&&(s=e.stylize("[Setter]","special")),A(i,n)||(o="["+n+"]"),s||(e.seen.indexOf(u.value)<0?(s=g(r)?c(e,u.value,null):c(e,u.value,r-1),s.indexOf("\n")>-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]"===S(e)}function I(e){return"object"==typeof e&&null!==e;
+}function E(e){return I(e)&&"[object Date]"===S(e)}function U(e){return I(e)&&("[object Error]"===S(e)||e instanceof Error)}function D(e){return"function"==typeof e}function P(e){return null===e||"boolean"==typeof e||"number"==typeof e||"string"==typeof e||"symbol"==typeof e||"undefined"==typeof e}function S(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<arguments.length;r++)t.push(n(arguments[r]));return t.join(" ")}for(var r=1,i=arguments,a=i.length,o=String(e).replace(C,function(e){if("%%"===e)return"%";if(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<a;s=i[++r])o+=g(s)||!I(s)?" "+s:" "+n(s);return o},r.deprecate=function(e,n){function a(){if(!o){if(t.throwDeprecation)throw new Error(n);t.traceDeprecation,o=!0}return e.apply(this,arguments)}if(k(i.process))return function(){return r.deprecate(e,n).apply(this,arguments)};if(t.noDeprecation===!0)return e;var o=!1;return a};var T,x={};r.debuglog=function(e){if(k(T)&&(T=t.env.NODE_DEBUG||""),e=e.toUpperCase(),!x[e])if(new RegExp("\\b"+e+"\\b","i").test(T)){t.pid;x[e]=function(){r.format.apply(r,arguments)}}else x[e]=function(){};return x[e]},r.inspect=n,n.colors={bold:[1,22],italic:[3,23],underline:[4,24],inverse:[7,27],white:[37,39],grey:[90,39],black:[30,39],blue:[34,39],cyan:[36,39],green:[32,39],magenta:[35,39],red:[31,39],yellow:[33,39]},n.styles={special:"cyan",number:"yellow","boolean":"yellow",undefined:"grey","null":"bold",string:"green",date:"magenta",regexp:"red"},r.isArray=h,r.isBoolean=v,r.isNull=g,r.isNullOrUndefined=m,r.isNumber=_,r.isString=b,r.isSymbol=y,r.isUndefined=k,r.isRegExp=w,r.isObject=I,r.isDate=E,r.isError=U,r.isFunction=D,r.isPrimitive=P,r.isBuffer=e("./support/isBuffer");r.log=function(){},r.inherits=e("inherits"),r._extend=function(e,t){if(!t||!I(t))return e;for(var r=Object.keys(t),i=r.length;i--;)e[r[i]]=t[r[i]];return e}}).call(this,e("_process"),"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./support/isBuffer":29,_process:27,inherits:28}],31:[function(e,t,r){function i(e,t){var r;return r=t?new a(e,t):new a(e)}var n=function(){return this}(),a=n.WebSocket||n.MozWebSocket,o=e("./version");t.exports={w3cwebsocket:a?i:null,version:o}},{"./version":32}],32:[function(e,t,r){t.exports=e("../package.json").version},{"../package.json":33}],33:[function(e,t,r){t.exports={_args:[[{raw:"websocket@latest",scope:null,escapedName:"websocket",name:"websocket",rawSpec:"latest",spec:"latest",type:"tag"},"/Users/home/Documents/Malli_Workspace/BitBucket/WB-Polyfill/lib/blueapp-wb"]],_from:"websocket@latest",_id:"websocket@1.0.23",_inCache:!0,_installable:!0,_location:"/websocket",_nodeVersion:"0.10.45",_npmOperationalInternal:{host:"packages-16-east.internal.npmjs.com",tmp:"tmp/websocket-1.0.23.tgz_1463625793005_0.4532310354989022"},_npmUser:{name:"theturtle32",email:"brian@worlize.com"},_npmVersion:"2.15.1",_phantomChildren:{},_requested:{raw:"websocket@latest",scope:null,escapedName:"websocket",name:"websocket",rawSpec:"latest",spec:"latest",type:"tag"},_requiredBy:["/blueapp-wb","/gatt-ip"],_resolved:"https://registry.npmjs.org/websocket/-/websocket-1.0.23.tgz",_shasum:"20de8ec4a7126b09465578cd5dbb29a9c296aac6",_shrinkwrap:null,_spec:"websocket@latest",_where:"/Users/home/Documents/Malli_Workspace/BitBucket/WB-Polyfill/lib/blueapp-wb",author:{name:"Brian McKelvey",email:"brian@worlize.com",url:"https://www.worlize.com/"},browser:"lib/browser.js",bugs:{url:"https://github.com/theturtle32/WebSocket-Node/issues"},config:{verbose:!1},contributors:[{name:"IƱaki Baz Castillo",email:"ibc@aliax.net",url:"http://dev.sipdoc.net"}],dependencies:{debug:"^2.2.0",nan:"^2.3.3","typedarray-to-buffer":"^3.1.2",yaeti:"^0.0.4"},description:"Websocket Client & Server Library implementing the WebSocket protocol as specified in RFC 6455.",devDependencies:{"buffer-equal":"^0.0.1",faucet:"^0.0.1",gulp:"git+https://github.com/gulpjs/gulp.git#4.0","gulp-jshint":"^1.11.2","jshint-stylish":"^1.0.2",tape:"^4.0.1"},directories:{lib:"./lib"},dist:{shasum:"20de8ec4a7126b09465578cd5dbb29a9c296aac6",tarball:"https://registry.npmjs.org/websocket/-/websocket-1.0.23.tgz"},engines:{node:">=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
diff --git a/blueapp.io.min.js b/blueapp.io.min.js
index 8f335cc..a6fa828 100644
--- a/blueapp.io.min.js
+++ b/blueapp.io.min.js
@@ -1,7 +1,7 @@
 /* blueapp.io v0.0.1 */
-require=function e(t,r,i){function n(s,o){if(!r[s]){if(!t[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=r[s]={exports:{}};t[s][0].call(l.exports,function(e){var r=t[s][1][e];return n(r?r:e)},l,l.exports,e,t,r,i)}return r[s].exports}for(var a="function"==typeof require&&require,s=0;s<i.length;s++)n(i[s]);return n}({1:[function(e,t,r){function i(e,t,r){s.instantiateEmitter(this);var i=this,c=e.peripheral(),u=c.gattip(),l={},f={};a.requireUUID("Characteristic","uuid",t),this.uuid=t,r||(r={}),f=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 o(i,e);return l[e]=t},this.addDescriptor=function(e){return l[e.uuid]=e},this.hasProperty=function(e){return f[e]&&f[e].enabled},this.setProperty=function(e,t){return f[e]=t},this.allProperties=function(){return f},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"),s=e("./lib/event-emitter"),o=e("./descriptor").Descriptor;s.makeEmitter(i),t.exports.Characteristic=i},{"./descriptor":2,"./lib/constants.js":6,"./lib/event-emitter":7,"./lib/message-helper":10}],2:[function(e,t,r){function i(e,t){var r=this,i=e.service(),s=i.peripheral(),o=s.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 s},this.gattip=function(){return o},this.readValue=function(e){var t=a.populateParams(r);o.request(n.kGetDescriptorValue,t,e,function(t){a.requireFields("readValue",t,[n.kValue],[]),r.value=t[n.kValue],o.fulfill(e,r,r.value)})},this.writeValue=function(e,t){var i=a.populateParams(r);a.requireHexValue("writeValue","value",t),o.request(n.kWriteDescriptorValue,i,e,function(i){r.value=t,o.fulfill(e,r)})},this.respondToReadRequest=function(e,t){var i=a.populateParams(r);a.requireHexValue("respondToReadRequest","value",t),i[n.kValue]=t,o.respond(e,i)},this.respondToWriteRequest=function(e){var t=a.populateParams(r);o.respond(e,t)}}var n=e("./lib/constants.js").C,a=e("./lib/message-helper");t.exports.Descriptor=i},{"./lib/constants.js":6,"./lib/message-helper":10}],3:[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)}},{}],4:[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 s={};s[n.kDeviceAccessToken]=i,s[n.kGetVersionInfo]=a,e.request(n.kOpen,s,t,function(i){if(i.isAuthenticated===!0)e.fulfill(t,r);else{if(i[n.kOpen]!==!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 s={};"undefined"!=typeof i&&(s[n.kShowPowerAlert]=i),"undefined"!=typeof a&&(s[n.kIdentifierKey]=a),e.request(n.kConfigure,{},t,function(i){e.fulfill(t,r)})},this.handleScanIndication=function(i){var o=i[n.kPeripheralUUID];if(!o)throw new s("Peripheral UUID is not availabvle");if(t&&t.uuids)for(var c=0;c<t.uuids.length;c++){var u=t.uuids[c];if(u&&u.length&&u!=o)return}var l=r.getPeripheral(o);l?l._updateFromScanData(i[n.kPeripheralName],i[n.kRSSIkey],i[n.kCBAdvertisementDataTxPowerLevel],i[n.kCBAdvertisementDataIsConnectable],i[n.kCBAdvertisementDataServiceUUIDsKey],i[n.kCBAdvertisementDataManufacturerDataKey],i[n.kCBAdvertisementDataServiceDataKey],i[n.kAdvertisementDataKey],i[n.kScanRecord]):l=r.addPeripheral(new a(e,o,i[n.kPeripheralName],i[n.kRSSIkey],i[n.kCBAdvertisementDataTxPowerLevel],i[n.kCBAdvertisementDataIsConnectable],i[n.kCBAdvertisementDataServiceUUIDsKey],i[n.kCBAdvertisementDataManufacturerDataKey],i[n.kCBAdvertisementDataServiceDataKey],i[n.kAdvertisementDataKey],i[n.kScanRecord])),r.emit("scan",l)},this.addPeripheralWithValues=function(t,n,o,c,u,l,f){if(!t)throw new s("Attempting to add an empty peripheral");var p=r.addPeripheral(new a(e,t,n,o,c,u,l,f));return i[t]=p,p},this.addPeripheral=function(e){if(!e||!e.uuid)throw new s("Attempting to add an empty peripheral");return i[e.uuid]=e,e},this.removePeripheral=function(e){if(!e||!e.uuid)throw new s("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 s("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 s('_getObjects: Argument "type" is required')}throw new o('Descriptor "'+a+'" not found in the service table')}throw new o('Characteristic "'+n+'" not found in the service table')}throw new o('Service "'+r+'" not found in the service table')}throw new o("Peripheral with id "+t+" not found")},this.getObjectsFromMessage=function(e,t){if(!t)throw new s("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 s(i.message,i.detail)}}}var n=e("./lib/constants").C,a=(e("./lib/message-helper"),e("./peripheral").Peripheral),s=e("./errors").InternalError,o=e("./errors").ApplicationError,c=e("./lib/event-emitter");c.makeEmitter(i),t.exports.Gateway=i},{"./errors":3,"./lib/constants":6,"./lib/event-emitter":7,"./lib/message-helper":10,"./peripheral":14}],5:[function(e,t,r){function i(){function t(e){k.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,k=this;this.getGateway=function(){return m},this.traceMessage=function(e,t){k.traceEnabled&&"object"==typeof e&&(e=JSON.stringify(e))},this.getServerMessageHandler=function(){return v||t(new o("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){k.traceMessage(e,"<req:"),r(!1,e,v.processMessage)}),h.on("indication",function(e){t(new s("Received an indication on a server stream:"+JSON.stringify(e)))}),m=y,k.emit("ready",y)):e.isPassThrough?I():y.configure(function(){y.centralState(function(){if(y.isPoweredOn())y.isPoweredOn()&&I();else{k.emit("state",y.isPoweredOn());var e=setInterval(function(){y.centralState(function(){y.isPoweredOn()&&(k.emit("state",y.isPoweredOn()),clearInterval(e),I())})},500)}})})}function I(){h.on("indication",function(e){k.traceMessage(e,"<ind:"),r(!1,e,d.handleIndication)}),h.on("request",function(e){t(new a("Received a request on a client stream:"+JSON.stringify(e)))}),m=y,k.emit("ready",y)}function E(e){e.token?y._authenticate(function(){g(e)},e.token,e.version):g(e)}var y=new l(this,n.scanFilters);if(h=new u(this),d=new c(this,y),v=new f(this,y),n.trace===!0&&(k.traceEnabled=!0),n.url){var S;S="object"==typeof window?window.WebSocket:e("websocket").w3cwebsocket,i=new S(n.url,(void 0),(void 0),(void 0),(void 0),p),i.onopen=function(){E(n)},i.onclose=function(e){k.emit("onclose",e)},i.onerror=function(e){k.emit("onerror",e)}}else{if(!n.stream)throw new s("URL or stream implementing a socket interface is required");i=n.stream,E(n)}i.onmessage=function(e){r(!0,e.data,h.onMessageReceived)},h.on("response",function(e,t){k.traceMessage(e,"<rsp:");try{e.error?k.reject(t.cb,new o(e.error)):t.handler?t.handler(e.params):k.fulfill(t.cb)}catch(r){k.reject(t.cb,r)}}),h.on("error",function(e){k.emit("error",e)})},this.close=function(){i&&i.close()},this.request=function(e,t,r,n){var a=d.createUserContext(e,t,r,n),s=a.originalMessage;h.register(s,a),k.traceMessage(s,">req:"),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:"cbl",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.connectable="true":e.connectable="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;i<advArrayLength;i++)e.url+=String.fromCharCode(parseInt(t[i],16));for(var n in p.AllDomains)t[advArrayLength]==n&&(e.url+=p.AllDomains[n])}function f(e,t){e.frameType="TLM",e.advPacketCount="",e.timeInterval="",e.batteryVoltage="",e.eddyVersion=parseInt(t[5],16);for(var r=6;r<8;r++)e.batteryVoltage+=t[r];e.batteryVoltage=parseInt(e.batteryVoltage,16),e.temperature=Math.ceil(parseInt(t[8],16)),e.temperature+=".";var i=Math.ceil(1/256*parseInt(t[9],16));i.length>2?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;l<t.length;l+=2)u[l/2]=t.charAt(l)+t.charAt(l+1);else for(var f=0;f<t.length;f++)u[f]=t.charAt(2*f)+t.charAt(2*f+1);for(;;){var h=u[1];if(h==p.kGAP_ADTYPE_FLAGS)i(r,u);else if(h==p.kGAP_ADTYPE_POWER_LEVEL)n(r,u);else if(h==p.kGAP_ADTYPE_INCOMPLETE_16BIT_SERVICEUUID||h==p.kGAP_ADTYPE_COMPLETE_16BIT_SERVICEUUID)s(r,u);else if(h==p.kGAP_ADTYPE_INCOMPLETE_32BIT_SERVICEUUID||h==p.kGAP_ADTYPE_COMPLETE_32BIT_SERVICEUUID)s(r,u);else if(h==p.kGAP_ADTYPE_INCOMPLETE_128BIT_SERVICEUUID||h==p.kGAP_ADTYPE_COMPLETE_128BIT_SERVICEUUID)o(r,u);else if(h==p.kGAP_ADTYPE_MANUFACTURER_SPECIFIC)a(r,u);else if(h==p.kGAP_ADTYPE_16BIT_SERVICE_DATA)c(r,u);else if("00"==h)u.splice(0,1);else{var d=parseInt(u[0],16);u.splice(0,d+1)}if(0===u.length)break}}},{"./constants":6}],9:[function(e,t,r){var i=e("./constants").C,n=e("./message-helper"),a=e("./../errors").InternalError,s=e("./../errors").ApplicationError;t.exports.MessageHandler=function(e,t){this.createUserContext=function(e,t,r,i){var n={method:e,params:t,jsonrpc:"2.0"};return{originalMessage:n,cb:r,handler:i}},this.wrapResponse=function(e,t){var r={params:t,jsonrpc:"2.0"};return n.requireAndPopulateFieldsFromCookie("wrapResponse",e,r),r},this.handleIndication=function(e){if(e.error)throw new s(JSON.stringify(e));var r=e.params;switch(e.result){case i.kScanForPeripherals:t.handleScanIndication(r);break;case i.kDisconnect:!function(){n.requireFields("Disconnect indication",r,[i.kPeripheralUUID]);var e=t.getPeripheral(r[i.kPeripheralUUID]);e&&e.handleDisconnectIndication(e)}();break;case i.kSetValueNotification:!function(){n.requireFields("Disconnect indication",r,[i.kPeripheralUUID]);var a=t.getPeripheral(r[i.kPeripheralUUID]);if(a){n.requireFields("Value notification",r,[i.kPeripheralUUID,i.kServiceUUID,i.kCharacteristicUUID,i.kValue]);var s=t.getObjectsFromMessage("c",e.params);s.characteristic.handleValueNotification(r)}}();break;default:!function(){throw new a("Unknown indication received from the gateway:",JSON.stringify(e))}()}}}},{"./../errors":3,"./constants":6,"./message-helper":10}],10:[function(e,t,r){function i(e){var t="";if("object"==typeof e){if(Array.isArray(e)){for(var r in e)0!=r&&(t+=" ,"),t+=e[r]}for(var n in e)if(e.hasOwnProperty(n)){var s=e[n],o=a[n];o||(o=n),t+="object"==typeof s?Array.isArray(s)?" "+o+":["+i(s)+"]":" "+o+":{"+i(s)+"}":" "+o+"="+s}}return t}var n=e("./constants").C,a={},s=e("./../errors").InternalError,o=e("./../errors").ApplicationError;for(var c in n){var u=n[c];0==c.indexOf("k")&&(c=c.substring(1,c.length),a[u]=c)}t.exports.isEmpty=function(e){for(var t in e)if(e.hasOwnProperty(t))return!1;return JSON.stringify(e)===JSON.stringify({})},t.exports.arrayAsHex=function(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},t.exports.toString=function(e){return i(e.params).trim()},t.exports.requireAndAssignParameters=function(e,r,i,n){t.exports.requireFields(e+" call parameters ",r,i,n)},t.exports.requireBooleanValue=function(e,t,r){if("boolean"!=typeof r)throw new o(e+" missing parameter "+t)},t.exports.requireHexValue=function(e,t,r){if("string"!=typeof r)throw new o(e+" missing parameter "+t);if(r.length>0&&(r.length%2!=0||!/^[0-9a-fA-F]+$/.test(r)))throw new o(e+" value "+t+" is not a valid hex string")},t.exports.requireUUID=function(e,t,r){if("string"!=typeof r)throw new o(e+" missing parameter "+t);if(r.length<4||!/^[0-9A-F-]+$/.test(r))throw new o(e+" value "+t+" is not a valid UUID")},t.exports.requireHexValues=function(e,t,r){var i=[];if(!Array.isArray(t)||!Array.isArray(r))throw new s("Illegal use of requireHexValues");for(var n=0;n<t.length;n++){var a=t[n],c=r[n];("string"!=typeof c||c.length<2||c.length%2!=0||!/^#[0-9A-F]$/i.test(c))&&i.push(a)}if(i)throw new o(e+" missing parameters "+i)},t.exports.requireFields=function(e,t,r,i){var n=[];if(i||(i={}),!t)throw new s(e+"Object is undefined");for(var a=0;a<r.length;a++){var o=r[a];void 0==typeof t[o]&&(void 0==typeof i[a]?n.push(r):t[o]=i[a])}if(n.length)throw new s(e+" missing "+n)},t.exports.requireAndPopulateFieldsFromCookie=function(e,t,r){if(!t)throw new o('Error: "'+e+" is missing the cookie");if(!t.original.id)throw new o('Error: "'+e+" is missing the cookie ID");if(!t.original.session_id)throw new o('Error: "'+e+" is missing the cookie session ID");if(!t.original.method)throw new o('Error: "'+e+" is missing the cookie request");r[n.kMessageId]=t.original.id,r[n.kSessionId]=t.original.session_id,r.result=t.result},t.exports.populateParams=function(e,t){function r(e,r){u--;var i=r.uuid;if(!i)throw new s('UUID for object of type "'+r.type+'" is missing');t[e]=i}if(t||(t={}),!e)throw new s("populateParams: service object is undefined");var i,a,o,c,u=23132;switch(e.type){case"d":u=4,c=e;break;case"c":u=3,o=e;break;case"s":u=2,a=e;break;case"p":u=1,i=e;break;default:throw new s('type must be one of: "s", "c" or "d"')}if(c&&(r(n.kDescriptorUUID,c),o=c.characteristic()),o&&(r(n.kCharacteristicUUID,o),a=o.service()),a&&(r(n.kServiceUUID,a),i=o.peripheral()),i&&r(n.kPeripheralUUID,i),0!=u)throw new s("Expected "+u+" more parts when constructing params of "+e.type);return t}},{"./../errors":3,"./constants":6}],11:[function(e,t,r){function i(e,t,r,i){this.msg=t,this.userContext=r,"undefined"==typeof t.id&&(t.id=Number(c++).toString()),this.id=t.id,i||(i=s.DEFAULT_MESSAGE_TIMEOUT_MS);var n=this;this.timeout=setTimeout(function(){delete n.timeout,e.emit("error",new o("Timed out : "+JSON.stringify(t)),n.userContext.cb)},i)}function n(){a.instantiateEmitter(this);var e=this,t={};this.register=function(r,n,a){if(Object.keys(t).length>s.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){a.instantiateEmitter(this);var r=this;this.processMessage=function(e){function i(i){var a=l[n.kPeripheralUUID],s={};if(s.peripheral=t.getPeripheral(a),s.peripheral&&s.peripheral.uuid){if("p"===i)return s;var o=l[n.kServiceUUID];if(s.service=s.peripheral.findService(o),s.service&&s.service.uuid){if("s"===i)return s;var c=l[n.kCharacteristicUUID];if(s.characteristic=s.service.findCharacteristic(c),s.characteristic&&s.characteristic.uuid){if("c"===i)return s;var u=l[n.kDescriptorUUID];if(s.descriptor=s.characteristic.findDescriptor(u),s.descriptor&&s.descriptor.uuid)return s;throw r.sendErrorResponse(e.method,n.kErrorDescriptorNotFound,"Descriptor not found in the service database"),new Error("Descriptor not found")}throw r.sendErrorResponse(e.method,n.kErrorCharacteristicNotFound,"Characteristic not found in the service database"),new Error("Characteristic not found")}throw r.sendErrorResponse(e.method,n.kErrorServiceNotFound,"Service not found in the service database"),new Error("Service not found")}throw r.sendErrorResponse(e.method,n.kErrorPeripheralNotFound,"Peripheral not found in the service database"),new Error("Peripheral not found")}var a;if("undefined"!=typeof e&&e&&!e.error){if(e.result&&(e.result==n.kMessage||e.result==n.kAuthenticate)){var s=!1;return e.error||"object"!=typeof e.params||e.params[n.kAuthenticate]!==!0||(s=!0),void r.emit("authenticated",s)}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 r.send(c)}var u={original:e},l=e.params;switch(e.method){case n.kConfigure:r.emit("configure",u,l[n.kShowPowerAlert],l[n.kIdentifierKey]);break;case n.kScanForPeripherals:r.emit("scan",u,l[n.kScanOptionAllowDuplicatesKey],l[n.kServiceUUIDs]);break;case n.kStopScanning:r.emit("stopScan",u);break;case n.kCentralState:r.emit("getCentralState",u);break;case n.kConnect:try{a=i("p"),r.emit("connect",u,a.peripheral.uuid)}catch(f){}break;case n.kDisconnect:try{a=i("p"),r.emit("disconnect",u,a.peripheral.uuid)}catch(f){}break;case n.kGetCharacteristicValue:try{a=i("c",u),r.emit("readCharacteristic",u,a.peripheral.uuid,a.service.uuid,a.characteristic.uuid)}catch(f){}break;case n.kWriteCharacteristicValue:try{a=i("c",u),r.emit("writeCharacteristic",u,a.peripheral.uuid,a.service.uuid,a.characteristic.uuid,e.params[n.kValue])}catch(f){}break;case n.kSetValueNotification:try{a=i("c",u),r.emit("enableNotifications",u,a.peripheral.uuid,a.service.uuid,a.characteristic.uuid,e.params[n.kIsNotifying])}catch(f){}break;case n.kGetDescriptorValue:try{a=i("d",u),r.emit("readDescriptor",u,a.peripheral.uuid,a.service.uuid,a.characteristic.uuid,a.descriptor.uuid)}catch(f){}break;case n.kWriteDescriptorValue:try{a=i("d",u),r.emit("writeDescriptor",u,a.peripheral.uuid,a.service.uuid,a.characteristic.uuid,a.descriptor.uuid,e.params[n.kValue])}catch(f){}break;default:return void r.sendErrorResponse(u,e.method,n.kInvalidRequest,"Request not handled by server")}}},r.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)},r.configureResponse=function(t){t.result=n.kConfigure,e.respond(t,{})},r.centralStateResponse=function(t,r){var i={};i[n.kState]=r,t.result=n.kCentralState,e.respond(t,i)},r.stopScanResponse=function(t){t.result=n.kStopScanning,e.respond(t,{})},r.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)},r.scanResponse=function(t,r,i,a,o,c,u,l,f){if(t)return t.result=n.kScanForPeripherals,void e.respond(t,{});var p,h,d={};if(!s.isEmpty(u)){p={};for(var v in u){var m=v.toUpperCase();p[m]=s.arrayAsHex(u[v]).toUpperCase()}}if(!s.isEmpty(l)){h={};for(var k in l){var g=k.toUpperCase();h[g]=s.arrayAsHex(l[k]).toUpperCase()}}d[n.kPeripheralName]=i,d[n.kPeripheralUUID]=r,d[n.kRSSIkey]=a,d[n.kCBAdvertisementDataTxPowerLevel]=o,d[n.kCBAdvertisementDataIsConnectable]=f,d[n.kCBAdvertisementDataServiceUUIDsKey]=c&&c.length>0?c:void 0,d[n.kCBAdvertisementDataManufacturerDataKey]=p,d[n.kCBAdvertisementDataServiceDataKey]=h,e.sendIndications(n.kScanForPeripherals,d)},r.addPeripheral=function(e,t,i,n,a){var s=new Peripheral(this,e,t,i,n,a);return r.peripherals[s.uuid]=s,s}}var n=e("./constants.js").C,a=e("./event-emitter"),s=e("./message-helper");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,"./message-helper":10}],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,c,u,l,f){this.name=e,this.rssi=t,this.txPowerLevel=r,this.connectable=n;if(c)for(var p in c){
-var d=p.toUpperCase();v[d]=c[p].toUpperCase()}if(u)for(var g in u)m[g]=u[g];if(a)for(var I=0;I<a.length;I++)i(k,a[I]);if(l){if(o.parseAdvArray(h,l.c2),h.advdata.connectable&&(h.connectable="true"===h.advdata.connectable),h.advdata.txPowerLevel&&(this.txPowerLevel=h.advdata.txPowerLevel),h.advdata.manufacturerData&&!s.isEmpty(h.advdata.manufacturerData))for(var E in h.advdata.manufacturerData){var y=E.toUpperCase();v[y]=h.advdata.manufacturerData[E].toUpperCase()}h.advdata.serviceUUIDs&&h.advdata.serviceUUIDs.length>0&&i(k,h.advdata.serviceUUIDs)}},this.findService=function(e){return d[e]},this.getMfrData=function(e){return v[e]},this.getSvcData=function(e){return m[e]},this.hasAdvertisedServiceUUID=function(e){return k.indexOf(e)>=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;c<i;c++)u[c].apply(this,a);return!0},i.prototype.addListener=function(e,t){var r;if(!n(t))throw TypeError("listener must be a function");return this._events||(this._events={}),this._events.newListener&&this.emit("newListener",e,n(t.listener)?t.listener:t),this._events[e]?s(this._events[e])?this._events[e].push(t):this._events[e]=[this._events[e],t]:this._events[e]=t,s(this._events[e])&&!this._events[e].warned&&(r=o(this._maxListeners)?i.defaultMaxListeners:this._maxListeners,r&&r>0&&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&&o&&(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=[];++f<t;)o&&o[f].run();f=-1,t=u.length}o=null,l=!1,clearTimeout(e)}}function a(e,t){this.fun=e,this.array=t}function s(){}var o,c=t.exports={},u=[],l=!1,f=-1;c.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var r=1;r<arguments.length;r++)t[r-1]=arguments[r];u.push(new a(e,t)),1!==u.length||l||setTimeout(n,0)},a.prototype.run=function(){this.fun.apply(null,this.array)},c.title="browser",c.browser=!0,c.env={},c.argv=[],c.version="",c.versions={},c.on=s,c.addListener=s,c.once=s,c.off=s,c.removeListener=s,c.removeAllListeners=s,c.emit=s,c.binding=function(e){throw new Error("process.binding is not supported")},c.cwd=function(){return"/"},c.chdir=function(e){throw new Error("process.chdir is not supported")},c.umask=function(){return 0}},{}],20:[function(e,t,r){t.exports=function(e){return e&&"object"==typeof e&&"function"==typeof e.copy&&"function"==typeof e.fill&&"function"==typeof e.readUInt8}},{}],21:[function(e,t,r){(function(t,i){function n(e,t){var i={seen:[],stylize:s};return arguments.length>=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&&C(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(C(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=["[","]"]),C(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<o;++s)U(t,String(s))?a.push(p(e,t,r,i,String(s),!0)):a.push("");return n.forEach(function(n){n.match(/^\d+$/)||a.push(p(e,t,r,i,n,!0))}),a}function p(e,t,r,i,n,a){var s,o,u;if(u=Object.getOwnPropertyDescriptor(t,n)||{value:t[n]},u.get?o=u.set?e.stylize("[Getter/Setter]","special"):e.stylize("[Getter]","special"):u.set&&(o=e.stylize("[Setter]","special")),U(i,n)||(s="["+n+"]"),o||(e.seen.indexOf(u.value)<0?(o=m(r)?c(e,u.value,null):c(e,u.value,r-1),o.indexOf("\n")>-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]"===_(e)}function P(e){return"object"==typeof e&&null!==e}function D(e){return P(e)&&"[object Date]"===_(e)}function A(e){return P(e)&&("[object Error]"===_(e)||e instanceof Error)}function C(e){return"function"==typeof e}function b(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 U(e,t){return Object.prototype.hasOwnProperty.call(e,t)}var w=/%[sdj%]/g;r.format=function(e){if(!I(e)){for(var t=[],r=0;r<arguments.length;r++)t.push(n(arguments[r]));return t.join(" ")}for(var r=1,i=arguments,a=i.length,s=String(e).replace(w,function(e){if("%%"===e)return"%";if(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<a;o=i[++r])s+=m(o)||!P(o)?" "+o:" "+n(o);return s},r.deprecate=function(e,n){function a(){if(!s){if(t.throwDeprecation)throw new Error(n);t.traceDeprecation,s=!0}return e.apply(this,arguments)}if(y(i.process))return function(){return r.deprecate(e,n).apply(this,arguments)};if(t.noDeprecation===!0)return e;var s=!1;return a};var T,R={};r.debuglog=function(e){if(y(T)&&(T=t.env.NODE_DEBUG||""),e=e.toUpperCase(),!R[e])if(new RegExp("\\b"+e+"\\b","i").test(T)){t.pid;R[e]=function(){r.format.apply(r,arguments)}}else R[e]=function(){};return R[e]},r.inspect=n,n.colors={bold:[1,22],italic:[3,23],underline:[4,24],inverse:[7,27],white:[37,39],grey:[90,39],black:[30,39],blue:[34,39],cyan:[36,39],green:[32,39],magenta:[35,39],red:[31,39],yellow:[33,39]},n.styles={special:"cyan",number:"yellow","boolean":"yellow",undefined:"grey","null":"bold",string:"green",date:"magenta",regexp:"red"},r.isArray=d,r.isBoolean=v,r.isNull=m,r.isNullOrUndefined=k,r.isNumber=g,r.isString=I,r.isSymbol=E,r.isUndefined=y,r.isRegExp=S,r.isObject=P,r.isDate=D,r.isError=A,r.isFunction=C,r.isPrimitive=b,r.isBuffer=e("./support/isBuffer");r.log=function(){},r.inherits=e("inherits"),r._extend=function(e,t){if(!t||!P(t))return e;for(var r=Object.keys(t),i=r.length;i--;)e[r[i]]=t[r[i]];return e}}).call(this,e("_process"),"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./support/isBuffer":20,_process:19,inherits:18}],"gatt-ip":[function(e,t,r){t.exports.GATTIP=e("./gattip").GATTIP,t.exports.C=e("./lib/constants").C},{"./gattip":5,"./lib/constants":6}]},{},[]);
+require=function e(t,r,i){function n(s,o){if(!r[s]){if(!t[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=r[s]={exports:{}};t[s][0].call(l.exports,function(e){var r=t[s][1][e];return n(r?r:e)},l,l.exports,e,t,r,i)}return r[s].exports}for(var a="function"==typeof require&&require,s=0;s<i.length;s++)n(i[s]);return n}({1:[function(e,t,r){function i(e,t,r){s.instantiateEmitter(this);var i=this,c=e.peripheral(),u=c.gattip(),l={},f={};a.requireUUID("Characteristic","uuid",t),this.uuid=t,r||(r={}),f=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 o(i,e);return l[e]=t},this.addDescriptor=function(e){return l[e.uuid]=e},this.hasProperty=function(e){return f[e]&&f[e].enabled},this.setProperty=function(e,t){return f[e]=t},this.allProperties=function(){return f},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"),s=e("./lib/event-emitter"),o=e("./descriptor").Descriptor;s.makeEmitter(i),t.exports.Characteristic=i},{"./descriptor":2,"./lib/constants.js":6,"./lib/event-emitter":7,"./lib/message-helper":10}],2:[function(e,t,r){function i(e,t){var r=this,i=e.service(),s=i.peripheral(),o=s.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 s},this.gattip=function(){return o},this.readValue=function(e){var t=a.populateParams(r);o.request(n.kGetDescriptorValue,t,e,function(t){a.requireFields("readValue",t,[n.kValue],[]),r.value=t[n.kValue],o.fulfill(e,r,r.value)})},this.writeValue=function(e,t){var i=a.populateParams(r);a.requireHexValue("writeValue","value",t),o.request(n.kWriteDescriptorValue,i,e,function(i){r.value=t,o.fulfill(e,r)})},this.respondToReadRequest=function(e,t){var i=a.populateParams(r);a.requireHexValue("respondToReadRequest","value",t),i[n.kValue]=t,o.respond(e,i)},this.respondToWriteRequest=function(e){var t=a.populateParams(r);o.respond(e,t)}}var n=e("./lib/constants.js").C,a=e("./lib/message-helper");t.exports.Descriptor=i},{"./lib/constants.js":6,"./lib/message-helper":10}],3:[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)}},{}],4:[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 s={};s[n.kDeviceAccessToken]=i,s[n.kGetVersionInfo]=a,e.request(n.kOpen,s,t,function(i){if(i.isAuthenticated===!0)e.fulfill(t,r);else{if(i[n.kOpen]!==!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 s={};"undefined"!=typeof i&&(s[n.kShowPowerAlert]=i),"undefined"!=typeof a&&(s[n.kIdentifierKey]=a),e.request(n.kConfigure,{},t,function(i){e.fulfill(t,r)})},this.handleScanIndication=function(i){var o=i[n.kPeripheralUUID];if(!o)throw new s("Peripheral UUID is not availabvle");if(t&&t.uuids)for(var c=0;c<t.uuids.length;c++){var u=t.uuids[c];if(u&&u.length&&u!=o)return}var l=r.getPeripheral(o);l?l._updateFromScanData(i[n.kPeripheralName],i[n.kRSSIkey],i[n.kCBAdvertisementDataTxPowerLevel],i[n.kCBAdvertisementDataIsConnectable],i[n.kCBAdvertisementDataServiceUUIDsKey],i[n.kCBAdvertisementDataManufacturerDataKey],i[n.kCBAdvertisementDataServiceDataKey],i[n.kAdvertisementDataKey],i[n.kScanRecord]):l=r.addPeripheral(new a(e,o,i[n.kPeripheralName],i[n.kRSSIkey],i[n.kCBAdvertisementDataTxPowerLevel],i[n.kCBAdvertisementDataIsConnectable],i[n.kCBAdvertisementDataServiceUUIDsKey],i[n.kCBAdvertisementDataManufacturerDataKey],i[n.kCBAdvertisementDataServiceDataKey],i[n.kAdvertisementDataKey],i[n.kScanRecord])),r.emit("scan",l)},this.addPeripheralWithValues=function(t,n,o,c,u,l,f){if(!t)throw new s("Attempting to add an empty peripheral");var p=r.addPeripheral(new a(e,t,n,o,c,u,l,f));return i[t]=p,p},this.addPeripheral=function(e){if(!e||!e.uuid)throw new s("Attempting to add an empty peripheral");return i[e.uuid]=e,e},this.removePeripheral=function(e){if(!e||!e.uuid)throw new s("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 s("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 s('_getObjects: Argument "type" is required')}throw new o('Descriptor "'+a+'" not found in the service table')}throw new o('Characteristic "'+n+'" not found in the service table')}throw new o('Service "'+r+'" not found in the service table')}throw new o("Peripheral with id "+t+" not found")},this.getObjectsFromMessage=function(e,t){if(!t)throw new s("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 s(i.message,i.detail)}}}var n=e("./lib/constants").C,a=(e("./lib/message-helper"),e("./peripheral").Peripheral),s=e("./errors").InternalError,o=e("./errors").ApplicationError,c=e("./lib/event-emitter");c.makeEmitter(i),t.exports.Gateway=i},{"./errors":3,"./lib/constants":6,"./lib/event-emitter":7,"./lib/message-helper":10,"./peripheral":14}],5:[function(e,t,r){function i(){function t(e){k.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,k=this;this.getGateway=function(){return m},this.traceMessage=function(e,t){k.traceEnabled&&"object"==typeof e&&(e=JSON.stringify(e))},this.getServerMessageHandler=function(){return v||t(new o("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){k.traceMessage(e,"<req:"),r(!1,e,v.processMessage)}),h.on("indication",function(e){t(new s("Received an indication on a server stream:"+JSON.stringify(e)))}),m=y,k.emit("ready",y)):e.isPassThrough?I():y.configure(function(){y.centralState(function(){if(y.isPoweredOn())y.isPoweredOn()&&I();else{k.emit("state",y.isPoweredOn());var e=setInterval(function(){y.centralState(function(){y.isPoweredOn()&&(k.emit("state",y.isPoweredOn()),clearInterval(e),I())})},500)}})})}function I(){h.on("indication",function(e){k.traceMessage(e,"<ind:"),r(!1,e,d.handleIndication)}),h.on("request",function(e){t(new a("Received a request on a client stream:"+JSON.stringify(e)))}),m=y,k.emit("ready",y)}function E(e){e.token?y._authenticate(function(){g(e)},e.token,e.version):g(e)}var y=new l(this,n.scanFilters);if(h=new u(this),d=new c(this,y),v=new f(this,y),n.trace===!0&&(k.traceEnabled=!0),n.url){var S;S="object"==typeof window?window.WebSocket:e("websocket").w3cwebsocket,i=new S(n.url,(void 0),(void 0),(void 0),(void 0),p),i.onopen=function(){E(n)},i.onclose=function(e){k.emit("onclose",e)},i.onerror=function(e){k.emit("onerror",e)}}else{if(!n.stream)throw new s("URL or stream implementing a socket interface is required");i=n.stream,E(n)}i.onmessage=function(e){r(!0,e.data,h.onMessageReceived)},h.on("response",function(e,t){k.traceMessage(e,"<rsp:");try{e.error?k.reject(t.cb,new o(e.error)):t.handler?t.handler(e.params):k.fulfill(t.cb)}catch(r){k.reject(t.cb,r)}}),h.on("error",function(e){k.emit("error",e)})},this.close=function(){i&&i.close()},this.request=function(e,t,r,n){var a=d.createUserContext(e,t,r,n),s=a.originalMessage;h.register(s,a),k.traceMessage(s,">req:"),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:"cbl",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.connectable="true":e.connectable="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;i<advArrayLength;i++)e.url+=String.fromCharCode(parseInt(t[i],16));for(var n in p.AllDomains)t[advArrayLength]==n&&(e.url+=p.AllDomains[n])}function f(e,t){e.frameType="TLM",e.advPacketCount="",e.timeInterval="",e.batteryVoltage="",e.eddyVersion=parseInt(t[5],16);for(var r=6;r<8;r++)e.batteryVoltage+=t[r];e.batteryVoltage=parseInt(e.batteryVoltage,16),e.temperature=Math.ceil(parseInt(t[8],16)),e.temperature+=".";var i=Math.ceil(1/256*parseInt(t[9],16));i.length>2?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;l<t.length;l+=2)u[l/2]=t.charAt(l)+t.charAt(l+1);else for(var f=0;f<t.length;f++)u[f]=t.charAt(2*f)+t.charAt(2*f+1);for(;;){var h=u[1];if(h==p.kGAP_ADTYPE_FLAGS)i(r,u);else if(h==p.kGAP_ADTYPE_POWER_LEVEL)n(r,u);else if(h==p.kGAP_ADTYPE_INCOMPLETE_16BIT_SERVICEUUID||h==p.kGAP_ADTYPE_COMPLETE_16BIT_SERVICEUUID)s(r,u);else if(h==p.kGAP_ADTYPE_INCOMPLETE_32BIT_SERVICEUUID||h==p.kGAP_ADTYPE_COMPLETE_32BIT_SERVICEUUID)s(r,u);else if(h==p.kGAP_ADTYPE_INCOMPLETE_128BIT_SERVICEUUID||h==p.kGAP_ADTYPE_COMPLETE_128BIT_SERVICEUUID)o(r,u);else if(h==p.kGAP_ADTYPE_MANUFACTURER_SPECIFIC)a(r,u);else if(h==p.kGAP_ADTYPE_16BIT_SERVICE_DATA)c(r,u);else if("00"==h)u.splice(0,1);else{var d=parseInt(u[0],16);u.splice(0,d+1)}if(0===u.length)break}}},{"./constants":6}],9:[function(e,t,r){var i=e("./constants").C,n=e("./message-helper"),a=e("./../errors").InternalError,s=e("./../errors").ApplicationError;t.exports.MessageHandler=function(e,t){this.createUserContext=function(e,t,r,i){var n={method:e,params:t,jsonrpc:"2.0"};return{originalMessage:n,cb:r,handler:i}},this.wrapResponse=function(e,t){var r={params:t,jsonrpc:"2.0"};return n.requireAndPopulateFieldsFromCookie("wrapResponse",e,r),r},this.handleIndication=function(e){if(e.error)throw new s(JSON.stringify(e));var r=e.params;switch(e.result){case i.kScanForPeripherals:t.handleScanIndication(r);break;case i.kDisconnect:!function(){n.requireFields("Disconnect indication",r,[i.kPeripheralUUID]);var e=t.getPeripheral(r[i.kPeripheralUUID]);e&&e.handleDisconnectIndication(e)}();break;case i.kSetValueNotification:!function(){n.requireFields("Disconnect indication",r,[i.kPeripheralUUID]);var a=t.getPeripheral(r[i.kPeripheralUUID]);if(a){n.requireFields("Value notification",r,[i.kPeripheralUUID,i.kServiceUUID,i.kCharacteristicUUID,i.kValue]);var s=t.getObjectsFromMessage("c",e.params);s.characteristic.handleValueNotification(r)}}();break;default:!function(){throw new a("Unknown indication received from the gateway:",JSON.stringify(e))}()}}}},{"./../errors":3,"./constants":6,"./message-helper":10}],10:[function(e,t,r){function i(e){var t="";if("object"==typeof e){if(Array.isArray(e)){for(var r in e)0!=r&&(t+=" ,"),t+=e[r]}for(var n in e)if(e.hasOwnProperty(n)){var s=e[n],o=a[n];o||(o=n),t+="object"==typeof s?Array.isArray(s)?" "+o+":["+i(s)+"]":" "+o+":{"+i(s)+"}":" "+o+"="+s}}return t}var n=e("./constants").C,a={},s=e("./../errors").InternalError,o=e("./../errors").ApplicationError;for(var c in n){var u=n[c];0==c.indexOf("k")&&(c=c.substring(1,c.length),a[u]=c)}t.exports.isEmpty=function(e){for(var t in e)if(e.hasOwnProperty(t))return!1;return JSON.stringify(e)===JSON.stringify({})},t.exports.arrayAsHex=function(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},t.exports.toString=function(e){return i(e.params).trim()},t.exports.requireAndAssignParameters=function(e,r,i,n){t.exports.requireFields(e+" call parameters ",r,i,n)},t.exports.requireBooleanValue=function(e,t,r){if("boolean"!=typeof r)throw new o(e+" missing parameter "+t)},t.exports.requireHexValue=function(e,t,r){if("string"!=typeof r)throw new o(e+" missing parameter "+t);if(r.length>0&&(r.length%2!=0||!/^[0-9a-fA-F]+$/.test(r)))throw new o(e+" value "+t+" is not a valid hex string")},t.exports.requireUUID=function(e,t,r){if("string"!=typeof r)throw new o(e+" missing parameter "+t);if(r.length<4||!/^[0-9A-F-]+$/.test(r))throw new o(e+" value "+t+" is not a valid UUID")},t.exports.requireHexValues=function(e,t,r){var i=[];if(!Array.isArray(t)||!Array.isArray(r))throw new s("Illegal use of requireHexValues");for(var n=0;n<t.length;n++){var a=t[n],c=r[n];("string"!=typeof c||c.length<2||c.length%2!=0||!/^#[0-9A-F]$/i.test(c))&&i.push(a)}if(i)throw new o(e+" missing parameters "+i)},t.exports.requireFields=function(e,t,r,i){var n=[];if(i||(i={}),!t)throw new s(e+"Object is undefined");for(var a=0;a<r.length;a++){var o=r[a];void 0==typeof t[o]&&(void 0==typeof i[a]?n.push(r):t[o]=i[a])}if(n.length)throw new s(e+" missing "+n)},t.exports.requireAndPopulateFieldsFromCookie=function(e,t,r){if(!t)throw new o('Error: "'+e+" is missing the cookie");if(!t.original.id)throw new o('Error: "'+e+" is missing the cookie ID");if(!t.original.session_id)throw new o('Error: "'+e+" is missing the cookie session ID");if(!t.original.method)throw new o('Error: "'+e+" is missing the cookie request");r[n.kMessageId]=t.original.id,r[n.kSessionId]=t.original.session_id,r.result=t.result},t.exports.populateParams=function(e,t){function r(e,r){u--;var i=r.uuid;if(!i)throw new s('UUID for object of type "'+r.type+'" is missing');t[e]=i}if(t||(t={}),!e)throw new s("populateParams: service object is undefined");var i,a,o,c,u=23132;switch(e.type){case"d":u=4,c=e;break;case"c":u=3,o=e;break;case"s":u=2,a=e;break;case"p":u=1,i=e;break;default:throw new s('type must be one of: "s", "c" or "d"')}if(c&&(r(n.kDescriptorUUID,c),o=c.characteristic()),o&&(r(n.kCharacteristicUUID,o),a=o.service()),a&&(r(n.kServiceUUID,a),i=o.peripheral()),i&&r(n.kPeripheralUUID,i),0!=u)throw new s("Expected "+u+" more parts when constructing params of "+e.type);return t}},{"./../errors":3,"./constants":6}],11:[function(e,t,r){function i(e,t,r,i){this.msg=t,this.userContext=r,"undefined"==typeof t.id&&(t.id=Number(c++).toString()),this.id=t.id,i||(i=s.DEFAULT_MESSAGE_TIMEOUT_MS);var n=this;this.timeout=setTimeout(function(){delete n.timeout,e.emit("error",new o("Timed out : "+JSON.stringify(t)),n.userContext.cb)},i)}function n(){a.instantiateEmitter(this);var e=this,t={};this.register=function(r,n,a){if(Object.keys(t).length>s.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){a.instantiateEmitter(this);var r=this;this.processMessage=function(e){function i(i){var a=l[n.kPeripheralUUID],s={};if(s.peripheral=t.getPeripheral(a),s.peripheral&&s.peripheral.uuid){if("p"===i)return s;var o=l[n.kServiceUUID];if(s.service=s.peripheral.findService(o),s.service&&s.service.uuid){if("s"===i)return s;var c=l[n.kCharacteristicUUID];if(s.characteristic=s.service.findCharacteristic(c),s.characteristic&&s.characteristic.uuid){if("c"===i)return s;var u=l[n.kDescriptorUUID];if(s.descriptor=s.characteristic.findDescriptor(u),s.descriptor&&s.descriptor.uuid)return s;throw r.sendErrorResponse(e.method,n.kErrorDescriptorNotFound,"Descriptor not found in the service database"),new Error("Descriptor not found")}throw r.sendErrorResponse(e.method,n.kErrorCharacteristicNotFound,"Characteristic not found in the service database"),new Error("Characteristic not found")}throw r.sendErrorResponse(e.method,n.kErrorServiceNotFound,"Service not found in the service database"),new Error("Service not found")}throw r.sendErrorResponse(e.method,n.kErrorPeripheralNotFound,"Peripheral not found in the service database"),new Error("Peripheral not found")}var a;if("undefined"!=typeof e&&e&&!e.error){if(e.result&&(e.result==n.kMessage||e.result==n.kAuthenticate)){var s=!1;return e.error||"object"!=typeof e.params||e.params[n.kAuthenticate]!==!0||(s=!0),void r.emit("authenticated",s)}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 r.send(c)}var u={original:e},l=e.params;switch(e.method){case n.kConfigure:r.emit("configure",u,l[n.kShowPowerAlert],l[n.kIdentifierKey]);break;case n.kScanForPeripherals:r.emit("scan",u,l[n.kScanOptionAllowDuplicatesKey],l[n.kServiceUUIDs]);break;case n.kStopScanning:r.emit("stopScan",u);break;case n.kCentralState:r.emit("getCentralState",u);break;case n.kConnect:try{a=i("p"),r.emit("connect",u,a.peripheral.uuid)}catch(f){}break;case n.kDisconnect:try{a=i("p"),r.emit("disconnect",u,a.peripheral.uuid)}catch(f){}break;case n.kGetCharacteristicValue:try{a=i("c",u),r.emit("readCharacteristic",u,a.peripheral.uuid,a.service.uuid,a.characteristic.uuid)}catch(f){}break;case n.kWriteCharacteristicValue:try{a=i("c",u),r.emit("writeCharacteristic",u,a.peripheral.uuid,a.service.uuid,a.characteristic.uuid,e.params[n.kValue])}catch(f){}break;case n.kSetValueNotification:try{a=i("c",u),r.emit("enableNotifications",u,a.peripheral.uuid,a.service.uuid,a.characteristic.uuid,e.params[n.kIsNotifying])}catch(f){}break;case n.kGetDescriptorValue:try{a=i("d",u),r.emit("readDescriptor",u,a.peripheral.uuid,a.service.uuid,a.characteristic.uuid,a.descriptor.uuid)}catch(f){}break;case n.kWriteDescriptorValue:try{a=i("d",u),r.emit("writeDescriptor",u,a.peripheral.uuid,a.service.uuid,a.characteristic.uuid,a.descriptor.uuid,e.params[n.kValue])}catch(f){}break;default:return void r.sendErrorResponse(u,e.method,n.kInvalidRequest,"Request not handled by server")}}},r.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)},r.configureResponse=function(t){t.result=n.kConfigure,e.respond(t,{})},r.centralStateResponse=function(t,r){var i={};i[n.kState]=r,t.result=n.kCentralState,e.respond(t,i)},r.stopScanResponse=function(t){t.result=n.kStopScanning,e.respond(t,{})},r.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)},r.scanResponse=function(t,r,i,a,o,c,u,l,f){if(t)return t.result=n.kScanForPeripherals,void e.respond(t,{});var p,h,d={};if(!s.isEmpty(u)){p={};for(var v in u){var m=v.toUpperCase();p[m]=s.arrayAsHex(u[v]).toUpperCase()}}if(!s.isEmpty(l)){h={};for(var k in l){var g=k.toUpperCase();h[g]=s.arrayAsHex(l[k]).toUpperCase()}}d[n.kPeripheralName]=i,d[n.kPeripheralUUID]=r,d[n.kRSSIkey]=a,d[n.kCBAdvertisementDataTxPowerLevel]=o,d[n.kCBAdvertisementDataIsConnectable]=f,d[n.kCBAdvertisementDataServiceUUIDsKey]=c&&c.length>0?c:void 0,d[n.kCBAdvertisementDataManufacturerDataKey]=p,d[n.kCBAdvertisementDataServiceDataKey]=h,e.sendIndications(n.kScanForPeripherals,d)},r.addPeripheral=function(e,t,i,n,a){var s=new Peripheral(this,e,t,i,n,a);return r.peripherals[s.uuid]=s,s}}var n=e("./constants.js").C,a=e("./event-emitter"),s=e("./message-helper");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,"./message-helper":10}],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,h,d,v){c.instantiateEmitter(this);var m=this;this.type="p",this.uuid=t,this.isConnected=!1;var k={},g={},I={},E=[];this._updateFromScanData=function(e,t,r,n,a,c,u,l,f){this.name=e,this.rssi=t,this.txPowerLevel=r,this.connectable=n;if(c)for(var p in c){
+var h=p.toUpperCase();g[h]=c[p].toUpperCase()}if(u)for(var d in u)I[d]=u[d];if(a)for(var v=0;v<a.length;v++)i(E,a[v]);if(l){if(o.parseAdvArray(m,l.c2),m.advdata.connectable&&(m.connectable="true"===m.advdata.connectable),m.advdata.txPowerLevel&&(this.txPowerLevel=m.advdata.txPowerLevel),m.advdata.manufacturerData&&!s.isEmpty(m.advdata.manufacturerData))for(var k in m.advdata.manufacturerData){var y=k.toUpperCase();g[y]=m.advdata.manufacturerData[k].toUpperCase()}m.advdata.serviceUUIDs&&m.advdata.serviceUUIDs.length>0&&i(E,m.advdata.serviceUUIDs)}},this.findService=function(e){return k[e]},this.getMfrData=function(e){return g[e]},this.getSvcData=function(e){return I[e]},this.hasAdvertisedServiceUUID=function(e){return E.indexOf(e)>=0},this.getAllServices=function(){return k},this.getAllMfrData=function(){return g},this.getAllSvcData=function(){return I},this.getAllAdvertisedServiceUUIDs=function(){return E},this.addServiceWithUUID=function(e){var t=new l(m,e);return k[e]=t},this.addService=function(e){return k[e.uuid]=e},this.gattip=function(){return e},this.connectOnce=function(t){var r=s.populateParams(m);e.request(a.kConnect,r,t,function(r){u.parseServiceRecord(m,r),m.isConnected=!0,e.fulfill(t,m)})},this.connect=function(t,r){function i(r){s++,s<=a.NUM_CONNECT_ATTEMPTS?m.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(m);e.request(a.kDisconnect,r,t,function(r){m.isConnected=!1,e.fulfill(t,m)})},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(){m.isConnected=!1,m.emit("disconnected",m)},this._updateFromScanData(r,n,f,p,h,d,v)}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;c<i;c++)u[c].apply(this,a);return!0},i.prototype.addListener=function(e,t){var r;if(!n(t))throw TypeError("listener must be a function");return this._events||(this._events={}),this._events.newListener&&this.emit("newListener",e,n(t.listener)?t.listener:t),this._events[e]?s(this._events[e])?this._events[e].push(t):this._events[e]=[this._events[e],t]:this._events[e]=t,s(this._events[e])&&!this._events[e].warned&&(r=o(this._maxListeners)?i.defaultMaxListeners:this._maxListeners,r&&r>0&&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&&o&&(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=[];++f<t;)o&&o[f].run();f=-1,t=u.length}o=null,l=!1,clearTimeout(e)}}function a(e,t){this.fun=e,this.array=t}function s(){}var o,c=t.exports={},u=[],l=!1,f=-1;c.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var r=1;r<arguments.length;r++)t[r-1]=arguments[r];u.push(new a(e,t)),1!==u.length||l||setTimeout(n,0)},a.prototype.run=function(){this.fun.apply(null,this.array)},c.title="browser",c.browser=!0,c.env={},c.argv=[],c.version="",c.versions={},c.on=s,c.addListener=s,c.once=s,c.off=s,c.removeListener=s,c.removeAllListeners=s,c.emit=s,c.binding=function(e){throw new Error("process.binding is not supported")},c.cwd=function(){return"/"},c.chdir=function(e){throw new Error("process.chdir is not supported")},c.umask=function(){return 0}},{}],20:[function(e,t,r){t.exports=function(e){return e&&"object"==typeof e&&"function"==typeof e.copy&&"function"==typeof e.fill&&"function"==typeof e.readUInt8}},{}],21:[function(e,t,r){(function(t,i){function n(e,t){var i={seen:[],stylize:s};return arguments.length>=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&&C(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(C(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=["[","]"]),C(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<o;++s)U(t,String(s))?a.push(p(e,t,r,i,String(s),!0)):a.push("");return n.forEach(function(n){n.match(/^\d+$/)||a.push(p(e,t,r,i,n,!0))}),a}function p(e,t,r,i,n,a){var s,o,u;if(u=Object.getOwnPropertyDescriptor(t,n)||{value:t[n]},u.get?o=u.set?e.stylize("[Getter/Setter]","special"):e.stylize("[Getter]","special"):u.set&&(o=e.stylize("[Setter]","special")),U(i,n)||(s="["+n+"]"),o||(e.seen.indexOf(u.value)<0?(o=m(r)?c(e,u.value,null):c(e,u.value,r-1),o.indexOf("\n")>-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]"===_(e)}function P(e){return"object"==typeof e&&null!==e}function D(e){return P(e)&&"[object Date]"===_(e)}function A(e){return P(e)&&("[object Error]"===_(e)||e instanceof Error)}function C(e){return"function"==typeof e}function b(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 U(e,t){return Object.prototype.hasOwnProperty.call(e,t)}var w=/%[sdj%]/g;r.format=function(e){if(!I(e)){for(var t=[],r=0;r<arguments.length;r++)t.push(n(arguments[r]));return t.join(" ")}for(var r=1,i=arguments,a=i.length,s=String(e).replace(w,function(e){if("%%"===e)return"%";if(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<a;o=i[++r])s+=m(o)||!P(o)?" "+o:" "+n(o);return s},r.deprecate=function(e,n){function a(){if(!s){if(t.throwDeprecation)throw new Error(n);t.traceDeprecation,s=!0}return e.apply(this,arguments)}if(y(i.process))return function(){return r.deprecate(e,n).apply(this,arguments)};if(t.noDeprecation===!0)return e;var s=!1;return a};var T,R={};r.debuglog=function(e){if(y(T)&&(T=t.env.NODE_DEBUG||""),e=e.toUpperCase(),!R[e])if(new RegExp("\\b"+e+"\\b","i").test(T)){t.pid;R[e]=function(){r.format.apply(r,arguments)}}else R[e]=function(){};return R[e]},r.inspect=n,n.colors={bold:[1,22],italic:[3,23],underline:[4,24],inverse:[7,27],white:[37,39],grey:[90,39],black:[30,39],blue:[34,39],cyan:[36,39],green:[32,39],magenta:[35,39],red:[31,39],yellow:[33,39]},n.styles={special:"cyan",number:"yellow","boolean":"yellow",undefined:"grey","null":"bold",string:"green",date:"magenta",regexp:"red"},r.isArray=d,r.isBoolean=v,r.isNull=m,r.isNullOrUndefined=k,r.isNumber=g,r.isString=I,r.isSymbol=E,r.isUndefined=y,r.isRegExp=S,r.isObject=P,r.isDate=D,r.isError=A,r.isFunction=C,r.isPrimitive=b,r.isBuffer=e("./support/isBuffer");r.log=function(){},r.inherits=e("inherits"),r._extend=function(e,t){if(!t||!P(t))return e;for(var r=Object.keys(t),i=r.length;i--;)e[r[i]]=t[r[i]];return e}}).call(this,e("_process"),"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./support/isBuffer":20,_process:19,inherits:18}],"gatt-ip":[function(e,t,r){t.exports.GATTIP=e("./gattip").GATTIP,t.exports.C=e("./lib/constants").C},{"./gattip":5,"./lib/constants":6}]},{},[]);
 /* blueapp.io v0.0.1 */
 !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;o<i.length;o++)n(i[o]);return n}({1:[function(e,t,r){!function(){function t(){Object.defineProperty?Object.defineProperty(navigator,"bluetooth",{get:p}):Object.prototype.__defineGetter__&&navigator.__defineGetter__("bluetooth",p);navigator.bluetooth}for(var r,i=/\+/g,n=/([^&=]+)=?([^&]*)/g,a=function(e){return decodeURIComponent(e.replace(i," "))},o=window.location.search.substring(1),s={};r=n.exec(o);)s[a(r[1])]=a(r[2]);var c=s.token,u=s.uuid,l=s.proxyUrl;window.cordovaApp=s.app;var p=function(){if("object"==typeof window.bawb)return window.bawb;var t;if(cordovaApp){t={};var r=function(e){t.onerror&&t.onerror(e)},i=function(e){if(e&&t.onmessage){var r={data:e};t.onmessage(r)}};t.close=function(){blueappio.request("close",data,i,r)},t.send=function(e){blueappio.request("message",e,i,r)},blueappio.request("init",{},i,r)}return window.bawb=e("blueapp-wb").init({url:l,token:c,scanFilters:{uuids:[u]},stream:t}).navigator.bluetooth,window.bawb};"object"==typeof window&&"object"==typeof navigator&&(cordovaApp?document.addEventListener("deviceready",t,!1):c&&t())}()},{"blueapp-wb":3}],2:[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}],3:[function(e,t,r){"use strict";function i(e){this.gateway=e}function n(e,t){var r=!1,i=-1;if("undefined"!=typeof e){for(i=0;i<e.length;i++)if(e[i].uuid===t.uuid){r=!0;break}}else e=[];return r?(e.splice(i,1,t),e):(e.push(t),e)}function a(e,t){for(var r=void 0,i=void 0,n=[],a=0;a<t.length;a++)if(t[a].name&&(r=t[a].name),t[a].services)for(var o=0;o<t[a].services.length;o++)"number"==typeof t[a].services[o]&&(t[a].services[o]=t[a].services[o].toString(16)),i=i?i+","+t[a].services[o]:t[a].services[o]+"";if(""!==i&&"undefined"!=typeof i){n=i.trim().split(/\s*,\s*/);for(var a=0;a<n.length;a++)n[a]=n[a].toUpperCase()}var s=!1,c=0;if(e.advdata&&e.advdata.serviceUUIDs.length>0?e.serviceUUIDs=e.advdata.serviceUUIDs:e.serviceUUIDs=e.getAllAdvertisedServiceUUIDs(),n.length>0&&""!==r&&"undefined"!=typeof r){if(n.length>0){for(var u=0;u<n.length;u++)"undefined"!=typeof e.serviceUUIDs&&e.serviceUUIDs.length>0&&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;o<n.length;o++)"undefined"!=typeof e.serviceUUIDs&&e.serviceUUIDs.length>0&&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}}var o=e("gatt-ip").GATTIP,s=e("./util.js"),c=e("./thirdparty"),u=e("./wb-device").BluetoothDevice;t.exports.navigator=void 0,t.exports.window=void 0,i.prototype.requestDevice=function(e){var t=e.filters,r=this.gateway,i=[];return s.errorLoggingPromise(function(e,t){r.getGateway()?e(r.getGateway()):r.once("ready",function(t){e(t)})}).then(function(){return s.errorLoggingPromise(function(e,o){function s(o){if(clearTimeout(c),"true"==cordovaApp){var p=a(o,t);if(p){i=n(i,p);for(var f='<table cellpadding="0" cellspacing="0"><tbody><tr>',d=0;d<i.length;d++)f+="</tr><tr onclick='onPeripheralSelect(\""+i[d].uuid+"\")'>",f+="<td>"+i[d].name+"</td>";document.getElementById("peripheral").innerHTML=f}}else l.stopScan(function(){l.removeListener("scan",s);var t=new u(r,o);t.gatt=t,e(t)})}var c=setTimeout(function(){o("Timed out")},3e4),l=r.getGateway();window.onPeripheralSelect=function(t){l.stopScan(function(){var n=document.getElementById("picker");n.style.display="none";for(var a=0;a<i.length;a++)if(i[a].uuid==t){var o=new u(r,i[a]);o.gatt=o,e(o);break}})},window.onCancel=function(){l.stopScan(function(){});var t=document.getElementById("picker");t.style.display="none",e()},l.scan(function(){"true"==cordovaApp&&(document.getElementById("scanDialog").innerHTML='<style>.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;;}</style><div id= "picker" style= "z-index: 100;" class= "modal">    <div class= "modal-content">       <div style="font-size: 15px; padding-bottom: 10px; color: black"> App wants to pair with : </div>        <div class= "spacing-table div-border" style="color: black" id=\'peripheral\'>        </div>        <div style="text-align: right; margin-top: 10px; font-size: 14px;">        <button type= "button" onclick= "onCancel()" style="padding: 4px;">Cancel</button>    </div>    </div></div>'),l.on("scan",s)})})})},t.exports.init=function(e){var t={};t.bluetooth={},t.BluetoothUUID=c.BluetoothUUID,e||(e={});var r=new o;r.BluetoothUUID=c.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("state",function(e){if("true"==cordovaApp)if(e){var t=document.getElementById("BluetoothAlert");t&&(t.style.display="none")}else document.getElementById("scanDialog").innerHTML='<style>.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;;}</style><div id= "BluetoothAlert" style= "z-index: 100;" class= "modal">    <div class= "modal-content">       <div style="font-size: 15px;text-align: center; color: black"> Please turn on the Bluetooth... </div>    </div></div>'}),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;r<e.length-1;r+=2)t.push(parseInt(e.substr(r,2),16));return t},t.exports.arrayAsHex=function(e){var t="";for(var r in e){byte=e[r];var i=(255&byte).toString(16);1==i.length&&(i="0"+i),t+=i}return t.toUpperCase()},t.exports.uncaughtError=function(e){},t.exports.gattIpRequestPromise=function(e){return new Promise(function(r,i){try{e(r,i)}catch(n){throw t.exports.uncaughtError(n),n}})},t.exports.errorLoggingPromise=function(e){return new Promise(function(r,i){try{e(r,i)}catch(n){throw t.exports.uncaughtError(n),n}})}},{}],6:[function(e,t,r){function i(e,t){function r(e,t){var r=a.hexAsArray(t);i._value=new DataView(new Uint8Array(r).buffer),i.emit("characteristicvaluechanged",{target:i})}o.instantiateEmitter(this);var i=this;this._gattIp=e._gattIp,this._service=e,this._gattipCharacteristic=t,t.wbCharacteristic=this,this._properties=new n(t.allProperties()),this._value=null,Object.defineProperty(this,"uuid",{get:function(){return a.toWbUUID(i._gattipCharacteristic.uuid)}}),Object.defineProperty(this,"service",{get:function(){return i._service}}),Object.defineProperty(this,"properties",{get:function(){return i._properties}}),Object.defineProperty(this,"value",{get:function(){return i._value}}),this.getAllDescriptors=function(e){return a.errorLoggingPromise(function(e,t){t("Not implemented")})},this.getDescriptor=function(e){var t=this;return a.errorLoggingPromise(function(r,i){var n=a.toVensiUUID(t._gattIp.BluetoothUUID.getDescriptor(e));if("undefined"==typeof n)i("Unable to find descriptor with requested UUID "+e);else{var o=t._gattipCharacteristic.findDescriptor(n);o?r(new s(t,o)):i("Descriptor "+e+" not found")}})},this.readValue=function(){var e=this;return a.errorLoggingPromise(function(t,r){e._gattipCharacteristic.readValue({fulfill:function(e,r){var i=a.hexAsArray(r);t(new DataView(new Uint8Array(i).buffer))},reject:r})})},this.writeValue=function(e){var t=this;return a.errorLoggingPromise(function(r,i){t._gattipCharacteristic.writeValue({fulfill:r,reject:i},a.arrayAsHex(Array.prototype.slice.call(e)))})},this.startNotifications=function(){var e=this;return a.errorLoggingPromise(function(t,i){return e._isNotifying?void i("Already notifying"):void e._gattipCharacteristic.enableNotifications({fulfill:function(n,a){a?(e._isNotifying=!0,n.on("valueChange",r),t()):i("Did not receive expected response from the gateway")},reject:i},!0)})},this.stopNotifications=function(){var e=this;return a.errorLoggingPromise(function(t,i){return e._isNotifying?void e._gattipCharacteristic.enableNotifications({fulfill:function(n,a){a?i("Did not receive expected response from the gateway"):(e._isNotifying=!1,n.removeListener("valueChange",r),t())},reject:i},!1):void i("Was not notifying")})},this.addEventListener=function(e,t){this.on(e,t)},this.removeEventListener=function(e,t){this.removeListener(e,t)}}function n(e){function t(e){return e.charAt(0).toUpperCase()+e.slice(1)}for(var r in c){wbPropName=c[r];var i=t(wbPropName);"object"==typeof e[i]?this[wbPropName]=1==e[i].enabled:"reliableWrite"!=wbPropName&&"writableAuxiliaries"!=wbPropName||(e.ExtendedProperties&&1===e.ExtendedProperties.enabled?this[wbPropName]=!1:this[wbPropName]=!1)}}var a=e("./util.js"),o=e("./event-emitter"),s=e("./wb-descriptor").BluetoothGattDescriptor,c=["broadcast","read","writeWithoutResponse","write","notify","indicate","authenticatedSignedWrites","reliableWrite","writableAuxiliaries"];t.exports.BluetoothGattCharacteristic=i,o.makeEmitter(i)},{"./event-emitter":2,"./util.js":5,"./wb-descriptor":7}],7:[function(e,t,r){function i(e,t){this._gattIp=e._gattIp,this._characteristic=e,this._gattIpDescriptor=t,this._value=null}var n=e("./util");t.exports.BluetoothGattDescriptor=i,i.prototype={get uuid(){return n.toWbUUID(this._gattIpDescriptor.uuid)},get characteristic(){return this._characteristic},get value(){return this._value},readValue:function(){var e=this;return n.errorLoggingPromise(function(t,r){e._gattIpDescriptor.readValue({fulfill:function(e,r){var i=n.hexAsArray(r);t(new DataView(new Uint8Array(i).buffer))},reject:r})})},writeValue:function(e){var t=this;return n.errorLoggingPromise(function(r,i){t._gattIpDescriptor.writeValue({fulfill:r,reject:i},n.arrayAsHex(Array.prototype.slice.call(e)))})}}},{"./util":5}],8:[function(e,t,r){function i(e,t){this._gattIp=e,this._gattIpPeripheral=t}var n=e("./util.js"),a=e("./wb-service").BluetoothGattService;t.exports.BluetoothDevice=i,i.prototype={get name(){return this._gattIpPeripheral.name},get uuid(){return this._gattIpPeripheral.uuid},get deviceClass(){},get vendorIdSource(){},get vendorId(){},get productId(){},get productVersion(){},get paired(){return!1},get connected(){return this._gattIpPeripheral.isConnected},get uuids(){return this._gattIpPeripheral.serviceUUIDs},connect:function(){var e=this;return new Promise(function(t,r){e._gattIpPeripheral.connect({fulfill:function(r){e._gattIpPeripheral=r,t(e)},reject:r})})},disconnect:function(){var e=this;return n.errorLoggingPromise(function(t,r){e._gattIpPeripheral.disconnect({fulfill:t,reject:r})})},getAllServices:function(e){return n.errorLoggingPromise(function(e,t){t("Not implemented")})},getService:function(e){var t=this;return n.errorLoggingPromise(function(r,i){var o=n.toVensiUUID(t._gattIp.BluetoothUUID.getService(e));if("undefined"==typeof o)i("Unable to find service with requested UUID "+e);else{var s=t._gattIpPeripheral.findService(o);s?r(new a(t,s)):(s=t._gattIpPeripheral.findService(e),s?r(new a(t,s)):i("Service "+e+" not found"))}})}},i.prototype.connectGATT=i.prototype.connect,i.prototype.getPrimaryService=i.prototype.getService},{"./util.js":5,"./wb-service":9}],9:[function(e,t,r){function i(e,t){this._gattIp=e._gattIp,this._device=e,this._gattIpService=t}var n=e("./util.js"),a=e("./wb-characteristic").BluetoothGattCharacteristic;t.exports.BluetoothGattService=i,i.prototype={get uuid(){return n.toWbUUID(this._service.uuid)},get isPrimary(){return!0},get device(){return this._device},getCharacteristic:function(e){var t=this;return n.errorLoggingPromise(function(r,i){var o=n.toVensiUUID(t._gattIp.BluetoothUUID.getCharacteristic(e));if("undefined"==typeof o)i("Unable to find characteristic with requested UUID "+e);else{var s=t._gattIpService.findCharacteristic(o);s?r(new a(t,s)):(s=t._gattIpService.findCharacteristic(e),s?r(new a(t,s)):i("Characteristic "+e+" not found"))}})},getIncludedService:function(e){return n.errorLoggingPromise(function(e,t){t("Not implemented")})}}},{"./util.js":5,"./wb-characteristic":6}],10:[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 o(e){return"object"==typeof e&&null!==e}function s(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||o(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],s(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:for(i=arguments.length,a=new Array(i-1),c=1;c<i;c++)a[c-1]=arguments[c];r.apply(this,a)}else if(o(r)){for(i=arguments.length,a=new Array(i-1),c=1;c<i;c++)a[c-1]=arguments[c];for(u=r.slice(),i=u.length,c=0;c<i;c++)u[c].apply(this,a)}return!0},i.prototype.addListener=function(e,t){var r;if(!n(t))throw TypeError("listener must be a function");if(this._events||(this._events={}),this._events.newListener&&this.emit("newListener",e,n(t.listener)?t.listener:t),this._events[e]?o(this._events[e])?this._events[e].push(t):this._events[e]=[this._events[e],t]:this._events[e]=t,o(this._events[e])&&!this._events[e].warned){var r;r=s(this._maxListeners)?i.defaultMaxListeners:this._maxListeners,r&&r>0&&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)e.fulfill(t,r);else{if(i[n.kOpen]!==!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=0;c<t.uuids.length;c++){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.kCBAdvertisementDataIsConnectable],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.kCBAdvertisementDataIsConnectable],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:"),r(!1,e,v.processMessage)}),d.on("indication",function(e){t(new o("Received an indication on a server stream:"+JSON.stringify(e)))}),g=k,m.emit("ready",k)):e.isPassThrough?b():k.configure(function(){k.centralState(function(){if(k.isPoweredOn())k.isPoweredOn()&&b();else{m.emit("state",k.isPoweredOn());var e=setInterval(function(){k.centralState(function(){k.isPoweredOn()&&(m.emit("state",k.isPoweredOn()),clearInterval(e),b())})},500)}})})}function b(){d.on("indication",function(e){m.traceMessage(e,"<ind:"),r(!1,e,h.handleIndication)}),d.on("request",function(e){t(new a("Received a request on a client stream:"+JSON.stringify(e)))}),g=k,m.emit("ready",k)}function y(e){e.token?k._authenticate(function(){_(e)},e.token,e.version):_(e)}var k=new l(this,n.scanFilters);if(d=new u(this),h=new c(this,k),v=new p(this,k),n.trace===!0&&(m.traceEnabled=!0),n.url){var w;w="object"==typeof window?window.WebSocket:e("websocket").w3cwebsocket,i=new w(n.url,(void 0),(void 0),(void 0),(void 0),f),i.onopen=function(){y(n)},i.onclose=function(e){m.emit("onclose",e)},i.onerror=function(e){m.emit("onerror",e)}}else{if(!n.stream)throw new o("URL or stream implementing a socket interface is required");i=n.stream,y(n)}i.onmessage=function(e){r(!0,e.data,d.onMessageReceived)},d.on("response",function(e,t){m.traceMessage(e,"<rsp:");try{e.error?m.reject(t.cb,new s(e.error)):t.handler?t.handler(e.params):m.fulfill(t.cb)}catch(r){m.reject(t.cb,r)}}),d.on("error",function(e){m.emit("error",e)})},this.close=function(){i&&i.close()},this.request=function(e,t,r,n){var a=h.createUserContext(e,t,r,n),o=a.originalMessage;d.register(o,a),m.traceMessage(o,">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,t.exports.C=e("./lib/constants").C},{"./gattip":15,"./lib/constants":17}],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:"cbl",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.connectable="true":e.connectable="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;i<advArrayLength;i++)e.url+=String.fromCharCode(parseInt(t[i],16));for(var n in f.AllDomains)t[advArrayLength]==n&&(e.url+=f.AllDomains[n])}function p(e,t){e.frameType="TLM",e.advPacketCount="",e.timeInterval="",e.batteryVoltage="",e.eddyVersion=parseInt(t[5],16);for(var r=6;r<8;r++)e.batteryVoltage+=t[r];e.batteryVoltage=parseInt(e.batteryVoltage,16),e.temperature=Math.ceil(parseInt(t[8],16)),e.temperature+=".";var i=Math.ceil(1/256*parseInt(t[9],16));i.length>2?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;l<t.length;l+=2)u[l/2]=t.charAt(l)+t.charAt(l+1);else for(var p=0;p<t.length;p++)u[p]=t.charAt(2*p)+t.charAt(2*p+1);for(;;){var d=u[1];if(d==f.kGAP_ADTYPE_FLAGS)i(r,u);else if(d==f.kGAP_ADTYPE_POWER_LEVEL)n(r,u);else if(d==f.kGAP_ADTYPE_INCOMPLETE_16BIT_SERVICEUUID||d==f.kGAP_ADTYPE_COMPLETE_16BIT_SERVICEUUID)o(r,u);else if(d==f.kGAP_ADTYPE_INCOMPLETE_32BIT_SERVICEUUID||d==f.kGAP_ADTYPE_COMPLETE_32BIT_SERVICEUUID)o(r,u);else if(d==f.kGAP_ADTYPE_INCOMPLETE_128BIT_SERVICEUUID||d==f.kGAP_ADTYPE_COMPLETE_128BIT_SERVICEUUID)s(r,u);else if(d==f.kGAP_ADTYPE_MANUFACTURER_SPECIFIC)a(r,u);else if(d==f.kGAP_ADTYPE_16BIT_SERVICE_DATA)c(r,u);else if("00"==d)u.splice(0,1);else{var h=parseInt(u[0],16);u.splice(0,h+1)}if(0===u.length)break}}},{"./constants":17}],20:[function(e,t,r){var i=e("./constants").C,n=e("./message-helper"),a=e("./../errors").InternalError,o=e("./../errors").ApplicationError;t.exports.MessageHandler=function(e,t){this.createUserContext=function(e,t,r,i){var n={method:e,params:t,jsonrpc:"2.0"};return{originalMessage:n,cb:r,handler:i}},this.wrapResponse=function(e,t){var r={params:t,jsonrpc:"2.0"};return n.requireAndPopulateFieldsFromCookie("wrapResponse",e,r),r},this.handleIndication=function(e){if(e.error)throw new o(JSON.stringify(e));var r=e.params;switch(e.result){case i.kScanForPeripherals:t.handleScanIndication(r);break;case i.kDisconnect:!function(){n.requireFields("Disconnect indication",r,[i.kPeripheralUUID]);var e=t.getPeripheral(r[i.kPeripheralUUID]);e&&e.handleDisconnectIndication(e)}();break;case i.kSetValueNotification:!function(){n.requireFields("Disconnect indication",r,[i.kPeripheralUUID]);var a=t.getPeripheral(r[i.kPeripheralUUID]);if(a){n.requireFields("Value notification",r,[i.kPeripheralUUID,i.kServiceUUID,i.kCharacteristicUUID,i.kValue]);var o=t.getObjectsFromMessage("c",e.params);o.characteristic.handleValueNotification(r)}}();break;default:!function(){throw new a("Unknown indication received from the gateway:",JSON.stringify(e))}()}}}},{"./../errors":13,"./constants":17,"./message-helper":21}],21:[function(e,t,r){function i(e){var t="";if("object"==typeof e){if(Array.isArray(e)){for(var r in e)0!=r&&(t+=" ,"),t+=e[r]}for(var n in e)if(e.hasOwnProperty(n)){var o=e[n],s=a[n];s||(s=n),t+="object"==typeof o?Array.isArray(o)?" "+s+":["+i(o)+"]":" "+s+":{"+i(o)+"}":" "+s+"="+o}}return t}var n=e("./constants").C,a={},o=e("./../errors").InternalError,s=e("./../errors").ApplicationError;for(var c in n){var u=n[c];0==c.indexOf("k")&&(c=c.substring(1,c.length),a[u]=c)}t.exports.isEmpty=function(e){for(var t in e)if(e.hasOwnProperty(t))return!1;return JSON.stringify(e)===JSON.stringify({})},t.exports.arrayAsHex=function(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},t.exports.toString=function(e){return i(e.params).trim()},t.exports.requireAndAssignParameters=function(e,r,i,n){t.exports.requireFields(e+" call parameters ",r,i,n)},t.exports.requireBooleanValue=function(e,t,r){if("boolean"!=typeof r)throw new s(e+" missing parameter "+t)},t.exports.requireHexValue=function(e,t,r){if("string"!=typeof r)throw new s(e+" missing parameter "+t);if(r.length>0&&(r.length%2!=0||!/^[0-9a-fA-F]+$/.test(r)))throw new s(e+" value "+t+" is not a valid hex string")},t.exports.requireUUID=function(e,t,r){if("string"!=typeof r)throw new s(e+" missing parameter "+t);if(r.length<4||!/^[0-9A-F-]+$/.test(r))throw new s(e+" value "+t+" is not a valid UUID")},t.exports.requireHexValues=function(e,t,r){var i=[];if(!Array.isArray(t)||!Array.isArray(r))throw new o("Illegal use of requireHexValues");for(var n=0;n<t.length;n++){var a=t[n],c=r[n];("string"!=typeof c||c.length<2||c.length%2!=0||!/^#[0-9A-F]$/i.test(c))&&i.push(a)}if(i)throw new s(e+" missing parameters "+i)},t.exports.requireFields=function(e,t,r,i){var n=[];if(i||(i={}),!t)throw new o(e+"Object is undefined");for(var a=0;a<r.length;a++){var s=r[a];void 0==typeof t[s]&&(void 0==typeof i[a]?n.push(r):t[s]=i[a])}if(n.length)throw new o(e+" missing "+n)},t.exports.requireAndPopulateFieldsFromCookie=function(e,t,r){if(!t)throw new s('Error: "'+e+" is missing the cookie");if(!t.original.id)throw new s('Error: "'+e+" is missing the cookie ID");if(!t.original.session_id)throw new s('Error: "'+e+" is missing the cookie session ID");if(!t.original.method)throw new s('Error: "'+e+" is missing the cookie request");r[n.kMessageId]=t.original.id,r[n.kSessionId]=t.original.session_id,r.result=t.result},t.exports.populateParams=function(e,t){function r(e,r){u--;var i=r.uuid;if(!i)throw new o('UUID for object of type "'+r.type+'" is missing');t[e]=i}if(t||(t={}),!e)throw new o("populateParams: service object is undefined");var i,a,s,c,u=23132;switch(e.type){case"d":u=4,c=e;break;case"c":u=3,s=e;break;case"s":u=2,a=e;break;case"p":u=1,i=e;break;default:throw new o('type must be one of: "s", "c" or "d"')}if(c&&(r(n.kDescriptorUUID,c),s=c.characteristic()),s&&(r(n.kCharacteristicUUID,s),a=s.service()),a&&(r(n.kServiceUUID,a),i=s.peripheral()),i&&r(n.kPeripheralUUID,i),0!=u)throw new o("Expected "+u+" more parts when constructing params of "+e.type);return t}},{"./../errors":13,"./constants":17}],22:[function(e,t,r){function i(e,t,r,i){this.msg=t,this.userContext=r,"undefined"==typeof t.id&&(t.id=Number(c++).toString()),this.id=t.id,i||(i=o.DEFAULT_MESSAGE_TIMEOUT_MS);var n=this;this.timeout=setTimeout(function(){delete n.timeout,e.emit("error",new s("Timed out : "+JSON.stringify(t)),n.userContext.cb)},i)}function n(){a.instantiateEmitter(this);var e=this,t={};this.register=function(r,n,a){if(Object.keys(t).length>o.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){a.instantiateEmitter(this);var r=this;this.processMessage=function(e){function i(i){var a=l[n.kPeripheralUUID],o={};if(o.peripheral=t.getPeripheral(a),o.peripheral&&o.peripheral.uuid){if("p"===i)return o;var s=l[n.kServiceUUID];if(o.service=o.peripheral.findService(s),o.service&&o.service.uuid){if("s"===i)return o;var c=l[n.kCharacteristicUUID];if(o.characteristic=o.service.findCharacteristic(c),o.characteristic&&o.characteristic.uuid){if("c"===i)return o;var u=l[n.kDescriptorUUID];if(o.descriptor=o.characteristic.findDescriptor(u),o.descriptor&&o.descriptor.uuid)return o;throw r.sendErrorResponse(e.method,n.kErrorDescriptorNotFound,"Descriptor not found in the service database"),new Error("Descriptor not found")}throw r.sendErrorResponse(e.method,n.kErrorCharacteristicNotFound,"Characteristic not found in the service database"),new Error("Characteristic not found")}throw r.sendErrorResponse(e.method,n.kErrorServiceNotFound,"Service not found in the service database"),new Error("Service not found")}throw r.sendErrorResponse(e.method,n.kErrorPeripheralNotFound,"Peripheral not found in the service database"),new Error("Peripheral not found")}var a;if("undefined"!=typeof e&&e&&!e.error){if(e.result&&(e.result==n.kMessage||e.result==n.kAuthenticate)){var o=!1;return e.error||"object"!=typeof e.params||e.params[n.kAuthenticate]!==!0||(o=!0),void r.emit("authenticated",o)}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 r.send(c)}var u={original:e},l=e.params;switch(e.method){case n.kConfigure:r.emit("configure",u,l[n.kShowPowerAlert],l[n.kIdentifierKey]);break;case n.kScanForPeripherals:r.emit("scan",u,l[n.kScanOptionAllowDuplicatesKey],l[n.kServiceUUIDs]);break;case n.kStopScanning:r.emit("stopScan",u);break;case n.kCentralState:r.emit("getCentralState",u);break;case n.kConnect:try{a=i("p"),r.emit("connect",u,a.peripheral.uuid)}catch(p){}break;case n.kDisconnect:try{a=i("p"),r.emit("disconnect",u,a.peripheral.uuid)}catch(p){}break;case n.kGetCharacteristicValue:try{a=i("c",u),r.emit("readCharacteristic",u,a.peripheral.uuid,a.service.uuid,a.characteristic.uuid)}catch(p){}break;case n.kWriteCharacteristicValue:try{a=i("c",u),r.emit("writeCharacteristic",u,a.peripheral.uuid,a.service.uuid,a.characteristic.uuid,e.params[n.kValue])}catch(p){}break;case n.kSetValueNotification:try{a=i("c",u),r.emit("enableNotifications",u,a.peripheral.uuid,a.service.uuid,a.characteristic.uuid,e.params[n.kIsNotifying])}catch(p){}break;case n.kGetDescriptorValue:try{a=i("d",u),r.emit("readDescriptor",u,a.peripheral.uuid,a.service.uuid,a.characteristic.uuid,a.descriptor.uuid)}catch(p){}break;case n.kWriteDescriptorValue:try{a=i("d",u),r.emit("writeDescriptor",u,a.peripheral.uuid,a.service.uuid,a.characteristic.uuid,a.descriptor.uuid,e.params[n.kValue])}catch(p){}break;default:return void r.sendErrorResponse(u,e.method,n.kInvalidRequest,"Request not handled by server")}}},r.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)},r.configureResponse=function(t){t.result=n.kConfigure,e.respond(t,{})},r.centralStateResponse=function(t,r){var i={};i[n.kState]=r,t.result=n.kCentralState,e.respond(t,i)},r.stopScanResponse=function(t){t.result=n.kStopScanning,e.respond(t,{})},r.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)},r.scanResponse=function(t,r,i,a,s,c,u,l,p){if(t)return t.result=n.kScanForPeripherals,void e.respond(t,{});var f,d,h={};if(!o.isEmpty(u)){f={};for(var v in u){var g=v.toUpperCase();f[g]=o.arrayAsHex(u[v]).toUpperCase()}}if(!o.isEmpty(l)){d={};for(var m in l){var _=m.toUpperCase();d[_]=o.arrayAsHex(l[m]).toUpperCase()}}h[n.kPeripheralName]=i,h[n.kPeripheralUUID]=r,h[n.kRSSIkey]=a,h[n.kCBAdvertisementDataTxPowerLevel]=s,h[n.kCBAdvertisementDataIsConnectable]=p,h[n.kCBAdvertisementDataServiceUUIDsKey]=c&&c.length>0?c:void 0,h[n.kCBAdvertisementDataManufacturerDataKey]=f,h[n.kCBAdvertisementDataServiceDataKey]=d,e.sendIndications(n.kScanForPeripherals,h)},r.addPeripheral=function(e,t,i,n,a){var o=new Peripheral(this,e,t,i,n,a);return r.peripherals[o.uuid]=o,o}}var n=e("./constants.js").C,a=e("./event-emitter"),o=e("./message-helper");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,"./message-helper":21}],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,c,u,l,p){this.name=e,this.rssi=t,this.txPowerLevel=r,this.connectable=n;if(c)for(var f in c){var h=f.toUpperCase();v[h]=c[f].toUpperCase()}if(u)for(var _ in u)g[_]=u[_];if(a)for(var b=0;b<a.length;b++)i(m,a[b]);if(l){if(s.parseAdvArray(d,l.c2),d.advdata.connectable&&(d.connectable="true"===d.advdata.connectable),d.advdata.txPowerLevel&&(this.txPowerLevel=d.advdata.txPowerLevel),d.advdata.manufacturerData&&!o.isEmpty(d.advdata.manufacturerData))for(var y in d.advdata.manufacturerData){var k=y.toUpperCase();v[k]=d.advdata.manufacturerData[y].toUpperCase()}d.advdata.serviceUUIDs&&d.advdata.serviceUUIDs.length>0&&i(m,d.advdata.serviceUUIDs)}},this.findService=function(e){return h[e]},this.getMfrData=function(e){return v[e]},this.getSvcData=function(e){return g[e]},this.hasAdvertisedServiceUUID=function(e){return m.indexOf(e)>=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 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=[];++m<t;)h&&h[m].run();m=-1,t=v.length}h=null,g=!1,o(e)}}function u(e,t){this.fun=e,this.array=t}function l(){}var p,f,d=t.exports={};!function(){try{p="function"==typeof setTimeout?setTimeout:i}catch(e){p=i}try{f="function"==typeof clearTimeout?clearTimeout:n}catch(e){f=n}}();var h,v=[],g=!1,m=-1;d.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var r=1;r<arguments.length;r++)t[r-1]=arguments[r];v.push(new u(e,t)),1!==v.length||g||a(c)},u.prototype.run=function(){this.fun.apply(null,this.array)},d.title="browser",d.browser=!0,d.env={},d.argv=[],d.version="",d.versions={},d.on=l,d.addListener=l,d.once=l,d.off=l,d.removeListener=l,d.removeAllListeners=l,d.emit=l,d.binding=function(e){throw new Error("process.binding is not supported")},d.cwd=function(){return"/"},d.chdir=function(e){throw new Error("process.chdir is not supported")},d.umask=function(){return 0}},{}],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){t.exports=function(e){return e&&"object"==typeof e&&"function"==typeof e.copy&&"function"==typeof e.fill&&"function"==typeof e.readUInt8}},{}],30:[function(e,t,r){(function(t,i){function n(e,t){var i={seen:[],stylize:o};return arguments.length>=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<s;++o)A(t,String(o))?a.push(f(e,t,r,i,String(o),!0)):a.push("");return n.forEach(function(n){n.match(/^\d+$/)||a.push(f(e,t,r,i,n,!0))}),a}function f(e,t,r,i,n,a){var o,s,u;if(u=Object.getOwnPropertyDescriptor(t,n)||{value:t[n]},u.get?s=u.set?e.stylize("[Getter/Setter]","special"):e.stylize("[Getter]","special"):u.set&&(s=e.stylize("[Setter]","special")),A(i,n)||(o="["+n+"]"),s||(e.seen.indexOf(u.value)<0?(s=g(r)?c(e,u.value,null):c(e,u.value,r-1),s.indexOf("\n")>-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]"===S(e)}function I(e){return"object"==typeof e&&null!==e;
+},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:"),r(!1,e,v.processMessage)}),d.on("indication",function(e){t(new o("Received an indication on a server stream:"+JSON.stringify(e)))}),g=k,m.emit("ready",k)):e.isPassThrough?b():k.configure(function(){k.centralState(function(){if(k.isPoweredOn())k.isPoweredOn()&&b();else{m.emit("state",k.isPoweredOn());var e=setInterval(function(){k.centralState(function(){k.isPoweredOn()&&(m.emit("state",k.isPoweredOn()),clearInterval(e),b())})},500)}})})}function b(){d.on("indication",function(e){m.traceMessage(e,"<ind:"),r(!1,e,h.handleIndication)}),d.on("request",function(e){t(new a("Received a request on a client stream:"+JSON.stringify(e)))}),g=k,m.emit("ready",k)}function y(e){e.token?k._authenticate(function(){_(e)},e.token,e.version):_(e)}var k=new l(this,n.scanFilters);if(d=new u(this),h=new c(this,k),v=new p(this,k),n.trace===!0&&(m.traceEnabled=!0),n.url){var w;w="object"==typeof window?window.WebSocket:e("websocket").w3cwebsocket,i=new w(n.url,(void 0),(void 0),(void 0),(void 0),f),i.onopen=function(){y(n)},i.onclose=function(e){m.emit("onclose",e)},i.onerror=function(e){m.emit("onerror",e)}}else{if(!n.stream)throw new o("URL or stream implementing a socket interface is required");i=n.stream,y(n)}i.onmessage=function(e){r(!0,e.data,d.onMessageReceived)},d.on("response",function(e,t){m.traceMessage(e,"<rsp:");try{e.error?m.reject(t.cb,new s(e.error)):t.handler?t.handler(e.params):m.fulfill(t.cb)}catch(r){m.reject(t.cb,r)}}),d.on("error",function(e){m.emit("error",e)})},this.close=function(){i&&i.close()},this.request=function(e,t,r,n){var a=h.createUserContext(e,t,r,n),o=a.originalMessage;d.register(o,a),m.traceMessage(o,">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,t.exports.C=e("./lib/constants").C},{"./gattip":15,"./lib/constants":17}],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:"cbl",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.connectable="true":e.connectable="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;i<advArrayLength;i++)e.url+=String.fromCharCode(parseInt(t[i],16));for(var n in f.AllDomains)t[advArrayLength]==n&&(e.url+=f.AllDomains[n])}function p(e,t){e.frameType="TLM",e.advPacketCount="",e.timeInterval="",e.batteryVoltage="",e.eddyVersion=parseInt(t[5],16);for(var r=6;r<8;r++)e.batteryVoltage+=t[r];e.batteryVoltage=parseInt(e.batteryVoltage,16),e.temperature=Math.ceil(parseInt(t[8],16)),e.temperature+=".";var i=Math.ceil(1/256*parseInt(t[9],16));i.length>2?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;l<t.length;l+=2)u[l/2]=t.charAt(l)+t.charAt(l+1);else for(var p=0;p<t.length;p++)u[p]=t.charAt(2*p)+t.charAt(2*p+1);for(;;){var d=u[1];if(d==f.kGAP_ADTYPE_FLAGS)i(r,u);else if(d==f.kGAP_ADTYPE_POWER_LEVEL)n(r,u);else if(d==f.kGAP_ADTYPE_INCOMPLETE_16BIT_SERVICEUUID||d==f.kGAP_ADTYPE_COMPLETE_16BIT_SERVICEUUID)o(r,u);else if(d==f.kGAP_ADTYPE_INCOMPLETE_32BIT_SERVICEUUID||d==f.kGAP_ADTYPE_COMPLETE_32BIT_SERVICEUUID)o(r,u);else if(d==f.kGAP_ADTYPE_INCOMPLETE_128BIT_SERVICEUUID||d==f.kGAP_ADTYPE_COMPLETE_128BIT_SERVICEUUID)s(r,u);else if(d==f.kGAP_ADTYPE_MANUFACTURER_SPECIFIC)a(r,u);else if(d==f.kGAP_ADTYPE_16BIT_SERVICE_DATA)c(r,u);else if("00"==d)u.splice(0,1);else{var h=parseInt(u[0],16);u.splice(0,h+1)}if(0===u.length)break}}},{"./constants":17}],20:[function(e,t,r){var i=e("./constants").C,n=e("./message-helper"),a=e("./../errors").InternalError,o=e("./../errors").ApplicationError;t.exports.MessageHandler=function(e,t){this.createUserContext=function(e,t,r,i){var n={method:e,params:t,jsonrpc:"2.0"};return{originalMessage:n,cb:r,handler:i}},this.wrapResponse=function(e,t){var r={params:t,jsonrpc:"2.0"};return n.requireAndPopulateFieldsFromCookie("wrapResponse",e,r),r},this.handleIndication=function(e){if(e.error)throw new o(JSON.stringify(e));var r=e.params;switch(e.result){case i.kScanForPeripherals:t.handleScanIndication(r);break;case i.kDisconnect:!function(){n.requireFields("Disconnect indication",r,[i.kPeripheralUUID]);var e=t.getPeripheral(r[i.kPeripheralUUID]);e&&e.handleDisconnectIndication(e)}();break;case i.kSetValueNotification:!function(){n.requireFields("Disconnect indication",r,[i.kPeripheralUUID]);var a=t.getPeripheral(r[i.kPeripheralUUID]);if(a){n.requireFields("Value notification",r,[i.kPeripheralUUID,i.kServiceUUID,i.kCharacteristicUUID,i.kValue]);var o=t.getObjectsFromMessage("c",e.params);o.characteristic.handleValueNotification(r)}}();break;default:!function(){throw new a("Unknown indication received from the gateway:",JSON.stringify(e))}()}}}},{"./../errors":13,"./constants":17,"./message-helper":21}],21:[function(e,t,r){function i(e){var t="";if("object"==typeof e){if(Array.isArray(e)){for(var r in e)0!=r&&(t+=" ,"),t+=e[r]}for(var n in e)if(e.hasOwnProperty(n)){var o=e[n],s=a[n];s||(s=n),t+="object"==typeof o?Array.isArray(o)?" "+s+":["+i(o)+"]":" "+s+":{"+i(o)+"}":" "+s+"="+o}}return t}var n=e("./constants").C,a={},o=e("./../errors").InternalError,s=e("./../errors").ApplicationError;for(var c in n){var u=n[c];0==c.indexOf("k")&&(c=c.substring(1,c.length),a[u]=c)}t.exports.isEmpty=function(e){for(var t in e)if(e.hasOwnProperty(t))return!1;return JSON.stringify(e)===JSON.stringify({})},t.exports.arrayAsHex=function(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},t.exports.toString=function(e){return i(e.params).trim()},t.exports.requireAndAssignParameters=function(e,r,i,n){t.exports.requireFields(e+" call parameters ",r,i,n)},t.exports.requireBooleanValue=function(e,t,r){if("boolean"!=typeof r)throw new s(e+" missing parameter "+t)},t.exports.requireHexValue=function(e,t,r){if("string"!=typeof r)throw new s(e+" missing parameter "+t);if(r.length>0&&(r.length%2!=0||!/^[0-9a-fA-F]+$/.test(r)))throw new s(e+" value "+t+" is not a valid hex string")},t.exports.requireUUID=function(e,t,r){if("string"!=typeof r)throw new s(e+" missing parameter "+t);if(r.length<4||!/^[0-9A-F-]+$/.test(r))throw new s(e+" value "+t+" is not a valid UUID")},t.exports.requireHexValues=function(e,t,r){var i=[];if(!Array.isArray(t)||!Array.isArray(r))throw new o("Illegal use of requireHexValues");for(var n=0;n<t.length;n++){var a=t[n],c=r[n];("string"!=typeof c||c.length<2||c.length%2!=0||!/^#[0-9A-F]$/i.test(c))&&i.push(a)}if(i)throw new s(e+" missing parameters "+i)},t.exports.requireFields=function(e,t,r,i){var n=[];if(i||(i={}),!t)throw new o(e+"Object is undefined");for(var a=0;a<r.length;a++){var s=r[a];void 0==typeof t[s]&&(void 0==typeof i[a]?n.push(r):t[s]=i[a])}if(n.length)throw new o(e+" missing "+n)},t.exports.requireAndPopulateFieldsFromCookie=function(e,t,r){if(!t)throw new s('Error: "'+e+" is missing the cookie");if(!t.original.id)throw new s('Error: "'+e+" is missing the cookie ID");if(!t.original.session_id)throw new s('Error: "'+e+" is missing the cookie session ID");if(!t.original.method)throw new s('Error: "'+e+" is missing the cookie request");r[n.kMessageId]=t.original.id,r[n.kSessionId]=t.original.session_id,r.result=t.result},t.exports.populateParams=function(e,t){function r(e,r){u--;var i=r.uuid;if(!i)throw new o('UUID for object of type "'+r.type+'" is missing');t[e]=i}if(t||(t={}),!e)throw new o("populateParams: service object is undefined");var i,a,s,c,u=23132;switch(e.type){case"d":u=4,c=e;break;case"c":u=3,s=e;break;case"s":u=2,a=e;break;case"p":u=1,i=e;break;default:throw new o('type must be one of: "s", "c" or "d"')}if(c&&(r(n.kDescriptorUUID,c),s=c.characteristic()),s&&(r(n.kCharacteristicUUID,s),a=s.service()),a&&(r(n.kServiceUUID,a),i=s.peripheral()),i&&r(n.kPeripheralUUID,i),0!=u)throw new o("Expected "+u+" more parts when constructing params of "+e.type);return t}},{"./../errors":13,"./constants":17}],22:[function(e,t,r){function i(e,t,r,i){this.msg=t,this.userContext=r,"undefined"==typeof t.id&&(t.id=Number(c++).toString()),this.id=t.id,i||(i=o.DEFAULT_MESSAGE_TIMEOUT_MS);var n=this;this.timeout=setTimeout(function(){delete n.timeout,e.emit("error",new s("Timed out : "+JSON.stringify(t)),n.userContext.cb)},i)}function n(){a.instantiateEmitter(this);var e=this,t={};this.register=function(r,n,a){if(Object.keys(t).length>o.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){a.instantiateEmitter(this);var r=this;this.processMessage=function(e){function i(i){var a=l[n.kPeripheralUUID],o={};if(o.peripheral=t.getPeripheral(a),o.peripheral&&o.peripheral.uuid){if("p"===i)return o;var s=l[n.kServiceUUID];if(o.service=o.peripheral.findService(s),o.service&&o.service.uuid){if("s"===i)return o;var c=l[n.kCharacteristicUUID];if(o.characteristic=o.service.findCharacteristic(c),o.characteristic&&o.characteristic.uuid){if("c"===i)return o;var u=l[n.kDescriptorUUID];if(o.descriptor=o.characteristic.findDescriptor(u),o.descriptor&&o.descriptor.uuid)return o;throw r.sendErrorResponse(e.method,n.kErrorDescriptorNotFound,"Descriptor not found in the service database"),new Error("Descriptor not found")}throw r.sendErrorResponse(e.method,n.kErrorCharacteristicNotFound,"Characteristic not found in the service database"),new Error("Characteristic not found")}throw r.sendErrorResponse(e.method,n.kErrorServiceNotFound,"Service not found in the service database"),new Error("Service not found")}throw r.sendErrorResponse(e.method,n.kErrorPeripheralNotFound,"Peripheral not found in the service database"),new Error("Peripheral not found")}var a;if("undefined"!=typeof e&&e&&!e.error){if(e.result&&(e.result==n.kMessage||e.result==n.kAuthenticate)){var o=!1;return e.error||"object"!=typeof e.params||e.params[n.kAuthenticate]!==!0||(o=!0),void r.emit("authenticated",o)}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 r.send(c)}var u={original:e},l=e.params;switch(e.method){case n.kConfigure:r.emit("configure",u,l[n.kShowPowerAlert],l[n.kIdentifierKey]);break;case n.kScanForPeripherals:r.emit("scan",u,l[n.kScanOptionAllowDuplicatesKey],l[n.kServiceUUIDs]);break;case n.kStopScanning:r.emit("stopScan",u);break;case n.kCentralState:r.emit("getCentralState",u);break;case n.kConnect:try{a=i("p"),r.emit("connect",u,a.peripheral.uuid)}catch(p){}break;case n.kDisconnect:try{a=i("p"),r.emit("disconnect",u,a.peripheral.uuid)}catch(p){}break;case n.kGetCharacteristicValue:try{a=i("c",u),r.emit("readCharacteristic",u,a.peripheral.uuid,a.service.uuid,a.characteristic.uuid)}catch(p){}break;case n.kWriteCharacteristicValue:try{a=i("c",u),r.emit("writeCharacteristic",u,a.peripheral.uuid,a.service.uuid,a.characteristic.uuid,e.params[n.kValue])}catch(p){}break;case n.kSetValueNotification:try{a=i("c",u),r.emit("enableNotifications",u,a.peripheral.uuid,a.service.uuid,a.characteristic.uuid,e.params[n.kIsNotifying])}catch(p){}break;case n.kGetDescriptorValue:try{a=i("d",u),r.emit("readDescriptor",u,a.peripheral.uuid,a.service.uuid,a.characteristic.uuid,a.descriptor.uuid)}catch(p){}break;case n.kWriteDescriptorValue:try{a=i("d",u),r.emit("writeDescriptor",u,a.peripheral.uuid,a.service.uuid,a.characteristic.uuid,a.descriptor.uuid,e.params[n.kValue])}catch(p){}break;default:return void r.sendErrorResponse(u,e.method,n.kInvalidRequest,"Request not handled by server")}}},r.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)},r.configureResponse=function(t){t.result=n.kConfigure,e.respond(t,{})},r.centralStateResponse=function(t,r){var i={};i[n.kState]=r,t.result=n.kCentralState,e.respond(t,i)},r.stopScanResponse=function(t){t.result=n.kStopScanning,e.respond(t,{})},r.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)},r.scanResponse=function(t,r,i,a,s,c,u,l,p){if(t)return t.result=n.kScanForPeripherals,void e.respond(t,{});var f,d,h={};if(!o.isEmpty(u)){f={};for(var v in u){var g=v.toUpperCase();f[g]=o.arrayAsHex(u[v]).toUpperCase()}}if(!o.isEmpty(l)){d={};for(var m in l){var _=m.toUpperCase();d[_]=o.arrayAsHex(l[m]).toUpperCase()}}h[n.kPeripheralName]=i,h[n.kPeripheralUUID]=r,h[n.kRSSIkey]=a,h[n.kCBAdvertisementDataTxPowerLevel]=s,h[n.kCBAdvertisementDataIsConnectable]=p,h[n.kCBAdvertisementDataServiceUUIDsKey]=c&&c.length>0?c:void 0,h[n.kCBAdvertisementDataManufacturerDataKey]=f,h[n.kCBAdvertisementDataServiceDataKey]=d,e.sendIndications(n.kScanForPeripherals,h)},r.addPeripheral=function(e,t,i,n,a){var o=new Peripheral(this,e,t,i,n,a);return r.peripherals[o.uuid]=o,o}}var n=e("./constants.js").C,a=e("./event-emitter"),o=e("./message-helper");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,"./message-helper":21}],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,d,h,v){c.instantiateEmitter(this);var g=this;this.type="p",this.uuid=t,this.isConnected=!1;var m={},_={},b={},y=[];this._updateFromScanData=function(e,t,r,n,a,c,u,l,p){this.name=e,this.rssi=t,this.txPowerLevel=r,this.connectable=n;if(c)for(var f in c){var d=f.toUpperCase();_[d]=c[f].toUpperCase()}if(u)for(var h in u)b[h]=u[h];if(a)for(var v=0;v<a.length;v++)i(y,a[v]);if(l){if(s.parseAdvArray(g,l.c2),g.advdata.connectable&&(g.connectable="true"===g.advdata.connectable),g.advdata.txPowerLevel&&(this.txPowerLevel=g.advdata.txPowerLevel),g.advdata.manufacturerData&&!o.isEmpty(g.advdata.manufacturerData))for(var m in g.advdata.manufacturerData){var k=m.toUpperCase();_[k]=g.advdata.manufacturerData[m].toUpperCase()}g.advdata.serviceUUIDs&&g.advdata.serviceUUIDs.length>0&&i(y,g.advdata.serviceUUIDs)}},this.findService=function(e){return m[e]},this.getMfrData=function(e){return _[e]},this.getSvcData=function(e){return b[e]},this.hasAdvertisedServiceUUID=function(e){return y.indexOf(e)>=0},this.getAllServices=function(){return m},this.getAllMfrData=function(){return _},this.getAllSvcData=function(){return b},this.getAllAdvertisedServiceUUIDs=function(){return y},this.addServiceWithUUID=function(e){var t=new l(g,e);return m[e]=t},this.addService=function(e){return m[e.uuid]=e},this.gattip=function(){return e},this.connectOnce=function(t){var r=o.populateParams(g);e.request(a.kConnect,r,t,function(r){u.parseServiceRecord(g,r),g.isConnected=!0,e.fulfill(t,g)})},this.connect=function(t,r){function i(r){o++,o<=a.NUM_CONNECT_ATTEMPTS?g.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(g);e.request(a.kDisconnect,r,t,function(r){g.isConnected=!1,e.fulfill(t,g)})},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(){g.isConnected=!1,g.emit("disconnected",g)},this._updateFromScanData(r,n,p,f,d,h,v)}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 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=[];++m<t;)h&&h[m].run();m=-1,t=v.length}h=null,g=!1,o(e)}}function u(e,t){this.fun=e,this.array=t}function l(){}var p,f,d=t.exports={};!function(){try{p="function"==typeof setTimeout?setTimeout:i}catch(e){p=i}try{f="function"==typeof clearTimeout?clearTimeout:n}catch(e){f=n}}();var h,v=[],g=!1,m=-1;d.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var r=1;r<arguments.length;r++)t[r-1]=arguments[r];v.push(new u(e,t)),1!==v.length||g||a(c)},u.prototype.run=function(){this.fun.apply(null,this.array)},d.title="browser",d.browser=!0,d.env={},d.argv=[],d.version="",d.versions={},d.on=l,d.addListener=l,d.once=l,d.off=l,d.removeListener=l,d.removeAllListeners=l,d.emit=l,d.binding=function(e){throw new Error("process.binding is not supported")},d.cwd=function(){return"/"},d.chdir=function(e){throw new Error("process.chdir is not supported")},d.umask=function(){return 0}},{}],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){t.exports=function(e){return e&&"object"==typeof e&&"function"==typeof e.copy&&"function"==typeof e.fill&&"function"==typeof e.readUInt8}},{}],30:[function(e,t,r){(function(t,i){function n(e,t){var i={seen:[],stylize:o};return arguments.length>=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<s;++o)A(t,String(o))?a.push(f(e,t,r,i,String(o),!0)):a.push("");return n.forEach(function(n){n.match(/^\d+$/)||a.push(f(e,t,r,i,n,!0))}),a}function f(e,t,r,i,n,a){var o,s,u;if(u=Object.getOwnPropertyDescriptor(t,n)||{value:t[n]},u.get?s=u.set?e.stylize("[Getter/Setter]","special"):e.stylize("[Getter]","special"):u.set&&(s=e.stylize("[Setter]","special")),A(i,n)||(o="["+n+"]"),s||(e.seen.indexOf(u.value)<0?(s=g(r)?c(e,u.value,null):c(e,u.value,r-1),s.indexOf("\n")>-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]"===S(e)}function I(e){return"object"==typeof e&&null!==e;
 }function E(e){return I(e)&&"[object Date]"===S(e)}function U(e){return I(e)&&("[object Error]"===S(e)||e instanceof Error)}function D(e){return"function"==typeof e}function P(e){return null===e||"boolean"==typeof e||"number"==typeof e||"string"==typeof e||"symbol"==typeof e||"undefined"==typeof e}function S(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<arguments.length;r++)t.push(n(arguments[r]));return t.join(" ")}for(var r=1,i=arguments,a=i.length,o=String(e).replace(C,function(e){if("%%"===e)return"%";if(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<a;s=i[++r])o+=g(s)||!I(s)?" "+s:" "+n(s);return o},r.deprecate=function(e,n){function a(){if(!o){if(t.throwDeprecation)throw new Error(n);t.traceDeprecation,o=!0}return e.apply(this,arguments)}if(k(i.process))return function(){return r.deprecate(e,n).apply(this,arguments)};if(t.noDeprecation===!0)return e;var o=!1;return a};var T,x={};r.debuglog=function(e){if(k(T)&&(T=t.env.NODE_DEBUG||""),e=e.toUpperCase(),!x[e])if(new RegExp("\\b"+e+"\\b","i").test(T)){t.pid;x[e]=function(){r.format.apply(r,arguments)}}else x[e]=function(){};return x[e]},r.inspect=n,n.colors={bold:[1,22],italic:[3,23],underline:[4,24],inverse:[7,27],white:[37,39],grey:[90,39],black:[30,39],blue:[34,39],cyan:[36,39],green:[32,39],magenta:[35,39],red:[31,39],yellow:[33,39]},n.styles={special:"cyan",number:"yellow","boolean":"yellow",undefined:"grey","null":"bold",string:"green",date:"magenta",regexp:"red"},r.isArray=h,r.isBoolean=v,r.isNull=g,r.isNullOrUndefined=m,r.isNumber=_,r.isString=b,r.isSymbol=y,r.isUndefined=k,r.isRegExp=w,r.isObject=I,r.isDate=E,r.isError=U,r.isFunction=D,r.isPrimitive=P,r.isBuffer=e("./support/isBuffer");r.log=function(){},r.inherits=e("inherits"),r._extend=function(e,t){if(!t||!I(t))return e;for(var r=Object.keys(t),i=r.length;i--;)e[r[i]]=t[r[i]];return e}}).call(this,e("_process"),"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./support/isBuffer":29,_process:27,inherits:28}],31:[function(e,t,r){function i(e,t){var r;return r=t?new a(e,t):new a(e)}var n=function(){return this}(),a=n.WebSocket||n.MozWebSocket,o=e("./version");t.exports={w3cwebsocket:a?i:null,version:o}},{"./version":32}],32:[function(e,t,r){t.exports=e("../package.json").version},{"../package.json":33}],33:[function(e,t,r){t.exports={_args:[[{raw:"websocket@latest",scope:null,escapedName:"websocket",name:"websocket",rawSpec:"latest",spec:"latest",type:"tag"},"/Users/home/Documents/Malli_Workspace/BitBucket/WB-Polyfill/lib/blueapp-wb"]],_from:"websocket@latest",_id:"websocket@1.0.23",_inCache:!0,_installable:!0,_location:"/websocket",_nodeVersion:"0.10.45",_npmOperationalInternal:{host:"packages-16-east.internal.npmjs.com",tmp:"tmp/websocket-1.0.23.tgz_1463625793005_0.4532310354989022"},_npmUser:{name:"theturtle32",email:"brian@worlize.com"},_npmVersion:"2.15.1",_phantomChildren:{},_requested:{raw:"websocket@latest",scope:null,escapedName:"websocket",name:"websocket",rawSpec:"latest",spec:"latest",type:"tag"},_requiredBy:["/blueapp-wb","/gatt-ip"],_resolved:"https://registry.npmjs.org/websocket/-/websocket-1.0.23.tgz",_shasum:"20de8ec4a7126b09465578cd5dbb29a9c296aac6",_shrinkwrap:null,_spec:"websocket@latest",_where:"/Users/home/Documents/Malli_Workspace/BitBucket/WB-Polyfill/lib/blueapp-wb",author:{name:"Brian McKelvey",email:"brian@worlize.com",url:"https://www.worlize.com/"},browser:"lib/browser.js",bugs:{url:"https://github.com/theturtle32/WebSocket-Node/issues"},config:{verbose:!1},contributors:[{name:"IƱaki Baz Castillo",email:"ibc@aliax.net",url:"http://dev.sipdoc.net"}],dependencies:{debug:"^2.2.0",nan:"^2.3.3","typedarray-to-buffer":"^3.1.2",yaeti:"^0.0.4"},description:"Websocket Client & Server Library implementing the WebSocket protocol as specified in RFC 6455.",devDependencies:{"buffer-equal":"^0.0.1",faucet:"^0.0.1",gulp:"git+https://github.com/gulpjs/gulp.git#4.0","gulp-jshint":"^1.11.2","jshint-stylish":"^1.0.2",tape:"^4.0.1"},directories:{lib:"./lib"},dist:{shasum:"20de8ec4a7126b09465578cd5dbb29a9c296aac6",tarball:"https://registry.npmjs.org/websocket/-/websocket-1.0.23.tgz"},engines:{node:">=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
diff --git a/bower.json b/bower.json
index b5cdaeb..1e88a4a 100644
--- a/bower.json
+++ b/bower.json
@@ -1,6 +1,6 @@
 {
   "name": "blueapp.io",
-  "version": "1.1.2",
+  "version": "1.1.3",
   "homepage": "https://github.com/blueappio/blueapp.io",
   "license": "Copyright 2016 Vensi, Inc.",
   "main": "blueapp.io.min.js",
@@ -24,6 +24,7 @@
   "ignore": [
    "1.0.0",
    "1.1.0",
-   "1.1.1"
+   "1.1.1",
+   "1.1.2"
  ]
 }