@neurosity/sdk 6.1.1 → 6.2.1-next.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.
Files changed (306) hide show
  1. package/dist/{cjs/Neurosity.d.ts → Neurosity.d.ts} +116 -2
  2. package/dist/{cjs/api → api}/bluetooth/BluetoothClient.d.ts +6 -6
  3. package/dist/{cjs/api → api}/bluetooth/constants.d.ts +0 -0
  4. package/dist/{cjs/api → api}/bluetooth/index.d.ts +1 -0
  5. package/dist/{esm/api → api}/bluetooth/react-native/ReactNativeTransport.d.ts +5 -4
  6. package/dist/{cjs/api → api}/bluetooth/types/index.d.ts +2 -2
  7. package/dist/{cjs/api → api}/bluetooth/utils/create6DigitPin.d.ts +0 -0
  8. package/dist/{cjs/api → api}/bluetooth/utils/csvBufferToEpoch.d.ts +0 -0
  9. package/dist/{cjs/api → api}/bluetooth/utils/encoding.d.ts +0 -0
  10. package/dist/{cjs/api → api}/bluetooth/utils/osHasBluetoothSupport.d.ts +0 -0
  11. package/dist/{cjs/api → api}/bluetooth/utils/stitch.d.ts +1 -1
  12. package/dist/{esm/api → api}/bluetooth/web/WebBluetoothTransport.d.ts +1 -1
  13. package/dist/{cjs/api → api}/bluetooth/web/isMaybeWebWorkerContext.d.ts +0 -0
  14. package/dist/{cjs/api → api}/bluetooth/web/isWebBluetoothSupported.d.ts +0 -0
  15. package/dist/{cjs/api → api}/firebase/FirebaseApp.d.ts +0 -0
  16. package/dist/{cjs/api → api}/firebase/FirebaseDevice.d.ts +1 -1
  17. package/dist/{cjs/api → api}/firebase/FirebaseUser.d.ts +0 -0
  18. package/dist/{cjs/api → api}/firebase/config.d.ts +0 -0
  19. package/dist/{cjs/api → api}/firebase/deviceStore.d.ts +0 -0
  20. package/dist/{cjs/api → api}/firebase/index.d.ts +0 -0
  21. package/dist/{cjs/api → api}/https/config.d.ts +0 -0
  22. package/dist/{cjs/api → api}/https/createOAuthURL.d.ts +0 -0
  23. package/dist/{cjs/api → api}/https/getOAuthToken.d.ts +0 -0
  24. package/dist/{cjs/api → api}/https/utils.d.ts +0 -0
  25. package/dist/{esm/api → api}/index.d.ts +8 -0
  26. package/dist/index.cjs +2 -0
  27. package/dist/index.cjs.map +1 -0
  28. package/dist/{cjs/index.d.ts → index.d.ts} +0 -0
  29. package/dist/index.m.js +2 -0
  30. package/dist/index.m.js.map +1 -0
  31. package/dist/index.umd.js +2 -0
  32. package/dist/index.umd.js.map +1 -0
  33. package/dist/{cjs/subscriptions → subscriptions}/SubscriptionManager.d.ts +0 -0
  34. package/dist/{cjs/timesync → timesync}/Timesync.d.ts +1 -1
  35. package/dist/{cjs/timesync → timesync}/index.d.ts +0 -0
  36. package/dist/{cjs/types → types}/status.d.ts +0 -0
  37. package/dist/{cjs/types → types}/streaming.d.ts +0 -0
  38. package/dist/{cjs/utils → utils}/errors.d.ts +0 -0
  39. package/dist/{cjs/utils → utils}/filterInternalKeys.d.ts +0 -0
  40. package/dist/{cjs/utils → utils}/hapticEffects.d.ts +0 -0
  41. package/dist/{cjs/utils → utils}/heartbeat.d.ts +0 -0
  42. package/dist/{cjs/utils → utils}/is-node.d.ts +0 -0
  43. package/dist/utils/metrics.d.ts +6 -0
  44. package/dist/{cjs/utils → utils}/oauth.d.ts +1 -1
  45. package/dist/{cjs/utils → utils}/pipes.d.ts +0 -0
  46. package/dist/{cjs/utils → utils}/platform.d.ts +0 -0
  47. package/dist/{cjs/utils → utils}/subscription.d.ts +0 -0
  48. package/dist/{cjs/utils → utils}/whileOnline.d.ts +1 -1
  49. package/package.json +15 -23
  50. package/CHANGELOG.md +0 -25
  51. package/dist/browser/neurosity.iife.js +0 -48711
  52. package/dist/browser/neurosity.js +0 -666
  53. package/dist/browser/neurosity.js.map +0 -1
  54. package/dist/cjs/Neurosity.js +0 -1244
  55. package/dist/cjs/api/bluetooth/BluetoothClient.js +0 -310
  56. package/dist/cjs/api/bluetooth/BluetoothTransport.d.ts +0 -33
  57. package/dist/cjs/api/bluetooth/BluetoothTransport.js +0 -2
  58. package/dist/cjs/api/bluetooth/constants.js +0 -9
  59. package/dist/cjs/api/bluetooth/index.js +0 -20
  60. package/dist/cjs/api/bluetooth/react-native/ReactNativeTransport.d.ts +0 -69
  61. package/dist/cjs/api/bluetooth/react-native/ReactNativeTransport.js +0 -405
  62. package/dist/cjs/api/bluetooth/react-native/types/BleManagerTypes.d.ts +0 -63
  63. package/dist/cjs/api/bluetooth/react-native/types/BleManagerTypes.js +0 -11
  64. package/dist/cjs/api/bluetooth/react-native/types/ReactNativeTypes.d.ts +0 -180
  65. package/dist/cjs/api/bluetooth/react-native/types/ReactNativeTypes.js +0 -10
  66. package/dist/cjs/api/bluetooth/types/index.js +0 -22
  67. package/dist/cjs/api/bluetooth/utils/create6DigitPin.js +0 -8
  68. package/dist/cjs/api/bluetooth/utils/csvBufferToEpoch.js +0 -36
  69. package/dist/cjs/api/bluetooth/utils/encoding.js +0 -22
  70. package/dist/cjs/api/bluetooth/utils/osHasBluetoothSupport.js +0 -23
  71. package/dist/cjs/api/bluetooth/utils/stitch.js +0 -22
  72. package/dist/cjs/api/bluetooth/web/WebBluetoothTransport.d.ts +0 -54
  73. package/dist/cjs/api/bluetooth/web/WebBluetoothTransport.js +0 -430
  74. package/dist/cjs/api/bluetooth/web/isMaybeWebWorkerContext.js +0 -8
  75. package/dist/cjs/api/bluetooth/web/isWebBluetoothSupported.js +0 -11
  76. package/dist/cjs/api/firebase/FirebaseApp.js +0 -70
  77. package/dist/cjs/api/firebase/FirebaseDevice.js +0 -146
  78. package/dist/cjs/api/firebase/FirebaseUser.js +0 -434
  79. package/dist/cjs/api/firebase/config.js +0 -11
  80. package/dist/cjs/api/firebase/deviceStore.js +0 -191
  81. package/dist/cjs/api/firebase/index.js +0 -19
  82. package/dist/cjs/api/https/config.js +0 -4
  83. package/dist/cjs/api/https/createOAuthURL.js +0 -18
  84. package/dist/cjs/api/https/getOAuthToken.js +0 -34
  85. package/dist/cjs/api/https/utils.js +0 -13
  86. package/dist/cjs/api/index.d.ts +0 -109
  87. package/dist/cjs/api/index.js +0 -307
  88. package/dist/cjs/index.js +0 -18
  89. package/dist/cjs/subscriptions/SubscriptionManager.js +0 -27
  90. package/dist/cjs/timesync/Timesync.js +0 -78
  91. package/dist/cjs/timesync/index.js +0 -17
  92. package/dist/cjs/types/accelerometer.d.ts +0 -10
  93. package/dist/cjs/types/accelerometer.js +0 -2
  94. package/dist/cjs/types/actions.d.ts +0 -16
  95. package/dist/cjs/types/actions.js +0 -2
  96. package/dist/cjs/types/awareness.d.ts +0 -1
  97. package/dist/cjs/types/awareness.js +0 -2
  98. package/dist/cjs/types/brainwaves.d.ts +0 -26
  99. package/dist/cjs/types/brainwaves.js +0 -2
  100. package/dist/cjs/types/calm.d.ts +0 -6
  101. package/dist/cjs/types/calm.js +0 -2
  102. package/dist/cjs/types/client.d.ts +0 -22
  103. package/dist/cjs/types/client.js +0 -2
  104. package/dist/cjs/types/credentials.d.ts +0 -12
  105. package/dist/cjs/types/credentials.js +0 -2
  106. package/dist/cjs/types/deviceInfo.d.ts +0 -18
  107. package/dist/cjs/types/deviceInfo.js +0 -2
  108. package/dist/cjs/types/epoch.d.ts +0 -12
  109. package/dist/cjs/types/epoch.js +0 -2
  110. package/dist/cjs/types/experiment.d.ts +0 -9
  111. package/dist/cjs/types/experiment.js +0 -2
  112. package/dist/cjs/types/focus.d.ts +0 -6
  113. package/dist/cjs/types/focus.js +0 -2
  114. package/dist/cjs/types/hapticEffects.d.ts +0 -125
  115. package/dist/cjs/types/hapticEffects.js +0 -2
  116. package/dist/cjs/types/kinesis.d.ts +0 -6
  117. package/dist/cjs/types/kinesis.js +0 -2
  118. package/dist/cjs/types/marker.d.ts +0 -7
  119. package/dist/cjs/types/marker.js +0 -2
  120. package/dist/cjs/types/metrics.d.ts +0 -21
  121. package/dist/cjs/types/metrics.js +0 -2
  122. package/dist/cjs/types/oauth.d.ts +0 -20
  123. package/dist/cjs/types/oauth.js +0 -2
  124. package/dist/cjs/types/options.d.ts +0 -51
  125. package/dist/cjs/types/options.js +0 -2
  126. package/dist/cjs/types/sample.d.ts +0 -15
  127. package/dist/cjs/types/sample.js +0 -2
  128. package/dist/cjs/types/settings.d.ts +0 -13
  129. package/dist/cjs/types/settings.js +0 -2
  130. package/dist/cjs/types/signalQuality.d.ts +0 -13
  131. package/dist/cjs/types/signalQuality.js +0 -2
  132. package/dist/cjs/types/skill.d.ts +0 -68
  133. package/dist/cjs/types/skill.js +0 -2
  134. package/dist/cjs/types/status.js +0 -22
  135. package/dist/cjs/types/streaming.js +0 -20
  136. package/dist/cjs/types/subscriptions.d.ts +0 -23
  137. package/dist/cjs/types/subscriptions.js +0 -2
  138. package/dist/cjs/types/training.d.ts +0 -19
  139. package/dist/cjs/types/training.js +0 -2
  140. package/dist/cjs/types/user.d.ts +0 -12
  141. package/dist/cjs/types/user.js +0 -2
  142. package/dist/cjs/utils/errors.js +0 -17
  143. package/dist/cjs/utils/filterInternalKeys.js +0 -21
  144. package/dist/cjs/utils/hapticEffects.js +0 -130
  145. package/dist/cjs/utils/heartbeat.js +0 -41
  146. package/dist/cjs/utils/is-node.js +0 -9
  147. package/dist/cjs/utils/metrics.d.ts +0 -1
  148. package/dist/cjs/utils/metrics.js +0 -56
  149. package/dist/cjs/utils/oauth.js +0 -92
  150. package/dist/cjs/utils/pick.d.ts +0 -1
  151. package/dist/cjs/utils/pick.js +0 -5
  152. package/dist/cjs/utils/pipes.js +0 -71
  153. package/dist/cjs/utils/platform.js +0 -47
  154. package/dist/cjs/utils/subscription.js +0 -55
  155. package/dist/cjs/utils/transferDevice.d.ts +0 -9
  156. package/dist/cjs/utils/transferDevice.js +0 -2
  157. package/dist/cjs/utils/whileOnline.js +0 -15
  158. package/dist/electron/index.js +0 -86
  159. package/dist/electron/index.js.map +0 -1
  160. package/dist/esm/Neurosity.d.ts +0 -619
  161. package/dist/esm/Neurosity.js +0 -1213
  162. package/dist/esm/api/bluetooth/BluetoothClient.d.ts +0 -72
  163. package/dist/esm/api/bluetooth/BluetoothClient.js +0 -306
  164. package/dist/esm/api/bluetooth/BluetoothTransport.d.ts +0 -33
  165. package/dist/esm/api/bluetooth/BluetoothTransport.js +0 -1
  166. package/dist/esm/api/bluetooth/constants.d.ts +0 -4
  167. package/dist/esm/api/bluetooth/constants.js +0 -6
  168. package/dist/esm/api/bluetooth/index.d.ts +0 -4
  169. package/dist/esm/api/bluetooth/index.js +0 -4
  170. package/dist/esm/api/bluetooth/react-native/ReactNativeTransport.js +0 -401
  171. package/dist/esm/api/bluetooth/react-native/types/BleManagerTypes.d.ts +0 -63
  172. package/dist/esm/api/bluetooth/react-native/types/BleManagerTypes.js +0 -8
  173. package/dist/esm/api/bluetooth/react-native/types/ReactNativeTypes.d.ts +0 -180
  174. package/dist/esm/api/bluetooth/react-native/types/ReactNativeTypes.js +0 -9
  175. package/dist/esm/api/bluetooth/types/index.d.ts +0 -31
  176. package/dist/esm/api/bluetooth/types/index.js +0 -19
  177. package/dist/esm/api/bluetooth/utils/create6DigitPin.d.ts +0 -1
  178. package/dist/esm/api/bluetooth/utils/create6DigitPin.js +0 -4
  179. package/dist/esm/api/bluetooth/utils/csvBufferToEpoch.d.ts +0 -11
  180. package/dist/esm/api/bluetooth/utils/csvBufferToEpoch.js +0 -31
  181. package/dist/esm/api/bluetooth/utils/encoding.d.ts +0 -3
  182. package/dist/esm/api/bluetooth/utils/encoding.js +0 -17
  183. package/dist/esm/api/bluetooth/utils/osHasBluetoothSupport.d.ts +0 -2
  184. package/dist/esm/api/bluetooth/utils/osHasBluetoothSupport.js +0 -16
  185. package/dist/esm/api/bluetooth/utils/stitch.d.ts +0 -5
  186. package/dist/esm/api/bluetooth/utils/stitch.js +0 -18
  187. package/dist/esm/api/bluetooth/web/WebBluetoothTransport.js +0 -426
  188. package/dist/esm/api/bluetooth/web/isMaybeWebWorkerContext.d.ts +0 -1
  189. package/dist/esm/api/bluetooth/web/isMaybeWebWorkerContext.js +0 -4
  190. package/dist/esm/api/bluetooth/web/isWebBluetoothSupported.d.ts +0 -1
  191. package/dist/esm/api/bluetooth/web/isWebBluetoothSupported.js +0 -7
  192. package/dist/esm/api/firebase/FirebaseApp.d.ts +0 -20
  193. package/dist/esm/api/firebase/FirebaseApp.js +0 -63
  194. package/dist/esm/api/firebase/FirebaseDevice.d.ts +0 -68
  195. package/dist/esm/api/firebase/FirebaseDevice.js +0 -139
  196. package/dist/esm/api/firebase/FirebaseUser.d.ts +0 -53
  197. package/dist/esm/api/firebase/FirebaseUser.js +0 -426
  198. package/dist/esm/api/firebase/config.d.ts +0 -8
  199. package/dist/esm/api/firebase/config.js +0 -8
  200. package/dist/esm/api/firebase/deviceStore.d.ts +0 -26
  201. package/dist/esm/api/firebase/deviceStore.js +0 -184
  202. package/dist/esm/api/firebase/index.d.ts +0 -3
  203. package/dist/esm/api/firebase/index.js +0 -3
  204. package/dist/esm/api/https/config.d.ts +0 -1
  205. package/dist/esm/api/https/config.js +0 -1
  206. package/dist/esm/api/https/createOAuthURL.d.ts +0 -3
  207. package/dist/esm/api/https/createOAuthURL.js +0 -11
  208. package/dist/esm/api/https/getOAuthToken.d.ts +0 -3
  209. package/dist/esm/api/https/getOAuthToken.js +0 -27
  210. package/dist/esm/api/https/utils.d.ts +0 -2
  211. package/dist/esm/api/https/utils.js +0 -9
  212. package/dist/esm/api/index.js +0 -300
  213. package/dist/esm/index.d.ts +0 -2
  214. package/dist/esm/index.js +0 -2
  215. package/dist/esm/neurosity.mjs +0 -48699
  216. package/dist/esm/subscriptions/SubscriptionManager.d.ts +0 -11
  217. package/dist/esm/subscriptions/SubscriptionManager.js +0 -23
  218. package/dist/esm/timesync/Timesync.d.ts +0 -20
  219. package/dist/esm/timesync/Timesync.js +0 -71
  220. package/dist/esm/timesync/index.d.ts +0 -1
  221. package/dist/esm/timesync/index.js +0 -1
  222. package/dist/esm/types/accelerometer.d.ts +0 -10
  223. package/dist/esm/types/accelerometer.js +0 -1
  224. package/dist/esm/types/actions.d.ts +0 -16
  225. package/dist/esm/types/actions.js +0 -1
  226. package/dist/esm/types/awareness.d.ts +0 -1
  227. package/dist/esm/types/awareness.js +0 -1
  228. package/dist/esm/types/brainwaves.d.ts +0 -26
  229. package/dist/esm/types/brainwaves.js +0 -1
  230. package/dist/esm/types/calm.d.ts +0 -6
  231. package/dist/esm/types/calm.js +0 -1
  232. package/dist/esm/types/client.d.ts +0 -22
  233. package/dist/esm/types/client.js +0 -1
  234. package/dist/esm/types/credentials.d.ts +0 -12
  235. package/dist/esm/types/credentials.js +0 -1
  236. package/dist/esm/types/deviceInfo.d.ts +0 -18
  237. package/dist/esm/types/deviceInfo.js +0 -1
  238. package/dist/esm/types/epoch.d.ts +0 -12
  239. package/dist/esm/types/epoch.js +0 -1
  240. package/dist/esm/types/experiment.d.ts +0 -9
  241. package/dist/esm/types/experiment.js +0 -1
  242. package/dist/esm/types/focus.d.ts +0 -6
  243. package/dist/esm/types/focus.js +0 -1
  244. package/dist/esm/types/hapticEffects.d.ts +0 -125
  245. package/dist/esm/types/hapticEffects.js +0 -1
  246. package/dist/esm/types/kinesis.d.ts +0 -6
  247. package/dist/esm/types/kinesis.js +0 -1
  248. package/dist/esm/types/marker.d.ts +0 -7
  249. package/dist/esm/types/marker.js +0 -1
  250. package/dist/esm/types/metrics.d.ts +0 -21
  251. package/dist/esm/types/metrics.js +0 -1
  252. package/dist/esm/types/oauth.d.ts +0 -20
  253. package/dist/esm/types/oauth.js +0 -1
  254. package/dist/esm/types/options.d.ts +0 -51
  255. package/dist/esm/types/options.js +0 -1
  256. package/dist/esm/types/sample.d.ts +0 -15
  257. package/dist/esm/types/sample.js +0 -1
  258. package/dist/esm/types/settings.d.ts +0 -13
  259. package/dist/esm/types/settings.js +0 -1
  260. package/dist/esm/types/signalQuality.d.ts +0 -13
  261. package/dist/esm/types/signalQuality.js +0 -1
  262. package/dist/esm/types/skill.d.ts +0 -68
  263. package/dist/esm/types/skill.js +0 -1
  264. package/dist/esm/types/status.d.ts +0 -26
  265. package/dist/esm/types/status.js +0 -19
  266. package/dist/esm/types/streaming.d.ts +0 -15
  267. package/dist/esm/types/streaming.js +0 -17
  268. package/dist/esm/types/subscriptions.d.ts +0 -23
  269. package/dist/esm/types/subscriptions.js +0 -1
  270. package/dist/esm/types/training.d.ts +0 -19
  271. package/dist/esm/types/training.js +0 -1
  272. package/dist/esm/types/user.d.ts +0 -12
  273. package/dist/esm/types/user.js +0 -1
  274. package/dist/esm/utils/errors.d.ts +0 -5
  275. package/dist/esm/utils/errors.js +0 -11
  276. package/dist/esm/utils/filterInternalKeys.d.ts +0 -3
  277. package/dist/esm/utils/filterInternalKeys.js +0 -17
  278. package/dist/esm/utils/hapticEffects.d.ts +0 -123
  279. package/dist/esm/utils/hapticEffects.js +0 -125
  280. package/dist/esm/utils/heartbeat.d.ts +0 -4
  281. package/dist/esm/utils/heartbeat.js +0 -33
  282. package/dist/esm/utils/is-node.d.ts +0 -1
  283. package/dist/esm/utils/is-node.js +0 -5
  284. package/dist/esm/utils/metrics.d.ts +0 -1
  285. package/dist/esm/utils/metrics.js +0 -52
  286. package/dist/esm/utils/oauth.d.ts +0 -9
  287. package/dist/esm/utils/oauth.js +0 -64
  288. package/dist/esm/utils/pick.d.ts +0 -1
  289. package/dist/esm/utils/pick.js +0 -1
  290. package/dist/esm/utils/pipes.d.ts +0 -46
  291. package/dist/esm/utils/pipes.js +0 -65
  292. package/dist/esm/utils/platform.d.ts +0 -30
  293. package/dist/esm/utils/platform.js +0 -41
  294. package/dist/esm/utils/subscription.d.ts +0 -6
  295. package/dist/esm/utils/subscription.js +0 -24
  296. package/dist/esm/utils/transferDevice.d.ts +0 -9
  297. package/dist/esm/utils/transferDevice.js +0 -1
  298. package/dist/esm/utils/whileOnline.d.ts +0 -8
  299. package/dist/esm/utils/whileOnline.js +0 -11
  300. package/dist/examples/auth.html +0 -32
  301. package/dist/examples/cloud.html +0 -17
  302. package/dist/examples/index.html +0 -1
  303. package/dist/examples/neurosity.iife.js +0 -48711
  304. package/dist/examples/neurosity.js +0 -666
  305. package/dist/examples/neurosity.mjs +0 -48699
  306. package/dist/examples/training.html +0 -49
@@ -3,8 +3,9 @@ import { CloudClient, createUser } from "./api/index";
3
3
  import { SDKOptions } from "./types/options";
4
4
  import { STREAMING_MODE, STREAMING_TYPE } from "./types/streaming";
5
5
  import { Training } from "./types/training";
6
- import { Credentials } from "./types/credentials";
7
- import { Settings } from "./types/settings";
6
+ import { Credentials, EmailAndPassword } from "./types/credentials";
7
+ import { CustomToken } from "./types/credentials";
8
+ import { Settings, ChangeSettings } from "./types/settings";
8
9
  import { SignalQuality } from "./types/signalQuality";
9
10
  import { Kinesis } from "./types/kinesis";
10
11
  import { Calm } from "./types/calm";
@@ -17,7 +18,9 @@ import { Action } from "./types/actions";
17
18
  import { HapticEffects } from "./types/hapticEffects";
18
19
  import { OAuthConfig, OAuthQuery } from "./types/oauth";
19
20
  import { OAuthQueryResult, OAuthRemoveResponse } from "./types/oauth";
21
+ import { UserClaims } from "./types/user";
20
22
  import { Experiment } from "./types/experiment";
23
+ import { TransferDeviceOptions } from "./utils/transferDevice";
21
24
  import { BluetoothClient } from "./api/bluetooth";
22
25
  /**
23
26
  * import StreamingModes from "@site/src/components/StreamingModes";
@@ -146,6 +149,11 @@ export declare class Neurosity {
146
149
  *
147
150
  */
148
151
  logout(): Promise<void>;
152
+ /**
153
+ * @internal
154
+ * Not user facing.
155
+ */
156
+ __getApp(): import("firebase").default.app.App;
149
157
  /**
150
158
  * Subscribe to auth state changes
151
159
  *
@@ -158,6 +166,31 @@ export declare class Neurosity {
158
166
  * ```
159
167
  */
160
168
  onAuthStateChanged(): Observable<any>;
169
+ /**
170
+ * @internal
171
+ * Not user facing yet
172
+ */
173
+ addDevice(deviceId: string): Promise<void>;
174
+ /**
175
+ * @internal
176
+ * Not user facing yet
177
+ */
178
+ removeDevice(deviceId: string): Promise<void>;
179
+ /**
180
+ * @internal
181
+ * Not user facing yet
182
+ */
183
+ transferDevice(options: TransferDeviceOptions): Promise<void>;
184
+ /**
185
+ * @internal
186
+ * Not user facing yet
187
+ */
188
+ onUserDevicesChange(): Observable<DeviceInfo[]>;
189
+ /**
190
+ * @internal
191
+ * Not user facing yet
192
+ */
193
+ onUserClaimsChange(): Observable<UserClaims>;
161
194
  /**
162
195
  * Get user devices
163
196
  *
@@ -230,6 +263,13 @@ export declare class Neurosity {
230
263
  * ```
231
264
  */
232
265
  disconnect(): Promise<void>;
266
+ /**
267
+ * <StreamingModes wifi={true} bluetooth={true} />
268
+ *
269
+ * @internal
270
+ * Not user facing
271
+ */
272
+ private dispatchAction;
233
273
  /**
234
274
  * <StreamingModes wifi={true} bluetooth={true} />
235
275
  *
@@ -454,6 +494,25 @@ export declare class Neurosity {
454
494
  * @returns Observable of `status` metric events
455
495
  */
456
496
  status(): Observable<DeviceStatus>;
497
+ /**
498
+ * @internal
499
+ * Not user facing yet
500
+ *
501
+ * <StreamingModes wifi={true} />
502
+ *
503
+ * Changes device settings programmatically. These settings can be
504
+ * also changed from the developer console under device settings.
505
+ *
506
+ * Available settings [[ChangeSettings]]
507
+ *
508
+ * Example
509
+ * ```typescript
510
+ * neurosity.changeSettings({
511
+ * lsl: true
512
+ * });
513
+ * ```
514
+ */
515
+ changeSettings(settings: ChangeSettings): Promise<void>;
457
516
  /**
458
517
  * <StreamingModes wifi={true} />
459
518
  *
@@ -472,6 +531,61 @@ export declare class Neurosity {
472
531
  * @returns Training methods
473
532
  */
474
533
  get training(): Training;
534
+ /**
535
+ * @internal
536
+ * Proof of Concept for disconnecting db
537
+ */
538
+ goOffline(): void;
539
+ /**
540
+ * @internal
541
+ * Proof of Concept for resuming db connection
542
+ */
543
+ goOnline(): void;
544
+ /**
545
+ * @internal
546
+ * Not user facing yet
547
+ *
548
+ * Creates user account and automatically signs in with same credentials
549
+ *
550
+ * @param emailAndPasswordObject
551
+ * @returns user credential
552
+ */
553
+ createAccount(credentials: EmailAndPassword): Promise<any>;
554
+ /**
555
+ * @internal
556
+ * Not user facing yet
557
+ *
558
+ * Removes all devices from an account and then deletes the account
559
+ */
560
+ deleteAccount(): Promise<void>;
561
+ /**
562
+ * @internal
563
+ * Not user facing
564
+ *
565
+ * Creates token (JWT) designed to authenticate and authorize Bluetooth clients/centrals.
566
+ *
567
+ * @returns token
568
+ */
569
+ createBluetoothToken(): Promise<string>;
570
+ /**
571
+ * @internal
572
+ * Not user facing yet
573
+ *
574
+ * Creates custom token (JWT) to use to login with `{ customToken }`.
575
+ *
576
+ * @returns custom token
577
+ */
578
+ createCustomToken(): Promise<CustomToken>;
579
+ /**
580
+ * @internal
581
+ * Not user facing yet
582
+ *
583
+ * Gets the offset between the device's clock and the client's clock
584
+ * Requires option.timesync to be true
585
+ *
586
+ * @returns timesyncOffset
587
+ */
588
+ getTimesyncOffset(): number;
475
589
  /**
476
590
  * Create OAuth URL
477
591
  * 💡 OAuth requires developers to register their apps with Neurosity
@@ -8,12 +8,12 @@ import { Epoch } from "../../types/epoch";
8
8
  import { BLUETOOTH_CONNECTION } from "./types";
9
9
  import { DeviceNicknameOrPeripheral } from "./BluetoothTransport";
10
10
  import { Peripheral } from "./react-native/types/BleManagerTypes";
11
- export declare type BluetoothTransport = WebBluetoothTransport | ReactNativeTransport;
12
- declare type IsAuthenticated = boolean;
13
- declare type ExpiresIn = number;
14
- declare type IsAuthenticatedResponse = [IsAuthenticated, ExpiresIn];
15
- declare type CreateBluetoothToken = () => Promise<string>;
16
- declare type Options = {
11
+ export type BluetoothTransport = WebBluetoothTransport | ReactNativeTransport;
12
+ type IsAuthenticated = boolean;
13
+ type ExpiresIn = number;
14
+ type IsAuthenticatedResponse = [IsAuthenticated, ExpiresIn];
15
+ type CreateBluetoothToken = () => Promise<string>;
16
+ type Options = {
17
17
  transport: BluetoothTransport;
18
18
  selectedDevice$: Observable<DeviceInfo>;
19
19
  createBluetoothToken: CreateBluetoothToken;
File without changes
@@ -2,3 +2,4 @@ export * from "./BluetoothClient";
2
2
  export * from "./web/WebBluetoothTransport";
3
3
  export * from "./react-native/ReactNativeTransport";
4
4
  export * from "./utils/osHasBluetoothSupport";
5
+ export * from "./types/index";
@@ -8,26 +8,27 @@ import { Peripheral } from "./types/BleManagerTypes";
8
8
  import { NativeEventEmitter } from "./types/ReactNativeTypes";
9
9
  import { PlatformOSType } from "./types/ReactNativeTypes";
10
10
  import { DeviceInfo } from "../../../types/deviceInfo";
11
- declare type Characteristic = {
11
+ type Characteristic = {
12
12
  characteristicUUID: string;
13
13
  serviceUUID: string;
14
14
  peripheralId: string;
15
15
  };
16
- declare type CharacteristicsByName = {
16
+ type CharacteristicsByName = {
17
17
  [name: string]: Characteristic;
18
18
  };
19
- declare type Options = {
19
+ type Options = {
20
20
  BleManager: BleManager;
21
21
  bleManagerEmitter: NativeEventEmitter;
22
22
  platform: PlatformOSType;
23
23
  autoConnect?: boolean;
24
24
  };
25
- declare type BleManagerEvents = {
25
+ type BleManagerEvents = {
26
26
  stopScan$: Observable<void>;
27
27
  discoverPeripheral$: Observable<Peripheral>;
28
28
  connectPeripheral$: Observable<void>;
29
29
  disconnectPeripheral$: Observable<void>;
30
30
  didUpdateValueForCharacteristic$: Observable<any>;
31
+ didUpdateState$: Observable<any>;
31
32
  };
32
33
  export declare class ReactNativeTransport implements BluetoothTransport {
33
34
  type: TRANSPORT_TYPE;
@@ -1,14 +1,14 @@
1
1
  /**
2
2
  * @hidden
3
3
  */
4
- export declare type ActionOptions = {
4
+ export type ActionOptions = {
5
5
  characteristicName: string;
6
6
  action: any;
7
7
  };
8
8
  /**
9
9
  * @hidden
10
10
  */
11
- export declare type SubscribeOptions = {
11
+ export type SubscribeOptions = {
12
12
  characteristicName: string;
13
13
  manageNotifications?: boolean;
14
14
  };
@@ -1,4 +1,4 @@
1
- declare type StitchChunkOptions = {
1
+ type StitchChunkOptions = {
2
2
  delimiter: string;
3
3
  };
4
4
  export declare function stitchChunks({ delimiter }: StitchChunkOptions): import("rxjs").UnaryFunction<import("rxjs").Observable<string>, import("rxjs").Observable<string>>;
@@ -5,7 +5,7 @@ import { BluetoothTransport } from "../BluetoothTransport";
5
5
  import { ActionOptions, SubscribeOptions } from "../types";
6
6
  import { TRANSPORT_TYPE, BLUETOOTH_CONNECTION } from "../types";
7
7
  import { DeviceInfo } from "../../../types/deviceInfo";
8
- declare type Options = {
8
+ type Options = {
9
9
  autoConnect?: boolean;
10
10
  };
11
11
  export declare class WebBluetoothTransport implements BluetoothTransport {
File without changes
@@ -1,7 +1,7 @@
1
1
  import firebase from "firebase/app";
2
2
  import { FirebaseApp } from "./FirebaseApp";
3
3
  import { SDKDependencies } from "../../types/options";
4
- declare type FirebaseDeviceOptions = {
4
+ type FirebaseDeviceOptions = {
5
5
  deviceId: string;
6
6
  firebaseApp: FirebaseApp;
7
7
  dependencies: SDKDependencies;
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -30,6 +30,10 @@ export declare class CloudClient implements Client {
30
30
  protected timesync: Timesync;
31
31
  protected subscriptionManager: SubscriptionManager;
32
32
  protected status$: Observable<DeviceStatus>;
33
+ /**
34
+ * @internal
35
+ */
36
+ private _selectedDevice;
33
37
  constructor(options: SDKOptions);
34
38
  onDeviceChange(): Observable<DeviceInfo>;
35
39
  private setAutoSelectedDevice;
@@ -106,4 +110,8 @@ export declare class CloudClient implements Client {
106
110
  changeSettings(settings: ChangeSettings): Promise<void>;
107
111
  goOffline(): void;
108
112
  goOnline(): void;
113
+ /**
114
+ * @internal
115
+ */
116
+ __getApp(): import("firebase").default.app.App;
109
117
  }
package/dist/index.cjs ADDED
@@ -0,0 +1,2 @@
1
+ var e=require("rxjs"),t=require("rxjs/operators"),n=require("fast-deep-equal"),r=require("firebase/app");require("firebase/database"),require("firebase/auth"),require("firebase/functions"),require("firebase/firestore");var i=require("outliers"),o=require("@neurosity/ipk"),s=require("axios"),c=require("semver/functions/gte");function a(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var u=/*#__PURE__*/a(n),l=/*#__PURE__*/a(r),h=/*#__PURE__*/a(i),d=/*#__PURE__*/a(s),f=/*#__PURE__*/a(c);function m(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,"symbol"==typeof(i=function(e,t){if("object"!=typeof e||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,"string");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(r.key))?i:String(i),r)}var i}function p(e,t,n){return t&&m(e.prototype,t),n&&m(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function v(){return v=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},v.apply(this,arguments)}function g(e,t){return g=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},g(e,t)}function _(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(e){return!1}}function b(e,t,n){return b=_()?Reflect.construct.bind():function(e,t,n){var r=[null];r.push.apply(r,t);var i=new(Function.bind.apply(e,r));return n&&g(i,n.prototype),i},b.apply(null,arguments)}var C={apiKey:"AIzaSyB0TkZ83Fj0CIzn8AAmE-Osc92s3ER8hy8",authDomain:"neurosity-device.firebaseapp.com",databaseURL:"https://neurosity-device.firebaseio.com",projectId:"neurosity-device",storageBucket:"neurosity-device.appspot.com",messagingSenderId:"212595049674"},P=l.default.database.ServerValue.TIMESTAMP,S=/*#__PURE__*/function(){function e(e){this.standalone=void 0,this.app=void 0,this.app=this.getApp(e.deviceId),this.standalone=this.app.name===e.deviceId,e.emulator&&this.connectEmulators(e)}var t=e.prototype;return t.getApp=function(e){var t=l.default.apps,n="undefined"!=typeof window&&"firebase"in window&&"apps"in window.firebase?window.firebase.apps:[],r=[].concat(t,n).find(function(e){return"[DEFAULT]"===e.name&&e.options.databaseURL===C.databaseURL});if(r)return r;if(e){var i=e;return t.find(function(e){return e.name===i})||l.default.initializeApp(C,i)}return l.default.initializeApp(C)},t.connectEmulators=function(e){var t=e.emulatorHost,n=e.emulatorAuthPort,r=e.emulatorDatabasePort,i=e.emulatorFunctionsPort,o=e.emulatorFirestorePort,s=e.emulatorOptions;this.app.auth().useEmulator("http://"+t+":"+n),this.app.database().useEmulator(t,r,s),this.app.functions().useEmulator(t,i),this.app.firestore().useEmulator(t,o,s)},t.goOnline=function(){this.app.database().goOnline()},t.goOffline=function(){this.app.database().goOffline()},t.disconnect=function(){return this.standalone?this.app.delete():Promise.resolve()},e}(),w=l.default.database.ServerValue.TIMESTAMP,D=l.default.auth.EmailAuthProvider.credentialWithLink,T=/*#__PURE__*/function(){function n(e){var t=this;this.app=void 0,this.user=void 0,this.app=e.app,this.app.auth().onAuthStateChanged(function(e){t.user=e})}var r=n.prototype;return r.auth=function(){return this.app.auth()},r.createAccount=function(e){try{var t=e.email,n=e.password;return Promise.resolve(this.app.auth().createUserWithEmailAndPassword(t,n).then(function(e){return[null,e]}).catch(function(e){return[e,null]})).then(function(e){var t=e[0],n=e[1];return t?Promise.reject(t):n})}catch(e){return Promise.reject(e)}},r.deleteAccount=function(){try{var e=this,t=e.app.auth().currentUser;return t?Promise.resolve(e.getDevices().then(function(e){return[null,e]}).catch(function(e){return[e,null]})).then(function(n){var r,i=n[0],o=n[1];function s(e){return r?e:t.delete()}if(i)return Promise.reject(i);var c=function(){if(o.length)return Promise.resolve(Promise.all(o.map(function(t){return e.removeDevice(t.deviceId)})).then(function(){return null}).catch(function(e){return e})).then(function(e){if(e){var t=Promise.reject(e);return r=1,t}})}();return c&&c.then?c.then(s):s(c)}):Promise.reject(new Error("You are trying to delete an account that is not authenticated. To delete an account, the account must have signed in recently."))}catch(e){return Promise.reject(e)}},r.onAuthStateChanged=function(){var t=this;return new e.Observable(function(e){try{t.app.auth().onAuthStateChanged(function(t){e.next(t)},function(t){e.error(t)})}catch(t){e.error(t)}})},r.onLogin=function(){var t=this;return new e.Observable(function(e){var n=t.app.auth().onAuthStateChanged(function(t){t&&(e.next(t),e.complete())});return function(){return n()}})},r.login=function(e){if("customToken"in e){var t=e.customToken;return this.app.auth().signInWithCustomToken(t)}if("idToken"in e&&"providerId"in e){var n=new l.default.auth.OAuthProvider(e.providerId).credential(e.idToken);return this.app.auth().signInWithCredential(n)}if("email"in e&&"password"in e){var r=e.email,i=e.password;return this.app.auth().signInWithEmailAndPassword(r,i)}throw new Error("Either {email,password}, {customToken}, or {idToken,providerId} is required")},r.logout=function(){return this.app.auth().signOut()},r.createCustomToken=function(){try{return Promise.resolve(this.app.functions().httpsCallable("createCustomToken")().then(function(e){return[null,e.data]}).catch(function(e){return[e,null]})).then(function(e){var t=e[0],n=e[1];return t?Promise.reject(t):n})}catch(e){return Promise.reject(e)}},r.removeOAuthAccess=function(){try{var e,t=this;return(null==(e=t.user)?void 0:e.uid)?Promise.resolve(t.app.functions().httpsCallable("removeAccessOAuthApp")().then(function(e){return[null,e.data]}).catch(function(e){return[e,null]})).then(function(e){var n=e[0],r=e[1];return n?Promise.reject(n):Promise.resolve(t.logout().then(function(){return!1}).catch(function(e){return e})).then(function(e){return e?Promise.reject(e):r})}):Promise.reject("OAuth access can only be removed while logged in via OAuth.")}catch(e){return Promise.reject(e)}},r.getDevices=function(){try{var e,t=this;return(null==(e=t.user)?void 0:e.uid)?Promise.resolve(t.app.database().ref(t.getUserDevicesPath()).once("value")).then(function(e){var n=e.val();return t.userDevicesToDeviceInfoList(n)}):Promise.reject("Please login.")}catch(e){return Promise.reject(e)}},r.addDevice=function(e){try{var t,n=this,r=null==(t=n.user)?void 0:t.uid;return r?Promise.resolve(n.getDevices().catch(function(e){console.log(e)})).then(function(t){return t&&t.length&&t.map(function(e){return e.deviceId}).includes(e)?Promise.reject("The device is already added to this account."):Promise.resolve(n.isDeviceIdValid(e).then(function(e){return[e]}).catch(function(e){return[!1,e]})).then(function(t){var i;if(!t[0])return Promise.reject(t[1]);var o=n.getDeviceClaimedByPath(e),s=n.getUserClaimedDevicePath(e);return Promise.resolve(n.app.database().ref().update((i={},i[o]=r,i[s]={claimedOn:w},i)).then(function(){return[!1]}).catch(function(e){return[!0,e]})).then(function(e){if(e[0])return Promise.reject(e[1])})})}):Promise.reject("Please login.")}catch(e){return Promise.reject(e)}},r.removeDevice=function(e){try{var t,n=this;if(!(null==(t=n.user)?void 0:t.uid))return Promise.reject("Please login.");var r=n.getDeviceClaimedByPath(e),i=n.getUserClaimedDevicePath(e),o=n.app.database().ref(r),s=n.app.database().ref(i);return Promise.resolve(Promise.all([o.remove(),s.remove()]).then(function(){return[!1]}).catch(function(e){return[!0,e]})).then(function(e){if(e[0])return Promise.reject(e[1])})}catch(e){return Promise.reject(e)}},r.transferDevice=function(e){try{var t;return(null==(t=this.user)?void 0:t.uid)?"recipientsEmail"in e||"recipientsUserId"in e?null!=e&&e.deviceId?Promise.resolve(this.app.functions().httpsCallable("transferDeviceOwnership")(e).then(function(e){return[null,e.data]}).catch(function(e){return[e,null]})).then(function(e){var t=e[0];if(t)return Promise.reject(t)}):Promise.reject(new Error("transferDevice: a deviceId is required.")):Promise.reject(new Error("transferDevice: either 'recipientsEmail' or 'recipientsUserId' key is required.")):Promise.reject(new Error("transferDevice: auth is required."))}catch(e){return Promise.reject(e)}},r.isDeviceIdValid=function(e){try{if(!e||32!==e.length||!/[0-9A-Fa-f]{32}/g.test(e))return Promise.reject("The device id is incorrectly formatted.");var t=this.getDeviceClaimedByPath(e),n=this.app.database().ref(t);return Promise.resolve(n.once("value").catch(function(){return null})).then(function(e){return!(!e||e.exists())||Promise.reject("The device has already been claimed.")})}catch(e){return Promise.reject(e)}},r.onUserDevicesChange=function(){var n=this;return this.onAuthStateChanged().pipe(t.switchMap(function(r){if(!r)return e.EMPTY;var i=n.getUserDevicesPath(),o=n.app.database().ref(i);return e.fromEventPattern(function(e){return o.on("value",e)},function(e){return o.off("value",e)}).pipe(t.map(function(e){return e[0].val()}),t.switchMap(function(t){return e.from(n.userDevicesToDeviceInfoList(t))}))}))},r.onUserClaimsChange=function(){var n=this;return this.onAuthStateChanged().pipe(t.switchMap(function(r){if(!r)return e.EMPTY;var i=n.getUserClaimsUpdatedOnPath(),o=n.app.database().ref(i);return e.fromEventPattern(function(e){return o.on("value",e)},function(e){return o.off("value",e)}).pipe(t.map(function(e){return e[0].val()}),t.switchMap(function(){return e.from(n.getIdToken(!0)).pipe(t.switchMap(function(){return e.from(n.getClaims())}))}))}))},r.getIdToken=function(e){void 0===e&&(e=!1);try{var t,n=null==(t=this.app.auth())?void 0:t.currentUser;return n?Promise.resolve(n.getIdToken(e).catch(function(e){console.error(e)})).then(function(){}):Promise.reject("getUserIdToken: unable to get currentUser")}catch(e){return Promise.reject(e)}},r.getClaims=function(){var e,t=null==(e=this.app.auth())?void 0:e.currentUser;return t?t.getIdTokenResult().then(function(e){return e.claims}).catch(function(e){return console.error(e),null}):Promise.reject("getUserClaims: unable to get currentUser")},r.userDevicesToDeviceInfoList=function(e){try{var t=this,n=Object.keys(null!=e?e:{}).map(function(e){return t.app.database().ref(t.getDeviceInfoPath(e)).once("value")});return Promise.resolve(Promise.all(n).then(function(e){return e.map(function(e){return e.val()})})).then(function(t){var n=t.filter(function(e){return!!e});return n.sort(function(t,n){return e[t.deviceId].claimedOn-e[n.deviceId].claimedOn}),n})}catch(e){return Promise.reject(e)}},r.hasDevicePermission=function(e){try{var t=this.getDeviceInfoPath(e);return Promise.resolve(this.app.database().ref(t).once("value").then(function(){return!0}).catch(function(){return!1}))}catch(e){return Promise.reject(e)}},r.getDeviceClaimedByPath=function(e){return"devices/"+e+"/status/claimedBy"},r.getUserClaimedDevicePath=function(e){return"users/"+this.user.uid+"/devices/"+e},r.getUserDevicesPath=function(){return"users/"+this.user.uid+"/devices"},r.getUserClaimsUpdatedOnPath=function(){return"users/"+this.user.uid+"/claimsUpdatedOn"},r.getDeviceInfoPath=function(e){return"devices/"+e+"/info"},r.onUserExperiments=function(){var n=this;return this.onAuthStateChanged().pipe(t.switchMap(function(r){if(!r)return e.EMPTY;var i=n.user.uid,o=n.app.database().ref("experiments").orderByChild("userId").equalTo(i).limitToFirst(100);return e.fromEventPattern(function(e){return o.on("value",e)},function(e){return o.off("value",e)}).pipe(t.map(function(e){return e[0].val()}),t.map(function(e){return Object.entries(null!=e?e:{}).map(function(e){var t,n=e[1];return v({id:null!=(t=null==n?void 0:n.id)?t:e[0]},n)}).sort(function(e,t){return new Date(null==t?void 0:t.timestamp).getTime()-new Date(null==e?void 0:e.timestamp).getTime()})}))}))},r.deleteUserExperiment=function(e){try{var t=this;return e?Promise.resolve(Promise.all([function(e){return t.app.database().ref("experiments").child(e).remove()}(e),function(e){return t.app.functions().httpsCallable("removeRelations")({experimentId:e})}(e)]).catch(function(){})).then(function(){}):Promise.reject("deleteUserExperiment: please provide an experiment id")}catch(e){return Promise.reject(e)}},n}(),y=l.default.database.ServerValue.TIMESTAMP,E=l.default.database.ServerValue.TIMESTAMP,O=/*#__PURE__*/function(){function e(e){var t=e.deviceId,n=e.firebaseApp,r=e.dependencies;if(this.app=void 0,this.deviceStore=void 0,this.deviceId=void 0,!t)throw new Error("No Device ID provided.");this.deviceId=t,this.app=n.app,this.deviceStore=function(e,t,n){var r=e.database().ref("devices/"+t),i=r.child("subscriptions").push().key,o=r.child("clients/"+i),s=[],c=function(e,t){return r.child(e).set(t)},a=function(e,t){return r.child(e).update(t)},u=function(e,t,n){void 0===e&&(e="value");var i=r.child(t).on(e,function(e){n(e.val(),e)});return s.push(function(){r.child(t).off(e,i)}),i},l=function(e,t,n){n?r.child(e).off(t,n):r.child(e).off(t)},h=e.database().ref(".info/connected").on("value",function(e){e.val()&&o.onDisconnect().remove().then(function(){o.set(y),a("subscriptions",n.get()).then(function(){n.toList().forEach(function(e){r.child("subscriptions/"+e.id).onDisconnect().remove()})})})});return s.push(function(){e.database().ref(".info/connected").off("value",h)}),{set:c,once:function(e,t){void 0===t&&(t="value");try{return Promise.resolve(r.child(e).once(t)).then(function(e){return e.val()})}catch(e){return Promise.reject(e)}},update:a,lastOfChildValue:function(e,t,n){try{return Promise.resolve(r.child(e).orderByChild(t).equalTo(n).limitToLast(1).once("value")).then(function(e){var t=e.val();return Object.values(t||{})[0]||null})}catch(e){return Promise.reject(e)}},onNamespace:function(e,t){return u("value",e,function(e){t(e)})},offNamespace:function(e,t){l(e,"value",t)},dispatchAction:function(e){try{return Promise.resolve((t=e,r.child("actions").push(t))).then(function(t){var n=t.key,r="actions/"+n;if(t.onDisconnect().remove(),e.responseRequired){var i=e.responseTimeout||6e5,o=new Promise(function(e,n){var r=setTimeout(function(){clearTimeout(r),t.remove(),n("Action response timed out in "+i+"ms.")},i)}),s=new Promise(function(e){var t,n;n=e,u("value",t=r+"/response",function(e){null!==e&&(l(t,"value"),n(e))})});return Promise.race([s,o])}return n})}catch(e){return Promise.reject(e)}var t},nextMetric:function(e,t){try{return c("metrics/"+e,t),Promise.resolve()}catch(e){return Promise.reject(e)}},onMetric:function(e,t){var n=e.metric;return u("value",e.atomic?"metrics/"+n:"metrics/"+n+"/"+e.labels[0],function(e){null!==e&&t(e)})},subscribeToMetric:function(e){var t=r.child("subscriptions").push().key,n="subscriptions/"+t,o=v({id:t,clientId:i},e);return c(n,o),r.child(n).onDisconnect().remove(),o},unsubscribeFromMetric:function(e){r.child("subscriptions/"+e.id).remove()},removeMetricListener:function(e,t){var n=e.metric;l(e.atomic?"metrics/"+n:"metrics/"+n+"/"+e.labels[0],"value",t)},disconnect:function(){o.remove(),s.forEach(function(e){e()}),n.toList().filter(function(e){return e.clientId===i}).forEach(function(e){r.child("subscriptions/"+e.id).remove()})}}}(this.app,t,r.subscriptionManager)}var t=e.prototype;return t.dispatchAction=function(e){return this.deviceStore.dispatchAction(e)},t.getInfo=function(){try{return Promise.resolve(this.deviceStore.once("info"))}catch(e){return Promise.reject(e)}},t.onNamespace=function(e,t){return this.deviceStore.onNamespace(e,t)},t.onceNamespace=function(e){try{return Promise.resolve(this.deviceStore.once(e))}catch(e){return Promise.reject(e)}},t.offNamespace=function(e,t){this.deviceStore.offNamespace(e,t)},t.getTimesync=function(){try{return Promise.resolve(this.dispatchAction({command:"timesync",action:"get",responseRequired:!0,responseTimeout:250})).then(function(e){return e.timestamp})}catch(e){return Promise.reject(e)}},t.nextMetric=function(e,t){this.deviceStore.nextMetric(e,t)},t.onMetric=function(e,t){return this.deviceStore.onMetric(e,t)},t.subscribeToMetric=function(t){return this.deviceStore.subscribeToMetric(v({},t,{serverType:e.serverType}))},t.unsubscribeFromMetric=function(e){this.deviceStore.unsubscribeFromMetric(e)},t.removeMetricListener=function(e,t){this.deviceStore.removeMetricListener(e,t)},t.changeSettings=function(e){try{return Promise.resolve(this.deviceStore.update("settings",e))}catch(e){return Promise.reject(e)}},t.getSkill=function(e){try{return Promise.resolve(this.deviceStore.lastOfChildValue("skills","bundleId",e))}catch(e){return Promise.reject(e)}},t.createBluetoothToken=function(){try{return Promise.resolve(this.app.functions().httpsCallable("createBluetoothToken")({deviceId:this.deviceId}).then(function(e){var t=e.data;return[null,null==t?void 0:t.token]}).catch(function(e){return[e,null]})).then(function(e){var t,n=e[0],r=e[1];return n?Promise.reject(null!=(t=null==n?void 0:n.message)?t:n):r||Promise.reject("Failed to create Bluetooth token.")})}catch(e){return Promise.reject(e)}},t.disconnect=function(){this.deviceStore.disconnect()},p(e,[{key:"timestamp",get:function(){return E}}]),e}();function N(n){var r=n.allowWhileOnSleepMode;return e.pipe(t.withLatestFrom(n.status$),t.mergeMap(function(t){var n=t[0];return function(e,t){return!("online"!==e.state||!t&&e.sleepMode)}(t[1],r)?e.of(n):e.EMPTY}))}O.serverType="firebase";var A,M,I={bufferSize:100,updateInterval:6e4},U=/*#__PURE__*/function(){function n(e){this.options=void 0,this._offset=0,this.options=v({},I,e),this.start()}var r=n.prototype;return r.start=function(){var n=this,r=this.options,i=r.bufferSize,o=r.updateInterval,s=r.status$,c=e.range(0,i),a=e.timer(o,o).pipe(t.map(function(e){return i+e}),N({status$:s,allowWhileOnSleepMode:!0}));s.pipe(t.filter(function(e){return"online"===e.state}),t.take(1)).pipe(t.switchMap(function(){return c.pipe(t.concatWith(a),n.toOffset(),t.bufferCount(i,1),n.filterOutliers(),t.map(function(e){return n.average(e)}))})).subscribe(function(e){n._offset=e})},r.filterOutliers=function(){return e.pipe(t.map(function(e){return e.filter(h.default())}))},r.toOffset=function(){var n=this.options.getTimesync;return e.pipe(t.concatMap(function(){try{var e=Date.now();return Promise.resolve(n().then(function(e){return[null,e]}).catch(function(e){return[e]})).then(function(t){var n=t[1];if(t[0])return 0;var r=Date.now();return r-(r-e)/2-n})}catch(e){return Promise.reject(e)}}))},r.average=function(e){return Math.round(e.reduce(function(e,t){return e+t})/e.length)},p(n,[{key:"offset",get:function(){return this._offset}},{key:"timestamp",get:function(){return Date.now()+this._offset}}]),n}(),R=/*#__PURE__*/function(){function e(){this._subscriptions={}}var t=e.prototype;return t.get=function(){return this._subscriptions},t.toList=function(){return Object.values(this._subscriptions)},t.add=function(e){this._subscriptions[e.id]=e},t.remove=function(e){e.id in this._subscriptions&&Reflect.deleteProperty(this._subscriptions,e.id)},e}();!function(e){e.ONLINE="online",e.OFFLINE="offline",e.UPDATING="updating",e.BOOTING="booting",e.SHUTTING_OFF="shuttingOff"}(A||(A={})),function(e){e.UPDATING="updating",e.CHARGING="charging"}(M||(M={}));var j,L,k=/*#__PURE__*/function(){function n(n){var r,i,o,s=this;this.user=void 0,this.userClaims=void 0,this.options=void 0,this.firebaseApp=void 0,this.firebaseUser=void 0,this.firebaseDevice=void 0,this.timesync=void 0,this.subscriptionManager=void 0,this.status$=void 0,this._selectedDevice=new e.ReplaySubject(1),this.options=n,this.subscriptionManager=new R,this.firebaseApp=new S(n),this.firebaseUser=new T(this.firebaseApp),this._selectedDevice.next(void 0),this.status$=(r=this.observeNamespace("status").pipe(t.share()),i=r.pipe(t.map(function(e){return e.lastHeartbeat}),t.distinctUntilChanged(),t.map(function(){return Date.now()})),o=i.pipe(t.switchMap(function(){return e.timer(75e3)}),t.map(function(){return null}),t.startWith(null)),e.combineLatest({status:r,lostHeartbeat:o}).pipe(t.withLatestFrom(i),t.map(function(e){var t=e[0].status,n=e[1];if(!n)return t;var r=function(e,t){return"lastHeartbeat"in e&&Date.now()-t>75e3}(t,n);return r?v({},t,{state:A.OFFLINE}):t}),t.distinctUntilChanged(function(e,t){return u.default(e,t)}))).pipe(e.pipe(t.map(function(e){return e?Object.entries(e).reduce(function(e,t){var n=t[0],r=t[1];return n.startsWith("__")||(e[n]=r),e},{}):e})),t.shareReplay(1)),this.firebaseUser.onAuthStateChanged().subscribe(function(e){s.user=e}),this.firebaseUser.onUserClaimsChange().subscribe(function(e){s.userClaims=e}),this.onDeviceChange().subscribe(function(e){s.firebaseDevice&&s.firebaseDevice.disconnect(),e&&(s.firebaseDevice=new O({deviceId:e.deviceId,firebaseApp:s.firebaseApp,dependencies:{subscriptionManager:s.subscriptionManager}}),s.options.timesync&&(s.timesync=new U({status$:s.status(),getTimesync:s.firebaseDevice.getTimesync.bind(s.firebaseDevice)})))})}var r=n.prototype;return r.onDeviceChange=function(){return this._selectedDevice.asObservable().pipe(t.filter(function(e){return void 0!==e}))},r.setAutoSelectedDevice=function(){try{var e,t=function(t){var r;if(e)return t;var i=function(){if(!n.options.deviceId&&n.options.autoSelectDevice)return Promise.resolve(n.selectDevice(function(e){return e[0]})).then(function(e){return r=1,e})}();return i&&i.then?i.then(function(e){return r?e:null}):r?i:null},n=this,r=function(){if(n.options.deviceId)return Promise.resolve(n.selectDevice(function(e){return e.find(function(e){return e.deviceId===n.options.deviceId})})).then(function(t){return e=1,t})}();return Promise.resolve(r&&r.then?r.then(t):t(r))}catch(e){return Promise.reject(e)}},r.dispatchAction=function(e){try{return Promise.resolve(this.firebaseDevice.dispatchAction(e))}catch(e){return Promise.reject(e)}},r.disconnect=function(){try{return Promise.resolve(this.firebaseApp.disconnect())}catch(e){return Promise.reject(e)}},r.getInfo=function(){try{return Promise.resolve(this.firebaseDevice.getInfo())}catch(e){return Promise.reject(e)}},r.login=function(e){try{var t=this;return t.user?Promise.reject("Already logged in."):Promise.resolve(t.firebaseUser.login(e)).then(function(e){return Promise.resolve(t.setAutoSelectedDevice()).then(function(t){return v({},e,{selectedDevice:t})})})}catch(e){return Promise.reject(e)}},r.logout=function(){try{var e=this;return e.firebaseDevice&&e.firebaseDevice.disconnect(),Promise.resolve(e.firebaseUser.logout())}catch(e){return Promise.reject(e)}},r.onAuthStateChanged=function(){var e=this;return this.firebaseUser.onAuthStateChanged().pipe(t.switchMap(function(t){try{return t?Promise.resolve(e.didSelectDevice()?e.getSelectedDevice():e.setAutoSelectedDevice()).then(function(e){return v({},t,{selectedDevice:e})}):Promise.resolve(null)}catch(e){return Promise.reject(e)}}))},r.getDevices=function(){return this.firebaseUser.getDevices()},r.addDevice=function(e){return this.firebaseUser.addDevice(e)},r.removeDevice=function(e){try{var t=this;return Promise.resolve(t.firebaseUser.removeDevice(e).then(function(){return[!1]}).catch(function(e){return[!0,e]})).then(function(n){return n[0]?Promise.reject(n[1]):Promise.resolve(t.getSelectedDevice()).then(function(n){(null==n?void 0:n.deviceId)===e&&t._selectedDevice.next(null)})})}catch(e){return Promise.reject(e)}},r.transferDevice=function(e){try{var t=this;return Promise.resolve(t.firebaseUser.transferDevice(e).then(function(){return[!1]}).catch(function(e){return[!0,e]})).then(function(n){return n[0]?Promise.reject(n[1]):Promise.resolve(t.getSelectedDevice()).then(function(n){(null==n?void 0:n.deviceId)===e.deviceId&&t._selectedDevice.next(null)})})}catch(e){return Promise.reject(e)}},r.onUserDevicesChange=function(){return this.firebaseUser.onUserDevicesChange()},r.onUserClaimsChange=function(){return this.firebaseUser.onUserClaimsChange()},r.didSelectDevice=function(){try{return Promise.resolve(this.getSelectedDevice()).then(function(e){return!!e})}catch(e){return Promise.reject(e)}},r.selectDevice=function(e){try{var t=this;return Promise.resolve(t.getDevices()).then(function(n){if(!n)return Promise.reject("Did not find any devices for this user. Make sure your device is claimed by your Neurosity account.");var r="function"==typeof e?e(n):function(t){return t.find(function(t){if(!Array.isArray(e))return!1;var n=e[1];return JSON.stringify(null==t?void 0:t[e[0]])===JSON.stringify(n)})}(n);return r?Promise.resolve(t.firebaseUser.hasDevicePermission(r.deviceId)).then(function(e){return e?(t._selectedDevice.next(r),r):Promise.reject("Rejected device access due to permissions.")}):Promise.reject("A device was not provided. Try returning a device from the devicesList provided in the callback.")})}catch(e){return Promise.reject(e)}},r.getSelectedDevice=function(){try{return Promise.resolve(e.firstValueFrom(this._selectedDevice))}catch(e){return Promise.reject(e)}},r.status=function(){return this.status$},r.observeNamespace=function(n){var r=this;return this.onDeviceChange().pipe(t.switchMap(function(t){return t?e.fromEventPattern(function(e){return r.firebaseDevice.onNamespace(n,e)},function(e){return r.firebaseDevice.offNamespace(n,e)}):e.EMPTY}))},r.onceNamespace=function(e){try{return Promise.resolve(this.firebaseDevice.onceNamespace(e))}catch(e){return Promise.reject(e)}},r.createAccount=function(e){return this.firebaseUser.createAccount(e)},r.deleteAccount=function(){return this.firebaseUser.deleteAccount()},r.createBluetoothToken=function(){return this.firebaseDevice.createBluetoothToken()},r.createCustomToken=function(){return this.firebaseUser.createCustomToken()},r.removeOAuthAccess=function(){return this.firebaseUser.removeOAuthAccess()},r.onUserExperiments=function(){return this.firebaseUser.onUserExperiments()},r.deleteUserExperiment=function(e){return this.firebaseUser.deleteUserExperiment(e)},r.getTimesyncOffset=function(){return this.timesync.offset},r.changeSettings=function(e){return this.firebaseDevice.changeSettings(e)},r.goOffline=function(){this.firebaseApp.goOffline()},r.goOnline=function(){this.firebaseApp.goOnline()},r.__getApp=function(){return this.firebaseApp.app},p(n,[{key:"actions",get:function(){var e=this;return{dispatch:function(t){return e.firebaseDevice.dispatchAction(t)}}}},{key:"metrics",get:function(){var e=this;return{next:function(t,n){e.firebaseDevice.nextMetric(t,n)},on:function(t,n){return e.firebaseDevice.onMetric(t,n)},subscribe:function(t){var n=e.firebaseDevice.subscribeToMetric(t);return e.subscriptionManager.add(n),n},unsubscribe:function(t,n){e.subscriptionManager.remove(t),e.firebaseDevice.unsubscribeFromMetric(t),e.firebaseDevice.removeMetricListener(t,n)}}}},{key:"skills",get:function(){var e=this;return{get:function(t){try{return Promise.resolve(e.firebaseDevice.getSkill(t))}catch(e){return Promise.reject(e)}}}}},{key:"timestamp",get:function(){return this.options.timesync?this.timesync.timestamp:Date.now()}}]),n}();!function(e){e.WIFI="wifi",e.BLUETOOTH="bluetooth"}(j||(j={})),function(e){e.WIFI_ONLY="wifi-only",e.WIFI_WITH_BLUETOOTH_FALLBACK="wifi-with-bluetooth-fallback",e.BLUETOOTH_WITH_WIFI_FALLBACK="bluetooth-with-wifi-fallback"}(L||(L={}));var B,$,x,H,F,W,V="Neurosity SDK: ",z=new Error(V+'A device must be selected. Make sure to call "neurosity.selectDevice()"'),q=function(e,t){return new Error(""+V+e+" not supported on model version "+t+". See docs.neurosity.co for more info.")},Y=function(e,t){return new Error(""+V+e+" location not supported on model version "+t+". Check spelling or see docs.neurosity.co for more info.")},G=function(e){return Object.keys(o.metrics[e])},J="haptics",K="accel",Q=((B={})[1]=[],B[2]=[J,K],B[3]=[J,K],B),X=((H={})[1]={},H[2]={motorByMotorName:($={},$.P7=[],$.P8=[],$)},H[3]={motorByMotorName:(x={},x.P7=[],x.P8=[],x)},H),Z={__proto__:null,strongClick100:"strongClick100",strongClick60:"strongClick60",strongClick30:"strongClick30",sharpClick100:"sharpClick100",sharpClick60:"sharpClick60",sharpClick30:"sharpClick30",softBump100:"softBump100",softBump60:"softBump60",softBump30:"softBump30",doubleClick100:"doubleClick100",doubleClick60:"doubleClick60",tripleClick100:"tripleClick100",softFuzz60:"softFuzz60",strongBuzz100:"strongBuzz100",alert750ms:"alert750ms",alert1000ms:"alert1000ms",strongClick1_100:"strongClick1_100",strongClick2_80:"strongClick2_80",strongClick3_60:"strongClick3_60",strongClick4_30:"strongClick4_30",mediumClick1_100:"mediumClick1_100",mediumClick2_80:"mediumClick2_80",mediumClick3_60:"mediumClick3_60",sharpTick1_100:"sharpTick1_100",sharpTick2_80:"sharpTick2_80",sharpTick3_60:"sharpTick3_60",shortDoubleClickStrong1_100:"shortDoubleClickStrong1_100",shortDoubleClickStrong2_80:"shortDoubleClickStrong2_80",shortDoubleClickStrong3_60:"shortDoubleClickStrong3_60",shortDoubleClickStrong4_30:"shortDoubleClickStrong4_30",shortDoubleClickMedium1_100:"shortDoubleClickMedium1_100",shortDoubleClickMedium2_80:"shortDoubleClickMedium2_80",shortDoubleClickMedium3_60:"shortDoubleClickMedium3_60",shortDoubleSharpTick1_100:"shortDoubleSharpTick1_100",shortDoubleSharpTick2_80:"shortDoubleSharpTick2_80",shortDoubleSharpTick3_60:"shortDoubleSharpTick3_60",longDoubleSharpClickStrong1_100:"longDoubleSharpClickStrong1_100",longDoubleSharpClickStrong2_80:"longDoubleSharpClickStrong2_80",longDoubleSharpClickStrong3_60:"longDoubleSharpClickStrong3_60",longDoubleSharpClickStrong4_30:"longDoubleSharpClickStrong4_30",longDoubleSharpClickMedium1_100:"longDoubleSharpClickMedium1_100",longDoubleSharpClickMedium2_80:"longDoubleSharpClickMedium2_80",longDoubleSharpClickMedium3_60:"longDoubleSharpClickMedium3_60",longDoubleSharpTick1_100:"longDoubleSharpTick1_100",longDoubleSharpTick2_80:"longDoubleSharpTick2_80",longDoubleSharpTick3_60:"longDoubleSharpTick3_60",buzz1_100:"buzz1_100",buzz2_80:"buzz2_80",buzz3_60:"buzz3_60",buzz4_40:"buzz4_40",buzz5_20:"buzz5_20",pulsingStong1_100:"pulsingStong1_100",pulsingStong2_60:"pulsingStong2_60",pulsingMedium1_100:"pulsingMedium1_100",pulsingMedium2_60:"pulsingMedium2_60",pulsingSharp1_100:"pulsingSharp1_100",pulsingSharp2_60:"pulsingSharp2_60",transistionClick1_100:"transistionClick1_100",transistionClick2_80:"transistionClick2_80",transistionClick3_60:"transistionClick3_60",transistionClick4_40:"transistionClick4_40",transistionClick5_20:"transistionClick5_20",transistionClick6_10:"transistionClick6_10",transistionHum1_100:"transistionHum1_100",transistionHum2_80:"transistionHum2_80",transistionHum3_60:"transistionHum3_60",transistionHum4_40:"transistionHum4_40",transistionHum5_20:"transistionHum5_20",transistionHum6_10:"transistionHum6_10",transitionRampDownLongSmooth1_100_to_0:"transitionRampDownLongSmooth1_100_to_0",transitionRampDownLongSmooth2_100_to_0:"transitionRampDownLongSmooth2_100_to_0",transitionRampDownMediumSmooth1_100_to_0:"transitionRampDownMediumSmooth1_100_to_0",transitionRampDownMediumSmooth2_100_to_0:"transitionRampDownMediumSmooth2_100_to_0",transitionRampDownShortSmooth1_100_to_0:"transitionRampDownShortSmooth1_100_to_0",transitionRampDownShortSmooth2_100_to_0:"transitionRampDownShortSmooth2_100_to_0",transitionRampDownLongSharp1_100_to_0:"transitionRampDownLongSharp1_100_to_0",transitionRampDownLongSharp2_100_to_0:"transitionRampDownLongSharp2_100_to_0",transitionRampDownLongMedium1_100_to_0:"transitionRampDownLongMedium1_100_to_0",transitionRampDownLongMedium2_100_to_0:"transitionRampDownLongMedium2_100_to_0",transitionRampDownShortSharp1_100_to_0:"transitionRampDownShortSharp1_100_to_0",transitionRampDownShortSharp2_100_to_0:"transitionRampDownShortSharp2_100_to_0",transitionRampUpLongSmooth1_0_to_100:"transitionRampUpLongSmooth1_0_to_100",transitionRampUpLongSmooth2_0_to_100:"transitionRampUpLongSmooth2_0_to_100",transitionRampUpMediumSmooth1_0_to_100:"transitionRampUpMediumSmooth1_0_to_100",transitionRampUpMediumSmooth2_0_to_100:"transitionRampUpMediumSmooth2_0_to_100",transitionRampUpShortSmooth1_0_to_100:"transitionRampUpShortSmooth1_0_to_100",transitionRampUpShortSmooth2_0_to_100:"transitionRampUpShortSmooth2_0_to_100",transitionRampUpLongSharp1_0_to_100:"transitionRampUpLongSharp1_0_to_100",transitionRampUpLongSharp2_0_to_100:"transitionRampUpLongSharp2_0_to_100",transitionRampUpMediumSharp1_0_to_100:"transitionRampUpMediumSharp1_0_to_100",transitionRampUpMediumSharp2_0_to_100:"transitionRampUpMediumSharp2_0_to_100",transitionRampUpShortSharp1_0_to_100:"transitionRampUpShortSharp1_0_to_100",transitionRampUpShortSharp2_0_to_100:"transitionRampUpShortSharp2_0_to_100",transitionRampDownLongSmooth1_50_to_0:"transitionRampDownLongSmooth1_50_to_0",transitionRampDownLongSmooth2_50_to_0:"transitionRampDownLongSmooth2_50_to_0",transitionRampDownMediumSmooth1_50_to_0:"transitionRampDownMediumSmooth1_50_to_0",transitionRampDownMediumSmooth2_50_to_0:"transitionRampDownMediumSmooth2_50_to_0",transitionRampDownShortSmooth1_50_to_0:"transitionRampDownShortSmooth1_50_to_0",transitionRampDownShortSmooth2_50_to_0:"transitionRampDownShortSmooth2_50_to_0",transitionRampDownLongSharp1_50_to_0:"transitionRampDownLongSharp1_50_to_0",transitionRampDownLongSharp2_50_to_0:"transitionRampDownLongSharp2_50_to_0",transitionRampDownMediumSharp1_50_to_0:"transitionRampDownMediumSharp1_50_to_0",transitionRampDownMediumSharp2_50_to_0:"transitionRampDownMediumSharp2_50_to_0",transitionRampDownShortSharp1_50_to_0:"transitionRampDownShortSharp1_50_to_0",transitionRampDownShortSharp2_50_to_0:"transitionRampDownShortSharp2_50_to_0",transitionRampUpLongSmooth1_0_to_50:"transitionRampUpLongSmooth1_0_to_50",transitionRampUpLongSmooth2_0_to_50:"transitionRampUpLongSmooth2_0_to_50",transitionRampUpMediumSmooth1_0_to_50:"transitionRampUpMediumSmooth1_0_to_50",transitionRampUpMediumSmooth2_0_to_50:"transitionRampUpMediumSmooth2_0_to_50",transitionRampUpShortSmooth1_0_to_50:"transitionRampUpShortSmooth1_0_to_50",transitionRampUpShortSmooth2_0_to_50:"transitionRampUpShortSmooth2_0_to_50",transitionRampUpLongSharp1_0_to_50:"transitionRampUpLongSharp1_0_to_50",transitionRampUpLongSharp2_0_to_50:"transitionRampUpLongSharp2_0_to_50",transitionRampUpMediumSharp1_0_to_50:"transitionRampUpMediumSharp1_0_to_50",transitionRampUpMediumSharp2_0_to_50:"transitionRampUpMediumSharp2_0_to_50",transitionRampUpShortSharp1_0_to_50:"transitionRampUpShortSharp1_0_to_50",transitionRampUpShortSharp2_0_to_50:"transitionRampUpShortSharp2_0_to_50",longBuzzForProgrammaticStopping_100:"longBuzzForProgrammaticStopping_100",smoothHum1_50:"smoothHum1_50",smoothHum2_40:"smoothHum2_40",smoothHum3_30:"smoothHum3_30",smoothHum4_20:"smoothHum4_20",smoothHum5_10:"smoothHum5_10"},ee={"marker/add":"write:brainwave-markers","brainwaves/record":"write:brainwaves","haptics/queue":"write:haptics","training/record":"write:kinesis","training/stop":"write:kinesis","training/stopAll":"write:kinesis","wifi/reset":"write:wifi-settings"},te={accelerometer:"read:accelerometer",brainwaves:"read:brainwaves",calm:"read:calm",focus:"read:focus",kinesis:"read:kinesis",predictions:"read:kinesis",signalQuality:"read:signal-quality",getInfo:"read:devices-info",getSelectedDevice:"read:devices-info",selectDevice:"read:devices-info",onDeviceChange:"read:devices-info",onUserDevicesChange:"read:devices-info",settings:"read:devices-settings",changeSettings:"write:devices-settings",status:"read:devices-status",addDevice:"write:devices-add",removeDevice:"write:devices-remove",transferDevice:"write:devices-remove"};function ne(e,t){var n=null!=e?e:{};if(!n.oauth)return[!1,null];var r=n.scopes.split(","),i=te[t];return r.includes(i)?[!1,null]:[!0,re(i)]}function re(){return new Error(V+"You are trying to access data with an OAuth token without access to the following scopes: "+[].slice.call(arguments).join(", ")+".")}function ie(e){return e.emulator?"http://"+e.emulatorHost+":"+e.emulatorFunctionsPort+"/neurosity-device/us-central1":"https://us-central1-neurosity-device.cloudfunctions.net"}function oe(){return"undefined"!=typeof process&&null!=process.versions&&null!=process.versions.node}function se(n,r){var i=n.cloudClient,o=n.onDeviceChange,s=n.status,c=r.metric,a=r.labels,u=r.atomic,l=function(e,t,n){var r=G(e).join(", ");return t.length?function(e,t){return"skill"in t&&"metrics"in t.skill&&!t.skill.metrics.includes(e)}(e,n)?new Error(V+"No permission to access the "+e+" metric. To access this metric, edit the skill's permissions"):!!function(e,t){var n=G(e);return!t.every(function(e){return n.includes(e)})}(e,t)&&new Error(V+"One ore more labels provided to "+e+" are invalid. The valid labels for "+e+" are "+r):new Error(V+"At least one label is required for "+e+" metric. Please add one of the following labels: "+r)}(c,a,n.options);if(l)return e.throwError(function(){return l});var h=new e.Observable(function(e){var t=(u?[i.metrics.subscribe({metric:c,labels:a,atomic:u})]:a.map(function(e){return i.metrics.subscribe({metric:c,labels:[e],atomic:u})})).map(function(t){return{subscription:t,listener:i.metrics.on(t,function(){e.next.apply(e,[].slice.call(arguments))})}});return function(){t.forEach(function(e){i.metrics.unsubscribe(e.subscription,e.listener)})}});return o().pipe(t.switchMap(function(t){return t?h.pipe(N({status$:s(),allowWhileOnSleepMode:!1})):e.EMPTY}))}function ce(){return Math.floor(1e5+9e5*Math.random())}function ae(n){var r=n.delimiter;return e.pipe(t.scan(function(e,t){var n=e[0]+t;if(!n.includes(r))return[n,""];if(n.endsWith(r))return["",n];var i=n.lastIndexOf(r)+r.length,o=n.slice(0,i);return[n.slice(i),o]},["",""]),t.map(function(e){return e[1].slice(0,-r.length)}),t.filter(function(e){return!!e.length}))}exports.BLUETOOTH_CONNECTION=void 0,(F=exports.BLUETOOTH_CONNECTION||(exports.BLUETOOTH_CONNECTION={})).SCANNING="scanning",F.CONNECTED="connected",F.CONNECTING="connecting",F.DISCONNECTING="disconnecting",F.DISCONNECTED="disconnected",exports.TRANSPORT_TYPE=void 0,(W=exports.TRANSPORT_TYPE||(exports.TRANSPORT_TYPE={})).WEB="web",W.REACT_NATIVE="reactNative";var ue=new TextEncoder,le=new TextDecoder("utf-8");function he(e,t){return e===exports.TRANSPORT_TYPE.REACT_NATIVE?[].concat(ue.encode(t)):ue.encode(t)}function de(e,t){return e===exports.TRANSPORT_TYPE.REACT_NATIVE?le.decode(new Uint8Array(t)):le.decode(t)}var fe=Object.fromEntries(Object.entries(o.BLUETOOTH_CHARACTERISTICS).map(function(e){return e.reverse()}));function me(e){return!!e&&Number(e.modelVersion)>=3&&!(null!=e&&e.emulator)&&f.default(e.osVersion,"16.0.0")}function pe(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}var ve={autoConnect:!0},ge=/*#__PURE__*/function(){function n(n){var r,i,o=this;if(void 0===n&&(n={}),this.type=exports.TRANSPORT_TYPE.WEB,this.options=void 0,this.device=void 0,this.server=void 0,this.service=void 0,this.characteristicsByName={},this.connection$=new e.BehaviorSubject(exports.BLUETOOTH_CONNECTION.DISCONNECTED),this.pendingActions$=new e.BehaviorSubject([]),this.logs$=new e.ReplaySubject(10),this.onDisconnected$=this._onDisconnected().pipe(t.share()),this.connectionStream$=this.connection$.asObservable().pipe(t.filter(function(e){return!!e}),t.distinctUntilChanged(),t.shareReplay(1)),this._isAutoConnectEnabled$=new e.ReplaySubject(1),this.options=v({},ve,n),"undefined"==typeof window||!(null==(r=window)||null==(i=r.navigator)?void 0:i.bluetooth)){var s="Web Bluetooth is not supported";throw this.addLog(s),new Error(s)}this._isAutoConnectEnabled$.subscribe(function(e){o.addLog("Auto connect: "+(e?"enabled":"disabled"))}),this._isAutoConnectEnabled$.next(this.options.autoConnect),this.connection$.asObservable().subscribe(function(e){o.addLog("connection status is "+e)}),this.onDisconnected$.subscribe(function(){o.connection$.next(exports.BLUETOOTH_CONNECTION.DISCONNECTED)})}var r=n.prototype;return r._getPairedDevices=function(){try{return Promise.resolve(navigator.bluetooth.getDevices())}catch(e){return Promise.reject(e)}},r._autoConnect=function(n){var r=this,i=this,o=this;return this._isAutoConnectEnabled$.pipe(t.switchMap(function(r){return r?e.merge(n,o.onDisconnected$.pipe(t.switchMap(function(){return n}))):e.NEVER}),t.switchMap(function(t){return me(t)?e.of(t):e.EMPTY}),t.switchMap(function(e){try{var t=e.deviceNickname;return r.isConnected()?(r.addLog("Auto connect: "+t+" is already connected. Skipping auto connect."),Promise.resolve()):Promise.resolve(r._getPairedDevices().then(function(e){return[null,e]}).catch(function(e){return[e,null]})).then(function(e){var n,i=e[0],o=e[1];if(i)throw new Error("failed to get devices: "+(null!=(n=null==i?void 0:i.message)?n:i));r.addLog("Auto connect: found "+o.length+" devices "+o.map(function(e){return e.name}).join(", "));var s=o.findLast(function(e){return e.name===t});if(!s)throw new Error("couldn't find selected device in the list of paired devices.");return r.addLog("Auto connect: "+t+" was detected and previously paired"),s})}catch(e){return Promise.reject(e)}}),t.tap(function(){o.connection$.next(exports.BLUETOOTH_CONNECTION.SCANNING)}),t.switchMap(function(t){return function(t){return new e.Observable(function(e){var n=new AbortController,r=n.signal,i=t.addEventListener("advertisementreceived",function(t){n.abort(),e.next(t),e.complete()},{once:!0});try{t.watchAdvertisements({signal:r})}catch(t){e.error(t)}return function(){n.abort(),t.removeEventListener("advertisementreceived",i)}})}(t)}),t.switchMap(function(e){try{return i.addLog("Advertisement received for "+e.device.name),Promise.resolve(i.getServerServiceAndCharacteristics(e.device))}catch(e){return Promise.reject(e)}}))},r.enableAutoConnect=function(e){this._isAutoConnectEnabled$.next(e)},r.addLog=function(e){this.logs$.next(e)},r.isConnected=function(){return this.connection$.getValue()===exports.BLUETOOTH_CONNECTION.CONNECTED},r.connection=function(){return this.connectionStream$},r.connect=function(e){try{var t=this;return Promise.resolve(pe(function(){return Promise.resolve(t.requestDevice(e)).then(function(e){return Promise.resolve(t.getServerServiceAndCharacteristics(e)).then(function(){})})},function(e){return Promise.reject(e)}))}catch(e){return Promise.reject(e)}},r.requestDevice=function(e){try{var t=this;return Promise.resolve(pe(function(){t.addLog("Requesting Bluetooth Device...");var n=o.BLUETOOTH_DEVICE_NAME_PREFIXES.map(function(e){return{namePrefix:e}});return Promise.resolve(window.navigator.bluetooth.requestDevice({filters:[].concat(e?[{name:e}]:n,[{manufacturerData:[{companyIdentifier:o.BLUETOOTH_COMPANY_IDENTIFIER_HEX}]}]),optionalServices:[o.BLUETOOTH_PRIMARY_SERVICE_UUID_HEX]}))},function(e){return Promise.reject(e)}))}catch(e){return Promise.reject(e)}},r.getServerServiceAndCharacteristics=function(e){try{var t=this;return Promise.resolve(pe(function(){return t.device=e,t.connection$.getValue()===exports.BLUETOOTH_CONNECTION.CONNECTING||t.connection$.next(exports.BLUETOOTH_CONNECTION.CONNECTING),Promise.resolve(e.gatt.connect()).then(function(e){return t.server=e,t.addLog("Getting service..."),Promise.resolve(t.server.getPrimaryService(o.BLUETOOTH_PRIMARY_SERVICE_UUID_HEX)).then(function(e){return t.service=e,t.addLog("Got service "+t.service.uuid+", getting characteristics..."),Promise.resolve(t.service.getCharacteristics()).then(function(e){t.addLog("Got characteristics"),t.characteristicsByName=Object.fromEntries(e.map(function(e){return[fe[e.uuid],e]})),t.connection$.next(exports.BLUETOOTH_CONNECTION.CONNECTED)})})})},function(e){return Promise.reject(e)}))}catch(e){return Promise.reject(e)}},r._onDisconnected=function(){var n=this;return this.connection$.asObservable().pipe(t.switchMap(function(t){return t===exports.BLUETOOTH_CONNECTION.CONNECTED?_e(n.device,"gattserverdisconnected"):e.NEVER}))},r.disconnect=function(){try{var e,t,n=this;return(null==n||null==(e=n.device)||null==(t=e.gatt)?void 0:t.connected)&&n.device.gatt.disconnect(),Promise.resolve()}catch(e){return Promise.reject(e)}},r.getCharacteristicByName=function(e){try{var t;return Promise.resolve(null==(t=this.characteristicsByName)?void 0:t[e])}catch(e){return Promise.reject(e)}},r.subscribeToCharacteristic=function(n){var r=this,i=this,s=n.characteristicName,c=n.manageNotifications,a=void 0===c||c,u=e.defer(function(){return i.getCharacteristicByName(s)}).pipe(t.switchMap(function(e){try{var t=function(){if(r.isConnected()&&a){var t=pe(function(){return Promise.resolve(e.startNotifications()).then(function(){r.addLog("Started notifications for "+s+" characteristic")})},function(e){var t;r.addLog("Attemped to stop notifications for "+s+" characteristic: "+(null!=(t=null==e?void 0:e.message)?t:e))});if(t&&t.then)return t.then(function(){})}}();return Promise.resolve(t&&t.then?t.then(function(){return e}):e)}catch(e){return Promise.reject(e)}}),t.switchMap(function(e){return _e(e,"characteristicvaluechanged",function(){try{var t=function(){if(i.isConnected()&&a){var t=pe(function(){return Promise.resolve(e.stopNotifications()).then(function(){i.addLog("Stopped notifications for "+s+" characteristic")})},function(e){var t;i.addLog("Attemped to stop notifications for "+s+" characteristic: "+(null!=(t=null==e?void 0:e.message)?t:e))});if(t&&t.then)return t.then(function(){})}}();return Promise.resolve(t&&t.then?t.then(function(){}):void 0)}catch(e){return Promise.reject(e)}})}),t.map(function(e){var t=e.target.value,n=de(i.type,t);return i.addLog("Received chunk with buffer size of "+t.byteLength+" and decoded size "+n.length+" for "+s+" characteristic: \n"+n),n}),ae({delimiter:o.BLUETOOTH_CHUNK_DELIMITER}),t.map(function(e){try{return JSON.parse(e)}catch(n){var t;return i.addLog("Failed to parse JSON for "+s+" characteristic. Falling back to unparsed string. "+(null!=(t=null==n?void 0:n.message)?t:n)),e}}));return this.connection$.pipe(t.switchMap(function(t){return t===exports.BLUETOOTH_CONNECTION.CONNECTED?u:e.NEVER}))},r.readCharacteristic=function(e,t){void 0===t&&(t=!1);try{var n=this;return Promise.resolve(pe(function(){return n.addLog("Reading characteristic: "+e),Promise.resolve(n.getCharacteristicByName(e)).then(function(r){return r?Promise.resolve(r.readValue()).then(function(r){var i=de(n.type,r),o=t?JSON.parse(i):i;return n.addLog("Received read data from "+e+" characteristic: \n"+o),o}):(n.addLog("Did not fund "+e+" characteristic"),Promise.reject("Did not find characteristic by the name: "+e))})},function(e){return Promise.reject("Error reading characteristic: "+e.message)}))}catch(e){return Promise.reject(e)}},r.writeCharacteristic=function(e,t){try{var n=this;return n.addLog("Writing characteristic: "+e),Promise.resolve(n.getCharacteristicByName(e)).then(function(r){if(!r)return n.addLog("Did not fund "+e+" characteristic"),Promise.reject("Did not find characteristic by the name: "+e);var i=he(n.type,t);return Promise.resolve(r.writeValueWithResponse(i)).then(function(){})})}catch(e){return Promise.reject(e)}},r._addPendingAction=function(e){var t=this.pendingActions$.getValue();this.pendingActions$.next([].concat(t,[e]))},r._removePendingAction=function(e){var t=this.pendingActions$.getValue();this.pendingActions$.next(t.filter(function(t){return t!==e}))},r._autoToggleActionNotifications=function(n){try{var r,i=this,o=!1,s=i.connection$.asObservable().pipe(t.switchMap(function(n){return n===exports.BLUETOOTH_CONNECTION.CONNECTED?e.defer(function(){return i.getCharacteristicByName("actions")}).pipe(t.switchMap(function(e){return r=e,i.pendingActions$})):e.NEVER}),t.tap(function(e){try{var t=function(){var e=function(){if(!n&&o){o=!1;var e=pe(function(){return Promise.resolve(r.stopNotifications()).then(function(){i.addLog("Stopped notifications for actions characteristic")})},function(e){var t;i.addLog("Attemped to stop notifications for [actions] characteristic: "+(null!=(t=null==e?void 0:e.message)?t:e))});if(e&&e.then)return e.then(function(){})}}();if(e&&e.then)return e.then(function(){})},n=!!e.length,s=function(){if(n&&!o){o=!0;var e=pe(function(){return Promise.resolve(r.startNotifications()).then(function(){i.addLog("Started notifications for [actions] characteristic")})},function(e){var t;i.addLog("Attemped to start notifications for [actions] characteristic: "+(null!=(t=null==e?void 0:e.message)?t:e))});if(e&&e.then)return e.then(function(){})}}();return Promise.resolve(s&&s.then?s.then(t):t())}catch(e){return Promise.reject(e)}}));return n.pipe(t.switchMap(function(t){return me(t)?s:e.EMPTY})).subscribe(),Promise.resolve()}catch(e){return Promise.reject(e)}},r.dispatchAction=function(n){var r=n.characteristicName,i=n.action;try{var o=this,s=i.responseRequired,c=void 0!==s&&s,a=i.responseTimeout,u=void 0===a?6e4:a;return Promise.resolve(new Promise(function(n,s){try{return Promise.resolve(o.getCharacteristicByName(r).catch(function(){s("Did not find characteristic by the name: "+r)})).then(function(a){if(a){var l=ce(),h=JSON.stringify(v({actionId:l},i));if(o.addLog("Dispatched action with id "+l),c&&u){o._addPendingAction(l);var d=e.timer(u).subscribe(function(){o._removePendingAction(l),s("Action with id "+l+" timed out after "+u+"ms")});o.subscribeToCharacteristic({characteristicName:r,manageNotifications:!1}).pipe(t.filter(function(e){return(null==e?void 0:e.actionId)===l}),t.take(1)).subscribe(function(e){d.unsubscribe(),o._removePendingAction(l),n(e)}),o.writeCharacteristic(r,h).catch(function(e){o._removePendingAction(l),s(e.message)})}else o.writeCharacteristic(r,h).then(function(){n(null)}).catch(function(e){s(e.message)})}})}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},n}();function _e(t,n,r){return e.fromEventPattern(function(e){t.addEventListener(n,e)},function(e){try{var i=function(){t.removeEventListener(n,e)},o=function(){if(r)return Promise.resolve(r()).then(function(){})}();return Promise.resolve(o&&o.then?o.then(i):i())}catch(e){return Promise.reject(e)}})}function be(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}var Ce={autoConnect:!0},Pe=/*#__PURE__*/function(){function n(n){var r=this;if(this.type=exports.TRANSPORT_TYPE.REACT_NATIVE,this.options=void 0,this.BleManager=void 0,this.bleManagerEmitter=void 0,this.platform=void 0,this.bleEvents=void 0,this.device=void 0,this.characteristicsByName={},this.connection$=new e.BehaviorSubject(exports.BLUETOOTH_CONNECTION.DISCONNECTED),this.pendingActions$=new e.BehaviorSubject([]),this.logs$=new e.ReplaySubject(10),this.onDisconnected$=void 0,this.connectionStream$=this.connection$.asObservable().pipe(t.filter(function(e){return!!e}),t.distinctUntilChanged(),t.shareReplay(1)),this._isAutoConnectEnabled$=new e.ReplaySubject(1),!n){var i="React Native transport: missing options.";throw this.addLog(i),new Error(i)}this.options=v({},Ce,n);var o=this.options,s=o.BleManager,c=o.bleManagerEmitter,a=o.platform,u=o.autoConnect;if(!s){var l="React Native option: BleManager not provided.";throw this.addLog(l),new Error(l)}if(!c){var h="React Native option: bleManagerEmitter not provided.";throw this.addLog(h),new Error(h)}if(!a){var d="React Native option: platform not provided.";throw this.addLog(d),new Error(d)}this.BleManager=s,this.bleManagerEmitter=c,this.platform=a,this._isAutoConnectEnabled$.next(u),this._isAutoConnectEnabled$.subscribe(function(e){r.addLog("Auto connect: "+(e?"enabled":"disabled"))}),this.bleEvents={stopScan$:this._fromEvent("BleManagerStopScan"),discoverPeripheral$:this._fromEvent("BleManagerDiscoverPeripheral"),connectPeripheral$:this._fromEvent("BleManagerConnectPeripheral"),disconnectPeripheral$:this._fromEvent("BleManagerDisconnectPeripheral"),didUpdateValueForCharacteristic$:this._fromEvent("BleManagerDidUpdateValueForCharacteristic"),didUpdateState$:this._fromEvent("BleManagerDidUpdateState")},this.onDisconnected$=this.bleEvents.disconnectPeripheral$.pipe(t.share()),this.BleManager.start({showAlert:!1}).then(function(){r.addLog("BleManger started")}).catch(function(e){var t;r.addLog("BleManger failed to start. "+(null!=(t=null==e?void 0:e.message)?t:e))}),this.connection$.asObservable().subscribe(function(e){r.addLog("connection status is "+e)}),this.onDisconnected$.subscribe(function(){r.connection$.next(exports.BLUETOOTH_CONNECTION.DISCONNECTED)})}var r=n.prototype;return r.addLog=function(e){this.logs$.next(e)},r.isConnected=function(){return this.connection$.getValue()===exports.BLUETOOTH_CONNECTION.CONNECTED},r._autoConnect=function(n){var r=this,i=this,o=this.onDisconnected$.pipe(t.switchMap(function(){return n}));return this._isAutoConnectEnabled$.pipe(t.switchMap(function(t){return t?e.merge(n,o):e.NEVER}),t.switchMap(function(n){return me(n)?i.scan().pipe(t.switchMap(function(t){var r=t.find(function(e){return e.name===(null==n?void 0:n.deviceNickname)});return r?e.of(r):e.NEVER}),t.distinct(function(e){return e.id}),t.take(1)):e.NEVER}),t.switchMap(function(e){try{return Promise.resolve(r.connect(e))}catch(e){return Promise.reject(e)}}))},r.enableAutoConnect=function(e){this._isAutoConnectEnabled$.next(e)},r.connection=function(){return this.connectionStream$},r._fromEvent=function(n){var r=this;return e.fromEventPattern(function(e){r.bleManagerEmitter.addListener(n,e)},function(){r.bleManagerEmitter.removeAllListeners(n)}).pipe(t.share())},r.scan=function(n){var r,i,s=this,c=null!=(r=null==n?void 0:n.seconds)?r:10,a=null!=(i=null==n?void 0:n.once)&&i,u=[o.BLUETOOTH_PRIMARY_SERVICE_UUID_STRING],l={},h=new e.Observable(function(e){try{s.BleManager.scan(u,c,!0,l).then(function(){s.addLog("BleManger scanning "+(a?"once":"indefintely")),e.next()})}catch(n){var t;s.addLog("BleManger scanning "+(a?"once":"indefintely")+" failed. "+(null!=(t=null==n?void 0:n.message)?t:n)),e.error(n)}return function(){s.BleManager.stopScan()}}),d=(a?h:e.timer(0,1e4).pipe(t.switchMap(function(){return h}))).pipe(t.tap(function(){s.connection$.next(exports.BLUETOOTH_CONNECTION.SCANNING)}),t.takeUntil(this.onDisconnected$),t.switchMap(function(){return s.bleEvents.discoverPeripheral$}),t.filter(function(e){var t,n,r,i=null!=(t=null!=(n=null==e||null==(r=e.advertising)?void 0:r.localName)?n:e.name)?t:"";if(!i)return!1;var s=-1!==o.BLUETOOTH_DEVICE_NAME_PREFIXES.findIndex(function(e){return i.startsWith(e)});return s}),t.scan(function(e,t){var n,r,i,o,c,a,u,l,h=null!=(n=null!=(r=null==t||null==(i=t.advertising)?void 0:i.localName)?r:t.name)?n:"",d=null==(o=de(s.type,null!=(c=null==t||null==(a=t.advertising)||null==(u=a.manufacturerData)?void 0:u.bytes)?c:[]))||null==o.slice?void 0:o.slice(2);return v({},e,((l={})[t.id]=v({},t,{name:h,manufactureDataString:d}),l))},{}),t.distinctUntilChanged(function(e,t){return JSON.stringify(e)===JSON.stringify(t)}),t.map(function(e){return Object.values(e)}),t.share());return d},r.connect=function(e){try{var t=this;return Promise.resolve(new Promise(function(n,r){try{return Promise.resolve(be(function(){if(e)return t.connection$.next(exports.BLUETOOTH_CONNECTION.CONNECTING),Promise.resolve(t.BleManager.connect(e.id)).then(function(){return t.addLog("Getting service..."),Promise.resolve(t.BleManager.retrieveServices(e.id,[o.BLUETOOTH_PRIMARY_SERVICE_UUID_STRING])).then(function(i){function s(){t.addLog("Successfully connected to peripheral "+e.id),t.connection$.next(exports.BLUETOOTH_CONNECTION.CONNECTED),n()}if(!i)return t.addLog("Could not retreive services"),void r("Could not retreive services");t.addLog("Got service "+o.BLUETOOTH_PRIMARY_SERVICE_UUID_STRING+", getting characteristics..."),t.device=e,t.characteristicsByName=Object.fromEntries(i.characteristics.map(function(t){return[fe[t.characteristic.toLowerCase()],{characteristicUUID:t.characteristic,serviceUUID:t.service,peripheralId:e.id}]})),t.addLog("Got characteristics.");var c=function(){if("android"===t.platform)return t.addLog("Setting Android MTU to 512"),Promise.resolve(t.BleManager.requestMTU(e.id,512)).then(function(){})}();return c&&c.then?c.then(s):s()})});t.addLog("Peripheral not found")},function(e){r(e)}))}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},r.disconnect=function(){try{var e=this;return Promise.resolve(be(function(){var t=function(){var t;if(e.isConnected()&&null!=e&&null!=(t=e.device)&&t.id)return Promise.resolve(e.BleManager.disconnect(e.device.id)).then(function(){})}();if(t&&t.then)return t.then(function(){})},function(e){return Promise.reject(e)}))}catch(e){return Promise.reject(e)}},r.getCharacteristicByName=function(e){var t;if(!(e in this.characteristicsByName))throw new Error("Characteristic by name "+e+" is not found");return null==(t=this.characteristicsByName)?void 0:t[e]},r.subscribeToCharacteristic=function(n){var r=this,i=n.characteristicName,s=n.manageNotifications,c=void 0===s||s;return this.connection$.pipe(t.switchMap(function(n){return n===exports.BLUETOOTH_CONNECTION.CONNECTED?(s=r.getCharacteristicByName(i),a=s.peripheralId,u=s.serviceUUID,l=s.characteristicUUID,e.defer(function(){try{var e=function(){if(c){var e=be(function(){return Promise.resolve(r.BleManager.startNotification(a,u,l)).then(function(){r.addLog("Started notifications for "+i+" characteristic")})},function(e){var t;r.addLog("Attemped to stop notifications for "+i+" characteristic: "+(null!=(t=null==e?void 0:e.message)?t:e))});if(e&&e.then)return e.then(function(){})}}();return Promise.resolve(e&&e.then?e.then(function(){}):void 0)}catch(e){return Promise.reject(e)}}).pipe(t.switchMap(function(){return r.bleEvents.didUpdateValueForCharacteristic$}),t.finalize(function(){try{var e=function(){if(c){var e=be(function(){return Promise.resolve(r.BleManager.stopNotification(a,u,l)).then(function(){r.addLog("Stopped notifications for "+i+" characteristic")})},function(e){var t;r.addLog("Attemped to stop notifications for "+i+" characteristic: "+(null!=(t=null==e?void 0:e.message)?t:e))});if(e&&e.then)return e.then(function(){})}}();return Promise.resolve(e&&e.then?e.then(function(){}):void 0)}catch(e){return Promise.reject(e)}}),t.filter(function(e){return e.characteristic===l}),t.map(function(e){return de(r.type,e.value)}),ae({delimiter:o.BLUETOOTH_CHUNK_DELIMITER}),t.map(function(e){try{return JSON.parse(e)}catch(n){var t;return r.addLog("Failed to parse JSON for "+i+" characteristic. Falling back to unparsed string. "+(null!=(t=null==n?void 0:n.message)?t:n)),e}}))):e.NEVER;var s,a,u,l}))},r.readCharacteristic=function(e,t){void 0===t&&(t=!1);try{var n=this;n.addLog("Reading characteristic: "+e);var r=n.getCharacteristicByName(e),i=r.peripheralId,o=r.serviceUUID,s=r.characteristicUUID;return s?Promise.resolve(be(function(){return Promise.resolve(n.BleManager.read(i,o,s)).then(function(r){var i=de(n.type,r),o=t?JSON.parse(i):i;return n.addLog("Received read data from "+e+" characteristic: \n"+o),o})},function(t){var n;return Promise.reject("readCharacteristic "+e+" error. "+(null!=(n=null==t?void 0:t.message)?n:t))})):Promise.reject("Did not find characteristic matching "+e)}catch(e){return Promise.reject(e)}},r.writeCharacteristic=function(e,t){try{var n=this;n.addLog("Writing characteristic: "+e);var r=n.getCharacteristicByName(e),i=r.peripheralId,o=r.serviceUUID,s=r.characteristicUUID;if(!s)return Promise.reject("Did not find characteristic matching "+e);var c=he(n.type,t);return Promise.resolve(n.BleManager.write(i,o,s,c,512)).then(function(){})}catch(e){return Promise.reject(e)}},r._addPendingAction=function(e){var t=this.pendingActions$.getValue();this.pendingActions$.next([].concat(t,[e]))},r._removePendingAction=function(e){var t=this.pendingActions$.getValue();this.pendingActions$.next(t.filter(function(t){return t!==e}))},r._autoToggleActionNotifications=function(n){try{var r=this,i=!1,o=r.connection$.asObservable().pipe(t.switchMap(function(t){return t===exports.BLUETOOTH_CONNECTION.CONNECTED?r.pendingActions$:e.NEVER}),t.tap(function(e){try{var t=function(){var e=function(){if(!a&&i){i=!1;var e=be(function(){return Promise.resolve(r.BleManager.stopNotification(o,s,c)).then(function(){r.addLog("Stopped notifications for actions characteristic")})},function(e){var t;r.addLog("Attemped to stop notifications for [actions] characteristic: "+(null!=(t=null==e?void 0:e.message)?t:e))});if(e&&e.then)return e.then(function(){})}}();if(e&&e.then)return e.then(function(){})},n=r.getCharacteristicByName("actions"),o=n.peripheralId,s=n.serviceUUID,c=n.characteristicUUID,a=!!e.length,u=function(){if(a&&!i){i=!0;var e=be(function(){return Promise.resolve(r.BleManager.startNotification(o,s,c)).then(function(){r.addLog("Started notifications for [actions] characteristic")})},function(e){var t;r.addLog("Attemped to start notifications for [actions] characteristic: "+(null!=(t=null==e?void 0:e.message)?t:e))});if(e&&e.then)return e.then(function(){})}}();return Promise.resolve(u&&u.then?u.then(t):t())}catch(e){return Promise.reject(e)}}));return n.pipe(t.switchMap(function(t){return me(t)?o:e.EMPTY})).subscribe(),Promise.resolve()}catch(e){return Promise.reject(e)}},r.dispatchAction=function(n){var r=n.characteristicName,i=n.action;try{var o=this,s=i.responseRequired,c=void 0!==s&&s,a=i.responseTimeout,u=void 0===a?6e4:a;return Promise.resolve(new Promise(function(n,s){try{var a=ce(),l=JSON.stringify(v({actionId:a},i));if(o.addLog("Dispatched action with id "+a),c&&u){o._addPendingAction(a);var h=e.timer(u).subscribe(function(){o._removePendingAction(a),s("Action with id "+a+" timed out after "+u+"ms")});o.subscribeToCharacteristic({characteristicName:r,manageNotifications:!1}).pipe(t.filter(function(e){return(null==e?void 0:e.actionId)===a}),t.take(1)).subscribe(function(e){h.unsubscribe(),o._removePendingAction(a),n(e)}),o.writeCharacteristic(r,l).catch(function(e){o._removePendingAction(a),s(e.message)})}else o.writeCharacteristic(r,l).then(function(){n(null)}).catch(function(e){s(e.message)});return Promise.resolve()}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},n}(),Se="data",we=function(e){return e instanceof Object&&e===Object(e)},De=function(e){return"function"==typeof e};function Te(n){var r,i,o,s,c,a,u;return null!=n&&n.samplingRate||console.warn("Didn't receive a sampling rate, defaulting to 256"),e.pipe(e.pipe(t.mergeMap(function(t){return e.from(t)}),t.map(function(e){return{timestamp:e[0],data:e.slice(2)}})),(i={duration:16,interval:16,samplingRate:null!=(r=null==n?void 0:n.samplingRate)?r:256},o=i.duration,s=i.samplingRate,a=void 0===(c=i.dataProp)?Se:c,e.pipe(t.bufferCount(i.interval),t.scan(function(e,t){return e.concat(t).slice(e.length<o?0:-o)}),t.filter(function(e){return e.length===o}),function(n){var r=void 0===n?{}:n,i=r.samplingRate,o=void 0===i?256:i,s=r.dataProp,c=void 0===s?Se:s;return e.pipe(t.map(function(e){var t;return(t={})[c]=function(e,t){return void 0===t&&(t=Se),e[0][t].map(function(n,r){return e.map(function(e){return e[t][r]})})}(e,c),t.info=v({},e[0]&&e[0].info?e[0].info:{},{startTime:e[0].timestamp,samplingRate:e[0].info&&e[0].info.samplingRate?e[0].info.samplingRate:o}),t}))}({samplingRate:s,dataProp:a}))),(u={channelNames:n.channelNames,samplingRate:n.samplingRate},e.pipe(t.map(function(e){if(!we(e)||!we(u)&&!De(u))return e;var t=De(u)?u(e):u;return function(e){return function(t){var n;return v({},e,{info:v({},null!=(n=null==e?void 0:e.info)?n:{},t||{})})}}(e)(t)}))))}var ye=/*#__PURE__*/function(){function n(t){var n=this;this.transport=void 0,this.deviceInfo=void 0,this.selectedDevice$=new e.ReplaySubject(1),this.isAuthenticated$=new e.ReplaySubject(1),this._focus$=void 0,this._calm$=void 0,this._accelerometer$=void 0,this._brainwavesRaw$=void 0,this._brainwavesRawUnfiltered$=void 0,this._brainwavesPSD$=void 0,this._brainwavesPowerByBand$=void 0,this._signalQuality$=void 0,this._status$=void 0,this._settings$=void 0,this._wifiNearbyNetworks$=void 0,this._wifiConnections$=void 0;var r=null!=t?t:{},i=r.transport,o=r.selectedDevice$,s=r.createBluetoothToken;if(!i)throw new Error("No bluetooth transport provided.");this.transport=i,o&&o.subscribe(this.selectedDevice$),this.transport._autoConnect(this.selectedDevice$).subscribe({error:function(e){var t;n.transport.addLog("Auto connect: error -> "+(null!=(t=null==e?void 0:e.message)?t:e))}}),"function"==typeof s?(this.transport.addLog("Auto authentication enabled"),this._autoAuthenticate(s).subscribe()):this.transport.addLog("Auto authentication not enabled"),this.transport._autoToggleActionNotifications(this.selectedDevice$),this._focus$=this._subscribeWhileAuthenticated("focus"),this._calm$=this._subscribeWhileAuthenticated("calm"),this._accelerometer$=this._subscribeWhileAuthenticated("accelerometer"),this._brainwavesRaw$=this._subscribeWhileAuthenticated("raw"),this._brainwavesRawUnfiltered$=this._subscribeWhileAuthenticated("rawUnfiltered"),this._brainwavesPSD$=this._subscribeWhileAuthenticated("psd"),this._brainwavesPowerByBand$=this._subscribeWhileAuthenticated("powerByBand"),this._signalQuality$=this._subscribeWhileAuthenticated("signalQuality"),this._status$=this._subscribeWhileAuthenticated("status"),this._settings$=this._subscribeWhileAuthenticated("settings"),this._wifiNearbyNetworks$=this._subscribeWhileAuthenticated("wifiNearbyNetworks"),this._wifiConnections$=this._subscribeWhileAuthenticated("wifiConnections")}var r=n.prototype;return r._autoAuthenticate=function(n){var r=this,i=e.timer(0,36e5).pipe(t.tap(function(){r.transport.addLog("Auto authentication in progress...")}));return this.selectedDevice$.pipe(t.switchMap(function(o){return me(o)?r.connection().pipe(t.switchMap(function(t){return t===exports.BLUETOOTH_CONNECTION.CONNECTED?i:e.EMPTY}),t.switchMap(function(){try{return Promise.resolve(r.isAuthenticated())}catch(e){return Promise.reject(e)}}),t.tap(function(e){var t=e[0];try{var i=function(){if(!t)return Promise.resolve(n()).then(function(e){return Promise.resolve(r.authenticate(e)).then(function(){})});r.transport.addLog("Already authenticated")}();return Promise.resolve(i&&i.then?i.then(function(){}):void 0)}catch(e){return Promise.reject(e)}})):e.EMPTY}))},r.enableAutoConnect=function(e){this.transport.enableAutoConnect(e)},r._hasBluetoothSupport=function(){try{return Promise.resolve(e.firstValueFrom(this.selectedDevice$)).then(me)}catch(e){return Promise.reject(e)}},r.authenticate=function(e){try{var t=this;return Promise.resolve(t._hasBluetoothSupport()).then(function(n){if(!n){var r="authenticate method: The OS version does not support Bluetooth.";return t.transport.addLog(r),Promise.reject(r)}return Promise.resolve(t.transport.writeCharacteristic("auth",e)).then(function(){return Promise.resolve(t.isAuthenticated()).then(function(e){var n=e[0];return t.transport.addLog("Authentication "+(n?"succeeded":"failed")),t.isAuthenticated$.next(n),e})})})}catch(e){return Promise.reject(e)}},r.isAuthenticated=function(){try{var e=this;return Promise.resolve(e.transport.readCharacteristic("auth",!0)).then(function(t){var n=t[0],r=t[1];return e.isAuthenticated$.next(n),[n,r]})}catch(e){return Promise.reject(e)}},r.scan=function(e){if(this.transport instanceof Pe)return this.transport.scan(e);if(this.transport instanceof ge)throw new Error("scan method is compatibly with the React Native transport only");throw new Error("unknown transport")},r.connect=function(e){return this.transport instanceof Pe?this.transport.connect(e):this.transport instanceof ge?e?this.transport.connect(e):this.transport.connect():void 0},r.disconnect=function(){return this.transport.disconnect()},r.connection=function(){return this.transport.connection()},r.logs=function(){return this.transport.logs$.asObservable()},r.getDeviceId=function(){try{return Promise.resolve(this.transport.readCharacteristic("deviceId"))}catch(e){return Promise.reject(e)}},r._withAuthentication=function(t){try{var n=this;return Promise.resolve(n._hasBluetoothSupport()).then(function(r){if(!r){var i="The OS version does not support Bluetooth.";return n.transport.addLog(i),Promise.reject(i)}return Promise.resolve(e.firstValueFrom(n.isAuthenticated$)).then(function(e){if(!e){var r="Authentication required.";return n.transport.addLog(r),Promise.reject(r)}return Promise.resolve(t())})})}catch(e){return Promise.reject(e)}},r._subscribeWhileAuthenticated=function(n){var r=this;return this.selectedDevice$.pipe(t.switchMap(function(i){return me(i)?r.isAuthenticated$.pipe(t.distinctUntilChanged(),t.switchMap(function(t){return t?r.transport.subscribeToCharacteristic({characteristicName:n}):e.EMPTY})):e.EMPTY}),t.share())},r.focus=function(){return this._focus$},r.calm=function(){return this._calm$},r.accelerometer=function(){return this._accelerometer$},r.brainwaves=function(n){var r=this;switch(n){default:case"raw":return e.defer(function(){return r.getInfo()}).pipe(t.switchMap(function(e){return r._brainwavesRaw$.pipe(Te(e))}));case"rawUnfiltered":return e.defer(function(){return r.getInfo()}).pipe(t.switchMap(function(e){return r._brainwavesRawUnfiltered$.pipe(Te(e))}));case"psd":return this._brainwavesPSD$;case"powerByBand":return this._brainwavesPowerByBand$}},r.signalQuality=function(){return this._signalQuality$},r.addMarker=function(e){try{return Promise.resolve(this.dispatchAction({action:"marker",command:"add",message:{timestamp:Date.now(),label:e}})).then(function(){})}catch(e){return Promise.reject(e)}},r.getInfo=function(){try{var t=this;return Promise.resolve(t._withAuthentication(function(){return e.firstValueFrom(t.transport.subscribeToCharacteristic({characteristicName:"deviceInfo"}))}))}catch(e){return Promise.reject(e)}},r.status=function(){return this._status$},r.dispatchAction=function(e){try{var t=this;return Promise.resolve(t._withAuthentication(function(){return t.transport.dispatchAction({characteristicName:"actions",action:e})}))}catch(e){return Promise.reject(e)}},r.settings=function(){return this._settings$},r.haptics=function(e){return this.dispatchAction({action:"haptics",command:"queue",responseRequired:!0,responseTimeout:4e3,message:{effects:e}})},p(n,[{key:"wifi",get:function(){var e=this;return{nearbyNetworks:function(){return e._wifiNearbyNetworks$},connections:function(){return e._wifiConnections$},connect:function(t,n){return t?e.dispatchAction({action:"wifi",command:"connect",responseRequired:!0,responseTimeout:12e4,message:{ssid:t,password:null!=n?n:null}}):Promise.reject("Missing ssid")},forgetConnection:function(t){return t?e.dispatchAction({action:"wifi",command:"forget-connection",responseRequired:!0,responseTimeout:15e3,message:{ssid:t}}):Promise.reject("Missing ssid")},reset:function(){return e.dispatchAction({action:"wifi",command:"reset",responseRequired:!0,responseTimeout:3e4,message:{respondOnSuccess:!0}})},speedTest:function(){return e.dispatchAction({action:"wifi",command:"speed-test",responseRequired:!0,responseTimeout:6e4})}}}}]),n}(),Ee={timesync:!1,autoSelectDevice:!0,streamingMode:L.WIFI_ONLY,emulator:!1,emulatorHost:"localhost",emulatorAuthPort:9099,emulatorDatabasePort:9e3,emulatorFunctionsPort:5001,emulatorFirestorePort:8080,emulatorOptions:{}},Oe=/*#__PURE__*/function(){function n(t){void 0===t&&(t={}),this.options=void 0,this.cloudClient=void 0,this.bluetoothClient=void 0,this.isMissingBluetoothTransport=void 0,this.streamingMode$=new e.ReplaySubject(1);var n=t.streamingMode,r=t.bluetoothTransport;this.options=Object.freeze(v({},Ee,t)),this.cloudClient=new k(this.options),r&&(this.bluetoothClient=new ye({selectedDevice$:this.onDeviceChange(),createBluetoothToken:this.createBluetoothToken.bind(this),transport:r})),this._initStreamingMode(n,!!r)}var r=n.prototype;return r._initStreamingMode=function(e,t){var n=[L.BLUETOOTH_WITH_WIFI_FALLBACK,L.WIFI_WITH_BLUETOOTH_FALLBACK].includes(e),r=!Object.values(L).includes(e),i=n&&!t;this.isMissingBluetoothTransport=i,this.streamingMode$.next(!e||r||i?L.WIFI_ONLY:e)},r.streamingState=function(){var n=this,r=function(e){return[A.ONLINE,A.UPDATING].includes(e)};return this.streamingMode$.pipe(t.switchMap(function(i){return n.isMissingBluetoothTransport?n.cloudClient.status().pipe(t.map(function(e){return{connected:r(e.state),streamingMode:i,activeMode:j.WIFI}})):n.onDeviceChange().pipe(t.switchMap(function(o){return o?e.combineLatest({wifiStatus:n.cloudClient.status(),bluetoothConnection:null!=n&&n.bluetoothClient?n.bluetoothClient.connection():e.of(exports.BLUETOOTH_CONNECTION.DISCONNECTED)}).pipe(t.map(function(e){var t=e.wifiStatus,n=e.bluetoothConnection===exports.BLUETOOTH_CONNECTION.CONNECTED;switch(i){default:case L.WIFI_ONLY:return{connected:r(t.state),streamingMode:i,activeMode:j.WIFI};case L.WIFI_WITH_BLUETOOTH_FALLBACK:return{connected:r(t.state)||!n?r(t.state):n,streamingMode:i,activeMode:r(t.state)||!n?j.WIFI:j.BLUETOOTH};case L.BLUETOOTH_WITH_WIFI_FALLBACK:return{connected:!!n||r(t.state),streamingMode:i,activeMode:n?j.BLUETOOTH:j.WIFI}}}),t.distinctUntilChanged(function(e,t){return u.default(e,t)})):e.EMPTY}))}))},r._withStreamingModeObservable=function(e){var n=e.wifi,r=e.bluetooth;return this.streamingState().pipe(t.switchMap(function(e){switch(e.activeMode){case j.WIFI:return n();case j.BLUETOOTH:return r();default:return n()}}))},r._withStreamingModePromise=function(t){try{var n=t.wifi,r=t.bluetooth;return Promise.resolve(e.firstValueFrom(this.streamingState())).then(function(e){switch(e.activeMode){case j.WIFI:return Promise.resolve(n());case j.BLUETOOTH:return Promise.resolve(r());default:return Promise.resolve(n())}})}catch(e){return Promise.reject(e)}},r._getCloudMetricDependencies=function(){return{options:this.options,cloudClient:this.cloudClient,onDeviceChange:this.onDeviceChange.bind(this),status:this.status.bind(this)}},r.login=function(e){try{return Promise.resolve(this.cloudClient.login(e))}catch(e){return Promise.reject(e)}},r.logout=function(){try{return Promise.resolve(this.cloudClient.logout())}catch(e){return Promise.reject(e)}},r.__getApp=function(){return this.cloudClient.__getApp()},r.onAuthStateChanged=function(){return this.cloudClient.onAuthStateChanged()},r.addDevice=function(e){var t=ne(this.cloudClient.userClaims,"addDevice");return t[0]?Promise.reject(t[1]):this.cloudClient.addDevice(e)},r.removeDevice=function(e){var t=ne(this.cloudClient.userClaims,"removeDevice");return t[0]?Promise.reject(t[1]):this.cloudClient.removeDevice(e)},r.transferDevice=function(e){var t=ne(this.cloudClient.userClaims,"transferDevice");return t[0]?Promise.reject(t[1]):this.cloudClient.transferDevice(e)},r.onUserDevicesChange=function(){var t=ne(this.cloudClient.userClaims,"onUserDevicesChange"),n=t[1];return t[0]?e.throwError(function(){return n}):this.cloudClient.onUserDevicesChange()},r.onUserClaimsChange=function(){return this.cloudClient.onUserClaimsChange()},r.getDevices=function(){try{return Promise.resolve(this.cloudClient.getDevices())}catch(e){return Promise.reject(e)}},r.selectDevice=function(e){try{var t=ne(this.cloudClient.userClaims,"selectDevice");return t[0]?Promise.reject(t[1]):Promise.resolve(this.cloudClient.selectDevice(e))}catch(e){return Promise.reject(e)}},r.getSelectedDevice=function(){try{var e=ne(this.cloudClient.userClaims,"getSelectedDevice");return e[0]?Promise.reject(e[1]):Promise.resolve(this.cloudClient.getSelectedDevice())}catch(e){return Promise.reject(e)}},r.getInfo=function(){try{var e=this;return Promise.resolve(e.cloudClient.didSelectDevice()).then(function(t){if(!t)return Promise.reject(z);var n=ne(e.cloudClient.userClaims,"getInfo");return n[0]?Promise.reject(n[1]):Promise.resolve(e._withStreamingModePromise({wifi:function(){return e.cloudClient.getInfo()},bluetooth:function(){return e.bluetoothClient.getInfo()}}))})}catch(e){return Promise.reject(e)}},r.onDeviceChange=function(){var t=ne(this.cloudClient.userClaims,"onDeviceChange"),n=t[1];return t[0]?e.throwError(function(){return n}):this.cloudClient.onDeviceChange()},r.disconnect=function(){try{var e=this;return Promise.resolve(e._withStreamingModePromise({wifi:function(){return e.cloudClient.disconnect()},bluetooth:function(){return e.bluetoothClient.disconnect()}}))}catch(e){return Promise.reject(e)}},r.dispatchAction=function(e){try{var t=this;return Promise.resolve(t.cloudClient.didSelectDevice()).then(function(n){if(!n)return Promise.reject(z);var r=function(e,t){var n=null!=e?e:{};if(!n.oauth)return[!1,null];var r=n.scopes.split(","),i=ee[t.command+"/"+t.action];return r.includes(i)?[!1,null]:[!0,re(i)]}(t.cloudClient.userClaims,e);return r[0]?Promise.reject(r[1]):Promise.resolve(t._withStreamingModePromise({wifi:function(){return t.cloudClient.dispatchAction(e)},bluetooth:function(){return t.bluetoothClient.dispatchAction(e)}}))})}catch(e){return Promise.reject(e)}},r.addMarker=function(e){try{var t=this;return Promise.resolve(t.cloudClient.didSelectDevice()).then(function(n){if(!n)throw z;if(!e)throw new Error(V+"A label is required for addMarker");return Promise.resolve(t._withStreamingModePromise({wifi:function(){return t.cloudClient.dispatchAction({command:"marker",action:"add",message:{label:e,timestamp:t.cloudClient.timestamp}})},bluetooth:function(){return t.bluetoothClient.addMarker(e)}}))})}catch(e){return Promise.reject(e)}},r.haptics=function(e){try{var t=this,n="haptics";return Promise.resolve(t.cloudClient.didSelectDevice()).then(function(r){return r?Promise.resolve(t.getSelectedDevice()).then(function(r){var i=null==r?void 0:r.modelVersion,o=function(e){return Q[e].includes(J)}(i);if(!o)return Promise.reject(q(n,i));var s=function(e){var t,n=X[e];return v({},null!=(t=null==n?void 0:n.motorByMotorName)?t:{})}(i);for(var c in e){if(!Object.keys(s).includes(c))return Promise.reject(Y(c,i));var a=e[c];if(a.length>7)return Promise.reject(new Error(V+"Maximum items in array is 7"));s[c]=a}var u={command:n,action:"queue",responseRequired:!0,responseTimeout:1e3,message:{effects:s}};return Promise.resolve(t._withStreamingModePromise({wifi:function(){return t.cloudClient.dispatchAction(u)},bluetooth:function(){return t.bluetoothClient.dispatchAction(u)}}))}):Promise.reject(z)})}catch(e){return Promise.reject(e)}},r.getHapticEffects=function(){return Z},r.accelerometer=function(){var n=this,r="accelerometer",i=ne(this.cloudClient.userClaims,r),o=i[1];return i[0]?e.throwError(function(){return o}):this.onDeviceChange().pipe(t.switchMap(function(t){var i=(null==t?void 0:t.modelVersion)||"1",o=function(e){return Q[e].includes(K)}(i);return o?n._withStreamingModeObservable({wifi:function(){return se(n._getCloudMetricDependencies(),{metric:r,labels:G(r),atomic:!0})},bluetooth:function(){return n.bluetoothClient.accelerometer()}}):e.throwError(function(){return q(r,i)})}))},r.brainwaves=function(t){var n=this,r=ne(this.cloudClient.userClaims,"brainwaves"),i=r[1];return r[0]?e.throwError(function(){return i}):this._withStreamingModeObservable({wifi:function(){return se(n._getCloudMetricDependencies(),{metric:"brainwaves",labels:t?[t]:[],atomic:!1})},bluetooth:function(){return n.bluetoothClient.brainwaves(t)}})},r.calm=function(){var t=this,n=ne(this.cloudClient.userClaims,"calm"),r=n[1];return n[0]?e.throwError(function(){return r}):this._withStreamingModeObservable({wifi:function(){return se(t._getCloudMetricDependencies(),{metric:"awareness",labels:["calm"],atomic:!1})},bluetooth:function(){return t.bluetoothClient.calm()}})},r.signalQuality=function(){var t=this,n="signalQuality",r=ne(this.cloudClient.userClaims,n),i=r[1];return r[0]?e.throwError(function(){return i}):this._withStreamingModeObservable({wifi:function(){return se(t._getCloudMetricDependencies(),{metric:n,labels:G(n),atomic:!0})},bluetooth:function(){return t.bluetoothClient.signalQuality()}})},r.settings=function(){var t=ne(this.cloudClient.userClaims,"settings"),n=t[1];return t[0]?e.throwError(function(){return n}):this.cloudClient.observeNamespace("settings")},r.focus=function(){var t=this,n=ne(this.cloudClient.userClaims,"focus"),r=n[1];return n[0]?e.throwError(function(){return r}):this._withStreamingModeObservable({wifi:function(){return se(t._getCloudMetricDependencies(),{metric:"awareness",labels:["focus"],atomic:!1})},bluetooth:function(){return t.bluetoothClient.focus()}})},r.kinesis=function(t){var n="kinesis",r=ne(this.cloudClient.userClaims,n),i=r[1];return r[0]?e.throwError(function(){return i}):se(this._getCloudMetricDependencies(),{metric:n,labels:t?[t]:[],atomic:!1})},r.predictions=function(t){var n="predictions",r=ne(this.cloudClient.userClaims,n),i=r[1];return r[0]?e.throwError(function(){return i}):se(this._getCloudMetricDependencies(),{metric:n,labels:t?[t]:[],atomic:!1})},r.status=function(){var t=this,n=ne(this.cloudClient.userClaims,"status"),r=n[1];return n[0]?e.throwError(function(){return r}):this._withStreamingModeObservable({wifi:function(){return t.cloudClient.status()},bluetooth:function(){return t.bluetoothClient.status()}})},r.changeSettings=function(e){try{var t=this;return Promise.resolve(t.cloudClient.didSelectDevice()).then(function(n){if(!n)return Promise.reject(z);var r=ne(t.cloudClient.userClaims,"changeSettings");return r[0]?Promise.reject(r[1]):Promise.resolve(t.cloudClient.changeSettings(e))})}catch(e){return Promise.reject(e)}},r.goOffline=function(){this.cloudClient.goOffline()},r.goOnline=function(){this.cloudClient.goOnline()},r.createAccount=function(e){return this.cloudClient.createAccount(e)},r.deleteAccount=function(){return this.cloudClient.deleteAccount()},r.createBluetoothToken=function(){return this.cloudClient.createBluetoothToken()},r.createCustomToken=function(){return this.cloudClient.createCustomToken()},r.getTimesyncOffset=function(){return this.options.timesync||console.warn("getTimesyncOffset() requires options.timesync to be true."),this.options.timesync?this.cloudClient.getTimesyncOffset():0},r.createOAuthURL=function(e){return oe?function(e,t){var n=e.clientId,r=e.clientSecret,i=e.responseType,o=e.redirectUri,s=e.scope,c=e.state,a=ie(t);return d.default.get(a+"/authorize/entry",{params:v({client_id:n},r?{client_secret:r}:{},{response_type:i,redirect_uri:o,scope:s.join(","),state:c,redirect:"false"})}).then(function(e){return""+a+e.data.url})}(e,this.options):Promise.reject(new Error(V+"the createOAuthURL method must be used on the server side (node.js) for security reasons."))},r.getOAuthToken=function(e){return oe?function(e,t){try{var n=ie(t);return Promise.resolve(d.default.post(n+"/getOAuthRefreshToken",e)).then(function(t){return d.default.post(n+"/token",{grant_type:"refresh_token",refresh_token:t.data.data,client_id:e.clientId,client_secret:e.clientSecret}).then(function(e){return JSON.parse(e.data).access_token})})}catch(e){return Promise.reject(e)}}(e,this.options):Promise.reject(new Error(V+"the getOAuthToken method must be used on the server side (node.js) for security reasons."))},r.removeOAuthAccess=function(){return this.cloudClient.removeOAuthAccess()},r.onUserExperiments=function(){return this.cloudClient.onUserExperiments()},r.deleteUserExperiment=function(e){return this.cloudClient.deleteUserExperiment(e)},p(n,[{key:"bluetooth",get:function(){return null==this?void 0:this.bluetoothClient}},{key:"training",get:function(){var e=this,t=this,n=this;return{record:function(t){try{return Promise.resolve(e.cloudClient.didSelectDevice()).then(function(n){if(!n)throw z;var r=v({fit:!1,baseline:!1,timestamp:e.cloudClient.timestamp},t,{userId:e.cloudClient.user&&"uid"in e.cloudClient.user?e.cloudClient.user.uid:null});return Promise.resolve(e.cloudClient.actions.dispatch({command:"training",action:"record",message:r})).then(function(){})})}catch(e){return Promise.reject(e)}},stop:function(e){try{return Promise.resolve(t.cloudClient.didSelectDevice()).then(function(n){if(!n)throw z;return Promise.resolve(t.cloudClient.actions.dispatch({command:"training",action:"stop",message:v({},e)})).then(function(){})})}catch(e){return Promise.reject(e)}},stopAll:function(){try{return Promise.resolve(n.cloudClient.didSelectDevice()).then(function(e){if(!e)throw z;return Promise.resolve(n.cloudClient.actions.dispatch({command:"training",action:"stopAll",message:{}})).then(function(){})})}catch(e){return Promise.reject(e)}}}}}]),n}();Oe.credentialWithLink=D,Oe.createUser=function(){return b(l.default.User,[].slice.call(arguments))},Oe.SERVER_TIMESTAMP=P;var Ne=/*#__PURE__*/function(e){var t,n;function r(t){var n;return void 0===t&&(t={}),n=e.call(this,t)||this,console.log("The Notion class is deprecated and will be removed in the next version of the SDK. Please use the Neurosity class instead. e.g. new Notion() => new Neurosity()"),n}return n=e,(t=r).prototype=Object.create(n.prototype),t.prototype.constructor=t,g(t,n),r}(Oe);exports.BluetoothClient=ye,exports.Neurosity=Oe,exports.Notion=Ne,exports.ReactNativeTransport=Pe,exports.WebBluetoothTransport=ge,exports.osHasBluetoothSupport=me;
2
+ //# sourceMappingURL=index.cjs.map