@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
@@ -0,0 +1,31 @@
1
+ /**
2
+ * @hidden
3
+ */
4
+ export declare type ActionOptions = {
5
+ characteristicName: string;
6
+ action: any;
7
+ };
8
+ /**
9
+ * @hidden
10
+ */
11
+ export declare type SubscribeOptions = {
12
+ characteristicName: string;
13
+ manageNotifications?: boolean;
14
+ };
15
+ /**
16
+ * @hidden
17
+ */
18
+ export declare enum BLUETOOTH_CONNECTION {
19
+ SCANNING = "scanning",
20
+ CONNECTED = "connected",
21
+ CONNECTING = "connecting",
22
+ DISCONNECTING = "disconnecting",
23
+ DISCONNECTED = "disconnected"
24
+ }
25
+ /**
26
+ * @hidden
27
+ */
28
+ export declare enum TRANSPORT_TYPE {
29
+ WEB = "web",
30
+ REACT_NATIVE = "reactNative"
31
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * @hidden
3
+ */
4
+ export var BLUETOOTH_CONNECTION;
5
+ (function (BLUETOOTH_CONNECTION) {
6
+ BLUETOOTH_CONNECTION["SCANNING"] = "scanning";
7
+ BLUETOOTH_CONNECTION["CONNECTED"] = "connected";
8
+ BLUETOOTH_CONNECTION["CONNECTING"] = "connecting";
9
+ BLUETOOTH_CONNECTION["DISCONNECTING"] = "disconnecting";
10
+ BLUETOOTH_CONNECTION["DISCONNECTED"] = "disconnected";
11
+ })(BLUETOOTH_CONNECTION || (BLUETOOTH_CONNECTION = {}));
12
+ /**
13
+ * @hidden
14
+ */
15
+ export var TRANSPORT_TYPE;
16
+ (function (TRANSPORT_TYPE) {
17
+ TRANSPORT_TYPE["WEB"] = "web";
18
+ TRANSPORT_TYPE["REACT_NATIVE"] = "reactNative";
19
+ })(TRANSPORT_TYPE || (TRANSPORT_TYPE = {}));
@@ -0,0 +1 @@
1
+ export declare function create6DigitPin(): number;
@@ -0,0 +1,4 @@
1
+ // Creates a number of 6 digits and ensures the first digit will never be 0
2
+ export function create6DigitPin() {
3
+ return Math.floor(100000 + Math.random() * 900000);
4
+ }
@@ -0,0 +1,11 @@
1
+ import { Observable, UnaryFunction } from "rxjs";
2
+ import { Epoch } from "../../../types/epoch";
3
+ import { DeviceInfo } from "../../../types/deviceInfo";
4
+ /**
5
+ * @hidden
6
+ */
7
+ export declare function csvBufferToEpoch(deviceInfo: DeviceInfo): UnaryFunction<Observable<Epoch>, any>;
8
+ /**
9
+ * @hidden
10
+ */
11
+ export declare function csvBufferToSamples(): UnaryFunction<any, any>;
@@ -0,0 +1,31 @@
1
+ import { pipe, from } from "rxjs";
2
+ import { mergeMap, map } from "rxjs/operators";
3
+ import { epoch, addInfo } from "../../../utils/pipes";
4
+ const EPOCH_BUFFER_SIZE = 16;
5
+ const SAMPLING_RATE_FALLBACK = 256; // Crown's sampling rate
6
+ /**
7
+ * @hidden
8
+ */
9
+ export function csvBufferToEpoch(deviceInfo) {
10
+ var _a;
11
+ if (!(deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.samplingRate)) {
12
+ console.warn(`Didn't receive a sampling rate, defaulting to ${SAMPLING_RATE_FALLBACK}`);
13
+ }
14
+ return pipe(csvBufferToSamples(), epoch({
15
+ duration: EPOCH_BUFFER_SIZE,
16
+ interval: EPOCH_BUFFER_SIZE,
17
+ samplingRate: (_a = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.samplingRate) !== null && _a !== void 0 ? _a : SAMPLING_RATE_FALLBACK
18
+ }), addInfo({
19
+ channelNames: deviceInfo.channelNames,
20
+ samplingRate: deviceInfo.samplingRate
21
+ }));
22
+ }
23
+ /**
24
+ * @hidden
25
+ */
26
+ export function csvBufferToSamples() {
27
+ return pipe(mergeMap((samples) => from(samples)), map(([timestamp, marker, ...data]) => ({
28
+ timestamp,
29
+ data
30
+ })));
31
+ }
@@ -0,0 +1,3 @@
1
+ import { TRANSPORT_TYPE } from "../types";
2
+ export declare function encode(transportType: TRANSPORT_TYPE, data: string): Uint8Array | number[];
3
+ export declare function decode(transportType: TRANSPORT_TYPE, data: Uint8Array | number[]): string;
@@ -0,0 +1,17 @@
1
+ import { TRANSPORT_TYPE } from "../types";
2
+ const encoder = new TextEncoder();
3
+ const decoder = new TextDecoder("utf-8");
4
+ export function encode(transportType, data) {
5
+ if (transportType === TRANSPORT_TYPE.REACT_NATIVE) {
6
+ // React Native expects a plain array of numbers and not a Uint8Array
7
+ return [...encoder.encode(data)];
8
+ }
9
+ return encoder.encode(data);
10
+ }
11
+ export function decode(transportType, data) {
12
+ if (transportType === TRANSPORT_TYPE.REACT_NATIVE) {
13
+ // React Native outpouts a plain array of numbers and not a Uint8Array
14
+ return decoder.decode(new Uint8Array(data));
15
+ }
16
+ return decoder.decode(data);
17
+ }
@@ -0,0 +1,2 @@
1
+ import { DeviceInfo } from "../../../types/deviceInfo";
2
+ export declare function osHasBluetoothSupport(selectedDevice: DeviceInfo): any;
@@ -0,0 +1,16 @@
1
+ import semverGte from "semver/functions/gte";
2
+ export function osHasBluetoothSupport(selectedDevice) {
3
+ if (!selectedDevice) {
4
+ return false;
5
+ }
6
+ // Only the Crown supports Bluetooth
7
+ const isCrown = Number(selectedDevice.modelVersion) >= 3;
8
+ if (!isCrown) {
9
+ return false;
10
+ }
11
+ const isEmulator = !!(selectedDevice === null || selectedDevice === void 0 ? void 0 : selectedDevice.emulator);
12
+ if (isEmulator) {
13
+ return false;
14
+ }
15
+ return semverGte(selectedDevice.osVersion, "16.0.0");
16
+ }
@@ -0,0 +1,5 @@
1
+ declare type StitchChunkOptions = {
2
+ delimiter: string;
3
+ };
4
+ export declare function stitchChunks({ delimiter }: StitchChunkOptions): import("rxjs").UnaryFunction<import("rxjs").Observable<string>, import("rxjs").Observable<string>>;
5
+ export {};
@@ -0,0 +1,18 @@
1
+ import { pipe } from "rxjs";
2
+ import { map, scan, filter } from "rxjs/operators";
3
+ export function stitchChunks({ delimiter }) {
4
+ return pipe(scan(([remainder], currentBuffer) => {
5
+ const nextBuffer = remainder + currentBuffer;
6
+ if (!nextBuffer.includes(delimiter)) {
7
+ return [nextBuffer, ""];
8
+ }
9
+ if (nextBuffer.endsWith(delimiter)) {
10
+ return ["", nextBuffer];
11
+ }
12
+ const remainderStart = nextBuffer.lastIndexOf(delimiter);
13
+ const remainderIndex = remainderStart + delimiter.length;
14
+ const nextPacket = nextBuffer.slice(0, remainderIndex);
15
+ const nextRemainder = nextBuffer.slice(remainderIndex);
16
+ return [nextRemainder, nextPacket];
17
+ }, ["", ""]), map(([, nextPacket]) => nextPacket.slice(0, -delimiter.length)), filter((nextPacket) => !!nextPacket.length));
18
+ }
@@ -0,0 +1,54 @@
1
+ /// <reference types="web-bluetooth" />
2
+ import { BehaviorSubject, ReplaySubject } from "rxjs";
3
+ import { Observable } from "rxjs";
4
+ import { BluetoothTransport } from "../BluetoothTransport";
5
+ import { ActionOptions, SubscribeOptions } from "../types";
6
+ import { TRANSPORT_TYPE, BLUETOOTH_CONNECTION } from "../types";
7
+ import { DeviceInfo } from "../../../types/deviceInfo";
8
+ declare type Options = {
9
+ autoConnect?: boolean;
10
+ };
11
+ export declare class WebBluetoothTransport implements BluetoothTransport {
12
+ type: TRANSPORT_TYPE;
13
+ options: Options;
14
+ device: BluetoothDevice;
15
+ server: BluetoothRemoteGATTServer;
16
+ service: BluetoothRemoteGATTService;
17
+ characteristicsByName: {
18
+ [name: string]: BluetoothRemoteGATTCharacteristic;
19
+ };
20
+ connection$: BehaviorSubject<BLUETOOTH_CONNECTION>;
21
+ pendingActions$: BehaviorSubject<any[]>;
22
+ logs$: ReplaySubject<string>;
23
+ onDisconnected$: Observable<void>;
24
+ connectionStream$: Observable<BLUETOOTH_CONNECTION>;
25
+ _isAutoConnectEnabled$: ReplaySubject<boolean>;
26
+ constructor(options?: Options);
27
+ _getPairedDevices(): Promise<BluetoothDevice[]>;
28
+ _autoConnect(selectedDevice$: Observable<DeviceInfo>): Observable<void>;
29
+ enableAutoConnect(autoConnect: boolean): void;
30
+ addLog(log: string): void;
31
+ isConnected(): boolean;
32
+ connection(): Observable<BLUETOOTH_CONNECTION>;
33
+ connect(deviceNickname?: string): Promise<void>;
34
+ requestDevice(deviceNickname?: string): Promise<BluetoothDevice>;
35
+ getServerServiceAndCharacteristics(device: BluetoothDevice): Promise<never>;
36
+ _onDisconnected(): Observable<any>;
37
+ disconnect(): Promise<void>;
38
+ /**
39
+ *
40
+ * Bluetooth GATT attributes, services, characteristics, etc. are invalidated
41
+ * when a device disconnects. This means your code should always retrieve
42
+ * (through getPrimaryService(s), getCharacteristic(s), etc.) these attributes
43
+ * after reconnecting.
44
+ */
45
+ getCharacteristicByName(characteristicName: string): Promise<BluetoothRemoteGATTCharacteristic>;
46
+ subscribeToCharacteristic({ characteristicName, manageNotifications }: SubscribeOptions): Observable<any>;
47
+ readCharacteristic(characteristicName: string, parse?: boolean): Promise<any>;
48
+ writeCharacteristic(characteristicName: string, data: string): Promise<void>;
49
+ _addPendingAction(actionId: number): void;
50
+ _removePendingAction(actionId: number): void;
51
+ _autoToggleActionNotifications(selectedDevice$: Observable<DeviceInfo>): Promise<void>;
52
+ dispatchAction({ characteristicName, action }: ActionOptions): Promise<any>;
53
+ }
54
+ export {};
@@ -0,0 +1,426 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { BLUETOOTH_PRIMARY_SERVICE_UUID_HEX } from "@neurosity/ipk";
11
+ import { BLUETOOTH_CHUNK_DELIMITER } from "@neurosity/ipk";
12
+ import { BLUETOOTH_DEVICE_NAME_PREFIXES } from "@neurosity/ipk";
13
+ import { BLUETOOTH_COMPANY_IDENTIFIER_HEX } from "@neurosity/ipk";
14
+ import { BehaviorSubject, defer, merge, of, ReplaySubject, timer } from "rxjs";
15
+ import { fromEventPattern, Observable, EMPTY, NEVER } from "rxjs";
16
+ import { switchMap, map, filter, tap } from "rxjs/operators";
17
+ import { shareReplay, distinctUntilChanged } from "rxjs/operators";
18
+ import { take, share } from "rxjs/operators";
19
+ import { isWebBluetoothSupported } from "./isWebBluetoothSupported";
20
+ import { create6DigitPin } from "../utils/create6DigitPin";
21
+ import { stitchChunks } from "../utils/stitch";
22
+ import { encode, decode } from "../utils/encoding";
23
+ import { TRANSPORT_TYPE, BLUETOOTH_CONNECTION } from "../types";
24
+ import { DEFAULT_ACTION_RESPONSE_TIMEOUT } from "../constants";
25
+ import { CHARACTERISTIC_UUIDS_TO_NAMES } from "../constants";
26
+ import { osHasBluetoothSupport } from "../utils/osHasBluetoothSupport";
27
+ const defaultOptions = {
28
+ autoConnect: true
29
+ };
30
+ export class WebBluetoothTransport {
31
+ constructor(options = {}) {
32
+ this.type = TRANSPORT_TYPE.WEB;
33
+ this.characteristicsByName = {};
34
+ this.connection$ = new BehaviorSubject(BLUETOOTH_CONNECTION.DISCONNECTED);
35
+ this.pendingActions$ = new BehaviorSubject([]);
36
+ this.logs$ = new ReplaySubject(10);
37
+ this.onDisconnected$ = this._onDisconnected().pipe(share());
38
+ this.connectionStream$ = this.connection$
39
+ .asObservable()
40
+ .pipe(filter((connection) => !!connection), distinctUntilChanged(), shareReplay(1));
41
+ this._isAutoConnectEnabled$ = new ReplaySubject(1);
42
+ this.options = Object.assign(Object.assign({}, defaultOptions), options);
43
+ if (!isWebBluetoothSupported()) {
44
+ const errorMessage = "Web Bluetooth is not supported";
45
+ this.addLog(errorMessage);
46
+ throw new Error(errorMessage);
47
+ }
48
+ this._isAutoConnectEnabled$.subscribe((autoConnect) => {
49
+ this.addLog(`Auto connect: ${autoConnect ? "enabled" : "disabled"}`);
50
+ });
51
+ this._isAutoConnectEnabled$.next(this.options.autoConnect);
52
+ this.connection$.asObservable().subscribe((connection) => {
53
+ this.addLog(`connection status is ${connection}`);
54
+ });
55
+ this.onDisconnected$.subscribe(() => {
56
+ this.connection$.next(BLUETOOTH_CONNECTION.DISCONNECTED);
57
+ });
58
+ }
59
+ _getPairedDevices() {
60
+ return __awaiter(this, void 0, void 0, function* () {
61
+ return yield navigator.bluetooth.getDevices();
62
+ });
63
+ }
64
+ _autoConnect(selectedDevice$) {
65
+ return this._isAutoConnectEnabled$.pipe(switchMap((isAutoConnectEnabled) => isAutoConnectEnabled
66
+ ? merge(selectedDevice$, this.onDisconnected$.pipe(switchMap(() => selectedDevice$)))
67
+ : NEVER), switchMap((selectedDevice) => osHasBluetoothSupport(selectedDevice) ? of(selectedDevice) : EMPTY), switchMap((selectedDevice) => __awaiter(this, void 0, void 0, function* () {
68
+ var _a;
69
+ const { deviceNickname } = selectedDevice;
70
+ if (this.isConnected()) {
71
+ this.addLog(`Auto connect: ${deviceNickname} is already connected. Skipping auto connect.`);
72
+ return;
73
+ }
74
+ const [devicesError, devices] = yield this._getPairedDevices()
75
+ .then((devices) => [null, devices])
76
+ .catch((error) => [error, null]);
77
+ if (devicesError) {
78
+ throw new Error(`failed to get devices: ${(_a = devicesError === null || devicesError === void 0 ? void 0 : devicesError.message) !== null && _a !== void 0 ? _a : devicesError}`);
79
+ }
80
+ this.addLog(`Auto connect: found ${devices.length} devices ${devices
81
+ .map(({ name }) => name)
82
+ .join(", ")}`);
83
+ // @important - Using `findLast` instead of `find` because somehow the browser
84
+ // is finding multiple peripherals with the same name
85
+ const device = devices.findLast((device) => device.name === deviceNickname);
86
+ if (!device) {
87
+ throw new Error(`couldn't find selected device in the list of paired devices.`);
88
+ }
89
+ this.addLog(`Auto connect: ${deviceNickname} was detected and previously paired`);
90
+ return device;
91
+ })), tap(() => {
92
+ this.connection$.next(BLUETOOTH_CONNECTION.SCANNING);
93
+ }), switchMap((device) => onAdvertisementReceived(device)), switchMap((advertisement) => __awaiter(this, void 0, void 0, function* () {
94
+ this.addLog(`Advertisement received for ${advertisement.device.name}`);
95
+ return yield this.getServerServiceAndCharacteristics(advertisement.device);
96
+ })));
97
+ }
98
+ enableAutoConnect(autoConnect) {
99
+ this._isAutoConnectEnabled$.next(autoConnect);
100
+ }
101
+ addLog(log) {
102
+ this.logs$.next(log);
103
+ }
104
+ isConnected() {
105
+ const connection = this.connection$.getValue();
106
+ return connection === BLUETOOTH_CONNECTION.CONNECTED;
107
+ }
108
+ connection() {
109
+ return this.connectionStream$;
110
+ }
111
+ connect(deviceNickname) {
112
+ return __awaiter(this, void 0, void 0, function* () {
113
+ try {
114
+ // requires user gesture
115
+ const device = yield this.requestDevice(deviceNickname);
116
+ yield this.getServerServiceAndCharacteristics(device);
117
+ }
118
+ catch (error) {
119
+ return Promise.reject(error);
120
+ }
121
+ });
122
+ }
123
+ requestDevice(deviceNickname) {
124
+ return __awaiter(this, void 0, void 0, function* () {
125
+ try {
126
+ this.addLog("Requesting Bluetooth Device...");
127
+ const prefixes = BLUETOOTH_DEVICE_NAME_PREFIXES.map((namePrefix) => ({
128
+ namePrefix
129
+ }));
130
+ // Ability to only show selectedDevice if provided
131
+ const filters = deviceNickname
132
+ ? [
133
+ {
134
+ name: deviceNickname
135
+ }
136
+ ]
137
+ : prefixes;
138
+ const device = yield window.navigator.bluetooth.requestDevice({
139
+ filters: [
140
+ ...filters,
141
+ {
142
+ manufacturerData: [
143
+ {
144
+ companyIdentifier: BLUETOOTH_COMPANY_IDENTIFIER_HEX
145
+ }
146
+ ]
147
+ }
148
+ ],
149
+ optionalServices: [BLUETOOTH_PRIMARY_SERVICE_UUID_HEX]
150
+ });
151
+ return device;
152
+ }
153
+ catch (error) {
154
+ return Promise.reject(error);
155
+ }
156
+ });
157
+ }
158
+ getServerServiceAndCharacteristics(device) {
159
+ return __awaiter(this, void 0, void 0, function* () {
160
+ try {
161
+ this.device = device;
162
+ const isConnecting = this.connection$.getValue() === BLUETOOTH_CONNECTION.CONNECTING;
163
+ if (!isConnecting) {
164
+ this.connection$.next(BLUETOOTH_CONNECTION.CONNECTING);
165
+ }
166
+ this.server = yield device.gatt.connect();
167
+ this.addLog(`Getting service...`);
168
+ this.service = yield this.server.getPrimaryService(BLUETOOTH_PRIMARY_SERVICE_UUID_HEX);
169
+ this.addLog(`Got service ${this.service.uuid}, getting characteristics...`);
170
+ const characteristicsList = yield this.service.getCharacteristics();
171
+ this.addLog(`Got characteristics`);
172
+ this.characteristicsByName = Object.fromEntries(characteristicsList.map((characteristic) => [
173
+ CHARACTERISTIC_UUIDS_TO_NAMES[characteristic.uuid],
174
+ characteristic
175
+ ]));
176
+ this.connection$.next(BLUETOOTH_CONNECTION.CONNECTED);
177
+ }
178
+ catch (error) {
179
+ return Promise.reject(error);
180
+ }
181
+ });
182
+ }
183
+ _onDisconnected() {
184
+ return this.connection$
185
+ .asObservable()
186
+ .pipe(switchMap((connection) => connection === BLUETOOTH_CONNECTION.CONNECTED
187
+ ? fromDOMEvent(this.device, "gattserverdisconnected")
188
+ : NEVER));
189
+ }
190
+ disconnect() {
191
+ var _a, _b;
192
+ return __awaiter(this, void 0, void 0, function* () {
193
+ const isDeviceConnected = (_b = (_a = this === null || this === void 0 ? void 0 : this.device) === null || _a === void 0 ? void 0 : _a.gatt) === null || _b === void 0 ? void 0 : _b.connected;
194
+ if (isDeviceConnected) {
195
+ this.device.gatt.disconnect();
196
+ }
197
+ });
198
+ }
199
+ /**
200
+ *
201
+ * Bluetooth GATT attributes, services, characteristics, etc. are invalidated
202
+ * when a device disconnects. This means your code should always retrieve
203
+ * (through getPrimaryService(s), getCharacteristic(s), etc.) these attributes
204
+ * after reconnecting.
205
+ */
206
+ getCharacteristicByName(characteristicName) {
207
+ var _a;
208
+ return __awaiter(this, void 0, void 0, function* () {
209
+ return (_a = this.characteristicsByName) === null || _a === void 0 ? void 0 : _a[characteristicName];
210
+ });
211
+ }
212
+ subscribeToCharacteristic({ characteristicName, manageNotifications = true }) {
213
+ const data$ = defer(() => this.getCharacteristicByName(characteristicName)).pipe(switchMap((characteristic) => __awaiter(this, void 0, void 0, function* () {
214
+ var _a;
215
+ if (this.isConnected() && manageNotifications) {
216
+ try {
217
+ yield characteristic.startNotifications();
218
+ this.addLog(`Started notifications for ${characteristicName} characteristic`);
219
+ }
220
+ catch (error) {
221
+ this.addLog(`Attemped to stop notifications for ${characteristicName} characteristic: ${(_a = error === null || error === void 0 ? void 0 : error.message) !== null && _a !== void 0 ? _a : error}`);
222
+ }
223
+ }
224
+ return characteristic;
225
+ })), switchMap((characteristic) => {
226
+ return fromDOMEvent(characteristic, "characteristicvaluechanged", () => __awaiter(this, void 0, void 0, function* () {
227
+ var _a;
228
+ if (this.isConnected() && manageNotifications) {
229
+ try {
230
+ yield characteristic.stopNotifications();
231
+ this.addLog(`Stopped notifications for ${characteristicName} characteristic`);
232
+ }
233
+ catch (error) {
234
+ this.addLog(`Attemped to stop notifications for ${characteristicName} characteristic: ${(_a = error === null || error === void 0 ? void 0 : error.message) !== null && _a !== void 0 ? _a : error}`);
235
+ }
236
+ }
237
+ }));
238
+ }), map((event) => {
239
+ const buffer = event.target.value;
240
+ const decoded = decode(this.type, buffer);
241
+ this.addLog(`Received chunk with buffer size of ${buffer.byteLength} and decoded size ${decoded.length} for ${characteristicName} characteristic: \n${decoded}`);
242
+ return decoded;
243
+ }), stitchChunks({ delimiter: BLUETOOTH_CHUNK_DELIMITER }), map((payload) => {
244
+ var _a;
245
+ try {
246
+ return JSON.parse(payload);
247
+ }
248
+ catch (error) {
249
+ this.addLog(`Failed to parse JSON for ${characteristicName} characteristic. Falling back to unparsed string. ${(_a = error === null || error === void 0 ? void 0 : error.message) !== null && _a !== void 0 ? _a : error}`);
250
+ return payload;
251
+ }
252
+ })
253
+ // when streaming at ultra-low latency, the logs will slow down rendering
254
+ // tap((data) => {
255
+ // this.addLog(
256
+ // `Received data for ${characteristicName} characteristic: \n${JSON.stringify(
257
+ // data,
258
+ // null,
259
+ // 2
260
+ // )}`
261
+ // );
262
+ // })
263
+ );
264
+ return this.connection$.pipe(switchMap((connection) => connection === BLUETOOTH_CONNECTION.CONNECTED ? data$ : NEVER));
265
+ }
266
+ readCharacteristic(characteristicName, parse = false) {
267
+ return __awaiter(this, void 0, void 0, function* () {
268
+ try {
269
+ this.addLog(`Reading characteristic: ${characteristicName}`);
270
+ const characteristic = yield this.getCharacteristicByName(characteristicName);
271
+ if (!characteristic) {
272
+ this.addLog(`Did not fund ${characteristicName} characteristic`);
273
+ return Promise.reject(`Did not find characteristic by the name: ${characteristicName}`);
274
+ }
275
+ const value = yield characteristic.readValue();
276
+ const uint8Array = value;
277
+ const decodedValue = decode(this.type, uint8Array);
278
+ const data = parse ? JSON.parse(decodedValue) : decodedValue;
279
+ this.addLog(`Received read data from ${characteristicName} characteristic: \n${data}`);
280
+ return data;
281
+ }
282
+ catch (error) {
283
+ return Promise.reject(`Error reading characteristic: ${error.message}`);
284
+ }
285
+ });
286
+ }
287
+ writeCharacteristic(characteristicName, data) {
288
+ return __awaiter(this, void 0, void 0, function* () {
289
+ this.addLog(`Writing characteristic: ${characteristicName}`);
290
+ const characteristic = yield this.getCharacteristicByName(characteristicName);
291
+ if (!characteristic) {
292
+ this.addLog(`Did not fund ${characteristicName} characteristic`);
293
+ return Promise.reject(`Did not find characteristic by the name: ${characteristicName}`);
294
+ }
295
+ const encoded = encode(this.type, data);
296
+ yield characteristic.writeValueWithResponse(encoded);
297
+ });
298
+ }
299
+ _addPendingAction(actionId) {
300
+ const actions = this.pendingActions$.getValue();
301
+ this.pendingActions$.next([...actions, actionId]);
302
+ }
303
+ _removePendingAction(actionId) {
304
+ const actions = this.pendingActions$.getValue();
305
+ this.pendingActions$.next(actions.filter((id) => id !== actionId));
306
+ }
307
+ _autoToggleActionNotifications(selectedDevice$) {
308
+ return __awaiter(this, void 0, void 0, function* () {
309
+ let actionsCharacteristic;
310
+ let started = false;
311
+ const sideEffects$ = this.connection$.asObservable().pipe(switchMap((connection) => connection === BLUETOOTH_CONNECTION.CONNECTED
312
+ ? defer(() => this.getCharacteristicByName("actions")).pipe(switchMap((characteristic) => {
313
+ actionsCharacteristic = characteristic;
314
+ return this.pendingActions$;
315
+ }))
316
+ : NEVER), tap((pendingActions) => __awaiter(this, void 0, void 0, function* () {
317
+ var _a, _b;
318
+ const hasPendingActions = !!pendingActions.length;
319
+ if (hasPendingActions && !started) {
320
+ started = true;
321
+ try {
322
+ yield actionsCharacteristic.startNotifications();
323
+ this.addLog(`Started notifications for [actions] characteristic`);
324
+ }
325
+ catch (error) {
326
+ this.addLog(`Attemped to start notifications for [actions] characteristic: ${(_a = error === null || error === void 0 ? void 0 : error.message) !== null && _a !== void 0 ? _a : error}`);
327
+ }
328
+ }
329
+ if (!hasPendingActions && started) {
330
+ started = false;
331
+ try {
332
+ yield actionsCharacteristic.stopNotifications();
333
+ this.addLog(`Stopped notifications for actions characteristic`);
334
+ }
335
+ catch (error) {
336
+ this.addLog(`Attemped to stop notifications for [actions] characteristic: ${(_b = error === null || error === void 0 ? void 0 : error.message) !== null && _b !== void 0 ? _b : error}`);
337
+ }
338
+ }
339
+ })));
340
+ selectedDevice$
341
+ .pipe(switchMap((selectedDevice) => !osHasBluetoothSupport(selectedDevice) ? EMPTY : sideEffects$))
342
+ .subscribe();
343
+ });
344
+ }
345
+ dispatchAction({ characteristicName, action }) {
346
+ return __awaiter(this, void 0, void 0, function* () {
347
+ const { responseRequired = false, responseTimeout = DEFAULT_ACTION_RESPONSE_TIMEOUT } = action;
348
+ return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
349
+ const characteristic = yield this.getCharacteristicByName(characteristicName).catch(() => {
350
+ reject(`Did not find characteristic by the name: ${characteristicName}`);
351
+ });
352
+ if (!characteristic) {
353
+ return;
354
+ }
355
+ const actionId = create6DigitPin(); // use to later identify and filter response
356
+ const payload = JSON.stringify(Object.assign({ actionId }, action)); // add the response id to the action
357
+ this.addLog(`Dispatched action with id ${actionId}`);
358
+ if (responseRequired && responseTimeout) {
359
+ this._addPendingAction(actionId);
360
+ const timeout = timer(responseTimeout).subscribe(() => {
361
+ this._removePendingAction(actionId);
362
+ reject(`Action with id ${actionId} timed out after ${responseTimeout}ms`);
363
+ });
364
+ // listen for a response before writing
365
+ this.subscribeToCharacteristic({
366
+ characteristicName,
367
+ manageNotifications: false
368
+ })
369
+ .pipe(filter((response) => (response === null || response === void 0 ? void 0 : response.actionId) === actionId), take(1))
370
+ .subscribe((response) => {
371
+ timeout.unsubscribe();
372
+ this._removePendingAction(actionId);
373
+ resolve(response);
374
+ });
375
+ // register action by writing
376
+ this.writeCharacteristic(characteristicName, payload).catch((error) => {
377
+ this._removePendingAction(actionId);
378
+ reject(error.message);
379
+ });
380
+ }
381
+ else {
382
+ this.writeCharacteristic(characteristicName, payload)
383
+ .then(() => {
384
+ resolve(null);
385
+ })
386
+ .catch((error) => {
387
+ reject(error.message);
388
+ });
389
+ }
390
+ }));
391
+ });
392
+ }
393
+ }
394
+ function fromDOMEvent(target, eventName, beforeRemove) {
395
+ return fromEventPattern((addHandler) => {
396
+ target.addEventListener(eventName, addHandler);
397
+ }, (removeHandler) => __awaiter(this, void 0, void 0, function* () {
398
+ if (beforeRemove) {
399
+ yield beforeRemove();
400
+ }
401
+ target.removeEventListener(eventName, removeHandler);
402
+ }));
403
+ }
404
+ function onAdvertisementReceived(device) {
405
+ return new Observable((subscriber) => {
406
+ const abortController = new AbortController();
407
+ const { signal } = abortController;
408
+ const listener = device.addEventListener("advertisementreceived", (advertisement) => {
409
+ abortController.abort();
410
+ subscriber.next(advertisement);
411
+ subscriber.complete();
412
+ }, {
413
+ once: true
414
+ });
415
+ try {
416
+ device.watchAdvertisements({ signal });
417
+ }
418
+ catch (error) {
419
+ subscriber.error(error);
420
+ }
421
+ return () => {
422
+ abortController.abort();
423
+ device.removeEventListener("advertisementreceived", listener);
424
+ };
425
+ });
426
+ }
@@ -0,0 +1 @@
1
+ export declare const isMaybeWebWorkerContext: () => boolean;
@@ -0,0 +1,4 @@
1
+ const self = this;
2
+ export const isMaybeWebWorkerContext = () => {
3
+ return self && (self === null || self === void 0 ? void 0 : self.document) === undefined;
4
+ };
@@ -0,0 +1 @@
1
+ export declare function isWebBluetoothSupported(): boolean;