@neurosity/sdk 6.4.0-next.0 → 6.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2307,11 +2307,6 @@ var Neurosity = (function (exports) {
2307
2307
 
2308
2308
  var NEVER = new Observable(noop);
2309
2309
 
2310
- var isArray$2 = Array.isArray;
2311
- function argsOrArgArray(args) {
2312
- return args.length === 1 && isArray$2(args[0]) ? args[0] : args;
2313
- }
2314
-
2315
2310
  function filter(predicate, thisArg) {
2316
2311
  return operate(function (source, subscriber) {
2317
2312
  var index = 0;
@@ -2440,27 +2435,6 @@ var Neurosity = (function (exports) {
2440
2435
  };
2441
2436
  }
2442
2437
 
2443
- function combineLatest$1() {
2444
- var args = [];
2445
- for (var _i = 0; _i < arguments.length; _i++) {
2446
- args[_i] = arguments[_i];
2447
- }
2448
- var resultSelector = popResultSelector(args);
2449
- return resultSelector
2450
- ? pipe(combineLatest$1.apply(void 0, __spreadArray([], __read(args))), mapOneOrManyArgs(resultSelector))
2451
- : operate(function (source, subscriber) {
2452
- combineLatestInit(__spreadArray([source], __read(argsOrArgArray(args))))(subscriber);
2453
- });
2454
- }
2455
-
2456
- function combineLatestWith() {
2457
- var otherSources = [];
2458
- for (var _i = 0; _i < arguments.length; _i++) {
2459
- otherSources[_i] = arguments[_i];
2460
- }
2461
- return combineLatest$1.apply(void 0, __spreadArray([], __read(otherSources)));
2462
- }
2463
-
2464
2438
  function concatMap(project, resultSelector) {
2465
2439
  return isFunction(resultSelector) ? mergeMap(project, resultSelector, 1) : mergeMap(project, 1);
2466
2440
  }
@@ -45780,684 +45754,110 @@ var Neurosity = (function (exports) {
45780
45754
  // Reverse BLUETOOTH_CHARACTERISTICS key/values for easy lookup
45781
45755
  const CHARACTERISTIC_UUIDS_TO_NAMES = Object.fromEntries(Object.entries(BLUETOOTH_CHARACTERISTICS).map((entries) => entries.reverse()));
45782
45756
 
45783
- const debug = (
45784
- typeof process === 'object' &&
45785
- process.env &&
45786
- process.env.NODE_DEBUG &&
45787
- /\bsemver\b/i.test(process.env.NODE_DEBUG)
45788
- ) ? (...args) => console.error('SEMVER', ...args)
45789
- : () => {};
45790
-
45791
- var debug_1 = debug;
45792
-
45793
- // Note: this is the semver.org version of the spec that it implements
45794
- // Not necessarily the package version of this code.
45795
- const SEMVER_SPEC_VERSION = '2.0.0';
45796
-
45797
- const MAX_LENGTH = 256;
45798
- const MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER ||
45799
- /* istanbul ignore next */ 9007199254740991;
45800
-
45801
- // Max safe segment length for coercion.
45802
- const MAX_SAFE_COMPONENT_LENGTH = 16;
45803
-
45804
- var constants = {
45805
- SEMVER_SPEC_VERSION,
45806
- MAX_LENGTH,
45807
- MAX_SAFE_INTEGER,
45808
- MAX_SAFE_COMPONENT_LENGTH,
45809
- };
45810
-
45811
- function createCommonjsModule(fn, module) {
45812
- return module = { exports: {} }, fn(module, module.exports), module.exports;
45813
- }
45814
-
45815
- var re_1 = createCommonjsModule(function (module, exports) {
45816
- const { MAX_SAFE_COMPONENT_LENGTH } = constants;
45817
-
45818
- exports = module.exports = {};
45819
-
45820
- // The actual regexps go on exports.re
45821
- const re = exports.re = [];
45822
- const src = exports.src = [];
45823
- const t = exports.t = {};
45824
- let R = 0;
45825
-
45826
- const createToken = (name, value, isGlobal) => {
45827
- const index = R++;
45828
- debug_1(name, index, value);
45829
- t[name] = index;
45830
- src[index] = value;
45831
- re[index] = new RegExp(value, isGlobal ? 'g' : undefined);
45832
- };
45833
-
45834
- // The following Regular Expressions can be used for tokenizing,
45835
- // validating, and parsing SemVer version strings.
45836
-
45837
- // ## Numeric Identifier
45838
- // A single `0`, or a non-zero digit followed by zero or more digits.
45839
-
45840
- createToken('NUMERICIDENTIFIER', '0|[1-9]\\d*');
45841
- createToken('NUMERICIDENTIFIERLOOSE', '[0-9]+');
45842
-
45843
- // ## Non-numeric Identifier
45844
- // Zero or more digits, followed by a letter or hyphen, and then zero or
45845
- // more letters, digits, or hyphens.
45846
-
45847
- createToken('NONNUMERICIDENTIFIER', '\\d*[a-zA-Z-][a-zA-Z0-9-]*');
45848
-
45849
- // ## Main Version
45850
- // Three dot-separated numeric identifiers.
45851
-
45852
- createToken('MAINVERSION', `(${src[t.NUMERICIDENTIFIER]})\\.` +
45853
- `(${src[t.NUMERICIDENTIFIER]})\\.` +
45854
- `(${src[t.NUMERICIDENTIFIER]})`);
45855
-
45856
- createToken('MAINVERSIONLOOSE', `(${src[t.NUMERICIDENTIFIERLOOSE]})\\.` +
45857
- `(${src[t.NUMERICIDENTIFIERLOOSE]})\\.` +
45858
- `(${src[t.NUMERICIDENTIFIERLOOSE]})`);
45859
-
45860
- // ## Pre-release Version Identifier
45861
- // A numeric identifier, or a non-numeric identifier.
45862
-
45863
- createToken('PRERELEASEIDENTIFIER', `(?:${src[t.NUMERICIDENTIFIER]
45864
- }|${src[t.NONNUMERICIDENTIFIER]})`);
45865
-
45866
- createToken('PRERELEASEIDENTIFIERLOOSE', `(?:${src[t.NUMERICIDENTIFIERLOOSE]
45867
- }|${src[t.NONNUMERICIDENTIFIER]})`);
45868
-
45869
- // ## Pre-release Version
45870
- // Hyphen, followed by one or more dot-separated pre-release version
45871
- // identifiers.
45872
-
45873
- createToken('PRERELEASE', `(?:-(${src[t.PRERELEASEIDENTIFIER]
45874
- }(?:\\.${src[t.PRERELEASEIDENTIFIER]})*))`);
45875
-
45876
- createToken('PRERELEASELOOSE', `(?:-?(${src[t.PRERELEASEIDENTIFIERLOOSE]
45877
- }(?:\\.${src[t.PRERELEASEIDENTIFIERLOOSE]})*))`);
45878
-
45879
- // ## Build Metadata Identifier
45880
- // Any combination of digits, letters, or hyphens.
45881
-
45882
- createToken('BUILDIDENTIFIER', '[0-9A-Za-z-]+');
45883
-
45884
- // ## Build Metadata
45885
- // Plus sign, followed by one or more period-separated build metadata
45886
- // identifiers.
45887
-
45888
- createToken('BUILD', `(?:\\+(${src[t.BUILDIDENTIFIER]
45889
- }(?:\\.${src[t.BUILDIDENTIFIER]})*))`);
45890
-
45891
- // ## Full Version String
45892
- // A main version, followed optionally by a pre-release version and
45893
- // build metadata.
45894
-
45895
- // Note that the only major, minor, patch, and pre-release sections of
45896
- // the version string are capturing groups. The build metadata is not a
45897
- // capturing group, because it should not ever be used in version
45898
- // comparison.
45899
-
45900
- createToken('FULLPLAIN', `v?${src[t.MAINVERSION]
45901
- }${src[t.PRERELEASE]}?${
45902
- src[t.BUILD]}?`);
45903
-
45904
- createToken('FULL', `^${src[t.FULLPLAIN]}$`);
45905
-
45906
- // like full, but allows v1.2.3 and =1.2.3, which people do sometimes.
45907
- // also, 1.0.0alpha1 (prerelease without the hyphen) which is pretty
45908
- // common in the npm registry.
45909
- createToken('LOOSEPLAIN', `[v=\\s]*${src[t.MAINVERSIONLOOSE]
45910
- }${src[t.PRERELEASELOOSE]}?${
45911
- src[t.BUILD]}?`);
45912
-
45913
- createToken('LOOSE', `^${src[t.LOOSEPLAIN]}$`);
45914
-
45915
- createToken('GTLT', '((?:<|>)?=?)');
45916
-
45917
- // Something like "2.*" or "1.2.x".
45918
- // Note that "x.x" is a valid xRange identifer, meaning "any version"
45919
- // Only the first item is strictly required.
45920
- createToken('XRANGEIDENTIFIERLOOSE', `${src[t.NUMERICIDENTIFIERLOOSE]}|x|X|\\*`);
45921
- createToken('XRANGEIDENTIFIER', `${src[t.NUMERICIDENTIFIER]}|x|X|\\*`);
45922
-
45923
- createToken('XRANGEPLAIN', `[v=\\s]*(${src[t.XRANGEIDENTIFIER]})` +
45924
- `(?:\\.(${src[t.XRANGEIDENTIFIER]})` +
45925
- `(?:\\.(${src[t.XRANGEIDENTIFIER]})` +
45926
- `(?:${src[t.PRERELEASE]})?${
45927
- src[t.BUILD]}?` +
45928
- `)?)?`);
45929
-
45930
- createToken('XRANGEPLAINLOOSE', `[v=\\s]*(${src[t.XRANGEIDENTIFIERLOOSE]})` +
45931
- `(?:\\.(${src[t.XRANGEIDENTIFIERLOOSE]})` +
45932
- `(?:\\.(${src[t.XRANGEIDENTIFIERLOOSE]})` +
45933
- `(?:${src[t.PRERELEASELOOSE]})?${
45934
- src[t.BUILD]}?` +
45935
- `)?)?`);
45936
-
45937
- createToken('XRANGE', `^${src[t.GTLT]}\\s*${src[t.XRANGEPLAIN]}$`);
45938
- createToken('XRANGELOOSE', `^${src[t.GTLT]}\\s*${src[t.XRANGEPLAINLOOSE]}$`);
45939
-
45940
- // Coercion.
45941
- // Extract anything that could conceivably be a part of a valid semver
45942
- createToken('COERCE', `${'(^|[^\\d])' +
45943
- '(\\d{1,'}${MAX_SAFE_COMPONENT_LENGTH}})` +
45944
- `(?:\\.(\\d{1,${MAX_SAFE_COMPONENT_LENGTH}}))?` +
45945
- `(?:\\.(\\d{1,${MAX_SAFE_COMPONENT_LENGTH}}))?` +
45946
- `(?:$|[^\\d])`);
45947
- createToken('COERCERTL', src[t.COERCE], true);
45948
-
45949
- // Tilde ranges.
45950
- // Meaning is "reasonably at or greater than"
45951
- createToken('LONETILDE', '(?:~>?)');
45952
-
45953
- createToken('TILDETRIM', `(\\s*)${src[t.LONETILDE]}\\s+`, true);
45954
- exports.tildeTrimReplace = '$1~';
45955
-
45956
- createToken('TILDE', `^${src[t.LONETILDE]}${src[t.XRANGEPLAIN]}$`);
45957
- createToken('TILDELOOSE', `^${src[t.LONETILDE]}${src[t.XRANGEPLAINLOOSE]}$`);
45958
-
45959
- // Caret ranges.
45960
- // Meaning is "at least and backwards compatible with"
45961
- createToken('LONECARET', '(?:\\^)');
45962
-
45963
- createToken('CARETTRIM', `(\\s*)${src[t.LONECARET]}\\s+`, true);
45964
- exports.caretTrimReplace = '$1^';
45965
-
45966
- createToken('CARET', `^${src[t.LONECARET]}${src[t.XRANGEPLAIN]}$`);
45967
- createToken('CARETLOOSE', `^${src[t.LONECARET]}${src[t.XRANGEPLAINLOOSE]}$`);
45968
-
45969
- // A simple gt/lt/eq thing, or just "" to indicate "any version"
45970
- createToken('COMPARATORLOOSE', `^${src[t.GTLT]}\\s*(${src[t.LOOSEPLAIN]})$|^$`);
45971
- createToken('COMPARATOR', `^${src[t.GTLT]}\\s*(${src[t.FULLPLAIN]})$|^$`);
45972
-
45973
- // An expression to strip any whitespace between the gtlt and the thing
45974
- // it modifies, so that `> 1.2.3` ==> `>1.2.3`
45975
- createToken('COMPARATORTRIM', `(\\s*)${src[t.GTLT]
45976
- }\\s*(${src[t.LOOSEPLAIN]}|${src[t.XRANGEPLAIN]})`, true);
45977
- exports.comparatorTrimReplace = '$1$2$3';
45978
-
45979
- // Something like `1.2.3 - 1.2.4`
45980
- // Note that these all use the loose form, because they'll be
45981
- // checked against either the strict or loose comparator form
45982
- // later.
45983
- createToken('HYPHENRANGE', `^\\s*(${src[t.XRANGEPLAIN]})` +
45984
- `\\s+-\\s+` +
45985
- `(${src[t.XRANGEPLAIN]})` +
45986
- `\\s*$`);
45987
-
45988
- createToken('HYPHENRANGELOOSE', `^\\s*(${src[t.XRANGEPLAINLOOSE]})` +
45989
- `\\s+-\\s+` +
45990
- `(${src[t.XRANGEPLAINLOOSE]})` +
45991
- `\\s*$`);
45992
-
45993
- // Star ranges basically just allow anything at all.
45994
- createToken('STAR', '(<|>)?=?\\s*\\*');
45995
- // >=0.0.0 is like a star
45996
- createToken('GTE0', '^\\s*>=\\s*0\\.0\\.0\\s*$');
45997
- createToken('GTE0PRE', '^\\s*>=\\s*0\\.0\\.0-0\\s*$');
45998
- });
45999
- var re_2 = re_1.re;
46000
- var re_3 = re_1.src;
46001
- var re_4 = re_1.t;
46002
- var re_5 = re_1.tildeTrimReplace;
46003
- var re_6 = re_1.caretTrimReplace;
46004
- var re_7 = re_1.comparatorTrimReplace;
46005
-
46006
- // parse out just the options we care about so we always get a consistent
46007
- // obj with keys in a consistent order.
46008
- const opts = ['includePrerelease', 'loose', 'rtl'];
46009
- const parseOptions = options =>
46010
- !options ? {}
46011
- : typeof options !== 'object' ? { loose: true }
46012
- : opts.filter(k => options[k]).reduce((o, k) => {
46013
- o[k] = true;
46014
- return o
46015
- }, {});
46016
- var parseOptions_1 = parseOptions;
46017
-
46018
- const numeric = /^[0-9]+$/;
46019
- const compareIdentifiers = (a, b) => {
46020
- const anum = numeric.test(a);
46021
- const bnum = numeric.test(b);
46022
-
46023
- if (anum && bnum) {
46024
- a = +a;
46025
- b = +b;
46026
- }
46027
-
46028
- return a === b ? 0
46029
- : (anum && !bnum) ? -1
46030
- : (bnum && !anum) ? 1
46031
- : a < b ? -1
46032
- : 1
45757
+ var __awaiter$d = function (thisArg, _arguments, P, generator) {
45758
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
45759
+ return new (P || (P = Promise))(function (resolve, reject) {
45760
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
45761
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
45762
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
45763
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
45764
+ });
46033
45765
  };
46034
-
46035
- const rcompareIdentifiers = (a, b) => compareIdentifiers(b, a);
46036
-
46037
- var identifiers = {
46038
- compareIdentifiers,
46039
- rcompareIdentifiers,
45766
+ const defaultOptions$1 = {
45767
+ autoConnect: true
46040
45768
  };
46041
-
46042
- const { MAX_LENGTH: MAX_LENGTH$1, MAX_SAFE_INTEGER: MAX_SAFE_INTEGER$1 } = constants;
46043
- const { re: re$1, t: t$1 } = re_1;
46044
-
46045
-
46046
- const { compareIdentifiers: compareIdentifiers$1 } = identifiers;
46047
- class SemVer {
46048
- constructor (version, options) {
46049
- options = parseOptions_1(options);
46050
-
46051
- if (version instanceof SemVer) {
46052
- if (version.loose === !!options.loose &&
46053
- version.includePrerelease === !!options.includePrerelease) {
46054
- return version
46055
- } else {
46056
- version = version.version;
46057
- }
46058
- } else if (typeof version !== 'string') {
46059
- throw new TypeError(`Invalid Version: ${version}`)
46060
- }
46061
-
46062
- if (version.length > MAX_LENGTH$1) {
46063
- throw new TypeError(
46064
- `version is longer than ${MAX_LENGTH$1} characters`
46065
- )
46066
- }
46067
-
46068
- debug_1('SemVer', version, options);
46069
- this.options = options;
46070
- this.loose = !!options.loose;
46071
- // this isn't actually relevant for versions, but keep it so that we
46072
- // don't run into trouble passing this.options around.
46073
- this.includePrerelease = !!options.includePrerelease;
46074
-
46075
- const m = version.trim().match(options.loose ? re$1[t$1.LOOSE] : re$1[t$1.FULL]);
46076
-
46077
- if (!m) {
46078
- throw new TypeError(`Invalid Version: ${version}`)
46079
- }
46080
-
46081
- this.raw = version;
46082
-
46083
- // these are actually numbers
46084
- this.major = +m[1];
46085
- this.minor = +m[2];
46086
- this.patch = +m[3];
46087
-
46088
- if (this.major > MAX_SAFE_INTEGER$1 || this.major < 0) {
46089
- throw new TypeError('Invalid major version')
46090
- }
46091
-
46092
- if (this.minor > MAX_SAFE_INTEGER$1 || this.minor < 0) {
46093
- throw new TypeError('Invalid minor version')
46094
- }
46095
-
46096
- if (this.patch > MAX_SAFE_INTEGER$1 || this.patch < 0) {
46097
- throw new TypeError('Invalid patch version')
46098
- }
46099
-
46100
- // numberify any prerelease numeric ids
46101
- if (!m[4]) {
46102
- this.prerelease = [];
46103
- } else {
46104
- this.prerelease = m[4].split('.').map((id) => {
46105
- if (/^[0-9]+$/.test(id)) {
46106
- const num = +id;
46107
- if (num >= 0 && num < MAX_SAFE_INTEGER$1) {
46108
- return num
46109
- }
45769
+ class WebBluetoothTransport {
45770
+ constructor(options = {}) {
45771
+ this.type = exports.TRANSPORT_TYPE.WEB;
45772
+ this.characteristicsByName = {};
45773
+ this.connection$ = new BehaviorSubject(exports.BLUETOOTH_CONNECTION.DISCONNECTED);
45774
+ this.pendingActions$ = new BehaviorSubject([]);
45775
+ this.logs$ = new ReplaySubject(10);
45776
+ this.onDisconnected$ = this._onDisconnected().pipe(share());
45777
+ this.connectionStream$ = this.connection$
45778
+ .asObservable()
45779
+ .pipe(filter((connection) => !!connection), distinctUntilChanged(), shareReplay(1));
45780
+ this._isAutoConnectEnabled$ = new ReplaySubject(1);
45781
+ this.options = Object.assign(Object.assign({}, defaultOptions$1), options);
45782
+ if (!isWebBluetoothSupported()) {
45783
+ const errorMessage = "Web Bluetooth is not supported";
45784
+ this.addLog(errorMessage);
45785
+ throw new Error(errorMessage);
46110
45786
  }
46111
- return id
46112
- });
45787
+ this._isAutoConnectEnabled$.subscribe((autoConnect) => {
45788
+ this.addLog(`Auto connect: ${autoConnect ? "enabled" : "disabled"}`);
45789
+ });
45790
+ this._isAutoConnectEnabled$.next(this.options.autoConnect);
45791
+ this.connection$.asObservable().subscribe((connection) => {
45792
+ this.addLog(`connection status is ${connection}`);
45793
+ });
45794
+ this.onDisconnected$.subscribe(() => {
45795
+ this.connection$.next(exports.BLUETOOTH_CONNECTION.DISCONNECTED);
45796
+ });
46113
45797
  }
46114
-
46115
- this.build = m[5] ? m[5].split('.') : [];
46116
- this.format();
46117
- }
46118
-
46119
- format () {
46120
- this.version = `${this.major}.${this.minor}.${this.patch}`;
46121
- if (this.prerelease.length) {
46122
- this.version += `-${this.prerelease.join('.')}`;
45798
+ _getPairedDevices() {
45799
+ return __awaiter$d(this, void 0, void 0, function* () {
45800
+ return yield navigator.bluetooth.getDevices();
45801
+ });
46123
45802
  }
46124
- return this.version
46125
- }
46126
-
46127
- toString () {
46128
- return this.version
46129
- }
46130
-
46131
- compare (other) {
46132
- debug_1('SemVer.compare', this.version, this.options, other);
46133
- if (!(other instanceof SemVer)) {
46134
- if (typeof other === 'string' && other === this.version) {
46135
- return 0
46136
- }
46137
- other = new SemVer(other, this.options);
45803
+ _autoConnect(selectedDevice$) {
45804
+ return this._isAutoConnectEnabled$.pipe(switchMap((isAutoConnectEnabled) => isAutoConnectEnabled
45805
+ ? merge(selectedDevice$, this.onDisconnected$.pipe(switchMap(() => selectedDevice$)))
45806
+ : NEVER), switchMap((selectedDevice) => __awaiter$d(this, void 0, void 0, function* () {
45807
+ var _a;
45808
+ const { deviceNickname } = selectedDevice;
45809
+ if (this.isConnected()) {
45810
+ this.addLog(`Auto connect: ${deviceNickname} is already connected. Skipping auto connect.`);
45811
+ return;
45812
+ }
45813
+ const [devicesError, devices] = yield this._getPairedDevices()
45814
+ .then((devices) => [null, devices])
45815
+ .catch((error) => [error, null]);
45816
+ if (devicesError) {
45817
+ throw new Error(`failed to get devices: ${(_a = devicesError === null || devicesError === void 0 ? void 0 : devicesError.message) !== null && _a !== void 0 ? _a : devicesError}`);
45818
+ }
45819
+ this.addLog(`Auto connect: found ${devices.length} devices ${devices
45820
+ .map(({ name }) => name)
45821
+ .join(", ")}`);
45822
+ // @important - Using `findLast` instead of `find` because somehow the browser
45823
+ // is finding multiple peripherals with the same name
45824
+ const device = devices.findLast((device) => device.name === deviceNickname);
45825
+ if (!device) {
45826
+ throw new Error(`couldn't find selected device in the list of paired devices.`);
45827
+ }
45828
+ this.addLog(`Auto connect: ${deviceNickname} was detected and previously paired`);
45829
+ return device;
45830
+ })), tap(() => {
45831
+ this.connection$.next(exports.BLUETOOTH_CONNECTION.SCANNING);
45832
+ }), switchMap((device) => onAdvertisementReceived(device)), switchMap((advertisement) => __awaiter$d(this, void 0, void 0, function* () {
45833
+ this.addLog(`Advertisement received for ${advertisement.device.name}`);
45834
+ return yield this.getServerServiceAndCharacteristics(advertisement.device);
45835
+ })));
46138
45836
  }
46139
-
46140
- if (other.version === this.version) {
46141
- return 0
45837
+ enableAutoConnect(autoConnect) {
45838
+ this._isAutoConnectEnabled$.next(autoConnect);
46142
45839
  }
46143
-
46144
- return this.compareMain(other) || this.comparePre(other)
46145
- }
46146
-
46147
- compareMain (other) {
46148
- if (!(other instanceof SemVer)) {
46149
- other = new SemVer(other, this.options);
45840
+ addLog(log) {
45841
+ this.logs$.next(log);
46150
45842
  }
46151
-
46152
- return (
46153
- compareIdentifiers$1(this.major, other.major) ||
46154
- compareIdentifiers$1(this.minor, other.minor) ||
46155
- compareIdentifiers$1(this.patch, other.patch)
46156
- )
46157
- }
46158
-
46159
- comparePre (other) {
46160
- if (!(other instanceof SemVer)) {
46161
- other = new SemVer(other, this.options);
45843
+ isConnected() {
45844
+ const connection = this.connection$.getValue();
45845
+ return connection === exports.BLUETOOTH_CONNECTION.CONNECTED;
46162
45846
  }
46163
-
46164
- // NOT having a prerelease is > having one
46165
- if (this.prerelease.length && !other.prerelease.length) {
46166
- return -1
46167
- } else if (!this.prerelease.length && other.prerelease.length) {
46168
- return 1
46169
- } else if (!this.prerelease.length && !other.prerelease.length) {
46170
- return 0
45847
+ connection() {
45848
+ return this.connectionStream$;
46171
45849
  }
46172
-
46173
- let i = 0;
46174
- do {
46175
- const a = this.prerelease[i];
46176
- const b = other.prerelease[i];
46177
- debug_1('prerelease compare', i, a, b);
46178
- if (a === undefined && b === undefined) {
46179
- return 0
46180
- } else if (b === undefined) {
46181
- return 1
46182
- } else if (a === undefined) {
46183
- return -1
46184
- } else if (a === b) {
46185
- continue
46186
- } else {
46187
- return compareIdentifiers$1(a, b)
46188
- }
46189
- } while (++i)
46190
- }
46191
-
46192
- compareBuild (other) {
46193
- if (!(other instanceof SemVer)) {
46194
- other = new SemVer(other, this.options);
46195
- }
46196
-
46197
- let i = 0;
46198
- do {
46199
- const a = this.build[i];
46200
- const b = other.build[i];
46201
- debug_1('prerelease compare', i, a, b);
46202
- if (a === undefined && b === undefined) {
46203
- return 0
46204
- } else if (b === undefined) {
46205
- return 1
46206
- } else if (a === undefined) {
46207
- return -1
46208
- } else if (a === b) {
46209
- continue
46210
- } else {
46211
- return compareIdentifiers$1(a, b)
46212
- }
46213
- } while (++i)
46214
- }
46215
-
46216
- // preminor will bump the version up to the next minor release, and immediately
46217
- // down to pre-release. premajor and prepatch work the same way.
46218
- inc (release, identifier) {
46219
- switch (release) {
46220
- case 'premajor':
46221
- this.prerelease.length = 0;
46222
- this.patch = 0;
46223
- this.minor = 0;
46224
- this.major++;
46225
- this.inc('pre', identifier);
46226
- break
46227
- case 'preminor':
46228
- this.prerelease.length = 0;
46229
- this.patch = 0;
46230
- this.minor++;
46231
- this.inc('pre', identifier);
46232
- break
46233
- case 'prepatch':
46234
- // If this is already a prerelease, it will bump to the next version
46235
- // drop any prereleases that might already exist, since they are not
46236
- // relevant at this point.
46237
- this.prerelease.length = 0;
46238
- this.inc('patch', identifier);
46239
- this.inc('pre', identifier);
46240
- break
46241
- // If the input is a non-prerelease version, this acts the same as
46242
- // prepatch.
46243
- case 'prerelease':
46244
- if (this.prerelease.length === 0) {
46245
- this.inc('patch', identifier);
46246
- }
46247
- this.inc('pre', identifier);
46248
- break
46249
-
46250
- case 'major':
46251
- // If this is a pre-major version, bump up to the same major version.
46252
- // Otherwise increment major.
46253
- // 1.0.0-5 bumps to 1.0.0
46254
- // 1.1.0 bumps to 2.0.0
46255
- if (
46256
- this.minor !== 0 ||
46257
- this.patch !== 0 ||
46258
- this.prerelease.length === 0
46259
- ) {
46260
- this.major++;
46261
- }
46262
- this.minor = 0;
46263
- this.patch = 0;
46264
- this.prerelease = [];
46265
- break
46266
- case 'minor':
46267
- // If this is a pre-minor version, bump up to the same minor version.
46268
- // Otherwise increment minor.
46269
- // 1.2.0-5 bumps to 1.2.0
46270
- // 1.2.1 bumps to 1.3.0
46271
- if (this.patch !== 0 || this.prerelease.length === 0) {
46272
- this.minor++;
46273
- }
46274
- this.patch = 0;
46275
- this.prerelease = [];
46276
- break
46277
- case 'patch':
46278
- // If this is not a pre-release version, it will increment the patch.
46279
- // If it is a pre-release it will bump up to the same patch version.
46280
- // 1.2.0-5 patches to 1.2.0
46281
- // 1.2.0 patches to 1.2.1
46282
- if (this.prerelease.length === 0) {
46283
- this.patch++;
46284
- }
46285
- this.prerelease = [];
46286
- break
46287
- // This probably shouldn't be used publicly.
46288
- // 1.0.0 'pre' would become 1.0.0-0 which is the wrong direction.
46289
- case 'pre':
46290
- if (this.prerelease.length === 0) {
46291
- this.prerelease = [0];
46292
- } else {
46293
- let i = this.prerelease.length;
46294
- while (--i >= 0) {
46295
- if (typeof this.prerelease[i] === 'number') {
46296
- this.prerelease[i]++;
46297
- i = -2;
46298
- }
46299
- }
46300
- if (i === -1) {
46301
- // didn't increment anything
46302
- this.prerelease.push(0);
46303
- }
46304
- }
46305
- if (identifier) {
46306
- // 1.2.0-beta.1 bumps to 1.2.0-beta.2,
46307
- // 1.2.0-beta.fooblz or 1.2.0-beta bumps to 1.2.0-beta.0
46308
- if (compareIdentifiers$1(this.prerelease[0], identifier) === 0) {
46309
- if (isNaN(this.prerelease[1])) {
46310
- this.prerelease = [identifier, 0];
46311
- }
46312
- } else {
46313
- this.prerelease = [identifier, 0];
46314
- }
46315
- }
46316
- break
46317
-
46318
- default:
46319
- throw new Error(`invalid increment argument: ${release}`)
46320
- }
46321
- this.format();
46322
- this.raw = this.version;
46323
- return this
46324
- }
46325
- }
46326
-
46327
- var semver = SemVer;
46328
-
46329
- const compare = (a, b, loose) =>
46330
- new semver(a, loose).compare(new semver(b, loose));
46331
-
46332
- var compare_1 = compare;
46333
-
46334
- const gte = (a, b, loose) => compare_1(a, b, loose) >= 0;
46335
- var gte_1 = gte;
46336
-
46337
- function osHasBluetoothSupport(selectedDevice, osVersion) {
46338
- if (!selectedDevice) {
46339
- return false;
46340
- }
46341
- // Only the Crown supports Bluetooth
46342
- const isCrown = Number(selectedDevice.modelVersion) >= 3;
46343
- if (!isCrown) {
46344
- return false;
46345
- }
46346
- const isEmulator = !!(selectedDevice === null || selectedDevice === void 0 ? void 0 : selectedDevice.emulator);
46347
- if (isEmulator) {
46348
- return false;
46349
- }
46350
- // `osVersion` is updated in real time,
46351
- // unlike accessing via `selectedDevice.osVersion`
46352
- return gte_1(osVersion !== null && osVersion !== void 0 ? osVersion : selectedDevice.osVersion, "16.0.0");
46353
- }
46354
-
46355
- var __awaiter$d = function (thisArg, _arguments, P, generator) {
46356
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
46357
- return new (P || (P = Promise))(function (resolve, reject) {
46358
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
46359
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
46360
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
46361
- step((generator = generator.apply(thisArg, _arguments || [])).next());
46362
- });
46363
- };
46364
- const defaultOptions$1 = {
46365
- autoConnect: true
46366
- };
46367
- class WebBluetoothTransport {
46368
- constructor(options = {}) {
46369
- this.type = exports.TRANSPORT_TYPE.WEB;
46370
- this.characteristicsByName = {};
46371
- this.connection$ = new BehaviorSubject(exports.BLUETOOTH_CONNECTION.DISCONNECTED);
46372
- this.pendingActions$ = new BehaviorSubject([]);
46373
- this.logs$ = new ReplaySubject(10);
46374
- this.onDisconnected$ = this._onDisconnected().pipe(share());
46375
- this.connectionStream$ = this.connection$
46376
- .asObservable()
46377
- .pipe(filter((connection) => !!connection), distinctUntilChanged(), shareReplay(1));
46378
- this._isAutoConnectEnabled$ = new ReplaySubject(1);
46379
- this.options = Object.assign(Object.assign({}, defaultOptions$1), options);
46380
- if (!isWebBluetoothSupported()) {
46381
- const errorMessage = "Web Bluetooth is not supported";
46382
- this.addLog(errorMessage);
46383
- throw new Error(errorMessage);
46384
- }
46385
- this._isAutoConnectEnabled$.subscribe((autoConnect) => {
46386
- this.addLog(`Auto connect: ${autoConnect ? "enabled" : "disabled"}`);
46387
- });
46388
- this._isAutoConnectEnabled$.next(this.options.autoConnect);
46389
- this.connection$.asObservable().subscribe((connection) => {
46390
- this.addLog(`connection status is ${connection}`);
46391
- });
46392
- this.onDisconnected$.subscribe(() => {
46393
- this.connection$.next(exports.BLUETOOTH_CONNECTION.DISCONNECTED);
46394
- });
46395
- }
46396
- _getPairedDevices() {
46397
- return __awaiter$d(this, void 0, void 0, function* () {
46398
- return yield navigator.bluetooth.getDevices();
46399
- });
46400
- }
46401
- _autoConnect(selectedDevice$, osVersion$) {
46402
- return this._isAutoConnectEnabled$.pipe(switchMap((isAutoConnectEnabled) => isAutoConnectEnabled
46403
- ? merge(selectedDevice$, this.onDisconnected$.pipe(switchMap(() => selectedDevice$)))
46404
- : NEVER), combineLatestWith(osVersion$), switchMap(([selectedDevice, osVersion]) => osHasBluetoothSupport(selectedDevice, osVersion)
46405
- ? of(selectedDevice)
46406
- : EMPTY), switchMap((selectedDevice) => __awaiter$d(this, void 0, void 0, function* () {
46407
- var _a;
46408
- const { deviceNickname } = selectedDevice;
46409
- if (this.isConnected()) {
46410
- this.addLog(`Auto connect: ${deviceNickname} is already connected. Skipping auto connect.`);
46411
- return;
46412
- }
46413
- const [devicesError, devices] = yield this._getPairedDevices()
46414
- .then((devices) => [null, devices])
46415
- .catch((error) => [error, null]);
46416
- if (devicesError) {
46417
- throw new Error(`failed to get devices: ${(_a = devicesError === null || devicesError === void 0 ? void 0 : devicesError.message) !== null && _a !== void 0 ? _a : devicesError}`);
46418
- }
46419
- this.addLog(`Auto connect: found ${devices.length} devices ${devices
46420
- .map(({ name }) => name)
46421
- .join(", ")}`);
46422
- // @important - Using `findLast` instead of `find` because somehow the browser
46423
- // is finding multiple peripherals with the same name
46424
- const device = devices.findLast((device) => device.name === deviceNickname);
46425
- if (!device) {
46426
- throw new Error(`couldn't find selected device in the list of paired devices.`);
46427
- }
46428
- this.addLog(`Auto connect: ${deviceNickname} was detected and previously paired`);
46429
- return device;
46430
- })), tap(() => {
46431
- this.connection$.next(exports.BLUETOOTH_CONNECTION.SCANNING);
46432
- }), switchMap((device) => onAdvertisementReceived(device)), switchMap((advertisement) => __awaiter$d(this, void 0, void 0, function* () {
46433
- this.addLog(`Advertisement received for ${advertisement.device.name}`);
46434
- return yield this.getServerServiceAndCharacteristics(advertisement.device);
46435
- })));
46436
- }
46437
- enableAutoConnect(autoConnect) {
46438
- this._isAutoConnectEnabled$.next(autoConnect);
46439
- }
46440
- addLog(log) {
46441
- this.logs$.next(log);
46442
- }
46443
- isConnected() {
46444
- const connection = this.connection$.getValue();
46445
- return connection === exports.BLUETOOTH_CONNECTION.CONNECTED;
46446
- }
46447
- connection() {
46448
- return this.connectionStream$;
46449
- }
46450
- connect(deviceNickname) {
46451
- return __awaiter$d(this, void 0, void 0, function* () {
46452
- try {
46453
- // requires user gesture
46454
- const device = yield this.requestDevice(deviceNickname);
46455
- yield this.getServerServiceAndCharacteristics(device);
46456
- }
46457
- catch (error) {
46458
- return Promise.reject(error);
46459
- }
46460
- });
45850
+ connect(deviceNickname) {
45851
+ return __awaiter$d(this, void 0, void 0, function* () {
45852
+ try {
45853
+ // requires user gesture
45854
+ const device = yield this.requestDevice(deviceNickname);
45855
+ yield this.getServerServiceAndCharacteristics(device);
45856
+ }
45857
+ catch (error) {
45858
+ return Promise.reject(error);
45859
+ }
45860
+ });
46461
45861
  }
46462
45862
  requestDevice(deviceNickname) {
46463
45863
  return __awaiter$d(this, void 0, void 0, function* () {
@@ -46643,45 +46043,38 @@ var Neurosity = (function (exports) {
46643
46043
  const actions = this.pendingActions$.getValue();
46644
46044
  this.pendingActions$.next(actions.filter((id) => id !== actionId));
46645
46045
  }
46646
- _autoToggleActionNotifications(selectedDevice$, osVersion$) {
46647
- return __awaiter$d(this, void 0, void 0, function* () {
46648
- let actionsCharacteristic;
46649
- let started = false;
46650
- const sideEffects$ = this.connection$.asObservable().pipe(switchMap((connection) => connection === exports.BLUETOOTH_CONNECTION.CONNECTED
46651
- ? defer(() => this.getCharacteristicByName("actions")).pipe(switchMap((characteristic) => {
46652
- actionsCharacteristic = characteristic;
46653
- return this.pendingActions$;
46654
- }))
46655
- : NEVER), tap((pendingActions) => __awaiter$d(this, void 0, void 0, function* () {
46656
- var _a, _b;
46657
- const hasPendingActions = !!pendingActions.length;
46658
- if (hasPendingActions && !started) {
46659
- started = true;
46660
- try {
46661
- yield actionsCharacteristic.startNotifications();
46662
- this.addLog(`Started notifications for [actions] characteristic`);
46663
- }
46664
- catch (error) {
46665
- this.addLog(`Attemped to start notifications for [actions] characteristic: ${(_a = error === null || error === void 0 ? void 0 : error.message) !== null && _a !== void 0 ? _a : error}`);
46666
- }
46046
+ _autoToggleActionNotifications() {
46047
+ let actionsCharacteristic;
46048
+ let started = false;
46049
+ return this.connection$.asObservable().pipe(switchMap((connection) => connection === exports.BLUETOOTH_CONNECTION.CONNECTED
46050
+ ? defer(() => this.getCharacteristicByName("actions")).pipe(switchMap((characteristic) => {
46051
+ actionsCharacteristic = characteristic;
46052
+ return this.pendingActions$;
46053
+ }))
46054
+ : NEVER), tap((pendingActions) => __awaiter$d(this, void 0, void 0, function* () {
46055
+ var _a, _b;
46056
+ const hasPendingActions = !!pendingActions.length;
46057
+ if (hasPendingActions && !started) {
46058
+ started = true;
46059
+ try {
46060
+ yield actionsCharacteristic.startNotifications();
46061
+ this.addLog(`Started notifications for [actions] characteristic`);
46667
46062
  }
46668
- if (!hasPendingActions && started) {
46669
- started = false;
46670
- try {
46671
- yield actionsCharacteristic.stopNotifications();
46672
- this.addLog(`Stopped notifications for actions characteristic`);
46673
- }
46674
- catch (error) {
46675
- this.addLog(`Attemped to stop notifications for [actions] characteristic: ${(_b = error === null || error === void 0 ? void 0 : error.message) !== null && _b !== void 0 ? _b : error}`);
46676
- }
46063
+ catch (error) {
46064
+ this.addLog(`Attemped to start notifications for [actions] characteristic: ${(_a = error === null || error === void 0 ? void 0 : error.message) !== null && _a !== void 0 ? _a : error}`);
46677
46065
  }
46678
- })));
46679
- selectedDevice$
46680
- .pipe(combineLatestWith(osVersion$), switchMap(([selectedDevice, osVersion]) => !osHasBluetoothSupport(selectedDevice, osVersion)
46681
- ? EMPTY
46682
- : sideEffects$))
46683
- .subscribe();
46684
- });
46066
+ }
46067
+ if (!hasPendingActions && started) {
46068
+ started = false;
46069
+ try {
46070
+ yield actionsCharacteristic.stopNotifications();
46071
+ this.addLog(`Stopped notifications for actions characteristic`);
46072
+ }
46073
+ catch (error) {
46074
+ this.addLog(`Attemped to stop notifications for [actions] characteristic: ${(_b = error === null || error === void 0 ? void 0 : error.message) !== null && _b !== void 0 ? _b : error}`);
46075
+ }
46076
+ }
46077
+ })));
46685
46078
  }
46686
46079
  dispatchAction({ characteristicName, action }) {
46687
46080
  return __awaiter$d(this, void 0, void 0, function* () {
@@ -46852,16 +46245,14 @@ var Neurosity = (function (exports) {
46852
46245
  const connection = this.connection$.getValue();
46853
46246
  return connection === exports.BLUETOOTH_CONNECTION.CONNECTED;
46854
46247
  }
46855
- _autoConnect(selectedDevice$, osVersion$) {
46248
+ _autoConnect(selectedDevice$) {
46856
46249
  const selectedDeviceAfterDisconnect$ = this.onDisconnected$.pipe(switchMap(() => selectedDevice$));
46857
46250
  return this._isAutoConnectEnabled$.pipe(switchMap((isAutoConnectEnabled) => isAutoConnectEnabled
46858
46251
  ? merge(selectedDevice$, selectedDeviceAfterDisconnect$)
46859
- : NEVER), combineLatestWith(osVersion$), switchMap(([selectedDevice, osVersion]) => !osHasBluetoothSupport(selectedDevice, osVersion)
46860
- ? NEVER
46861
- : this.scan().pipe(switchMap((peripherals) => {
46862
- const peripheralMatch = peripherals.find((peripheral) => peripheral.name === (selectedDevice === null || selectedDevice === void 0 ? void 0 : selectedDevice.deviceNickname));
46863
- return peripheralMatch ? of(peripheralMatch) : NEVER;
46864
- }), distinct((peripheral) => peripheral.id), take(1))), switchMap((peripheral) => __awaiter$e(this, void 0, void 0, function* () {
46252
+ : NEVER), switchMap((selectedDevice) => this.scan().pipe(switchMap((peripherals) => {
46253
+ const peripheralMatch = peripherals.find((peripheral) => peripheral.name === (selectedDevice === null || selectedDevice === void 0 ? void 0 : selectedDevice.deviceNickname));
46254
+ return peripheralMatch ? of(peripheralMatch) : NEVER;
46255
+ }), distinct((peripheral) => peripheral.id), take(1))), switchMap((peripheral) => __awaiter$e(this, void 0, void 0, function* () {
46865
46256
  return yield this.connect(peripheral);
46866
46257
  })));
46867
46258
  }
@@ -47084,42 +46475,35 @@ var Neurosity = (function (exports) {
47084
46475
  const actions = this.pendingActions$.getValue();
47085
46476
  this.pendingActions$.next(actions.filter((id) => id !== actionId));
47086
46477
  }
47087
- _autoToggleActionNotifications(selectedDevice$, osVersion$) {
47088
- return __awaiter$e(this, void 0, void 0, function* () {
47089
- let started = false;
47090
- const sideEffects$ = this.connection$.asObservable().pipe(switchMap((connection) => connection === exports.BLUETOOTH_CONNECTION.CONNECTED
47091
- ? this.pendingActions$
47092
- : NEVER), tap((pendingActions) => __awaiter$e(this, void 0, void 0, function* () {
47093
- var _a, _b;
47094
- const { peripheralId, serviceUUID, characteristicUUID } = this.getCharacteristicByName("actions");
47095
- const hasPendingActions = !!pendingActions.length;
47096
- if (hasPendingActions && !started) {
47097
- started = true;
47098
- try {
47099
- yield this.BleManager.startNotification(peripheralId, serviceUUID, characteristicUUID);
47100
- this.addLog(`Started notifications for [actions] characteristic`);
47101
- }
47102
- catch (error) {
47103
- this.addLog(`Attemped to start notifications for [actions] characteristic: ${(_a = error === null || error === void 0 ? void 0 : error.message) !== null && _a !== void 0 ? _a : error}`);
47104
- }
46478
+ _autoToggleActionNotifications() {
46479
+ let started = false;
46480
+ return this.connection$.asObservable().pipe(switchMap((connection) => connection === exports.BLUETOOTH_CONNECTION.CONNECTED
46481
+ ? this.pendingActions$
46482
+ : NEVER), tap((pendingActions) => __awaiter$e(this, void 0, void 0, function* () {
46483
+ var _a, _b;
46484
+ const { peripheralId, serviceUUID, characteristicUUID } = this.getCharacteristicByName("actions");
46485
+ const hasPendingActions = !!pendingActions.length;
46486
+ if (hasPendingActions && !started) {
46487
+ started = true;
46488
+ try {
46489
+ yield this.BleManager.startNotification(peripheralId, serviceUUID, characteristicUUID);
46490
+ this.addLog(`Started notifications for [actions] characteristic`);
47105
46491
  }
47106
- if (!hasPendingActions && started) {
47107
- started = false;
47108
- try {
47109
- yield this.BleManager.stopNotification(peripheralId, serviceUUID, characteristicUUID);
47110
- this.addLog(`Stopped notifications for actions characteristic`);
47111
- }
47112
- catch (error) {
47113
- this.addLog(`Attemped to stop notifications for [actions] characteristic: ${(_b = error === null || error === void 0 ? void 0 : error.message) !== null && _b !== void 0 ? _b : error}`);
47114
- }
46492
+ catch (error) {
46493
+ this.addLog(`Attemped to start notifications for [actions] characteristic: ${(_a = error === null || error === void 0 ? void 0 : error.message) !== null && _a !== void 0 ? _a : error}`);
47115
46494
  }
47116
- })));
47117
- selectedDevice$
47118
- .pipe(combineLatestWith(osVersion$), switchMap(([selectedDevice, osVersion]) => !osHasBluetoothSupport(selectedDevice, osVersion)
47119
- ? EMPTY
47120
- : sideEffects$))
47121
- .subscribe();
47122
- });
46495
+ }
46496
+ if (!hasPendingActions && started) {
46497
+ started = false;
46498
+ try {
46499
+ yield this.BleManager.stopNotification(peripheralId, serviceUUID, characteristicUUID);
46500
+ this.addLog(`Stopped notifications for actions characteristic`);
46501
+ }
46502
+ catch (error) {
46503
+ this.addLog(`Attemped to stop notifications for [actions] characteristic: ${(_b = error === null || error === void 0 ? void 0 : error.message) !== null && _b !== void 0 ? _b : error}`);
46504
+ }
46505
+ }
46506
+ })));
47123
46507
  }
47124
46508
  dispatchAction({ characteristicName, action }) {
47125
46509
  return __awaiter$e(this, void 0, void 0, function* () {
@@ -47270,9 +46654,9 @@ var Neurosity = (function (exports) {
47270
46654
  class BluetoothClient {
47271
46655
  constructor(options) {
47272
46656
  this.selectedDevice$ = new ReplaySubject(1);
47273
- this.osVersion$ = new ReplaySubject(1);
46657
+ this.osHasBluetoothSupport$ = new ReplaySubject(1);
47274
46658
  this.isAuthenticated$ = new ReplaySubject(1);
47275
- const { transport, selectedDevice$, createBluetoothToken } = options !== null && options !== void 0 ? options : {};
46659
+ const { transport, selectedDevice$, osHasBluetoothSupport$, createBluetoothToken } = options !== null && options !== void 0 ? options : {};
47276
46660
  if (!transport) {
47277
46661
  throw new Error(`No bluetooth transport provided.`);
47278
46662
  }
@@ -47281,9 +46665,14 @@ var Neurosity = (function (exports) {
47281
46665
  if (selectedDevice$) {
47282
46666
  selectedDevice$.subscribe(this.selectedDevice$);
47283
46667
  }
47284
- // Auto Connect
47285
- this.transport
47286
- ._autoConnect(this.selectedDevice$, this.osVersion$)
46668
+ // Pass events to the internal osHasBluetoothSupport$ if osHasBluetoothSupport$ is passed via options
46669
+ if (osHasBluetoothSupport$) {
46670
+ osHasBluetoothSupport$.subscribe(this.osHasBluetoothSupport$);
46671
+ }
46672
+ this.osHasBluetoothSupport$
46673
+ .pipe(switchMap((osHasBluetoothSupport) => osHasBluetoothSupport
46674
+ ? this.transport._autoConnect(this.selectedDevice$)
46675
+ : EMPTY))
47287
46676
  .subscribe({
47288
46677
  error: (error) => {
47289
46678
  var _a;
@@ -47299,7 +46688,11 @@ var Neurosity = (function (exports) {
47299
46688
  this.transport.addLog("Auto authentication not enabled");
47300
46689
  }
47301
46690
  // Auto manage action notifications
47302
- this.transport._autoToggleActionNotifications(this.selectedDevice$, this.osVersion$);
46691
+ this.osHasBluetoothSupport$
46692
+ .pipe(switchMap((osHasBluetoothSupport) => osHasBluetoothSupport
46693
+ ? this.transport._autoToggleActionNotifications()
46694
+ : EMPTY))
46695
+ .subscribe();
47303
46696
  // Multicast metrics (share)
47304
46697
  this._focus$ = this._subscribeWhileAuthenticated("focus");
47305
46698
  this._calm$ = this._subscribeWhileAuthenticated("calm");
@@ -47323,28 +46716,24 @@ var Neurosity = (function (exports) {
47323
46716
  const reauthenticateInterval$ = timer(0, REAUTHENTICATE_INTERVAL).pipe(tap(() => {
47324
46717
  this.transport.addLog(`Auto authentication in progress...`);
47325
46718
  }));
47326
- return this.selectedDevice$.pipe(combineLatestWith(this.osVersion$), switchMap(([selectedDevice, osVersion]) => !osHasBluetoothSupport(selectedDevice, osVersion)
47327
- ? EMPTY
47328
- : this.connection().pipe(switchMap((connection) => connection === exports.BLUETOOTH_CONNECTION.CONNECTED
47329
- ? reauthenticateInterval$
47330
- : EMPTY), switchMap(() => __awaiter$f(this, void 0, void 0, function* () { return yield this.isAuthenticated(); })), tap(([isAuthenticated]) => __awaiter$f(this, void 0, void 0, function* () {
47331
- if (!isAuthenticated) {
47332
- const token = yield createBluetoothToken();
47333
- yield this.authenticate(token);
47334
- }
47335
- else {
47336
- this.transport.addLog(`Already authenticated`);
47337
- }
47338
- })))));
46719
+ return this.osHasBluetoothSupport$.pipe(switchMap((osHasBluetoothSupport) => osHasBluetoothSupport ? this.connection() : EMPTY), switchMap((connection) => connection === exports.BLUETOOTH_CONNECTION.CONNECTED
46720
+ ? reauthenticateInterval$
46721
+ : EMPTY), switchMap(() => __awaiter$f(this, void 0, void 0, function* () { return yield this.isAuthenticated(); })), tap(([isAuthenticated]) => __awaiter$f(this, void 0, void 0, function* () {
46722
+ if (!isAuthenticated) {
46723
+ const token = yield createBluetoothToken();
46724
+ yield this.authenticate(token);
46725
+ }
46726
+ else {
46727
+ this.transport.addLog(`Already authenticated`);
46728
+ }
46729
+ })));
47339
46730
  }
47340
46731
  enableAutoConnect(autoConnect) {
47341
46732
  this.transport.enableAutoConnect(autoConnect);
47342
46733
  }
47343
46734
  _hasBluetoothSupport() {
47344
46735
  return __awaiter$f(this, void 0, void 0, function* () {
47345
- const selectedDevice = yield firstValueFrom(this.selectedDevice$);
47346
- const osVersion = yield firstValueFrom(this.osVersion$);
47347
- return osHasBluetoothSupport(selectedDevice, osVersion);
46736
+ return yield firstValueFrom(this.osHasBluetoothSupport$);
47348
46737
  });
47349
46738
  }
47350
46739
  authenticate(token) {
@@ -47425,13 +46814,11 @@ var Neurosity = (function (exports) {
47425
46814
  });
47426
46815
  }
47427
46816
  _subscribeWhileAuthenticated(characteristicName) {
47428
- return this.selectedDevice$.pipe(combineLatestWith(this.osVersion$), switchMap(([selectedDevice, osVersion]) => !osHasBluetoothSupport(selectedDevice, osVersion)
47429
- ? EMPTY
47430
- : this.isAuthenticated$.pipe(distinctUntilChanged(), switchMap((isAuthenticated) => isAuthenticated
47431
- ? this.transport.subscribeToCharacteristic({
47432
- characteristicName
47433
- })
47434
- : EMPTY))), share());
46817
+ return this.osHasBluetoothSupport$.pipe(switchMap((osHasBluetoothSupport) => osHasBluetoothSupport ? this.isAuthenticated$ : EMPTY), distinctUntilChanged(), switchMap((isAuthenticated) => isAuthenticated
46818
+ ? this.transport.subscribeToCharacteristic({
46819
+ characteristicName
46820
+ })
46821
+ : EMPTY), share());
47435
46822
  }
47436
46823
  focus() {
47437
46824
  return this._focus$;
@@ -47560,6 +46947,578 @@ var Neurosity = (function (exports) {
47560
46947
  }
47561
46948
  }
47562
46949
 
46950
+ const debug = (
46951
+ typeof process === 'object' &&
46952
+ process.env &&
46953
+ process.env.NODE_DEBUG &&
46954
+ /\bsemver\b/i.test(process.env.NODE_DEBUG)
46955
+ ) ? (...args) => console.error('SEMVER', ...args)
46956
+ : () => {};
46957
+
46958
+ var debug_1 = debug;
46959
+
46960
+ // Note: this is the semver.org version of the spec that it implements
46961
+ // Not necessarily the package version of this code.
46962
+ const SEMVER_SPEC_VERSION = '2.0.0';
46963
+
46964
+ const MAX_LENGTH = 256;
46965
+ const MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER ||
46966
+ /* istanbul ignore next */ 9007199254740991;
46967
+
46968
+ // Max safe segment length for coercion.
46969
+ const MAX_SAFE_COMPONENT_LENGTH = 16;
46970
+
46971
+ var constants = {
46972
+ SEMVER_SPEC_VERSION,
46973
+ MAX_LENGTH,
46974
+ MAX_SAFE_INTEGER,
46975
+ MAX_SAFE_COMPONENT_LENGTH,
46976
+ };
46977
+
46978
+ function createCommonjsModule(fn, module) {
46979
+ return module = { exports: {} }, fn(module, module.exports), module.exports;
46980
+ }
46981
+
46982
+ var re_1 = createCommonjsModule(function (module, exports) {
46983
+ const { MAX_SAFE_COMPONENT_LENGTH } = constants;
46984
+
46985
+ exports = module.exports = {};
46986
+
46987
+ // The actual regexps go on exports.re
46988
+ const re = exports.re = [];
46989
+ const src = exports.src = [];
46990
+ const t = exports.t = {};
46991
+ let R = 0;
46992
+
46993
+ const createToken = (name, value, isGlobal) => {
46994
+ const index = R++;
46995
+ debug_1(name, index, value);
46996
+ t[name] = index;
46997
+ src[index] = value;
46998
+ re[index] = new RegExp(value, isGlobal ? 'g' : undefined);
46999
+ };
47000
+
47001
+ // The following Regular Expressions can be used for tokenizing,
47002
+ // validating, and parsing SemVer version strings.
47003
+
47004
+ // ## Numeric Identifier
47005
+ // A single `0`, or a non-zero digit followed by zero or more digits.
47006
+
47007
+ createToken('NUMERICIDENTIFIER', '0|[1-9]\\d*');
47008
+ createToken('NUMERICIDENTIFIERLOOSE', '[0-9]+');
47009
+
47010
+ // ## Non-numeric Identifier
47011
+ // Zero or more digits, followed by a letter or hyphen, and then zero or
47012
+ // more letters, digits, or hyphens.
47013
+
47014
+ createToken('NONNUMERICIDENTIFIER', '\\d*[a-zA-Z-][a-zA-Z0-9-]*');
47015
+
47016
+ // ## Main Version
47017
+ // Three dot-separated numeric identifiers.
47018
+
47019
+ createToken('MAINVERSION', `(${src[t.NUMERICIDENTIFIER]})\\.` +
47020
+ `(${src[t.NUMERICIDENTIFIER]})\\.` +
47021
+ `(${src[t.NUMERICIDENTIFIER]})`);
47022
+
47023
+ createToken('MAINVERSIONLOOSE', `(${src[t.NUMERICIDENTIFIERLOOSE]})\\.` +
47024
+ `(${src[t.NUMERICIDENTIFIERLOOSE]})\\.` +
47025
+ `(${src[t.NUMERICIDENTIFIERLOOSE]})`);
47026
+
47027
+ // ## Pre-release Version Identifier
47028
+ // A numeric identifier, or a non-numeric identifier.
47029
+
47030
+ createToken('PRERELEASEIDENTIFIER', `(?:${src[t.NUMERICIDENTIFIER]
47031
+ }|${src[t.NONNUMERICIDENTIFIER]})`);
47032
+
47033
+ createToken('PRERELEASEIDENTIFIERLOOSE', `(?:${src[t.NUMERICIDENTIFIERLOOSE]
47034
+ }|${src[t.NONNUMERICIDENTIFIER]})`);
47035
+
47036
+ // ## Pre-release Version
47037
+ // Hyphen, followed by one or more dot-separated pre-release version
47038
+ // identifiers.
47039
+
47040
+ createToken('PRERELEASE', `(?:-(${src[t.PRERELEASEIDENTIFIER]
47041
+ }(?:\\.${src[t.PRERELEASEIDENTIFIER]})*))`);
47042
+
47043
+ createToken('PRERELEASELOOSE', `(?:-?(${src[t.PRERELEASEIDENTIFIERLOOSE]
47044
+ }(?:\\.${src[t.PRERELEASEIDENTIFIERLOOSE]})*))`);
47045
+
47046
+ // ## Build Metadata Identifier
47047
+ // Any combination of digits, letters, or hyphens.
47048
+
47049
+ createToken('BUILDIDENTIFIER', '[0-9A-Za-z-]+');
47050
+
47051
+ // ## Build Metadata
47052
+ // Plus sign, followed by one or more period-separated build metadata
47053
+ // identifiers.
47054
+
47055
+ createToken('BUILD', `(?:\\+(${src[t.BUILDIDENTIFIER]
47056
+ }(?:\\.${src[t.BUILDIDENTIFIER]})*))`);
47057
+
47058
+ // ## Full Version String
47059
+ // A main version, followed optionally by a pre-release version and
47060
+ // build metadata.
47061
+
47062
+ // Note that the only major, minor, patch, and pre-release sections of
47063
+ // the version string are capturing groups. The build metadata is not a
47064
+ // capturing group, because it should not ever be used in version
47065
+ // comparison.
47066
+
47067
+ createToken('FULLPLAIN', `v?${src[t.MAINVERSION]
47068
+ }${src[t.PRERELEASE]}?${
47069
+ src[t.BUILD]}?`);
47070
+
47071
+ createToken('FULL', `^${src[t.FULLPLAIN]}$`);
47072
+
47073
+ // like full, but allows v1.2.3 and =1.2.3, which people do sometimes.
47074
+ // also, 1.0.0alpha1 (prerelease without the hyphen) which is pretty
47075
+ // common in the npm registry.
47076
+ createToken('LOOSEPLAIN', `[v=\\s]*${src[t.MAINVERSIONLOOSE]
47077
+ }${src[t.PRERELEASELOOSE]}?${
47078
+ src[t.BUILD]}?`);
47079
+
47080
+ createToken('LOOSE', `^${src[t.LOOSEPLAIN]}$`);
47081
+
47082
+ createToken('GTLT', '((?:<|>)?=?)');
47083
+
47084
+ // Something like "2.*" or "1.2.x".
47085
+ // Note that "x.x" is a valid xRange identifer, meaning "any version"
47086
+ // Only the first item is strictly required.
47087
+ createToken('XRANGEIDENTIFIERLOOSE', `${src[t.NUMERICIDENTIFIERLOOSE]}|x|X|\\*`);
47088
+ createToken('XRANGEIDENTIFIER', `${src[t.NUMERICIDENTIFIER]}|x|X|\\*`);
47089
+
47090
+ createToken('XRANGEPLAIN', `[v=\\s]*(${src[t.XRANGEIDENTIFIER]})` +
47091
+ `(?:\\.(${src[t.XRANGEIDENTIFIER]})` +
47092
+ `(?:\\.(${src[t.XRANGEIDENTIFIER]})` +
47093
+ `(?:${src[t.PRERELEASE]})?${
47094
+ src[t.BUILD]}?` +
47095
+ `)?)?`);
47096
+
47097
+ createToken('XRANGEPLAINLOOSE', `[v=\\s]*(${src[t.XRANGEIDENTIFIERLOOSE]})` +
47098
+ `(?:\\.(${src[t.XRANGEIDENTIFIERLOOSE]})` +
47099
+ `(?:\\.(${src[t.XRANGEIDENTIFIERLOOSE]})` +
47100
+ `(?:${src[t.PRERELEASELOOSE]})?${
47101
+ src[t.BUILD]}?` +
47102
+ `)?)?`);
47103
+
47104
+ createToken('XRANGE', `^${src[t.GTLT]}\\s*${src[t.XRANGEPLAIN]}$`);
47105
+ createToken('XRANGELOOSE', `^${src[t.GTLT]}\\s*${src[t.XRANGEPLAINLOOSE]}$`);
47106
+
47107
+ // Coercion.
47108
+ // Extract anything that could conceivably be a part of a valid semver
47109
+ createToken('COERCE', `${'(^|[^\\d])' +
47110
+ '(\\d{1,'}${MAX_SAFE_COMPONENT_LENGTH}})` +
47111
+ `(?:\\.(\\d{1,${MAX_SAFE_COMPONENT_LENGTH}}))?` +
47112
+ `(?:\\.(\\d{1,${MAX_SAFE_COMPONENT_LENGTH}}))?` +
47113
+ `(?:$|[^\\d])`);
47114
+ createToken('COERCERTL', src[t.COERCE], true);
47115
+
47116
+ // Tilde ranges.
47117
+ // Meaning is "reasonably at or greater than"
47118
+ createToken('LONETILDE', '(?:~>?)');
47119
+
47120
+ createToken('TILDETRIM', `(\\s*)${src[t.LONETILDE]}\\s+`, true);
47121
+ exports.tildeTrimReplace = '$1~';
47122
+
47123
+ createToken('TILDE', `^${src[t.LONETILDE]}${src[t.XRANGEPLAIN]}$`);
47124
+ createToken('TILDELOOSE', `^${src[t.LONETILDE]}${src[t.XRANGEPLAINLOOSE]}$`);
47125
+
47126
+ // Caret ranges.
47127
+ // Meaning is "at least and backwards compatible with"
47128
+ createToken('LONECARET', '(?:\\^)');
47129
+
47130
+ createToken('CARETTRIM', `(\\s*)${src[t.LONECARET]}\\s+`, true);
47131
+ exports.caretTrimReplace = '$1^';
47132
+
47133
+ createToken('CARET', `^${src[t.LONECARET]}${src[t.XRANGEPLAIN]}$`);
47134
+ createToken('CARETLOOSE', `^${src[t.LONECARET]}${src[t.XRANGEPLAINLOOSE]}$`);
47135
+
47136
+ // A simple gt/lt/eq thing, or just "" to indicate "any version"
47137
+ createToken('COMPARATORLOOSE', `^${src[t.GTLT]}\\s*(${src[t.LOOSEPLAIN]})$|^$`);
47138
+ createToken('COMPARATOR', `^${src[t.GTLT]}\\s*(${src[t.FULLPLAIN]})$|^$`);
47139
+
47140
+ // An expression to strip any whitespace between the gtlt and the thing
47141
+ // it modifies, so that `> 1.2.3` ==> `>1.2.3`
47142
+ createToken('COMPARATORTRIM', `(\\s*)${src[t.GTLT]
47143
+ }\\s*(${src[t.LOOSEPLAIN]}|${src[t.XRANGEPLAIN]})`, true);
47144
+ exports.comparatorTrimReplace = '$1$2$3';
47145
+
47146
+ // Something like `1.2.3 - 1.2.4`
47147
+ // Note that these all use the loose form, because they'll be
47148
+ // checked against either the strict or loose comparator form
47149
+ // later.
47150
+ createToken('HYPHENRANGE', `^\\s*(${src[t.XRANGEPLAIN]})` +
47151
+ `\\s+-\\s+` +
47152
+ `(${src[t.XRANGEPLAIN]})` +
47153
+ `\\s*$`);
47154
+
47155
+ createToken('HYPHENRANGELOOSE', `^\\s*(${src[t.XRANGEPLAINLOOSE]})` +
47156
+ `\\s+-\\s+` +
47157
+ `(${src[t.XRANGEPLAINLOOSE]})` +
47158
+ `\\s*$`);
47159
+
47160
+ // Star ranges basically just allow anything at all.
47161
+ createToken('STAR', '(<|>)?=?\\s*\\*');
47162
+ // >=0.0.0 is like a star
47163
+ createToken('GTE0', '^\\s*>=\\s*0\\.0\\.0\\s*$');
47164
+ createToken('GTE0PRE', '^\\s*>=\\s*0\\.0\\.0-0\\s*$');
47165
+ });
47166
+ var re_2 = re_1.re;
47167
+ var re_3 = re_1.src;
47168
+ var re_4 = re_1.t;
47169
+ var re_5 = re_1.tildeTrimReplace;
47170
+ var re_6 = re_1.caretTrimReplace;
47171
+ var re_7 = re_1.comparatorTrimReplace;
47172
+
47173
+ // parse out just the options we care about so we always get a consistent
47174
+ // obj with keys in a consistent order.
47175
+ const opts = ['includePrerelease', 'loose', 'rtl'];
47176
+ const parseOptions = options =>
47177
+ !options ? {}
47178
+ : typeof options !== 'object' ? { loose: true }
47179
+ : opts.filter(k => options[k]).reduce((o, k) => {
47180
+ o[k] = true;
47181
+ return o
47182
+ }, {});
47183
+ var parseOptions_1 = parseOptions;
47184
+
47185
+ const numeric = /^[0-9]+$/;
47186
+ const compareIdentifiers = (a, b) => {
47187
+ const anum = numeric.test(a);
47188
+ const bnum = numeric.test(b);
47189
+
47190
+ if (anum && bnum) {
47191
+ a = +a;
47192
+ b = +b;
47193
+ }
47194
+
47195
+ return a === b ? 0
47196
+ : (anum && !bnum) ? -1
47197
+ : (bnum && !anum) ? 1
47198
+ : a < b ? -1
47199
+ : 1
47200
+ };
47201
+
47202
+ const rcompareIdentifiers = (a, b) => compareIdentifiers(b, a);
47203
+
47204
+ var identifiers = {
47205
+ compareIdentifiers,
47206
+ rcompareIdentifiers,
47207
+ };
47208
+
47209
+ const { MAX_LENGTH: MAX_LENGTH$1, MAX_SAFE_INTEGER: MAX_SAFE_INTEGER$1 } = constants;
47210
+ const { re: re$1, t: t$1 } = re_1;
47211
+
47212
+
47213
+ const { compareIdentifiers: compareIdentifiers$1 } = identifiers;
47214
+ class SemVer {
47215
+ constructor (version, options) {
47216
+ options = parseOptions_1(options);
47217
+
47218
+ if (version instanceof SemVer) {
47219
+ if (version.loose === !!options.loose &&
47220
+ version.includePrerelease === !!options.includePrerelease) {
47221
+ return version
47222
+ } else {
47223
+ version = version.version;
47224
+ }
47225
+ } else if (typeof version !== 'string') {
47226
+ throw new TypeError(`Invalid Version: ${version}`)
47227
+ }
47228
+
47229
+ if (version.length > MAX_LENGTH$1) {
47230
+ throw new TypeError(
47231
+ `version is longer than ${MAX_LENGTH$1} characters`
47232
+ )
47233
+ }
47234
+
47235
+ debug_1('SemVer', version, options);
47236
+ this.options = options;
47237
+ this.loose = !!options.loose;
47238
+ // this isn't actually relevant for versions, but keep it so that we
47239
+ // don't run into trouble passing this.options around.
47240
+ this.includePrerelease = !!options.includePrerelease;
47241
+
47242
+ const m = version.trim().match(options.loose ? re$1[t$1.LOOSE] : re$1[t$1.FULL]);
47243
+
47244
+ if (!m) {
47245
+ throw new TypeError(`Invalid Version: ${version}`)
47246
+ }
47247
+
47248
+ this.raw = version;
47249
+
47250
+ // these are actually numbers
47251
+ this.major = +m[1];
47252
+ this.minor = +m[2];
47253
+ this.patch = +m[3];
47254
+
47255
+ if (this.major > MAX_SAFE_INTEGER$1 || this.major < 0) {
47256
+ throw new TypeError('Invalid major version')
47257
+ }
47258
+
47259
+ if (this.minor > MAX_SAFE_INTEGER$1 || this.minor < 0) {
47260
+ throw new TypeError('Invalid minor version')
47261
+ }
47262
+
47263
+ if (this.patch > MAX_SAFE_INTEGER$1 || this.patch < 0) {
47264
+ throw new TypeError('Invalid patch version')
47265
+ }
47266
+
47267
+ // numberify any prerelease numeric ids
47268
+ if (!m[4]) {
47269
+ this.prerelease = [];
47270
+ } else {
47271
+ this.prerelease = m[4].split('.').map((id) => {
47272
+ if (/^[0-9]+$/.test(id)) {
47273
+ const num = +id;
47274
+ if (num >= 0 && num < MAX_SAFE_INTEGER$1) {
47275
+ return num
47276
+ }
47277
+ }
47278
+ return id
47279
+ });
47280
+ }
47281
+
47282
+ this.build = m[5] ? m[5].split('.') : [];
47283
+ this.format();
47284
+ }
47285
+
47286
+ format () {
47287
+ this.version = `${this.major}.${this.minor}.${this.patch}`;
47288
+ if (this.prerelease.length) {
47289
+ this.version += `-${this.prerelease.join('.')}`;
47290
+ }
47291
+ return this.version
47292
+ }
47293
+
47294
+ toString () {
47295
+ return this.version
47296
+ }
47297
+
47298
+ compare (other) {
47299
+ debug_1('SemVer.compare', this.version, this.options, other);
47300
+ if (!(other instanceof SemVer)) {
47301
+ if (typeof other === 'string' && other === this.version) {
47302
+ return 0
47303
+ }
47304
+ other = new SemVer(other, this.options);
47305
+ }
47306
+
47307
+ if (other.version === this.version) {
47308
+ return 0
47309
+ }
47310
+
47311
+ return this.compareMain(other) || this.comparePre(other)
47312
+ }
47313
+
47314
+ compareMain (other) {
47315
+ if (!(other instanceof SemVer)) {
47316
+ other = new SemVer(other, this.options);
47317
+ }
47318
+
47319
+ return (
47320
+ compareIdentifiers$1(this.major, other.major) ||
47321
+ compareIdentifiers$1(this.minor, other.minor) ||
47322
+ compareIdentifiers$1(this.patch, other.patch)
47323
+ )
47324
+ }
47325
+
47326
+ comparePre (other) {
47327
+ if (!(other instanceof SemVer)) {
47328
+ other = new SemVer(other, this.options);
47329
+ }
47330
+
47331
+ // NOT having a prerelease is > having one
47332
+ if (this.prerelease.length && !other.prerelease.length) {
47333
+ return -1
47334
+ } else if (!this.prerelease.length && other.prerelease.length) {
47335
+ return 1
47336
+ } else if (!this.prerelease.length && !other.prerelease.length) {
47337
+ return 0
47338
+ }
47339
+
47340
+ let i = 0;
47341
+ do {
47342
+ const a = this.prerelease[i];
47343
+ const b = other.prerelease[i];
47344
+ debug_1('prerelease compare', i, a, b);
47345
+ if (a === undefined && b === undefined) {
47346
+ return 0
47347
+ } else if (b === undefined) {
47348
+ return 1
47349
+ } else if (a === undefined) {
47350
+ return -1
47351
+ } else if (a === b) {
47352
+ continue
47353
+ } else {
47354
+ return compareIdentifiers$1(a, b)
47355
+ }
47356
+ } while (++i)
47357
+ }
47358
+
47359
+ compareBuild (other) {
47360
+ if (!(other instanceof SemVer)) {
47361
+ other = new SemVer(other, this.options);
47362
+ }
47363
+
47364
+ let i = 0;
47365
+ do {
47366
+ const a = this.build[i];
47367
+ const b = other.build[i];
47368
+ debug_1('prerelease compare', i, a, b);
47369
+ if (a === undefined && b === undefined) {
47370
+ return 0
47371
+ } else if (b === undefined) {
47372
+ return 1
47373
+ } else if (a === undefined) {
47374
+ return -1
47375
+ } else if (a === b) {
47376
+ continue
47377
+ } else {
47378
+ return compareIdentifiers$1(a, b)
47379
+ }
47380
+ } while (++i)
47381
+ }
47382
+
47383
+ // preminor will bump the version up to the next minor release, and immediately
47384
+ // down to pre-release. premajor and prepatch work the same way.
47385
+ inc (release, identifier) {
47386
+ switch (release) {
47387
+ case 'premajor':
47388
+ this.prerelease.length = 0;
47389
+ this.patch = 0;
47390
+ this.minor = 0;
47391
+ this.major++;
47392
+ this.inc('pre', identifier);
47393
+ break
47394
+ case 'preminor':
47395
+ this.prerelease.length = 0;
47396
+ this.patch = 0;
47397
+ this.minor++;
47398
+ this.inc('pre', identifier);
47399
+ break
47400
+ case 'prepatch':
47401
+ // If this is already a prerelease, it will bump to the next version
47402
+ // drop any prereleases that might already exist, since they are not
47403
+ // relevant at this point.
47404
+ this.prerelease.length = 0;
47405
+ this.inc('patch', identifier);
47406
+ this.inc('pre', identifier);
47407
+ break
47408
+ // If the input is a non-prerelease version, this acts the same as
47409
+ // prepatch.
47410
+ case 'prerelease':
47411
+ if (this.prerelease.length === 0) {
47412
+ this.inc('patch', identifier);
47413
+ }
47414
+ this.inc('pre', identifier);
47415
+ break
47416
+
47417
+ case 'major':
47418
+ // If this is a pre-major version, bump up to the same major version.
47419
+ // Otherwise increment major.
47420
+ // 1.0.0-5 bumps to 1.0.0
47421
+ // 1.1.0 bumps to 2.0.0
47422
+ if (
47423
+ this.minor !== 0 ||
47424
+ this.patch !== 0 ||
47425
+ this.prerelease.length === 0
47426
+ ) {
47427
+ this.major++;
47428
+ }
47429
+ this.minor = 0;
47430
+ this.patch = 0;
47431
+ this.prerelease = [];
47432
+ break
47433
+ case 'minor':
47434
+ // If this is a pre-minor version, bump up to the same minor version.
47435
+ // Otherwise increment minor.
47436
+ // 1.2.0-5 bumps to 1.2.0
47437
+ // 1.2.1 bumps to 1.3.0
47438
+ if (this.patch !== 0 || this.prerelease.length === 0) {
47439
+ this.minor++;
47440
+ }
47441
+ this.patch = 0;
47442
+ this.prerelease = [];
47443
+ break
47444
+ case 'patch':
47445
+ // If this is not a pre-release version, it will increment the patch.
47446
+ // If it is a pre-release it will bump up to the same patch version.
47447
+ // 1.2.0-5 patches to 1.2.0
47448
+ // 1.2.0 patches to 1.2.1
47449
+ if (this.prerelease.length === 0) {
47450
+ this.patch++;
47451
+ }
47452
+ this.prerelease = [];
47453
+ break
47454
+ // This probably shouldn't be used publicly.
47455
+ // 1.0.0 'pre' would become 1.0.0-0 which is the wrong direction.
47456
+ case 'pre':
47457
+ if (this.prerelease.length === 0) {
47458
+ this.prerelease = [0];
47459
+ } else {
47460
+ let i = this.prerelease.length;
47461
+ while (--i >= 0) {
47462
+ if (typeof this.prerelease[i] === 'number') {
47463
+ this.prerelease[i]++;
47464
+ i = -2;
47465
+ }
47466
+ }
47467
+ if (i === -1) {
47468
+ // didn't increment anything
47469
+ this.prerelease.push(0);
47470
+ }
47471
+ }
47472
+ if (identifier) {
47473
+ // 1.2.0-beta.1 bumps to 1.2.0-beta.2,
47474
+ // 1.2.0-beta.fooblz or 1.2.0-beta bumps to 1.2.0-beta.0
47475
+ if (compareIdentifiers$1(this.prerelease[0], identifier) === 0) {
47476
+ if (isNaN(this.prerelease[1])) {
47477
+ this.prerelease = [identifier, 0];
47478
+ }
47479
+ } else {
47480
+ this.prerelease = [identifier, 0];
47481
+ }
47482
+ }
47483
+ break
47484
+
47485
+ default:
47486
+ throw new Error(`invalid increment argument: ${release}`)
47487
+ }
47488
+ this.format();
47489
+ this.raw = this.version;
47490
+ return this
47491
+ }
47492
+ }
47493
+
47494
+ var semver = SemVer;
47495
+
47496
+ const compare = (a, b, loose) =>
47497
+ new semver(a, loose).compare(new semver(b, loose));
47498
+
47499
+ var compare_1 = compare;
47500
+
47501
+ const gte = (a, b, loose) => compare_1(a, b, loose) >= 0;
47502
+ var gte_1 = gte;
47503
+
47504
+ function osHasBluetoothSupport(selectedDevice, osVersion) {
47505
+ if (!selectedDevice) {
47506
+ return false;
47507
+ }
47508
+ // Only the Crown supports Bluetooth
47509
+ const isCrown = Number(selectedDevice.modelVersion) >= 3;
47510
+ if (!isCrown) {
47511
+ return false;
47512
+ }
47513
+ const isEmulator = !!(selectedDevice === null || selectedDevice === void 0 ? void 0 : selectedDevice.emulator);
47514
+ if (isEmulator) {
47515
+ return false;
47516
+ }
47517
+ // `osVersion` is updated in real time,
47518
+ // unlike accessing via `selectedDevice.osVersion`
47519
+ return gte_1(osVersion !== null && osVersion !== void 0 ? osVersion : selectedDevice.osVersion, "16.0.0");
47520
+ }
47521
+
47563
47522
  var __awaiter$g = function (thisArg, _arguments, P, generator) {
47564
47523
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
47565
47524
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -47612,7 +47571,7 @@ var Neurosity = (function (exports) {
47612
47571
  if (!!bluetoothTransport) {
47613
47572
  this.bluetoothClient = new BluetoothClient({
47614
47573
  selectedDevice$: this.onDeviceChange(),
47615
- osVersion$: this.osVersion(),
47574
+ osHasBluetoothSupport$: this._osHasBluetoothSupport(),
47616
47575
  createBluetoothToken: this.createBluetoothToken.bind(this),
47617
47576
  transport: bluetoothTransport
47618
47577
  });
@@ -47643,6 +47602,16 @@ var Neurosity = (function (exports) {
47643
47602
  this.streamingMode$.next(streamingMode);
47644
47603
  }
47645
47604
  }
47605
+ /**
47606
+ *
47607
+ * @hidden
47608
+ */
47609
+ _osHasBluetoothSupport() {
47610
+ return combineLatest({
47611
+ selectedDevice: this.onDeviceChange(),
47612
+ osVersion: this.osVersion().pipe(startWith(null))
47613
+ }).pipe(map(({ selectedDevice, osVersion }) => osHasBluetoothSupport(selectedDevice, osVersion)));
47614
+ }
47646
47615
  /**
47647
47616
  * Subscribe to the device's streaming state changes and the current strategy
47648
47617
  *
@@ -47658,12 +47627,14 @@ var Neurosity = (function (exports) {
47658
47627
  streamingState() {
47659
47628
  const isWifiOnline = (state) => [STATUS.ONLINE, STATUS.UPDATING].includes(state);
47660
47629
  return this.streamingMode$.pipe(switchMap((streamingMode) => {
47661
- return this.onDeviceChange().pipe(combineLatestWith(this.osVersion()), switchMap(([selectDevice, osVersion]) => {
47662
- if (!selectDevice) {
47630
+ return combineLatest({
47631
+ selectedDevice: this.onDeviceChange(),
47632
+ osHasBluetoothSupport: this._osHasBluetoothSupport()
47633
+ }).pipe(switchMap(({ selectedDevice, osHasBluetoothSupport: osHasBluetoothSupport$$1 }) => {
47634
+ if (!selectedDevice) {
47663
47635
  return EMPTY;
47664
47636
  }
47665
- const isUnableToUseBluetooth = this.isMissingBluetoothTransport ||
47666
- !osHasBluetoothSupport(selectDevice, osVersion);
47637
+ const isUnableToUseBluetooth = this.isMissingBluetoothTransport || !osHasBluetoothSupport$$1;
47667
47638
  if (isUnableToUseBluetooth) {
47668
47639
  return this.cloudClient.status().pipe(map(({ state }) => ({
47669
47640
  connected: isWifiOnline(state),