diff --git a/lib/lock.js b/lib/lock.js index de26855bea5f3bc0a6368e801ecfe7274a41e144..9f411079fecbdd17d4f9e734da293ff126e4c6b6 100644 --- a/lib/lock.js +++ b/lib/lock.js @@ -53,24 +53,24 @@ Lock.prototype.connect = function() { // initialize the secure session this._secureSession = new SecureLockSession( - this._peripheral, - characteristicByUuid("bd4ac6130b4511e38ffd0800200c9a66"), - characteristicByUuid("bd4ac6140b4511e38ffd0800200c9a66"), - this._offlineKeyOffset + this._peripheral, + characteristicByUuid("bd4ac6130b4511e38ffd0800200c9a66"), + characteristicByUuid("bd4ac6140b4511e38ffd0800200c9a66"), + this._offlineKeyOffset ); this._secureSession.setKey(this._offlineKey); // intialize the session this._session = new LockSession( - this._peripheral, - characteristicByUuid("bd4ac6110b4511e38ffd0800200c9a66"), - characteristicByUuid("bd4ac6120b4511e38ffd0800200c9a66") + this._peripheral, + characteristicByUuid("bd4ac6110b4511e38ffd0800200c9a66"), + characteristicByUuid("bd4ac6120b4511e38ffd0800200c9a66") ); // start the sessions return Promise.join( - this._secureSession.start(), - this._session.start() + this._secureSession.start(), + this._session.start() ); }.bind(this)).then(function() { // send SEC_LOCK_TO_MOBILE_KEY_EXCHANGE @@ -127,9 +127,9 @@ Lock.prototype.lock = function() { Lock.prototype.unlock = function() { return this.status(true).then(function(status) { - if (status == 'locked') + if (status == 'locked') return this.forceUnlock(); - }.bind(this)); + }.bind(this)); }; Lock.prototype.status = function() { @@ -178,4 +178,18 @@ Lock.prototype.disconnect = function() { } }; +Lock.prototype.isConnected = function() { + debug( 'checking connection...' ); + + if ( + this._session instanceof LockSession && + 'undefined' !== typeof this._session._peripheral.state && + 'disconnected' !== this._session._peripheral.state + ) { + return true; + } + + return false; +}; + module.exports = Lock;