UNPKG

fitbit-livedata

Version:

This project aims to getting `livedata` from Fitbit tracker

89 lines (79 loc) 4.85 kB
'use strict';Object.defineProperty(exports, "__esModule", { value: true });var _createClass = function () {function defineProperties(target, props) {for (var i = 0; i < props.length; i++) {var descriptor = props[i];descriptor.enumerable = descriptor.enumerable || false;descriptor.configurable = true;if ("value" in descriptor) descriptor.writable = true;Object.defineProperty(target, descriptor.key, descriptor);}}return function (Constructor, protoProps, staticProps) {if (protoProps) defineProperties(Constructor.prototype, protoProps);if (staticProps) defineProperties(Constructor, staticProps);return Constructor;};}();var _events = require('events');var _events2 = _interopRequireDefault(_events);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}function _classCallCheck(instance, Constructor) {if (!(instance instanceof Constructor)) {throw new TypeError("Cannot call a class as a function");}}function _possibleConstructorReturn(self, call) {if (!self) {throw new ReferenceError("this hasn't been initialised - super() hasn't been called");}return call && (typeof call === "object" || typeof call === "function") ? call : self;}function _inherits(subClass, superClass) {if (typeof superClass !== "function" && superClass !== null) {throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);}subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } });if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;}var GattServer = function (_EventEmitter) {_inherits(GattServer, _EventEmitter); function GattServer() {_classCallCheck(this, GattServer);var _this = _possibleConstructorReturn(this, (GattServer.__proto__ || Object.getPrototypeOf(GattServer)).call(this)); _this.isListening = false;return _this; }_createClass(GattServer, [{ key: 'listen', value: function listen() {var _this2 = this; if (process.platform === 'win32') { this.emit('error', 'win32 is not supported.'); return; } else if (this.isListening) { this.emit('listen'); return; } Promise.resolve().then(function () {return require('bleno');}).then(function (bleno) { var UUID_SERVICE_NOTIFICATION_CENTER = '16bcfd00-253f-c348-e831-0db3e334d580'; var UUID_CHARACTERISTICS_NOTIFICATION_SOURCE = '16bcfd02-253f-c348-e831-0db3e334d580'; // const UUID_CHARACTERISTICS_DATA_SOURCE = '16bcfd03-253f-c348-e831-0db3e334d580'; // const UUID_CHARACTERISTICS_LOCATIONSTATUS_QUALITY = '16bcfd04-253f-c348-e831-0db3e334d580'; var primaryService = new bleno.PrimaryService({ uuid: UUID_SERVICE_NOTIFICATION_CENTER, characteristics: [ new bleno.Characteristic({ uuid: UUID_CHARACTERISTICS_NOTIFICATION_SOURCE, properties: ['notify'], secure: [], value: null, descriptors: [], onReadRequest: null, onWriteRequest: null, onSubscribe: null, onUnsubscribe: null, onNotify: null, onIndicate: null // }, { // uuid: UUID_CHARACTERISTICS_DATA_SOURCE, // properties: ['notify'], // secure: [], // value: null, // descriptors: [ // ], // onReadRequest: null, // onWriteRequest: null, // onSubscribe: null, // onUnsubscribe: null, // onNotify: null, // onIndicate: null, // }, { // uuid: UUID_CHARACTERISTICS_LOCATIONSTATUS_QUALITY, // properties: ['notify', 'read'], // secure: [], // value: null, // descriptors: [ // ], // onReadRequest: null, // onWriteRequest: null, // onSubscribe: null, // onUnsubscribe: null, // onNotify: null, // onIndicate: null, })] }); var onComplete = function onComplete(error) { if (error) { _this2.emit('error', error); return; } _this2.emit('listen'); _this2.isListening = true; }; if (bleno.state === 'poweredOn') { bleno.setServices([primaryService], onComplete); } else { bleno.on('stateChange', function (state) { if (state === 'poweredOn') { bleno.setServices([primaryService], onComplete); } }); } }); } }]);return GattServer;}(_events2.default);exports.default = GattServer;