@neurosity/sdk 6.0.0-next.11

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