@neurosity/sdk 6.5.10 → 6.5.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 (130) hide show
  1. package/dist/browser/neurosity.iife.js +118 -49
  2. package/dist/browser/neurosity.js +112 -112
  3. package/dist/browser/neurosity.js.map +1 -1
  4. package/dist/cjs/__tests__/Neurosity.test.d.ts +1 -0
  5. package/dist/cjs/__tests__/Neurosity.test.js +201 -0
  6. package/dist/cjs/__tests__/WebBluetoothTransport.test.d.ts +1 -0
  7. package/dist/cjs/__tests__/WebBluetoothTransport.test.js +201 -0
  8. package/dist/cjs/__tests__/accelerometer.test.d.ts +1 -0
  9. package/dist/cjs/__tests__/accelerometer.test.js +158 -0
  10. package/dist/cjs/__tests__/auth.test.d.ts +1 -0
  11. package/dist/cjs/__tests__/auth.test.js +239 -0
  12. package/dist/cjs/__tests__/brainwaves.test.d.ts +1 -0
  13. package/dist/cjs/__tests__/brainwaves.test.js +291 -0
  14. package/dist/cjs/__tests__/device.test.d.ts +1 -0
  15. package/dist/cjs/__tests__/device.test.js +281 -0
  16. package/dist/cjs/__tests__/haptics.test.d.ts +1 -0
  17. package/dist/cjs/__tests__/haptics.test.js +162 -0
  18. package/dist/cjs/__tests__/metrics.test.d.ts +1 -0
  19. package/dist/cjs/__tests__/metrics.test.js +178 -0
  20. package/dist/cjs/__tests__/oauth.test.d.ts +1 -0
  21. package/dist/cjs/__tests__/oauth.test.js +138 -0
  22. package/dist/cjs/__tests__/settings.test.d.ts +1 -0
  23. package/dist/cjs/__tests__/settings.test.js +130 -0
  24. package/dist/cjs/__tests__/setup/webBluetooth.setup.d.ts +11 -0
  25. package/dist/cjs/__tests__/setup/webBluetooth.setup.js +35 -0
  26. package/dist/cjs/__tests__/setup.d.ts +0 -0
  27. package/dist/cjs/__tests__/setup.js +7 -0
  28. package/dist/cjs/__tests__/streaming.test.d.ts +1 -0
  29. package/dist/cjs/__tests__/streaming.test.js +259 -0
  30. package/dist/cjs/__tests__/timesync.test.d.ts +1 -0
  31. package/dist/cjs/__tests__/timesync.test.js +54 -0
  32. package/dist/cjs/__tests__/utils.test.d.ts +1 -0
  33. package/dist/cjs/__tests__/utils.test.js +281 -0
  34. package/dist/cjs/api/bluetooth/BluetoothClient.d.ts +6 -6
  35. package/dist/cjs/api/bluetooth/BluetoothTransport.d.ts +1 -1
  36. package/dist/cjs/api/bluetooth/react-native/ReactNativeTransport.d.ts +4 -4
  37. package/dist/cjs/api/bluetooth/react-native/types/ReactNativeTypes.d.ts +2 -2
  38. package/dist/cjs/api/bluetooth/types/index.d.ts +2 -2
  39. package/dist/cjs/api/bluetooth/utils/decodeJSONChunks.d.ts +1 -1
  40. package/dist/cjs/api/bluetooth/utils/stitch.d.ts +1 -1
  41. package/dist/cjs/api/bluetooth/utils/textCodec.d.ts +1 -1
  42. package/dist/cjs/api/bluetooth/web/WebBluetoothTransport.d.ts +1 -1
  43. package/dist/cjs/api/firebase/FirebaseDevice.d.ts +1 -1
  44. package/dist/cjs/api/firebase/FirebaseUser.d.ts +1 -1
  45. package/dist/cjs/api/index.js +1 -1
  46. package/dist/cjs/timesync/Timesync.d.ts +1 -1
  47. package/dist/cjs/types/awareness.d.ts +1 -1
  48. package/dist/cjs/types/brainwaves.d.ts +25 -12
  49. package/dist/cjs/types/credentials.d.ts +4 -4
  50. package/dist/cjs/types/deviceInfo.d.ts +4 -4
  51. package/dist/cjs/types/epoch.d.ts +1 -1
  52. package/dist/cjs/types/experiment.d.ts +1 -1
  53. package/dist/cjs/types/hapticEffects.d.ts +1 -1
  54. package/dist/cjs/types/marker.d.ts +1 -1
  55. package/dist/cjs/types/metrics.d.ts +2 -2
  56. package/dist/cjs/types/oauth.d.ts +4 -4
  57. package/dist/cjs/types/sample.d.ts +2 -2
  58. package/dist/cjs/types/signalQuality.d.ts +1 -1
  59. package/dist/cjs/types/skill.d.ts +2 -2
  60. package/dist/cjs/types/user.d.ts +3 -3
  61. package/dist/cjs/utils/oauth.d.ts +1 -1
  62. package/dist/cjs/utils/transferDevice.d.ts +3 -3
  63. package/dist/cjs/utils/whileOnline.d.ts +1 -1
  64. package/dist/electron/index.js +1 -1
  65. package/dist/electron/index.js.map +1 -1
  66. package/dist/esm/__tests__/Neurosity.test.d.ts +1 -0
  67. package/dist/esm/__tests__/Neurosity.test.js +199 -0
  68. package/dist/esm/__tests__/WebBluetoothTransport.test.d.ts +1 -0
  69. package/dist/esm/__tests__/WebBluetoothTransport.test.js +199 -0
  70. package/dist/esm/__tests__/accelerometer.test.d.ts +1 -0
  71. package/dist/esm/__tests__/accelerometer.test.js +156 -0
  72. package/dist/esm/__tests__/auth.test.d.ts +1 -0
  73. package/dist/esm/__tests__/auth.test.js +237 -0
  74. package/dist/esm/__tests__/brainwaves.test.d.ts +1 -0
  75. package/dist/esm/__tests__/brainwaves.test.js +289 -0
  76. package/dist/esm/__tests__/device.test.d.ts +1 -0
  77. package/dist/esm/__tests__/device.test.js +279 -0
  78. package/dist/esm/__tests__/haptics.test.d.ts +1 -0
  79. package/dist/esm/__tests__/haptics.test.js +160 -0
  80. package/dist/esm/__tests__/metrics.test.d.ts +1 -0
  81. package/dist/esm/__tests__/metrics.test.js +176 -0
  82. package/dist/esm/__tests__/oauth.test.d.ts +1 -0
  83. package/dist/esm/__tests__/oauth.test.js +133 -0
  84. package/dist/esm/__tests__/settings.test.d.ts +1 -0
  85. package/dist/esm/__tests__/settings.test.js +128 -0
  86. package/dist/esm/__tests__/setup/webBluetooth.setup.d.ts +11 -0
  87. package/dist/esm/__tests__/setup/webBluetooth.setup.js +35 -0
  88. package/dist/esm/__tests__/setup.d.ts +0 -0
  89. package/dist/esm/__tests__/setup.js +7 -0
  90. package/dist/esm/__tests__/streaming.test.d.ts +1 -0
  91. package/dist/esm/__tests__/streaming.test.js +257 -0
  92. package/dist/esm/__tests__/timesync.test.d.ts +1 -0
  93. package/dist/esm/__tests__/timesync.test.js +52 -0
  94. package/dist/esm/__tests__/utils.test.d.ts +1 -0
  95. package/dist/esm/__tests__/utils.test.js +279 -0
  96. package/dist/esm/api/bluetooth/BluetoothClient.d.ts +6 -6
  97. package/dist/esm/api/bluetooth/BluetoothTransport.d.ts +1 -1
  98. package/dist/esm/api/bluetooth/react-native/ReactNativeTransport.d.ts +4 -4
  99. package/dist/esm/api/bluetooth/react-native/types/ReactNativeTypes.d.ts +2 -2
  100. package/dist/esm/api/bluetooth/types/index.d.ts +2 -2
  101. package/dist/esm/api/bluetooth/utils/decodeJSONChunks.d.ts +1 -1
  102. package/dist/esm/api/bluetooth/utils/stitch.d.ts +1 -1
  103. package/dist/esm/api/bluetooth/utils/textCodec.d.ts +1 -1
  104. package/dist/esm/api/bluetooth/web/WebBluetoothTransport.d.ts +1 -1
  105. package/dist/esm/api/firebase/FirebaseDevice.d.ts +1 -1
  106. package/dist/esm/api/firebase/FirebaseUser.d.ts +1 -1
  107. package/dist/esm/api/index.js +2 -2
  108. package/dist/esm/neurosity.mjs +118 -49
  109. package/dist/esm/timesync/Timesync.d.ts +1 -1
  110. package/dist/esm/types/awareness.d.ts +1 -1
  111. package/dist/esm/types/brainwaves.d.ts +25 -12
  112. package/dist/esm/types/credentials.d.ts +4 -4
  113. package/dist/esm/types/deviceInfo.d.ts +4 -4
  114. package/dist/esm/types/epoch.d.ts +1 -1
  115. package/dist/esm/types/experiment.d.ts +1 -1
  116. package/dist/esm/types/hapticEffects.d.ts +1 -1
  117. package/dist/esm/types/marker.d.ts +1 -1
  118. package/dist/esm/types/metrics.d.ts +2 -2
  119. package/dist/esm/types/oauth.d.ts +4 -4
  120. package/dist/esm/types/sample.d.ts +2 -2
  121. package/dist/esm/types/signalQuality.d.ts +1 -1
  122. package/dist/esm/types/skill.d.ts +2 -2
  123. package/dist/esm/types/user.d.ts +3 -3
  124. package/dist/esm/utils/oauth.d.ts +1 -1
  125. package/dist/esm/utils/transferDevice.d.ts +3 -3
  126. package/dist/esm/utils/whileOnline.d.ts +1 -1
  127. package/dist/examples/neurosity.iife.js +118 -49
  128. package/dist/examples/neurosity.js +112 -112
  129. package/dist/examples/neurosity.mjs +118 -49
  130. package/package.json +16 -4
@@ -0,0 +1,239 @@
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
+ const Neurosity_1 = require("../Neurosity");
13
+ const rxjs_1 = require("rxjs");
14
+ // Mock CloudClient
15
+ jest.mock("../api", () => {
16
+ const originalModule = jest.requireActual("../api");
17
+ class MockCloudClient {
18
+ constructor(options) {
19
+ this.user = null;
20
+ this.userClaims = { scopes: ["brainwaves"] };
21
+ this.subscriptionManager = {
22
+ add: jest.fn(),
23
+ remove: jest.fn(),
24
+ removeAll: jest.fn()
25
+ };
26
+ this._selectedDevice = new rxjs_1.BehaviorSubject(undefined);
27
+ this._authStateSubject = new rxjs_1.BehaviorSubject(null);
28
+ this.login = jest.fn().mockImplementation((credentials) => __awaiter(this, void 0, void 0, function* () {
29
+ if (credentials.email === "invalid@example.com") {
30
+ throw new Error("Invalid credentials");
31
+ }
32
+ this._authStateSubject.next({ email: credentials.email });
33
+ return { user: { email: credentials.email } };
34
+ }));
35
+ this.logout = jest.fn().mockImplementation(() => __awaiter(this, void 0, void 0, function* () {
36
+ this._authStateSubject.next(null);
37
+ return {};
38
+ }));
39
+ this.createAccount = jest.fn().mockImplementation((credentials) => __awaiter(this, void 0, void 0, function* () {
40
+ var _a;
41
+ if ((_a = this._existingAccounts) === null || _a === void 0 ? void 0 : _a.includes(credentials.email)) {
42
+ throw new Error("Account already exists");
43
+ }
44
+ if (!this._existingAccounts) {
45
+ this._existingAccounts = [];
46
+ }
47
+ this._existingAccounts.push(credentials.email);
48
+ return { user: { email: credentials.email } };
49
+ }));
50
+ this.deleteAccount = jest.fn().mockImplementation(() => __awaiter(this, void 0, void 0, function* () {
51
+ this._authStateSubject.next(null);
52
+ return {};
53
+ }));
54
+ this.onAuthStateChanged = jest.fn().mockImplementation(() => {
55
+ return this._authStateSubject.asObservable();
56
+ });
57
+ this._existingAccounts = [];
58
+ this.options = options;
59
+ }
60
+ }
61
+ return Object.assign(Object.assign({}, originalModule), { CloudClient: jest
62
+ .fn()
63
+ .mockImplementation((options) => new MockCloudClient(options)) });
64
+ });
65
+ describe("Authentication", () => {
66
+ let neurosity;
67
+ const testDeviceId = "test-device-id";
68
+ const credentials = {
69
+ email: "test@example.com",
70
+ password: "testPassword123"
71
+ };
72
+ beforeEach(() => {
73
+ neurosity = new Neurosity_1.Neurosity({
74
+ deviceId: testDeviceId,
75
+ emulator: true
76
+ });
77
+ });
78
+ afterEach(() => __awaiter(void 0, void 0, void 0, function* () {
79
+ try {
80
+ yield neurosity.logout();
81
+ }
82
+ catch (error) {
83
+ // Ignore logout errors in cleanup
84
+ }
85
+ }));
86
+ describe("Basic Authentication", () => {
87
+ it("should handle login and logout flow", (done) => {
88
+ neurosity.login(credentials).then(() => {
89
+ neurosity
90
+ .onAuthStateChanged()
91
+ .pipe((0, rxjs_1.take)(1))
92
+ .subscribe({
93
+ next: (authState) => {
94
+ expect(authState).toBeTruthy();
95
+ expect(authState.email).toBe(credentials.email);
96
+ done();
97
+ },
98
+ error: done
99
+ });
100
+ });
101
+ });
102
+ it("should handle logout", (done) => {
103
+ neurosity.login(credentials).then(() => {
104
+ neurosity.logout().then(() => {
105
+ neurosity
106
+ .onAuthStateChanged()
107
+ .pipe((0, rxjs_1.take)(1))
108
+ .subscribe({
109
+ next: (loggedOutState) => {
110
+ expect(loggedOutState).toBeFalsy();
111
+ done();
112
+ },
113
+ error: done
114
+ });
115
+ });
116
+ });
117
+ });
118
+ it("should reject invalid credentials", () => __awaiter(void 0, void 0, void 0, function* () {
119
+ const invalidCredentials = {
120
+ email: "invalid@example.com",
121
+ password: "wrongPassword"
122
+ };
123
+ yield expect(neurosity.login(invalidCredentials)).rejects.toThrow("Invalid credentials");
124
+ }));
125
+ });
126
+ describe("Account Management", () => {
127
+ it("should create account", (done) => {
128
+ const newAccount = {
129
+ email: "new@example.com",
130
+ password: "newPassword123"
131
+ };
132
+ neurosity.createAccount(newAccount).then(() => {
133
+ neurosity.login(newAccount).then(() => {
134
+ neurosity
135
+ .onAuthStateChanged()
136
+ .pipe((0, rxjs_1.take)(1))
137
+ .subscribe({
138
+ next: (authState) => {
139
+ expect(authState).toBeTruthy();
140
+ expect(authState.email).toBe(newAccount.email);
141
+ done();
142
+ },
143
+ error: done
144
+ });
145
+ });
146
+ });
147
+ });
148
+ it("should delete account", (done) => {
149
+ const account = {
150
+ email: "delete@example.com",
151
+ password: "deletePassword123"
152
+ };
153
+ neurosity.createAccount(account).then(() => {
154
+ neurosity.login(account).then(() => {
155
+ neurosity.deleteAccount().then(() => {
156
+ neurosity
157
+ .onAuthStateChanged()
158
+ .pipe((0, rxjs_1.take)(1))
159
+ .subscribe({
160
+ next: (deletedState) => {
161
+ expect(deletedState).toBeFalsy();
162
+ done();
163
+ },
164
+ error: done
165
+ });
166
+ });
167
+ });
168
+ });
169
+ });
170
+ it("should prevent duplicate account creation", () => __awaiter(void 0, void 0, void 0, function* () {
171
+ const existingAccount = {
172
+ email: "existing@example.com",
173
+ password: "existingPassword123"
174
+ };
175
+ yield expect(neurosity.createAccount(existingAccount)).resolves.not.toThrow();
176
+ yield expect(neurosity.createAccount(existingAccount)).rejects.toThrow("Account already exists");
177
+ // Cleanup
178
+ yield neurosity.login(existingAccount);
179
+ yield neurosity.deleteAccount();
180
+ }));
181
+ });
182
+ describe("Auth State Changes", () => {
183
+ it("should emit initial auth state", (done) => {
184
+ neurosity
185
+ .onAuthStateChanged()
186
+ .pipe((0, rxjs_1.take)(1))
187
+ .subscribe({
188
+ next: (state) => {
189
+ expect(state).toBeFalsy(); // Initial state should be null
190
+ done();
191
+ },
192
+ error: done
193
+ });
194
+ });
195
+ it("should emit logged in state", (done) => {
196
+ neurosity.login(credentials).then(() => {
197
+ neurosity
198
+ .onAuthStateChanged()
199
+ .pipe((0, rxjs_1.take)(1))
200
+ .subscribe({
201
+ next: (loggedInState) => {
202
+ expect(loggedInState).toBeTruthy();
203
+ expect(loggedInState.email).toBe(credentials.email);
204
+ done();
205
+ },
206
+ error: done
207
+ });
208
+ });
209
+ });
210
+ it("should handle session expiration", (done) => {
211
+ neurosity.login(credentials).then(() => {
212
+ const cloudClient = neurosity.cloudClient;
213
+ cloudClient._authStateSubject.next(null);
214
+ neurosity
215
+ .onAuthStateChanged()
216
+ .pipe((0, rxjs_1.take)(1))
217
+ .subscribe({
218
+ next: (expiredState) => {
219
+ expect(expiredState).toBeFalsy();
220
+ done();
221
+ },
222
+ error: done
223
+ });
224
+ });
225
+ });
226
+ });
227
+ describe("Error Handling", () => {
228
+ it("should handle network errors during login", () => __awaiter(void 0, void 0, void 0, function* () {
229
+ const cloudClient = neurosity.cloudClient;
230
+ cloudClient.login.mockRejectedValueOnce(new Error("Network error"));
231
+ yield expect(neurosity.login(credentials)).rejects.toThrow("Network error");
232
+ }));
233
+ it("should handle server errors during account creation", () => __awaiter(void 0, void 0, void 0, function* () {
234
+ const cloudClient = neurosity.cloudClient;
235
+ cloudClient.createAccount.mockRejectedValueOnce(new Error("Server error"));
236
+ yield expect(neurosity.createAccount(credentials)).rejects.toThrow("Server error");
237
+ }));
238
+ });
239
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,291 @@
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
+ const Neurosity_1 = require("../Neurosity");
13
+ const rxjs_1 = require("rxjs");
14
+ const status_1 = require("../types/status");
15
+ const platform_1 = require("../utils/platform");
16
+ // Mock CloudClient
17
+ jest.mock("../api", () => {
18
+ const originalModule = jest.requireActual("../api");
19
+ class MockCloudClient {
20
+ constructor(options) {
21
+ this.user = null;
22
+ this.userClaims = { scopes: ["brainwaves"] };
23
+ this.subscriptionManager = {
24
+ add: jest.fn(),
25
+ remove: jest.fn(),
26
+ removeAll: jest.fn()
27
+ };
28
+ this._selectedDevice = new rxjs_1.ReplaySubject(1);
29
+ this._deviceInfo = {
30
+ deviceId: "test-device-id",
31
+ deviceNickname: "Test Device",
32
+ channelNames: ["CH1", "CH2"],
33
+ channels: 2,
34
+ samplingRate: 250,
35
+ manufacturer: "Neurosity",
36
+ model: "Crown",
37
+ modelName: "Crown",
38
+ modelVersion: platform_1.MODEL_VERSION_2,
39
+ apiVersion: "1.0.0",
40
+ osVersion: "1.0.0",
41
+ emulator: false
42
+ };
43
+ this.getInfo = jest.fn().mockResolvedValue(this._deviceInfo);
44
+ this.selectDevice = jest
45
+ .fn()
46
+ .mockImplementation((selector) => __awaiter(this, void 0, void 0, function* () {
47
+ const selectedDevice = selector([this._deviceInfo]);
48
+ this._selectedDevice.next(selectedDevice);
49
+ return selectedDevice;
50
+ }));
51
+ this.getSelectedDevice = jest.fn().mockResolvedValue(this._deviceInfo);
52
+ this.didSelectDevice = jest.fn().mockResolvedValue(true);
53
+ this.onDeviceChange = jest.fn().mockReturnValue((0, rxjs_1.of)({
54
+ state: status_1.STATUS.ONLINE,
55
+ charging: false,
56
+ battery: 100,
57
+ sleepMode: false,
58
+ updatingProgress: 0,
59
+ bluetoothEnabled: false,
60
+ sleepModeReason: null,
61
+ lastHeartbeat: Date.now(),
62
+ ssid: "test-network"
63
+ }));
64
+ this.status = jest.fn().mockReturnValue((0, rxjs_1.of)({
65
+ state: status_1.STATUS.ONLINE,
66
+ charging: false,
67
+ battery: 100,
68
+ sleepMode: false,
69
+ updatingProgress: 0,
70
+ bluetoothEnabled: false,
71
+ sleepModeReason: null,
72
+ lastHeartbeat: Date.now(),
73
+ ssid: "test-network"
74
+ }));
75
+ this.osVersion = jest.fn().mockReturnValue((0, rxjs_1.of)("1.0.0"));
76
+ this.metrics = {
77
+ subscribe: jest.fn().mockImplementation((subscription) => {
78
+ return subscription;
79
+ }),
80
+ unsubscribe: jest.fn(),
81
+ on: jest.fn().mockImplementation((subscription, callback) => {
82
+ switch (subscription.labels[0]) {
83
+ case "raw":
84
+ callback({
85
+ data: [
86
+ [100, 200],
87
+ [150, 250]
88
+ ],
89
+ info: {
90
+ samplingRate: 250,
91
+ startTime: Date.now(),
92
+ notchFrequency: "60Hz",
93
+ channelNames: [
94
+ "CP3",
95
+ "C3",
96
+ "F5",
97
+ "PO3",
98
+ "PO4",
99
+ "F6",
100
+ "C4",
101
+ "CP4"
102
+ ]
103
+ }
104
+ });
105
+ break;
106
+ case "rawUnfiltered":
107
+ callback({
108
+ data: [
109
+ [100, 200],
110
+ [150, 250]
111
+ ],
112
+ info: {
113
+ samplingRate: 250,
114
+ startTime: Date.now(),
115
+ channelNames: [
116
+ "CP3",
117
+ "C3",
118
+ "F5",
119
+ "PO3",
120
+ "PO4",
121
+ "F6",
122
+ "C4",
123
+ "CP4"
124
+ ]
125
+ }
126
+ });
127
+ break;
128
+ case "powerByBand":
129
+ callback({
130
+ gamma: [0.5, 0.6],
131
+ beta: [0.4, 0.5],
132
+ alpha: [0.3, 0.4],
133
+ theta: [0.2, 0.3],
134
+ delta: [0.1, 0.2],
135
+ info: {
136
+ channelNames: [
137
+ "CP3",
138
+ "C3",
139
+ "F5",
140
+ "PO3",
141
+ "PO4",
142
+ "F6",
143
+ "C4",
144
+ "CP4"
145
+ ],
146
+ samplingRate: 256,
147
+ startTime: Date.now()
148
+ }
149
+ });
150
+ break;
151
+ case "psd":
152
+ callback({
153
+ label: "psd",
154
+ psd: [
155
+ [0.1, 0.2],
156
+ [0.3, 0.4]
157
+ ],
158
+ freqs: [1, 2],
159
+ info: {
160
+ notchFrequency: "60Hz",
161
+ samplingRate: 250,
162
+ startTime: Date.now(),
163
+ channelNames: [
164
+ "CP3",
165
+ "C3",
166
+ "F5",
167
+ "PO3",
168
+ "PO4",
169
+ "F6",
170
+ "C4",
171
+ "CP4"
172
+ ]
173
+ }
174
+ });
175
+ break;
176
+ default:
177
+ throw new Error(`One ore more labels provided to brainwaves are invalid. The valid labels for brainwaves are raw, rawUnfiltered, frequency, powerByBand, psd`);
178
+ }
179
+ return () => { };
180
+ })
181
+ };
182
+ this.options = options;
183
+ this._selectedDevice.next(this._deviceInfo);
184
+ }
185
+ }
186
+ return Object.assign(Object.assign({}, originalModule), { CloudClient: jest
187
+ .fn()
188
+ .mockImplementation((options) => new MockCloudClient(options)) });
189
+ });
190
+ describe("Brainwaves", () => {
191
+ let neurosity;
192
+ const testDeviceId = "test-device-id";
193
+ beforeEach(() => {
194
+ neurosity = new Neurosity_1.Neurosity({
195
+ deviceId: testDeviceId,
196
+ emulator: true
197
+ });
198
+ });
199
+ describe("Raw Brainwaves", () => {
200
+ it("should get raw brainwaves data", () => __awaiter(void 0, void 0, void 0, function* () {
201
+ const data = (yield (0, rxjs_1.firstValueFrom)(neurosity.brainwaves("raw")));
202
+ expect(data).toBeDefined();
203
+ expect(data.data).toBeInstanceOf(Array);
204
+ expect(data.data[0]).toBeInstanceOf(Array);
205
+ expect(data.info.samplingRate).toBe(250);
206
+ expect(data.info.startTime).toBeDefined();
207
+ expect(data.info.notchFrequency).toBe("60Hz");
208
+ expect(data.info.channelNames).toEqual([
209
+ "CP3",
210
+ "C3",
211
+ "F5",
212
+ "PO3",
213
+ "PO4",
214
+ "F6",
215
+ "C4",
216
+ "CP4"
217
+ ]);
218
+ }));
219
+ it("should get raw unfiltered brainwaves data", () => __awaiter(void 0, void 0, void 0, function* () {
220
+ const data = (yield (0, rxjs_1.firstValueFrom)(neurosity.brainwaves("rawUnfiltered")));
221
+ expect(data).toBeDefined();
222
+ expect(data.data).toBeInstanceOf(Array);
223
+ expect(data.data[0]).toBeInstanceOf(Array);
224
+ expect(data.info.samplingRate).toBe(250);
225
+ expect(data.info.startTime).toBeDefined();
226
+ expect(data.info.channelNames).toEqual([
227
+ "CP3",
228
+ "C3",
229
+ "F5",
230
+ "PO3",
231
+ "PO4",
232
+ "F6",
233
+ "C4",
234
+ "CP4"
235
+ ]);
236
+ expect(data.info.notchFrequency).toBeUndefined();
237
+ }));
238
+ });
239
+ describe("Power by Band", () => {
240
+ it("should get power by band data", () => __awaiter(void 0, void 0, void 0, function* () {
241
+ const data = (yield (0, rxjs_1.firstValueFrom)(neurosity.brainwaves("powerByBand")));
242
+ expect(data).toBeDefined();
243
+ expect(data.gamma).toBeInstanceOf(Array);
244
+ expect(data.beta).toBeInstanceOf(Array);
245
+ expect(data.alpha).toBeInstanceOf(Array);
246
+ expect(data.theta).toBeInstanceOf(Array);
247
+ expect(data.delta).toBeInstanceOf(Array);
248
+ // Verify info object exists and has correct properties
249
+ expect(data.info).toBeDefined();
250
+ expect(data.info.samplingRate).toBe(256);
251
+ expect(data.info.startTime).toBeDefined();
252
+ expect(data.info.channelNames).toEqual([
253
+ "CP3",
254
+ "C3",
255
+ "F5",
256
+ "PO3",
257
+ "PO4",
258
+ "F6",
259
+ "C4",
260
+ "CP4"
261
+ ]);
262
+ }));
263
+ });
264
+ describe("Power Spectral Density", () => {
265
+ it("should get PSD data", () => __awaiter(void 0, void 0, void 0, function* () {
266
+ const data = (yield (0, rxjs_1.firstValueFrom)(neurosity.brainwaves("psd")));
267
+ expect(data).toBeDefined();
268
+ expect(data.label).toBe("psd");
269
+ expect(data.psd).toBeInstanceOf(Array);
270
+ expect(data.freqs).toBeInstanceOf(Array);
271
+ expect(data.info.samplingRate).toBe(250);
272
+ expect(data.info.startTime).toBeDefined();
273
+ expect(data.info.notchFrequency).toBe("60Hz");
274
+ expect(data.info.channelNames).toEqual([
275
+ "CP3",
276
+ "C3",
277
+ "F5",
278
+ "PO3",
279
+ "PO4",
280
+ "F6",
281
+ "C4",
282
+ "CP4"
283
+ ]);
284
+ }));
285
+ });
286
+ describe("Error Handling", () => {
287
+ it("should handle invalid brainwaves label", () => __awaiter(void 0, void 0, void 0, function* () {
288
+ yield expect((0, rxjs_1.firstValueFrom)(neurosity.brainwaves("invalid"))).rejects.toThrow("One ore more labels provided to brainwaves are invalid. The valid labels for brainwaves are raw, rawUnfiltered, frequency, powerByBand, psd");
289
+ }));
290
+ });
291
+ });
@@ -0,0 +1 @@
1
+ export {};