@neurosity/sdk 6.2.1-next.2 → 6.2.2

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 (305) hide show
  1. package/dist/browser/neurosity.iife.js +48717 -0
  2. package/dist/browser/neurosity.js +666 -0
  3. package/dist/browser/neurosity.js.map +1 -0
  4. package/dist/{Neurosity.d.ts → cjs/Neurosity.d.ts} +2 -116
  5. package/dist/cjs/Neurosity.js +1244 -0
  6. package/dist/{api → cjs/api}/bluetooth/BluetoothClient.d.ts +6 -6
  7. package/dist/cjs/api/bluetooth/BluetoothClient.js +310 -0
  8. package/dist/cjs/api/bluetooth/BluetoothTransport.d.ts +33 -0
  9. package/dist/cjs/api/bluetooth/BluetoothTransport.js +2 -0
  10. package/dist/{api → cjs/api}/bluetooth/constants.d.ts +0 -0
  11. package/dist/cjs/api/bluetooth/constants.js +9 -0
  12. package/dist/{api → cjs/api}/bluetooth/index.d.ts +0 -0
  13. package/dist/cjs/api/bluetooth/index.js +21 -0
  14. package/dist/{api → cjs/api}/bluetooth/react-native/ReactNativeTransport.d.ts +4 -4
  15. package/dist/cjs/api/bluetooth/react-native/ReactNativeTransport.js +411 -0
  16. package/dist/cjs/api/bluetooth/react-native/types/BleManagerTypes.d.ts +63 -0
  17. package/dist/cjs/api/bluetooth/react-native/types/BleManagerTypes.js +11 -0
  18. package/dist/cjs/api/bluetooth/react-native/types/ReactNativeTypes.d.ts +180 -0
  19. package/dist/cjs/api/bluetooth/react-native/types/ReactNativeTypes.js +10 -0
  20. package/dist/{api → cjs/api}/bluetooth/types/index.d.ts +2 -2
  21. package/dist/cjs/api/bluetooth/types/index.js +22 -0
  22. package/dist/{api → cjs/api}/bluetooth/utils/create6DigitPin.d.ts +0 -0
  23. package/dist/cjs/api/bluetooth/utils/create6DigitPin.js +8 -0
  24. package/dist/{api → cjs/api}/bluetooth/utils/csvBufferToEpoch.d.ts +0 -0
  25. package/dist/cjs/api/bluetooth/utils/csvBufferToEpoch.js +36 -0
  26. package/dist/{api → cjs/api}/bluetooth/utils/encoding.d.ts +0 -0
  27. package/dist/cjs/api/bluetooth/utils/encoding.js +22 -0
  28. package/dist/{api → cjs/api}/bluetooth/utils/osHasBluetoothSupport.d.ts +0 -0
  29. package/dist/cjs/api/bluetooth/utils/osHasBluetoothSupport.js +23 -0
  30. package/dist/{api → cjs/api}/bluetooth/utils/stitch.d.ts +1 -1
  31. package/dist/cjs/api/bluetooth/utils/stitch.js +22 -0
  32. package/dist/{api → cjs/api}/bluetooth/web/WebBluetoothTransport.d.ts +1 -1
  33. package/dist/cjs/api/bluetooth/web/WebBluetoothTransport.js +430 -0
  34. package/dist/{api → cjs/api}/bluetooth/web/isMaybeWebWorkerContext.d.ts +0 -0
  35. package/dist/cjs/api/bluetooth/web/isMaybeWebWorkerContext.js +8 -0
  36. package/dist/{api → cjs/api}/bluetooth/web/isWebBluetoothSupported.d.ts +0 -0
  37. package/dist/cjs/api/bluetooth/web/isWebBluetoothSupported.js +11 -0
  38. package/dist/{api → cjs/api}/firebase/FirebaseApp.d.ts +0 -0
  39. package/dist/cjs/api/firebase/FirebaseApp.js +70 -0
  40. package/dist/{api → cjs/api}/firebase/FirebaseDevice.d.ts +1 -1
  41. package/dist/cjs/api/firebase/FirebaseDevice.js +146 -0
  42. package/dist/{api → cjs/api}/firebase/FirebaseUser.d.ts +0 -0
  43. package/dist/cjs/api/firebase/FirebaseUser.js +434 -0
  44. package/dist/{api → cjs/api}/firebase/config.d.ts +0 -0
  45. package/dist/cjs/api/firebase/config.js +11 -0
  46. package/dist/{api → cjs/api}/firebase/deviceStore.d.ts +0 -0
  47. package/dist/cjs/api/firebase/deviceStore.js +191 -0
  48. package/dist/{api → cjs/api}/firebase/index.d.ts +0 -0
  49. package/dist/cjs/api/firebase/index.js +19 -0
  50. package/dist/{api → cjs/api}/https/config.d.ts +0 -0
  51. package/dist/cjs/api/https/config.js +4 -0
  52. package/dist/{api → cjs/api}/https/createOAuthURL.d.ts +0 -0
  53. package/dist/cjs/api/https/createOAuthURL.js +18 -0
  54. package/dist/{api → cjs/api}/https/getOAuthToken.d.ts +0 -0
  55. package/dist/cjs/api/https/getOAuthToken.js +34 -0
  56. package/dist/{api → cjs/api}/https/utils.d.ts +0 -0
  57. package/dist/cjs/api/https/utils.js +13 -0
  58. package/dist/{api → cjs/api}/index.d.ts +0 -8
  59. package/dist/cjs/api/index.js +307 -0
  60. package/dist/{index.d.ts → cjs/index.d.ts} +0 -0
  61. package/dist/cjs/index.js +18 -0
  62. package/dist/{subscriptions → cjs/subscriptions}/SubscriptionManager.d.ts +0 -0
  63. package/dist/cjs/subscriptions/SubscriptionManager.js +27 -0
  64. package/dist/{timesync → cjs/timesync}/Timesync.d.ts +1 -1
  65. package/dist/cjs/timesync/Timesync.js +78 -0
  66. package/dist/{timesync → cjs/timesync}/index.d.ts +0 -0
  67. package/dist/cjs/timesync/index.js +17 -0
  68. package/dist/cjs/types/accelerometer.d.ts +10 -0
  69. package/dist/cjs/types/accelerometer.js +2 -0
  70. package/dist/cjs/types/actions.d.ts +16 -0
  71. package/dist/cjs/types/actions.js +2 -0
  72. package/dist/cjs/types/awareness.d.ts +1 -0
  73. package/dist/cjs/types/awareness.js +2 -0
  74. package/dist/cjs/types/brainwaves.d.ts +26 -0
  75. package/dist/cjs/types/brainwaves.js +2 -0
  76. package/dist/cjs/types/calm.d.ts +6 -0
  77. package/dist/cjs/types/calm.js +2 -0
  78. package/dist/cjs/types/client.d.ts +22 -0
  79. package/dist/cjs/types/client.js +2 -0
  80. package/dist/cjs/types/credentials.d.ts +12 -0
  81. package/dist/cjs/types/credentials.js +2 -0
  82. package/dist/cjs/types/deviceInfo.d.ts +18 -0
  83. package/dist/cjs/types/deviceInfo.js +2 -0
  84. package/dist/cjs/types/epoch.d.ts +12 -0
  85. package/dist/cjs/types/epoch.js +2 -0
  86. package/dist/cjs/types/experiment.d.ts +9 -0
  87. package/dist/cjs/types/experiment.js +2 -0
  88. package/dist/cjs/types/focus.d.ts +6 -0
  89. package/dist/cjs/types/focus.js +2 -0
  90. package/dist/cjs/types/hapticEffects.d.ts +125 -0
  91. package/dist/cjs/types/hapticEffects.js +2 -0
  92. package/dist/cjs/types/kinesis.d.ts +6 -0
  93. package/dist/cjs/types/kinesis.js +2 -0
  94. package/dist/cjs/types/marker.d.ts +7 -0
  95. package/dist/cjs/types/marker.js +2 -0
  96. package/dist/cjs/types/metrics.d.ts +21 -0
  97. package/dist/cjs/types/metrics.js +2 -0
  98. package/dist/cjs/types/oauth.d.ts +20 -0
  99. package/dist/cjs/types/oauth.js +2 -0
  100. package/dist/cjs/types/options.d.ts +51 -0
  101. package/dist/cjs/types/options.js +2 -0
  102. package/dist/cjs/types/sample.d.ts +15 -0
  103. package/dist/cjs/types/sample.js +2 -0
  104. package/dist/cjs/types/settings.d.ts +13 -0
  105. package/dist/cjs/types/settings.js +2 -0
  106. package/dist/cjs/types/signalQuality.d.ts +13 -0
  107. package/dist/cjs/types/signalQuality.js +2 -0
  108. package/dist/cjs/types/skill.d.ts +68 -0
  109. package/dist/cjs/types/skill.js +2 -0
  110. package/dist/{types → cjs/types}/status.d.ts +0 -0
  111. package/dist/cjs/types/status.js +22 -0
  112. package/dist/{types → cjs/types}/streaming.d.ts +0 -0
  113. package/dist/cjs/types/streaming.js +20 -0
  114. package/dist/cjs/types/subscriptions.d.ts +23 -0
  115. package/dist/cjs/types/subscriptions.js +2 -0
  116. package/dist/cjs/types/training.d.ts +19 -0
  117. package/dist/cjs/types/training.js +2 -0
  118. package/dist/cjs/types/user.d.ts +12 -0
  119. package/dist/cjs/types/user.js +2 -0
  120. package/dist/{utils → cjs/utils}/errors.d.ts +0 -0
  121. package/dist/cjs/utils/errors.js +17 -0
  122. package/dist/{utils → cjs/utils}/filterInternalKeys.d.ts +0 -0
  123. package/dist/cjs/utils/filterInternalKeys.js +21 -0
  124. package/dist/{utils → cjs/utils}/hapticEffects.d.ts +0 -0
  125. package/dist/cjs/utils/hapticEffects.js +130 -0
  126. package/dist/{utils → cjs/utils}/heartbeat.d.ts +0 -0
  127. package/dist/cjs/utils/heartbeat.js +41 -0
  128. package/dist/{utils → cjs/utils}/is-node.d.ts +0 -0
  129. package/dist/cjs/utils/is-node.js +9 -0
  130. package/dist/cjs/utils/metrics.d.ts +1 -0
  131. package/dist/cjs/utils/metrics.js +56 -0
  132. package/dist/{utils → cjs/utils}/oauth.d.ts +1 -1
  133. package/dist/cjs/utils/oauth.js +92 -0
  134. package/dist/cjs/utils/pick.d.ts +1 -0
  135. package/dist/cjs/utils/pick.js +5 -0
  136. package/dist/{utils → cjs/utils}/pipes.d.ts +0 -0
  137. package/dist/cjs/utils/pipes.js +71 -0
  138. package/dist/{utils → cjs/utils}/platform.d.ts +0 -0
  139. package/dist/cjs/utils/platform.js +47 -0
  140. package/dist/{utils → cjs/utils}/subscription.d.ts +0 -0
  141. package/dist/cjs/utils/subscription.js +55 -0
  142. package/dist/cjs/utils/transferDevice.d.ts +9 -0
  143. package/dist/cjs/utils/transferDevice.js +2 -0
  144. package/dist/{utils → cjs/utils}/whileOnline.d.ts +1 -1
  145. package/dist/cjs/utils/whileOnline.js +15 -0
  146. package/dist/electron/index.js +86 -0
  147. package/dist/electron/index.js.map +1 -0
  148. package/dist/esm/Neurosity.d.ts +619 -0
  149. package/dist/esm/Neurosity.js +1213 -0
  150. package/dist/esm/api/bluetooth/BluetoothClient.d.ts +72 -0
  151. package/dist/esm/api/bluetooth/BluetoothClient.js +306 -0
  152. package/dist/esm/api/bluetooth/BluetoothTransport.d.ts +33 -0
  153. package/dist/esm/api/bluetooth/BluetoothTransport.js +1 -0
  154. package/dist/esm/api/bluetooth/constants.d.ts +4 -0
  155. package/dist/esm/api/bluetooth/constants.js +6 -0
  156. package/dist/esm/api/bluetooth/index.d.ts +5 -0
  157. package/dist/esm/api/bluetooth/index.js +5 -0
  158. package/dist/esm/api/bluetooth/react-native/ReactNativeTransport.d.ts +70 -0
  159. package/dist/esm/api/bluetooth/react-native/ReactNativeTransport.js +407 -0
  160. package/dist/esm/api/bluetooth/react-native/types/BleManagerTypes.d.ts +63 -0
  161. package/dist/esm/api/bluetooth/react-native/types/BleManagerTypes.js +8 -0
  162. package/dist/esm/api/bluetooth/react-native/types/ReactNativeTypes.d.ts +180 -0
  163. package/dist/esm/api/bluetooth/react-native/types/ReactNativeTypes.js +9 -0
  164. package/dist/esm/api/bluetooth/types/index.d.ts +31 -0
  165. package/dist/esm/api/bluetooth/types/index.js +19 -0
  166. package/dist/esm/api/bluetooth/utils/create6DigitPin.d.ts +1 -0
  167. package/dist/esm/api/bluetooth/utils/create6DigitPin.js +4 -0
  168. package/dist/esm/api/bluetooth/utils/csvBufferToEpoch.d.ts +11 -0
  169. package/dist/esm/api/bluetooth/utils/csvBufferToEpoch.js +31 -0
  170. package/dist/esm/api/bluetooth/utils/encoding.d.ts +3 -0
  171. package/dist/esm/api/bluetooth/utils/encoding.js +17 -0
  172. package/dist/esm/api/bluetooth/utils/osHasBluetoothSupport.d.ts +2 -0
  173. package/dist/esm/api/bluetooth/utils/osHasBluetoothSupport.js +16 -0
  174. package/dist/esm/api/bluetooth/utils/stitch.d.ts +5 -0
  175. package/dist/esm/api/bluetooth/utils/stitch.js +18 -0
  176. package/dist/esm/api/bluetooth/web/WebBluetoothTransport.d.ts +54 -0
  177. package/dist/esm/api/bluetooth/web/WebBluetoothTransport.js +426 -0
  178. package/dist/esm/api/bluetooth/web/isMaybeWebWorkerContext.d.ts +1 -0
  179. package/dist/esm/api/bluetooth/web/isMaybeWebWorkerContext.js +4 -0
  180. package/dist/esm/api/bluetooth/web/isWebBluetoothSupported.d.ts +1 -0
  181. package/dist/esm/api/bluetooth/web/isWebBluetoothSupported.js +7 -0
  182. package/dist/esm/api/firebase/FirebaseApp.d.ts +20 -0
  183. package/dist/esm/api/firebase/FirebaseApp.js +63 -0
  184. package/dist/esm/api/firebase/FirebaseDevice.d.ts +68 -0
  185. package/dist/esm/api/firebase/FirebaseDevice.js +139 -0
  186. package/dist/esm/api/firebase/FirebaseUser.d.ts +53 -0
  187. package/dist/esm/api/firebase/FirebaseUser.js +426 -0
  188. package/dist/esm/api/firebase/config.d.ts +8 -0
  189. package/dist/esm/api/firebase/config.js +8 -0
  190. package/dist/esm/api/firebase/deviceStore.d.ts +26 -0
  191. package/dist/esm/api/firebase/deviceStore.js +184 -0
  192. package/dist/esm/api/firebase/index.d.ts +3 -0
  193. package/dist/esm/api/firebase/index.js +3 -0
  194. package/dist/esm/api/https/config.d.ts +1 -0
  195. package/dist/esm/api/https/config.js +1 -0
  196. package/dist/esm/api/https/createOAuthURL.d.ts +3 -0
  197. package/dist/esm/api/https/createOAuthURL.js +11 -0
  198. package/dist/esm/api/https/getOAuthToken.d.ts +3 -0
  199. package/dist/esm/api/https/getOAuthToken.js +27 -0
  200. package/dist/esm/api/https/utils.d.ts +2 -0
  201. package/dist/esm/api/https/utils.js +9 -0
  202. package/dist/esm/api/index.d.ts +109 -0
  203. package/dist/esm/api/index.js +300 -0
  204. package/dist/esm/index.d.ts +2 -0
  205. package/dist/esm/index.js +2 -0
  206. package/dist/esm/neurosity.mjs +48705 -0
  207. package/dist/esm/subscriptions/SubscriptionManager.d.ts +11 -0
  208. package/dist/esm/subscriptions/SubscriptionManager.js +23 -0
  209. package/dist/esm/timesync/Timesync.d.ts +20 -0
  210. package/dist/esm/timesync/Timesync.js +71 -0
  211. package/dist/esm/timesync/index.d.ts +1 -0
  212. package/dist/esm/timesync/index.js +1 -0
  213. package/dist/esm/types/accelerometer.d.ts +10 -0
  214. package/dist/esm/types/accelerometer.js +1 -0
  215. package/dist/esm/types/actions.d.ts +16 -0
  216. package/dist/esm/types/actions.js +1 -0
  217. package/dist/esm/types/awareness.d.ts +1 -0
  218. package/dist/esm/types/awareness.js +1 -0
  219. package/dist/esm/types/brainwaves.d.ts +26 -0
  220. package/dist/esm/types/brainwaves.js +1 -0
  221. package/dist/esm/types/calm.d.ts +6 -0
  222. package/dist/esm/types/calm.js +1 -0
  223. package/dist/esm/types/client.d.ts +22 -0
  224. package/dist/esm/types/client.js +1 -0
  225. package/dist/esm/types/credentials.d.ts +12 -0
  226. package/dist/esm/types/credentials.js +1 -0
  227. package/dist/esm/types/deviceInfo.d.ts +18 -0
  228. package/dist/esm/types/deviceInfo.js +1 -0
  229. package/dist/esm/types/epoch.d.ts +12 -0
  230. package/dist/esm/types/epoch.js +1 -0
  231. package/dist/esm/types/experiment.d.ts +9 -0
  232. package/dist/esm/types/experiment.js +1 -0
  233. package/dist/esm/types/focus.d.ts +6 -0
  234. package/dist/esm/types/focus.js +1 -0
  235. package/dist/esm/types/hapticEffects.d.ts +125 -0
  236. package/dist/esm/types/hapticEffects.js +1 -0
  237. package/dist/esm/types/kinesis.d.ts +6 -0
  238. package/dist/esm/types/kinesis.js +1 -0
  239. package/dist/esm/types/marker.d.ts +7 -0
  240. package/dist/esm/types/marker.js +1 -0
  241. package/dist/esm/types/metrics.d.ts +21 -0
  242. package/dist/esm/types/metrics.js +1 -0
  243. package/dist/esm/types/oauth.d.ts +20 -0
  244. package/dist/esm/types/oauth.js +1 -0
  245. package/dist/esm/types/options.d.ts +51 -0
  246. package/dist/esm/types/options.js +1 -0
  247. package/dist/esm/types/sample.d.ts +15 -0
  248. package/dist/esm/types/sample.js +1 -0
  249. package/dist/esm/types/settings.d.ts +13 -0
  250. package/dist/esm/types/settings.js +1 -0
  251. package/dist/esm/types/signalQuality.d.ts +13 -0
  252. package/dist/esm/types/signalQuality.js +1 -0
  253. package/dist/esm/types/skill.d.ts +68 -0
  254. package/dist/esm/types/skill.js +1 -0
  255. package/dist/esm/types/status.d.ts +26 -0
  256. package/dist/esm/types/status.js +19 -0
  257. package/dist/esm/types/streaming.d.ts +15 -0
  258. package/dist/esm/types/streaming.js +17 -0
  259. package/dist/esm/types/subscriptions.d.ts +23 -0
  260. package/dist/esm/types/subscriptions.js +1 -0
  261. package/dist/esm/types/training.d.ts +19 -0
  262. package/dist/esm/types/training.js +1 -0
  263. package/dist/esm/types/user.d.ts +12 -0
  264. package/dist/esm/types/user.js +1 -0
  265. package/dist/esm/utils/errors.d.ts +5 -0
  266. package/dist/esm/utils/errors.js +11 -0
  267. package/dist/esm/utils/filterInternalKeys.d.ts +3 -0
  268. package/dist/esm/utils/filterInternalKeys.js +17 -0
  269. package/dist/esm/utils/hapticEffects.d.ts +123 -0
  270. package/dist/esm/utils/hapticEffects.js +125 -0
  271. package/dist/esm/utils/heartbeat.d.ts +4 -0
  272. package/dist/esm/utils/heartbeat.js +33 -0
  273. package/dist/esm/utils/is-node.d.ts +1 -0
  274. package/dist/esm/utils/is-node.js +5 -0
  275. package/dist/esm/utils/metrics.d.ts +1 -0
  276. package/dist/esm/utils/metrics.js +52 -0
  277. package/dist/esm/utils/oauth.d.ts +9 -0
  278. package/dist/esm/utils/oauth.js +64 -0
  279. package/dist/esm/utils/pick.d.ts +1 -0
  280. package/dist/esm/utils/pick.js +1 -0
  281. package/dist/esm/utils/pipes.d.ts +46 -0
  282. package/dist/esm/utils/pipes.js +65 -0
  283. package/dist/esm/utils/platform.d.ts +30 -0
  284. package/dist/esm/utils/platform.js +41 -0
  285. package/dist/esm/utils/subscription.d.ts +6 -0
  286. package/dist/esm/utils/subscription.js +24 -0
  287. package/dist/esm/utils/transferDevice.d.ts +9 -0
  288. package/dist/esm/utils/transferDevice.js +1 -0
  289. package/dist/esm/utils/whileOnline.d.ts +8 -0
  290. package/dist/esm/utils/whileOnline.js +11 -0
  291. package/dist/examples/auth.html +32 -0
  292. package/dist/examples/cloud.html +17 -0
  293. package/dist/examples/index.html +1 -0
  294. package/dist/examples/neurosity.iife.js +48717 -0
  295. package/dist/examples/neurosity.js +666 -0
  296. package/dist/examples/neurosity.mjs +48705 -0
  297. package/dist/examples/training.html +49 -0
  298. package/package.json +23 -18
  299. package/dist/index.cjs +0 -2
  300. package/dist/index.cjs.map +0 -1
  301. package/dist/index.m.js +0 -2
  302. package/dist/index.m.js.map +0 -1
  303. package/dist/index.umd.js +0 -2
  304. package/dist/index.umd.js.map +0 -1
  305. package/dist/utils/metrics.d.ts +0 -6
@@ -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 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 = {
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 = {
17
17
  transport: BluetoothTransport;
18
18
  selectedDevice$: Observable<DeviceInfo>;
19
19
  createBluetoothToken: CreateBluetoothToken;
@@ -0,0 +1,310 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.BluetoothClient = void 0;
13
+ const rxjs_1 = require("rxjs");
14
+ const rxjs_2 = require("rxjs");
15
+ const operators_1 = require("rxjs/operators");
16
+ const operators_2 = require("rxjs/operators");
17
+ const WebBluetoothTransport_1 = require("./web/WebBluetoothTransport");
18
+ const ReactNativeTransport_1 = require("./react-native/ReactNativeTransport");
19
+ const csvBufferToEpoch_1 = require("./utils/csvBufferToEpoch");
20
+ const types_1 = require("./types");
21
+ const osHasBluetoothSupport_1 = require("./utils/osHasBluetoothSupport");
22
+ class BluetoothClient {
23
+ constructor(options) {
24
+ this.selectedDevice$ = new rxjs_2.ReplaySubject(1);
25
+ this.isAuthenticated$ = new rxjs_2.ReplaySubject(1);
26
+ const { transport, selectedDevice$, createBluetoothToken } = options !== null && options !== void 0 ? options : {};
27
+ if (!transport) {
28
+ throw new Error(`No bluetooth transport provided.`);
29
+ }
30
+ this.transport = transport;
31
+ // Pass events to the internal selectedDevice$ if selectedDevice$ is passed via options
32
+ if (selectedDevice$) {
33
+ selectedDevice$.subscribe(this.selectedDevice$);
34
+ }
35
+ // Auto Connect
36
+ this.transport._autoConnect(this.selectedDevice$).subscribe({
37
+ error: (error) => {
38
+ var _a;
39
+ this.transport.addLog(`Auto connect: error -> ${(_a = error === null || error === void 0 ? void 0 : error.message) !== null && _a !== void 0 ? _a : error}`);
40
+ }
41
+ });
42
+ // Auto authentication
43
+ if (typeof createBluetoothToken === "function") {
44
+ this.transport.addLog("Auto authentication enabled");
45
+ this._autoAuthenticate(createBluetoothToken).subscribe();
46
+ }
47
+ else {
48
+ this.transport.addLog("Auto authentication not enabled");
49
+ }
50
+ // Auto manage action notifications
51
+ this.transport._autoToggleActionNotifications(this.selectedDevice$);
52
+ // Multicast metrics (share)
53
+ this._focus$ = this._subscribeWhileAuthenticated("focus");
54
+ this._calm$ = this._subscribeWhileAuthenticated("calm");
55
+ this._accelerometer$ = this._subscribeWhileAuthenticated("accelerometer");
56
+ this._brainwavesRaw$ = this._subscribeWhileAuthenticated("raw");
57
+ this._brainwavesRawUnfiltered$ =
58
+ this._subscribeWhileAuthenticated("rawUnfiltered");
59
+ this._brainwavesPSD$ = this._subscribeWhileAuthenticated("psd");
60
+ this._brainwavesPowerByBand$ =
61
+ this._subscribeWhileAuthenticated("powerByBand");
62
+ this._signalQuality$ = this._subscribeWhileAuthenticated("signalQuality");
63
+ this._status$ = this._subscribeWhileAuthenticated("status");
64
+ this._settings$ = this._subscribeWhileAuthenticated("settings");
65
+ this._wifiNearbyNetworks$ =
66
+ this._subscribeWhileAuthenticated("wifiNearbyNetworks");
67
+ this._wifiConnections$ =
68
+ this._subscribeWhileAuthenticated("wifiConnections");
69
+ }
70
+ _autoAuthenticate(createBluetoothToken) {
71
+ const REAUTHENTICATE_INTERVAL = 3600000; // 1 hour
72
+ const reauthenticateInterval$ = (0, rxjs_1.timer)(0, REAUTHENTICATE_INTERVAL).pipe((0, operators_1.tap)(() => {
73
+ this.transport.addLog(`Auto authentication in progress...`);
74
+ }));
75
+ return this.selectedDevice$.pipe((0, operators_1.switchMap)((selectedDevice) => !(0, osHasBluetoothSupport_1.osHasBluetoothSupport)(selectedDevice)
76
+ ? rxjs_2.EMPTY
77
+ : this.connection().pipe((0, operators_1.switchMap)((connection) => connection === types_1.BLUETOOTH_CONNECTION.CONNECTED
78
+ ? reauthenticateInterval$
79
+ : rxjs_2.EMPTY), (0, operators_1.switchMap)(() => __awaiter(this, void 0, void 0, function* () { return yield this.isAuthenticated(); })), (0, operators_1.tap)(([isAuthenticated]) => __awaiter(this, void 0, void 0, function* () {
80
+ if (!isAuthenticated) {
81
+ const token = yield createBluetoothToken();
82
+ yield this.authenticate(token);
83
+ }
84
+ else {
85
+ this.transport.addLog(`Already authenticated`);
86
+ }
87
+ })))));
88
+ }
89
+ enableAutoConnect(autoConnect) {
90
+ this.transport.enableAutoConnect(autoConnect);
91
+ }
92
+ _hasBluetoothSupport() {
93
+ return __awaiter(this, void 0, void 0, function* () {
94
+ const selectedDevice = yield (0, rxjs_1.firstValueFrom)(this.selectedDevice$);
95
+ return (0, osHasBluetoothSupport_1.osHasBluetoothSupport)(selectedDevice);
96
+ });
97
+ }
98
+ authenticate(token) {
99
+ return __awaiter(this, void 0, void 0, function* () {
100
+ const hasBluetoothSupport = yield this._hasBluetoothSupport();
101
+ if (!hasBluetoothSupport) {
102
+ const errorMessage = `authenticate method: The OS version does not support Bluetooth.`;
103
+ this.transport.addLog(errorMessage);
104
+ return Promise.reject(errorMessage);
105
+ }
106
+ yield this.transport.writeCharacteristic("auth", token);
107
+ const isAuthenticatedResponse = yield this.isAuthenticated();
108
+ const [isAuthenticated] = isAuthenticatedResponse;
109
+ this.transport.addLog(`Authentication ${isAuthenticated ? "succeeded" : "failed"}`);
110
+ this.isAuthenticated$.next(isAuthenticated);
111
+ return isAuthenticatedResponse;
112
+ });
113
+ }
114
+ isAuthenticated() {
115
+ return __awaiter(this, void 0, void 0, function* () {
116
+ const [isAuthenticated, expiresIn] = yield this.transport.readCharacteristic("auth", true);
117
+ this.isAuthenticated$.next(isAuthenticated);
118
+ return [isAuthenticated, expiresIn];
119
+ });
120
+ }
121
+ // Method for React Native only
122
+ scan(options) {
123
+ if (this.transport instanceof ReactNativeTransport_1.ReactNativeTransport) {
124
+ return this.transport.scan(options);
125
+ }
126
+ if (this.transport instanceof WebBluetoothTransport_1.WebBluetoothTransport) {
127
+ throw new Error(`scan method is compatibly with the React Native transport only`);
128
+ }
129
+ throw new Error(`unknown transport`);
130
+ }
131
+ // Argument for React Native only
132
+ connect(deviceNicknameORPeripheral) {
133
+ if (this.transport instanceof ReactNativeTransport_1.ReactNativeTransport) {
134
+ return this.transport.connect(deviceNicknameORPeripheral);
135
+ }
136
+ if (this.transport instanceof WebBluetoothTransport_1.WebBluetoothTransport) {
137
+ return deviceNicknameORPeripheral
138
+ ? this.transport.connect(deviceNicknameORPeripheral)
139
+ : this.transport.connect();
140
+ }
141
+ }
142
+ disconnect() {
143
+ return this.transport.disconnect();
144
+ }
145
+ connection() {
146
+ return this.transport.connection();
147
+ }
148
+ logs() {
149
+ return this.transport.logs$.asObservable();
150
+ }
151
+ getDeviceId() {
152
+ return __awaiter(this, void 0, void 0, function* () {
153
+ // This is a public characteristic and does not require authentication
154
+ return this.transport.readCharacteristic("deviceId");
155
+ });
156
+ }
157
+ _withAuthentication(getter) {
158
+ return __awaiter(this, void 0, void 0, function* () {
159
+ // First check if the OS supports Bluetooth before checking if the device is authenticated
160
+ const hasBluetoothSupport = yield this._hasBluetoothSupport();
161
+ if (!hasBluetoothSupport) {
162
+ const errorMessage = `The OS version does not support Bluetooth.`;
163
+ this.transport.addLog(errorMessage);
164
+ return Promise.reject(errorMessage);
165
+ }
166
+ const isAuthenticated = yield (0, rxjs_1.firstValueFrom)(this.isAuthenticated$);
167
+ if (!isAuthenticated) {
168
+ const errorMessage = `Authentication required.`;
169
+ this.transport.addLog(errorMessage);
170
+ return Promise.reject(errorMessage);
171
+ }
172
+ return yield getter();
173
+ });
174
+ }
175
+ _subscribeWhileAuthenticated(characteristicName) {
176
+ return this.selectedDevice$.pipe((0, operators_1.switchMap)((selectedDevice) => !(0, osHasBluetoothSupport_1.osHasBluetoothSupport)(selectedDevice)
177
+ ? rxjs_2.EMPTY
178
+ : this.isAuthenticated$.pipe((0, operators_2.distinctUntilChanged)(), (0, operators_1.switchMap)((isAuthenticated) => isAuthenticated
179
+ ? this.transport.subscribeToCharacteristic({
180
+ characteristicName
181
+ })
182
+ : rxjs_2.EMPTY))), (0, operators_1.share)());
183
+ }
184
+ focus() {
185
+ return this._focus$;
186
+ }
187
+ calm() {
188
+ return this._calm$;
189
+ }
190
+ accelerometer() {
191
+ return this._accelerometer$;
192
+ }
193
+ brainwaves(label) {
194
+ switch (label) {
195
+ default:
196
+ case "raw":
197
+ return (0, rxjs_1.defer)(() => this.getInfo()).pipe((0, operators_1.switchMap)((deviceInfo) => this._brainwavesRaw$.pipe((0, csvBufferToEpoch_1.csvBufferToEpoch)(deviceInfo))));
198
+ case "rawUnfiltered":
199
+ return (0, rxjs_1.defer)(() => this.getInfo()).pipe((0, operators_1.switchMap)((deviceInfo) => this._brainwavesRawUnfiltered$.pipe((0, csvBufferToEpoch_1.csvBufferToEpoch)(deviceInfo))));
200
+ case "psd":
201
+ return this._brainwavesPSD$;
202
+ case "powerByBand":
203
+ return this._brainwavesPowerByBand$;
204
+ }
205
+ }
206
+ signalQuality() {
207
+ return this._signalQuality$;
208
+ }
209
+ addMarker(label) {
210
+ return __awaiter(this, void 0, void 0, function* () {
211
+ yield this.dispatchAction({
212
+ action: "marker",
213
+ command: "add",
214
+ message: {
215
+ timestamp: Date.now(),
216
+ label
217
+ }
218
+ });
219
+ });
220
+ }
221
+ getInfo() {
222
+ return __awaiter(this, void 0, void 0, function* () {
223
+ return yield this._withAuthentication(() => (0, rxjs_1.firstValueFrom)(this.transport.subscribeToCharacteristic({
224
+ characteristicName: "deviceInfo"
225
+ })));
226
+ });
227
+ }
228
+ status() {
229
+ return this._status$;
230
+ }
231
+ dispatchAction(action) {
232
+ return __awaiter(this, void 0, void 0, function* () {
233
+ return yield this._withAuthentication(() => this.transport.dispatchAction({
234
+ characteristicName: "actions",
235
+ action
236
+ }));
237
+ });
238
+ }
239
+ settings() {
240
+ return this._settings$;
241
+ }
242
+ haptics(effects) {
243
+ const metric = "haptics";
244
+ return this.dispatchAction({
245
+ action: metric,
246
+ command: "queue",
247
+ responseRequired: true,
248
+ responseTimeout: 4000,
249
+ // @TODO: implement validation logic as per SDK
250
+ message: { effects }
251
+ });
252
+ }
253
+ get wifi() {
254
+ return {
255
+ nearbyNetworks: () => this._wifiNearbyNetworks$,
256
+ connections: () => this._wifiConnections$,
257
+ connect: (ssid, password) => {
258
+ if (!ssid) {
259
+ return Promise.reject(`Missing ssid`);
260
+ }
261
+ return this.dispatchAction({
262
+ action: "wifi",
263
+ command: "connect",
264
+ responseRequired: true,
265
+ responseTimeout: 1000 * 60 * 2,
266
+ message: {
267
+ ssid,
268
+ password: password !== null && password !== void 0 ? password : null
269
+ }
270
+ });
271
+ },
272
+ forgetConnection: (ssid) => {
273
+ if (!ssid) {
274
+ return Promise.reject(`Missing ssid`);
275
+ }
276
+ return this.dispatchAction({
277
+ action: "wifi",
278
+ command: "forget-connection",
279
+ responseRequired: true,
280
+ responseTimeout: 1000 * 15,
281
+ message: {
282
+ ssid
283
+ }
284
+ });
285
+ },
286
+ reset: () => {
287
+ return this.dispatchAction({
288
+ action: "wifi",
289
+ command: "reset",
290
+ responseRequired: true,
291
+ responseTimeout: 1000 * 30,
292
+ message: {
293
+ // without this, the action will resolve as soon as the
294
+ // action is received by the OS
295
+ respondOnSuccess: true
296
+ }
297
+ });
298
+ },
299
+ speedTest: () => {
300
+ return this.dispatchAction({
301
+ action: "wifi",
302
+ command: "speed-test",
303
+ responseRequired: true,
304
+ responseTimeout: 1000 * 60 * 1 // 1 minute
305
+ });
306
+ }
307
+ };
308
+ }
309
+ }
310
+ exports.BluetoothClient = BluetoothClient;
@@ -0,0 +1,33 @@
1
+ import { Observable, Subject } from "rxjs";
2
+ import { BLUETOOTH_CONNECTION, TRANSPORT_TYPE } from "./types";
3
+ import { Action } from "../../types/actions";
4
+ import { DeviceInfo } from "../../types/deviceInfo";
5
+ import { Peripheral } from "./react-native/types/BleManagerTypes";
6
+ export declare type DeviceNicknameOrPeripheral = string | Peripheral;
7
+ /**
8
+ * @hidden
9
+ */
10
+ export interface BluetoothTransport {
11
+ type: TRANSPORT_TYPE;
12
+ connect(deviceNicknameORPeripheral?: DeviceNicknameOrPeripheral): Promise<void>;
13
+ _autoConnect(selectedDevice$: Observable<DeviceInfo>): Observable<void>;
14
+ disconnect(): Promise<void>;
15
+ connection(): Observable<BLUETOOTH_CONNECTION>;
16
+ requestDevice?(): any;
17
+ addLog: (log: string) => void;
18
+ logs$: Subject<string>;
19
+ enableAutoConnect?(value: boolean): void;
20
+ scan?(options?: {
21
+ seconds?: number;
22
+ }): Observable<Peripheral[]>;
23
+ subscribeToCharacteristic(args: {
24
+ characteristicName: string;
25
+ manageNotifications?: boolean;
26
+ }): Observable<any>;
27
+ readCharacteristic(characteristicName: string, parse?: boolean): Promise<any>;
28
+ writeCharacteristic(characteristicName: string, data: string): Promise<void>;
29
+ dispatchAction(args: {
30
+ characteristicName: string;
31
+ action: Action;
32
+ }): Promise<any>;
33
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
File without changes
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CHARACTERISTIC_UUIDS_TO_NAMES = exports.DEFAULT_ACTION_RESPONSE_TIMEOUT = exports.REACT_NATIVE_MAX_BYTE_SIZE = exports.ANDROID_MAX_MTU = void 0;
4
+ const ipk_1 = require("@neurosity/ipk");
5
+ exports.ANDROID_MAX_MTU = 512;
6
+ exports.REACT_NATIVE_MAX_BYTE_SIZE = 512; // the default is 20
7
+ exports.DEFAULT_ACTION_RESPONSE_TIMEOUT = 1000 * 60; // 1 minute
8
+ // Reverse BLUETOOTH_CHARACTERISTICS key/values for easy lookup
9
+ exports.CHARACTERISTIC_UUIDS_TO_NAMES = Object.fromEntries(Object.entries(ipk_1.BLUETOOTH_CHARACTERISTICS).map((entries) => entries.reverse()));
File without changes
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./BluetoothClient"), exports);
18
+ __exportStar(require("./web/WebBluetoothTransport"), exports);
19
+ __exportStar(require("./react-native/ReactNativeTransport"), exports);
20
+ __exportStar(require("./utils/osHasBluetoothSupport"), exports);
21
+ __exportStar(require("./types/index"), exports);
@@ -8,21 +8,21 @@ 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
- type Characteristic = {
11
+ declare type Characteristic = {
12
12
  characteristicUUID: string;
13
13
  serviceUUID: string;
14
14
  peripheralId: string;
15
15
  };
16
- type CharacteristicsByName = {
16
+ declare type CharacteristicsByName = {
17
17
  [name: string]: Characteristic;
18
18
  };
19
- type Options = {
19
+ declare type Options = {
20
20
  BleManager: BleManager;
21
21
  bleManagerEmitter: NativeEventEmitter;
22
22
  platform: PlatformOSType;
23
23
  autoConnect?: boolean;
24
24
  };
25
- type BleManagerEvents = {
25
+ declare type BleManagerEvents = {
26
26
  stopScan$: Observable<void>;
27
27
  discoverPeripheral$: Observable<Peripheral>;
28
28
  connectPeripheral$: Observable<void>;