@neurodevs/node-lsl 19.0.0 → 22.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -6
- package/build/__tests__/AbstractPackageTest.d.ts +12 -11
- package/build/__tests__/AbstractPackageTest.js +32 -34
- package/build/__tests__/AbstractPackageTest.js.map +1 -1
- package/build/__tests__/impl/{BleDeviceController.test.d.ts → BleGattController.test.d.ts} +3 -3
- package/build/__tests__/impl/{BleDeviceController.test.js → BleGattController.test.js} +68 -70
- package/build/__tests__/impl/BleGattController.test.js.map +1 -0
- package/build/__tests__/impl/BleObserverController.test.d.ts +12 -0
- package/build/__tests__/impl/BleObserverController.test.js +62 -0
- package/build/__tests__/impl/BleObserverController.test.js.map +1 -0
- package/build/__tests__/impl/{LslEventMarkerEmitter.test.d.ts → LslEventMarkerOutlet.test.d.ts} +3 -3
- package/build/__tests__/impl/{LslEventMarkerEmitter.test.js → LslEventMarkerOutlet.test.js} +45 -46
- package/build/__tests__/impl/LslEventMarkerOutlet.test.js.map +1 -0
- package/build/__tests__/impl/LslJsonOutlet.test.d.ts +14 -0
- package/build/__tests__/impl/LslJsonOutlet.test.js +118 -0
- package/build/__tests__/impl/LslJsonOutlet.test.js.map +1 -0
- package/build/__tests__/impl/LslStreamInfo.test.js +2 -3
- package/build/__tests__/impl/LslStreamInfo.test.js.map +1 -1
- package/build/__tests__/impl/LslStreamInlet.test.d.ts +3 -5
- package/build/__tests__/impl/LslStreamInlet.test.js +13 -47
- package/build/__tests__/impl/LslStreamInlet.test.js.map +1 -1
- package/build/__tests__/impl/LslStreamOutlet.test.js +7 -13
- package/build/__tests__/impl/LslStreamOutlet.test.js.map +1 -1
- package/build/__tests__/impl/LslWebSocketBridge.test.js +9 -11
- package/build/__tests__/impl/LslWebSocketBridge.test.js.map +1 -1
- package/build/__tests__/impl/UsbDeviceController.test.js.map +1 -1
- package/build/__tests__/impl/WindowedClockRegressor.test.js +1 -1
- package/build/__tests__/impl/WindowedClockRegressor.test.js.map +1 -1
- package/build/assertions.js +1 -1
- package/build/assertions.js.map +1 -1
- package/build/impl/LslEventMarkerOutlet.d.ts +35 -0
- package/build/impl/{LslEventMarkerEmitter.js → LslEventMarkerOutlet.js} +2 -2
- package/build/impl/LslEventMarkerOutlet.js.map +1 -0
- package/build/impl/LslJsonOutlet.d.ts +33 -0
- package/build/impl/LslJsonOutlet.js +44 -0
- package/build/impl/LslJsonOutlet.js.map +1 -0
- package/build/impl/LslStreamInfo.d.ts +7 -7
- package/build/impl/LslStreamInfo.js.map +1 -1
- package/build/impl/LslStreamInlet.d.ts +63 -21
- package/build/impl/LslStreamInlet.js +221 -65
- package/build/impl/LslStreamInlet.js.map +1 -1
- package/build/impl/LslStreamOutlet.d.ts +16 -16
- package/build/impl/LslStreamOutlet.js +32 -36
- package/build/impl/LslStreamOutlet.js.map +1 -1
- package/build/impl/LslWebSocketBridge.d.ts +10 -10
- package/build/impl/LslWebSocketBridge.js.map +1 -1
- package/build/impl/clocks/WindowedClockRegressor.js.map +1 -0
- package/build/impl/controllers/{BleDeviceController.d.ts → BleGattController.d.ts} +10 -10
- package/build/impl/controllers/{BleDeviceController.js → BleGattController.js} +19 -19
- package/build/impl/controllers/BleGattController.js.map +1 -0
- package/build/impl/controllers/BleObserverController.d.ts +20 -0
- package/build/impl/controllers/BleObserverController.js +37 -0
- package/build/impl/controllers/BleObserverController.js.map +1 -0
- package/build/impl/controllers/UsbDeviceController.d.ts +9 -9
- package/build/impl/controllers/UsbDeviceController.js +7 -7
- package/build/impl/controllers/UsbDeviceController.js.map +1 -1
- package/build/index.d.ts +43 -31
- package/build/index.js +52 -39
- package/build/index.js.map +1 -1
- package/build/scripts/{runLslEventMarkerEmitter.js → runEventMarkerOutlet.js} +4 -3
- package/build/scripts/runEventMarkerOutlet.js.map +1 -0
- package/build/scripts/{runLslStreamOutlet.js → runLslOutlet.js} +1 -1
- package/build/scripts/runLslOutlet.js.map +1 -0
- package/build/scripts/runMuse.js +2 -2
- package/build/scripts/runMuse.js.map +1 -1
- package/build/testDoubles/{BleController/FakeBleController.d.ts → BleGatt/FakeBleGatt.d.ts} +6 -6
- package/build/testDoubles/{BleController/FakeBleController.js → BleGatt/FakeBleGatt.js} +8 -8
- package/build/testDoubles/BleGatt/FakeBleGatt.js.map +1 -0
- package/build/testDoubles/{BleController/SpyBleController.d.ts → BleGatt/SpyBleGatt.d.ts} +4 -4
- package/build/testDoubles/{BleController/SpyBleController.js → BleGatt/SpyBleGatt.js} +3 -3
- package/build/testDoubles/BleGatt/SpyBleGatt.js.map +1 -0
- package/build/testDoubles/BleObserver/FakeBleObserver.d.ts +10 -0
- package/build/testDoubles/BleObserver/FakeBleObserver.js +20 -0
- package/build/testDoubles/BleObserver/FakeBleObserver.js.map +1 -0
- package/build/testDoubles/ClockRegressor/FakeClockRegressor.d.ts +1 -1
- package/build/testDoubles/{EventMarkerEmitter/FakeEventMarkerEmitter.d.ts → EventMarkerOutlet/FakeEventMarkerOutlet.d.ts} +4 -4
- package/build/testDoubles/{EventMarkerEmitter/FakeEventMarkerEmitter.js → EventMarkerOutlet/FakeEventMarkerOutlet.js} +7 -7
- package/build/testDoubles/EventMarkerOutlet/FakeEventMarkerOutlet.js.map +1 -0
- package/build/testDoubles/EventMarkerOutlet/SpyEventMarkerOutlet.d.ts +10 -0
- package/build/testDoubles/EventMarkerOutlet/SpyEventMarkerOutlet.js +23 -0
- package/build/testDoubles/EventMarkerOutlet/SpyEventMarkerOutlet.js.map +1 -0
- package/build/testDoubles/EventMarkerOutlet/ThrowingEventMarkerOutlet.d.ts +9 -0
- package/build/testDoubles/{EventMarkerEmitter/ThrowingEventMarkerEmitter.js → EventMarkerOutlet/ThrowingEventMarkerOutlet.js} +2 -2
- package/build/testDoubles/EventMarkerOutlet/ThrowingEventMarkerOutlet.js.map +1 -0
- package/build/testDoubles/JsonOutlet/FakeJsonOutlet.d.ts +10 -0
- package/build/testDoubles/JsonOutlet/FakeJsonOutlet.js +20 -0
- package/build/testDoubles/JsonOutlet/FakeJsonOutlet.js.map +1 -0
- package/build/testDoubles/{StreamInfo/FakeStreamInfo.d.ts → LslInfo/FakeLslInfo.d.ts} +4 -4
- package/build/testDoubles/{StreamInfo/FakeStreamInfo.js → LslInfo/FakeLslInfo.js} +7 -7
- package/build/testDoubles/LslInfo/FakeLslInfo.js.map +1 -0
- package/build/testDoubles/LslInfo/SpyLslInfo.d.ts +10 -0
- package/build/testDoubles/{StreamInfo/SpyStreamInfo.js → LslInfo/SpyLslInfo.js} +4 -4
- package/build/testDoubles/LslInfo/SpyLslInfo.js.map +1 -0
- package/build/testDoubles/{StreamInlet/FakeStreamInlet.d.ts → LslInlet/FakeLslInlet.d.ts} +4 -4
- package/build/testDoubles/{StreamInlet/FakeStreamInlet.js → LslInlet/FakeLslInlet.js} +12 -11
- package/build/testDoubles/LslInlet/FakeLslInlet.js.map +1 -0
- package/build/testDoubles/LslInlet/SpyLslInlet.d.ts +4 -0
- package/build/testDoubles/{StreamInlet/SpyStreamInlet.js → LslInlet/SpyLslInlet.js} +2 -2
- package/build/testDoubles/LslInlet/SpyLslInlet.js.map +1 -0
- package/build/testDoubles/{StreamOutlet/FakeStreamOutlet.d.ts → LslOutlet/FakeLslOutlet.d.ts} +5 -5
- package/build/testDoubles/{StreamOutlet/FakeStreamOutlet.js → LslOutlet/FakeLslOutlet.js} +8 -8
- package/build/testDoubles/LslOutlet/FakeLslOutlet.js.map +1 -0
- package/build/testDoubles/LslWsBridge/FakeLslWsBridge.d.ts +14 -0
- package/build/testDoubles/{WebSocketBridge/FakeWebSocketBridge.js → LslWsBridge/FakeLslWsBridge.js} +14 -14
- package/build/testDoubles/LslWsBridge/FakeLslWsBridge.js.map +1 -0
- package/build/testDoubles/LslWsBridge/SpyLslWsBridge.d.ts +4 -0
- package/build/testDoubles/{WebSocketBridge/SpyLslWebSocketBridge.js → LslWsBridge/SpyLslWsBridge.js} +2 -2
- package/build/testDoubles/LslWsBridge/SpyLslWsBridge.js.map +1 -0
- package/build/testDoubles/UsbDevice/FakeUsbDevice.d.ts +12 -0
- package/build/testDoubles/UsbDevice/FakeUsbDevice.js +25 -0
- package/build/testDoubles/UsbDevice/FakeUsbDevice.js.map +1 -0
- package/build/testDoubles/consts.d.ts +2 -12
- package/build/testDoubles/consts.js +0 -20
- package/build/testDoubles/consts.js.map +1 -1
- package/build/testDoubles/generateRandomOutletOptions.d.ts +2 -2
- package/build/testDoubles/generateRandomOutletOptions.js.map +1 -1
- package/package.json +5 -4
- package/src/__tests__/AbstractPackageTest.ts +35 -42
- package/src/__tests__/impl/{BleDeviceController.test.ts → BleGattController.test.ts} +45 -47
- package/src/__tests__/impl/BleObserverController.test.ts +72 -0
- package/src/__tests__/impl/{LslEventMarkerEmitter.test.ts → LslEventMarkerOutlet.test.ts} +33 -37
- package/src/__tests__/impl/LslJsonOutlet.test.ts +135 -0
- package/src/__tests__/impl/LslStreamInfo.test.ts +8 -9
- package/src/__tests__/impl/LslStreamInlet.test.ts +21 -79
- package/src/__tests__/impl/LslStreamOutlet.test.ts +17 -25
- package/src/__tests__/impl/LslWebSocketBridge.test.ts +15 -19
- package/src/__tests__/impl/UsbDeviceController.test.ts +2 -2
- package/src/__tests__/impl/WindowedClockRegressor.test.ts +1 -1
- package/src/assertions.ts +1 -2
- package/src/impl/{LslEventMarkerEmitter.ts → LslEventMarkerOutlet.ts} +17 -17
- package/src/impl/LslJsonOutlet.ts +87 -0
- package/src/impl/LslStreamInfo.ts +7 -9
- package/src/impl/LslStreamInlet.ts +305 -81
- package/src/impl/LslStreamOutlet.ts +62 -59
- package/src/impl/LslWebSocketBridge.ts +15 -18
- package/src/impl/controllers/{BleDeviceController.ts → BleGattController.ts} +23 -28
- package/src/impl/controllers/BleObserverController.ts +62 -0
- package/src/impl/controllers/UsbDeviceController.ts +14 -16
- package/src/index.ts +64 -44
- package/src/scripts/{runLslEventMarkerEmitter.ts → runEventMarkerOutlet.ts} +3 -2
- package/src/scripts/runMuse.ts +2 -2
- package/src/testDoubles/{BleController/FakeBleController.ts → BleGatt/FakeBleGatt.ts} +14 -14
- package/src/testDoubles/{BleController/SpyBleController.ts → BleGatt/SpyBleGatt.ts} +5 -5
- package/src/testDoubles/BleObserver/FakeBleObserver.ts +28 -0
- package/src/testDoubles/ClockRegressor/FakeClockRegressor.ts +1 -1
- package/src/testDoubles/{EventMarkerEmitter/FakeEventMarkerEmitter.ts → EventMarkerOutlet/FakeEventMarkerOutlet.ts} +11 -11
- package/src/testDoubles/EventMarkerOutlet/SpyEventMarkerOutlet.ts +31 -0
- package/src/testDoubles/{EventMarkerEmitter/ThrowingEventMarkerEmitter.ts → EventMarkerOutlet/ThrowingEventMarkerOutlet.ts} +5 -5
- package/src/testDoubles/JsonOutlet/FakeJsonOutlet.ts +25 -0
- package/src/testDoubles/{StreamInfo/FakeStreamInfo.ts → LslInfo/FakeLslInfo.ts} +9 -9
- package/src/testDoubles/{StreamInfo/SpyStreamInfo.ts → LslInfo/SpyLslInfo.ts} +5 -5
- package/src/testDoubles/{StreamInlet/FakeStreamInlet.ts → LslInlet/FakeLslInlet.ts} +15 -14
- package/src/testDoubles/LslInlet/SpyLslInlet.ts +10 -0
- package/src/testDoubles/{StreamOutlet/FakeStreamOutlet.ts → LslOutlet/FakeLslOutlet.ts} +11 -14
- package/src/testDoubles/{WebSocketBridge/FakeWebSocketBridge.ts → LslWsBridge/FakeLslWsBridge.ts} +19 -19
- package/src/testDoubles/LslWsBridge/SpyLslWsBridge.ts +9 -0
- package/src/testDoubles/UsbDevice/FakeUsbDevice.ts +34 -0
- package/src/testDoubles/consts.ts +3 -23
- package/src/testDoubles/generateRandomOutletOptions.ts +2 -2
- package/build/__tests__/impl/BleDeviceController.test.js.map +0 -1
- package/build/__tests__/impl/LslEventMarkerEmitter.test.js.map +0 -1
- package/build/consts.d.ts +0 -11
- package/build/consts.js +0 -21
- package/build/consts.js.map +0 -1
- package/build/impl/LslEventMarkerEmitter.d.ts +0 -35
- package/build/impl/LslEventMarkerEmitter.js.map +0 -1
- package/build/impl/WindowedClockRegressor.js.map +0 -1
- package/build/impl/controllers/BleDeviceController.js.map +0 -1
- package/build/impl/workers/inlet/LslStreamInlet.worker.d.ts +0 -22
- package/build/impl/workers/inlet/LslStreamInlet.worker.js +0 -42
- package/build/impl/workers/inlet/LslStreamInlet.worker.js.map +0 -1
- package/build/impl/workers/inlet/StreamInletWorker.d.ts +0 -73
- package/build/impl/workers/inlet/StreamInletWorker.js +0 -253
- package/build/impl/workers/inlet/StreamInletWorker.js.map +0 -1
- package/build/impl/workers/outlet/LslStreamOutlet.worker.d.ts +0 -32
- package/build/impl/workers/outlet/LslStreamOutlet.worker.js +0 -82
- package/build/impl/workers/outlet/LslStreamOutlet.worker.js.map +0 -1
- package/build/scripts/discoverMuse.js +0 -40
- package/build/scripts/discoverMuse.js.map +0 -1
- package/build/scripts/runLslEventMarkerEmitter.js.map +0 -1
- package/build/scripts/runLslStreamOutlet.d.ts +0 -1
- package/build/scripts/runLslStreamOutlet.js.map +0 -1
- package/build/scripts/testDestroyOutlet.d.ts +0 -1
- package/build/scripts/testDestroyOutlet.js +0 -4
- package/build/scripts/testDestroyOutlet.js.map +0 -1
- package/build/testDoubles/BleController/FakeBleController.js.map +0 -1
- package/build/testDoubles/BleController/SpyBleController.js.map +0 -1
- package/build/testDoubles/EventMarkerEmitter/FakeEventMarkerEmitter.js.map +0 -1
- package/build/testDoubles/EventMarkerEmitter/SpyEventMarkerEmitter.d.ts +0 -10
- package/build/testDoubles/EventMarkerEmitter/SpyEventMarkerEmitter.js +0 -23
- package/build/testDoubles/EventMarkerEmitter/SpyEventMarkerEmitter.js.map +0 -1
- package/build/testDoubles/EventMarkerEmitter/ThrowingEventMarkerEmitter.d.ts +0 -9
- package/build/testDoubles/EventMarkerEmitter/ThrowingEventMarkerEmitter.js.map +0 -1
- package/build/testDoubles/StreamInfo/FakeStreamInfo.js.map +0 -1
- package/build/testDoubles/StreamInfo/SpyStreamInfo.d.ts +0 -10
- package/build/testDoubles/StreamInfo/SpyStreamInfo.js.map +0 -1
- package/build/testDoubles/StreamInlet/FakeStreamInlet.js.map +0 -1
- package/build/testDoubles/StreamInlet/SpyStreamInlet.d.ts +0 -4
- package/build/testDoubles/StreamInlet/SpyStreamInlet.js.map +0 -1
- package/build/testDoubles/StreamOutlet/FakeStreamOutlet.js.map +0 -1
- package/build/testDoubles/UsbController/FakeUsbController.d.ts +0 -12
- package/build/testDoubles/UsbController/FakeUsbController.js +0 -25
- package/build/testDoubles/UsbController/FakeUsbController.js.map +0 -1
- package/build/testDoubles/WebSocketBridge/FakeWebSocketBridge.d.ts +0 -14
- package/build/testDoubles/WebSocketBridge/FakeWebSocketBridge.js.map +0 -1
- package/build/testDoubles/WebSocketBridge/SpyLslWebSocketBridge.d.ts +0 -4
- package/build/testDoubles/WebSocketBridge/SpyLslWebSocketBridge.js.map +0 -1
- package/build/testDoubles/WorkerThreads/FakeWorker.d.ts +0 -27
- package/build/testDoubles/WorkerThreads/FakeWorker.js +0 -67
- package/build/testDoubles/WorkerThreads/FakeWorker.js.map +0 -1
- package/src/consts.ts +0 -21
- package/src/impl/workers/inlet/LslStreamInlet.worker.ts +0 -74
- package/src/impl/workers/inlet/StreamInletWorker.ts +0 -348
- package/src/impl/workers/outlet/LslStreamOutlet.worker.ts +0 -144
- package/src/scripts/discoverMuse.ts +0 -50
- package/src/scripts/testDestroyOutlet.ts +0 -5
- package/src/testDoubles/EventMarkerEmitter/SpyEventMarkerEmitter.ts +0 -31
- package/src/testDoubles/StreamInlet/SpyStreamInlet.ts +0 -10
- package/src/testDoubles/UsbController/FakeUsbController.ts +0 -34
- package/src/testDoubles/WebSocketBridge/SpyLslWebSocketBridge.ts +0 -9
- package/src/testDoubles/WorkerThreads/FakeWorker.ts +0 -99
- /package/build/impl/{WindowedClockRegressor.d.ts → clocks/WindowedClockRegressor.d.ts} +0 -0
- /package/build/impl/{WindowedClockRegressor.js → clocks/WindowedClockRegressor.js} +0 -0
- /package/build/scripts/{discoverMuse.d.ts → runEventMarkerOutlet.d.ts} +0 -0
- /package/build/scripts/{runLslEventMarkerEmitter.d.ts → runLslOutlet.d.ts} +0 -0
- /package/src/impl/{WindowedClockRegressor.ts → clocks/WindowedClockRegressor.ts} +0 -0
- /package/src/scripts/{runLslStreamOutlet.ts → runLslOutlet.ts} +0 -0
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
import { test, assert } from '@neurodevs/node-tdd'
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import SpyStreamInfo from '../../testDoubles/StreamInfo/SpyStreamInfo.js'
|
|
3
|
+
import LslStreamInfo, { LslInfoOptions } from '../../impl/LslStreamInfo.js'
|
|
4
|
+
import SpyLslInfo from '../../testDoubles/LslInfo/SpyLslInfo.js'
|
|
6
5
|
import AbstractPackageTest from '../AbstractPackageTest.js'
|
|
6
|
+
import { CHANNEL_FORMATS } from '@neurodevs/ndx-native'
|
|
7
7
|
|
|
8
8
|
export default class LslStreamInfoTest extends AbstractPackageTest {
|
|
9
|
-
private static instance:
|
|
9
|
+
private static instance: SpyLslInfo
|
|
10
10
|
|
|
11
11
|
protected static async beforeEach() {
|
|
12
12
|
await super.beforeEach()
|
|
13
13
|
|
|
14
|
-
this.
|
|
15
|
-
this.setSpyStreamInfo()
|
|
14
|
+
this.setSpyLslInfo()
|
|
16
15
|
|
|
17
16
|
this.instance = this.LslStreamInfo()
|
|
18
17
|
}
|
|
@@ -225,12 +224,12 @@ export default class LslStreamInfoTest extends AbstractPackageTest {
|
|
|
225
224
|
channelNames: this.channelNames,
|
|
226
225
|
channelFormat: 'float32',
|
|
227
226
|
sampleRateHz: 100 * Math.random(),
|
|
228
|
-
} as
|
|
227
|
+
} as LslInfoOptions
|
|
229
228
|
|
|
230
|
-
private static LslStreamInfo(options?: Partial<
|
|
229
|
+
private static LslStreamInfo(options?: Partial<LslInfoOptions>) {
|
|
231
230
|
return LslStreamInfo.Create({
|
|
232
231
|
...this.defaultOptions,
|
|
233
232
|
...options,
|
|
234
|
-
}) as
|
|
233
|
+
}) as SpyLslInfo
|
|
235
234
|
}
|
|
236
235
|
}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { Worker } from 'node:worker_threads'
|
|
2
|
-
|
|
3
1
|
import { FakeLiblsl } from '@neurodevs/ndx-native'
|
|
4
2
|
import { test, assert } from '@neurodevs/node-tdd'
|
|
5
3
|
import {
|
|
@@ -11,16 +9,12 @@ import {
|
|
|
11
9
|
unwrapPointer,
|
|
12
10
|
} from 'ffi-rs'
|
|
13
11
|
|
|
14
|
-
import LslStreamInlet, {
|
|
15
|
-
|
|
16
|
-
} from '../../impl/LslStreamInlet.js'
|
|
17
|
-
import StreamInletWorker from '../../impl/workers/inlet/StreamInletWorker.js'
|
|
18
|
-
import { SpyStreamInlet } from '../../testDoubles/StreamInlet/SpyStreamInlet.js'
|
|
19
|
-
import FakeWorker from '../../testDoubles/WorkerThreads/FakeWorker.js'
|
|
12
|
+
import LslStreamInlet, { LslInletOptions } from '../../impl/LslStreamInlet.js'
|
|
13
|
+
import SpyLslInlet from '../../testDoubles/LslInlet/SpyLslInlet.js'
|
|
20
14
|
import AbstractPackageTest from '../AbstractPackageTest.js'
|
|
21
15
|
|
|
22
16
|
export default class LslStreamInletTest extends AbstractPackageTest {
|
|
23
|
-
private static instance:
|
|
17
|
+
private static instance: SpyLslInlet
|
|
24
18
|
|
|
25
19
|
private static callsToOnData: {
|
|
26
20
|
samples: number[]
|
|
@@ -59,21 +53,14 @@ export default class LslStreamInletTest extends AbstractPackageTest {
|
|
|
59
53
|
protected static async beforeEach() {
|
|
60
54
|
await super.beforeEach()
|
|
61
55
|
|
|
62
|
-
this.
|
|
63
|
-
this.
|
|
64
|
-
this.setSpyStreamInlet()
|
|
56
|
+
this.setFakeLslInfo()
|
|
57
|
+
this.setSpyLslInlet()
|
|
65
58
|
|
|
66
59
|
this.callsToOnData = []
|
|
67
60
|
|
|
68
61
|
LslStreamInlet.waitAfterOpenStreamMs = 0
|
|
69
|
-
|
|
70
|
-
LslStreamInlet.
|
|
71
|
-
FakeWorker.resetTestDoubles()
|
|
72
|
-
|
|
73
|
-
StreamInletWorker.lsl = this.fakeLiblsl
|
|
74
|
-
StreamInletWorker.freePointer = () => {}
|
|
75
|
-
|
|
76
|
-
FakeWorker.fakeOnData = this.onData
|
|
62
|
+
LslStreamInlet.lsl = this.fakeLiblsl
|
|
63
|
+
LslStreamInlet.freePointer = () => {}
|
|
77
64
|
|
|
78
65
|
this.instance = await this.LslStreamInlet()
|
|
79
66
|
}
|
|
@@ -133,7 +120,7 @@ export default class LslStreamInletTest extends AbstractPackageTest {
|
|
|
133
120
|
|
|
134
121
|
let calls: FreePointerParams[] = []
|
|
135
122
|
|
|
136
|
-
|
|
123
|
+
LslStreamInlet.freePointer = (params: FreePointerParams) => {
|
|
137
124
|
calls.push(params)
|
|
138
125
|
}
|
|
139
126
|
|
|
@@ -201,9 +188,7 @@ export default class LslStreamInletTest extends AbstractPackageTest {
|
|
|
201
188
|
await this.startPulling()
|
|
202
189
|
|
|
203
190
|
assert.isEqual(
|
|
204
|
-
|
|
205
|
-
(msg) => msg.type === 'startPulling'
|
|
206
|
-
).length,
|
|
191
|
+
this.fakeLiblsl.createInletHitCount,
|
|
207
192
|
1,
|
|
208
193
|
'startPulling did not return early!'
|
|
209
194
|
)
|
|
@@ -243,7 +228,7 @@ export default class LslStreamInletTest extends AbstractPackageTest {
|
|
|
243
228
|
assert.isEqualDeep(
|
|
244
229
|
this.fakeLiblsl.lastOpenStreamOptions,
|
|
245
230
|
{
|
|
246
|
-
inletHandle:
|
|
231
|
+
inletHandle: instance['inletHandle'],
|
|
247
232
|
timeoutMs: openStreamTimeoutMs,
|
|
248
233
|
errorCodePtr: this.errorCodePtr,
|
|
249
234
|
},
|
|
@@ -253,27 +238,6 @@ export default class LslStreamInletTest extends AbstractPackageTest {
|
|
|
253
238
|
instance.stopPulling()
|
|
254
239
|
}
|
|
255
240
|
|
|
256
|
-
@test()
|
|
257
|
-
protected static async waitsAfterOpeningStreamWithPassedOption() {
|
|
258
|
-
const waitAfterOpenStreamMs = 10
|
|
259
|
-
|
|
260
|
-
const instance = await this.LslStreamInlet({
|
|
261
|
-
waitAfterOpenStreamMs,
|
|
262
|
-
})
|
|
263
|
-
|
|
264
|
-
let t0 = Date.now()
|
|
265
|
-
await this.startPulling(instance)
|
|
266
|
-
let elapsed = Date.now() - t0
|
|
267
|
-
|
|
268
|
-
instance.stopPulling()
|
|
269
|
-
|
|
270
|
-
assert.isAbove(
|
|
271
|
-
elapsed,
|
|
272
|
-
waitAfterOpenStreamMs * 0.8,
|
|
273
|
-
'Did not wait after opening stream!'
|
|
274
|
-
)
|
|
275
|
-
}
|
|
276
|
-
|
|
277
241
|
@test()
|
|
278
242
|
protected static async stopPullingClosesInletStream() {
|
|
279
243
|
await this.startPulling()
|
|
@@ -386,15 +350,10 @@ export default class LslStreamInletTest extends AbstractPackageTest {
|
|
|
386
350
|
protected static async pushSampleHandlesErrorCode() {
|
|
387
351
|
let passedErrorCode: number | undefined
|
|
388
352
|
|
|
389
|
-
|
|
353
|
+
LslStreamInlet.handleLslError = (errorCode: number) => {
|
|
390
354
|
passedErrorCode = errorCode
|
|
391
355
|
}
|
|
392
356
|
|
|
393
|
-
const fakeErrorCode = [-4, -3, -2, -1, 0][Math.floor(Math.random() * 5)]
|
|
394
|
-
const worker = this.getFakeWorker()
|
|
395
|
-
|
|
396
|
-
worker['inletWorker']['pullErrorBuffer'].writeInt32LE(fakeErrorCode)
|
|
397
|
-
|
|
398
357
|
await this.startThenStop()
|
|
399
358
|
|
|
400
359
|
assert.isEqualDeep(
|
|
@@ -414,10 +373,9 @@ export default class LslStreamInletTest extends AbstractPackageTest {
|
|
|
414
373
|
|
|
415
374
|
let pulls = 0
|
|
416
375
|
|
|
417
|
-
const
|
|
418
|
-
const original = inletWorker['pullDataOnce'].bind(inletWorker)
|
|
376
|
+
const original = instance['pullDataOnce'].bind(instance)
|
|
419
377
|
|
|
420
|
-
|
|
378
|
+
instance['pullDataOnce'] = async () => {
|
|
421
379
|
pulls++
|
|
422
380
|
await original()
|
|
423
381
|
}
|
|
@@ -508,32 +466,23 @@ export default class LslStreamInletTest extends AbstractPackageTest {
|
|
|
508
466
|
}
|
|
509
467
|
|
|
510
468
|
private static async runInletWithOptions(
|
|
511
|
-
options?: Partial<
|
|
469
|
+
options?: Partial<LslInletOptions>
|
|
512
470
|
) {
|
|
513
471
|
const inlet = await this.LslStreamInlet(options)
|
|
472
|
+
this.instance = inlet
|
|
514
473
|
await this.startThenStop(inlet)
|
|
515
474
|
return inlet
|
|
516
475
|
}
|
|
517
476
|
|
|
518
|
-
private static async startThenStop(inlet?:
|
|
477
|
+
private static async startThenStop(inlet?: SpyLslInlet) {
|
|
519
478
|
const instance = inlet || this.instance
|
|
520
479
|
await this.startPulling(instance)
|
|
521
480
|
await this.wait(10)
|
|
522
481
|
instance.stopPulling()
|
|
523
482
|
}
|
|
524
483
|
|
|
525
|
-
private static async startPulling(instance?:
|
|
526
|
-
|
|
527
|
-
const startPullingPromise = inst.startPulling()
|
|
528
|
-
|
|
529
|
-
while (!this.getFakeWorker(inst).createInletPromise) {
|
|
530
|
-
await this.wait(1)
|
|
531
|
-
}
|
|
532
|
-
|
|
533
|
-
await this.getFakeWorker(inst).createInletPromise
|
|
534
|
-
inst['workerReady'] = true
|
|
535
|
-
|
|
536
|
-
await startPullingPromise
|
|
484
|
+
private static async startPulling(instance?: SpyLslInlet) {
|
|
485
|
+
await (instance || this.instance).startPulling()
|
|
537
486
|
}
|
|
538
487
|
|
|
539
488
|
private static stopPulling() {
|
|
@@ -549,26 +498,19 @@ export default class LslStreamInletTest extends AbstractPackageTest {
|
|
|
549
498
|
}
|
|
550
499
|
|
|
551
500
|
private static get inletHandle() {
|
|
552
|
-
return this.
|
|
553
|
-
}
|
|
554
|
-
|
|
555
|
-
private static getFakeWorker(instance?: SpyStreamInlet) {
|
|
556
|
-
const inst = instance || this.instance
|
|
557
|
-
return inst['worker'] as unknown as FakeWorker
|
|
501
|
+
return this.instance['inletHandle']
|
|
558
502
|
}
|
|
559
503
|
|
|
560
504
|
private static onData = (samples: number[], timestamps: number[]) => {
|
|
561
505
|
this.callsToOnData.push({ samples, timestamps })
|
|
562
506
|
}
|
|
563
507
|
|
|
564
|
-
protected static async LslStreamInlet(
|
|
565
|
-
options?: Partial<StreamInletOptions>
|
|
566
|
-
) {
|
|
508
|
+
protected static async LslStreamInlet(options?: Partial<LslInletOptions>) {
|
|
567
509
|
return (await AbstractPackageTest.LslStreamInlet(
|
|
568
510
|
{
|
|
569
511
|
...options,
|
|
570
512
|
},
|
|
571
513
|
this.onData
|
|
572
|
-
)) as
|
|
514
|
+
)) as SpyLslInlet
|
|
573
515
|
}
|
|
574
516
|
}
|
|
@@ -1,27 +1,25 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
ChannelFormat,
|
|
3
|
+
LslSample,
|
|
4
|
+
FakeLiblsl,
|
|
5
|
+
CHANNEL_FORMATS,
|
|
6
|
+
} from '@neurodevs/ndx-native'
|
|
3
7
|
import { test, assert } from '@neurodevs/node-tdd'
|
|
4
8
|
|
|
5
|
-
import { CHANNEL_FORMATS } from '../../consts.js'
|
|
6
9
|
import LslStreamOutlet, {
|
|
7
|
-
|
|
10
|
+
LslOutletOptions,
|
|
8
11
|
} from '../../impl/LslStreamOutlet.js'
|
|
9
|
-
import {
|
|
10
|
-
setOutletHandleLslError,
|
|
11
|
-
setOutletLiblslAdapter,
|
|
12
|
-
} from '../../impl/workers/outlet/LslStreamOutlet.worker.js'
|
|
13
12
|
import {
|
|
14
13
|
TEST_SUPPORTED_CHANNEL_FORMATS,
|
|
15
14
|
TEST_UNSUPPORTED_CHANNEL_FORMATS,
|
|
16
15
|
TestChannelFormat,
|
|
17
16
|
} from '../../testDoubles/consts.js'
|
|
18
17
|
import generateRandomOutletOptions from '../../testDoubles/generateRandomOutletOptions.js'
|
|
19
|
-
import
|
|
20
|
-
import FakeWorker from '../../testDoubles/WorkerThreads/FakeWorker.js'
|
|
18
|
+
import FakeLslInfo from '../../testDoubles/LslInfo/FakeLslInfo.js'
|
|
21
19
|
import AbstractPackageTest from '../AbstractPackageTest.js'
|
|
22
20
|
|
|
23
21
|
export default class LslStreamOutletTest extends AbstractPackageTest {
|
|
24
|
-
private static randomOutletOptions:
|
|
22
|
+
private static randomOutletOptions: LslOutletOptions
|
|
25
23
|
|
|
26
24
|
protected static async beforeEach() {
|
|
27
25
|
await super.beforeEach()
|
|
@@ -30,13 +28,9 @@ export default class LslStreamOutletTest extends AbstractPackageTest {
|
|
|
30
28
|
|
|
31
29
|
this.randomOutletOptions = generateRandomOutletOptions()
|
|
32
30
|
|
|
33
|
-
this.
|
|
34
|
-
this.setFakeStreamInfo()
|
|
35
|
-
|
|
36
|
-
LslStreamOutlet.Worker = FakeWorker as unknown as typeof Worker
|
|
37
|
-
FakeWorker.resetTestDoubles()
|
|
31
|
+
this.setFakeLslInfo()
|
|
38
32
|
|
|
39
|
-
|
|
33
|
+
LslStreamOutlet.lsl = this.fakeLiblsl
|
|
40
34
|
}
|
|
41
35
|
|
|
42
36
|
@test()
|
|
@@ -175,7 +169,7 @@ export default class LslStreamOutletTest extends AbstractPackageTest {
|
|
|
175
169
|
protected static async constructionCreatesStreamInfo() {
|
|
176
170
|
await this.LslStreamOutlet()
|
|
177
171
|
|
|
178
|
-
assert.isEqualDeep(
|
|
172
|
+
assert.isEqualDeep(FakeLslInfo.callsToConstructor[0], {
|
|
179
173
|
channelNames: this.randomOutletOptions.channelNames,
|
|
180
174
|
channelFormat: this.randomOutletOptions.channelFormat,
|
|
181
175
|
sampleRateHz: this.randomOutletOptions.sampleRateHz,
|
|
@@ -241,9 +235,9 @@ export default class LslStreamOutletTest extends AbstractPackageTest {
|
|
|
241
235
|
protected static async pushSampleHandlesErrorCode() {
|
|
242
236
|
let passedErrorCode: number | undefined
|
|
243
237
|
|
|
244
|
-
|
|
238
|
+
LslStreamOutlet.handleLslError = (errorCode: number) => {
|
|
245
239
|
passedErrorCode = errorCode
|
|
246
|
-
}
|
|
240
|
+
}
|
|
247
241
|
|
|
248
242
|
FakeLiblsl.fakeErrorCode = [-4, -3, -2, -1, 0][
|
|
249
243
|
Math.floor(Math.random() * 5)
|
|
@@ -346,7 +340,7 @@ export default class LslStreamOutletTest extends AbstractPackageTest {
|
|
|
346
340
|
}
|
|
347
341
|
|
|
348
342
|
private static async createAndAssertThrows(
|
|
349
|
-
option: keyof
|
|
343
|
+
option: keyof LslOutletOptions,
|
|
350
344
|
value: number | string[] | ChannelFormat,
|
|
351
345
|
expectedMessage: string
|
|
352
346
|
) {
|
|
@@ -368,9 +362,7 @@ export default class LslStreamOutletTest extends AbstractPackageTest {
|
|
|
368
362
|
return await this.LslStreamOutlet({ channelFormat: 'float32' })
|
|
369
363
|
}
|
|
370
364
|
|
|
371
|
-
private static async LslStreamOutlet(
|
|
372
|
-
options?: Partial<StreamOutletOptions>
|
|
373
|
-
) {
|
|
365
|
+
private static async LslStreamOutlet(options?: Partial<LslOutletOptions>) {
|
|
374
366
|
return await LslStreamOutlet.Create({
|
|
375
367
|
...this.randomOutletOptions,
|
|
376
368
|
...options,
|
|
@@ -379,7 +371,7 @@ export default class LslStreamOutletTest extends AbstractPackageTest {
|
|
|
379
371
|
}
|
|
380
372
|
|
|
381
373
|
class CheckingOutlet extends LslStreamOutlet {
|
|
382
|
-
public constructor(options:
|
|
374
|
+
public constructor(options: LslOutletOptions) {
|
|
383
375
|
super(options)
|
|
384
376
|
}
|
|
385
377
|
}
|
|
@@ -2,30 +2,28 @@ import { randomInt } from 'node:crypto'
|
|
|
2
2
|
|
|
3
3
|
import { test, assert } from '@neurodevs/node-tdd'
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { LslInletOptions } from '../../impl/LslStreamInlet.js'
|
|
6
6
|
import LslWebSocketBridge, {
|
|
7
|
-
|
|
7
|
+
LslWsBridgeOptions,
|
|
8
8
|
} from '../../impl/LslWebSocketBridge.js'
|
|
9
|
-
import
|
|
10
|
-
import
|
|
9
|
+
import FakeLslInlet from '../../testDoubles/LslInlet/FakeLslInlet.js'
|
|
10
|
+
import SpyLslWsBridge from '../../testDoubles/LslWsBridge/SpyLslWsBridge.js'
|
|
11
11
|
import FakeWebSocket from '../../testDoubles/WebSockets/FakeWebSocket.js'
|
|
12
12
|
import FakeWebSocketServer from '../../testDoubles/WebSockets/FakeWebSocketServer.js'
|
|
13
13
|
import AbstractPackageTest from '../AbstractPackageTest.js'
|
|
14
14
|
|
|
15
15
|
export default class LslWebSocketBridgeTest extends AbstractPackageTest {
|
|
16
|
-
private static instance:
|
|
16
|
+
private static instance: SpyLslWsBridge
|
|
17
17
|
|
|
18
18
|
protected static async beforeEach() {
|
|
19
19
|
await super.beforeEach()
|
|
20
20
|
|
|
21
|
-
this.
|
|
22
|
-
this.setFakeStreamInlet()
|
|
21
|
+
this.setFakeLslInlet()
|
|
23
22
|
this.setFakeWebSocket()
|
|
24
23
|
this.setFakeWebSocketServer()
|
|
25
|
-
this.
|
|
24
|
+
this.setSpyLslWsBridge()
|
|
26
25
|
|
|
27
|
-
this.instance =
|
|
28
|
-
(await this.LslWebSocketBridge()) as SpyLslWebSocketBridge
|
|
26
|
+
this.instance = (await this.LslWebSocketBridge()) as SpyLslWsBridge
|
|
29
27
|
}
|
|
30
28
|
|
|
31
29
|
@test()
|
|
@@ -35,7 +33,7 @@ export default class LslWebSocketBridgeTest extends AbstractPackageTest {
|
|
|
35
33
|
|
|
36
34
|
@test()
|
|
37
35
|
protected static async createsLslStreamInlet() {
|
|
38
|
-
const call =
|
|
36
|
+
const call = FakeLslInlet.callsToConstructor[0]
|
|
39
37
|
|
|
40
38
|
const sourceId = call.options!.sourceId
|
|
41
39
|
const chunkSize = call.options!.chunkSize
|
|
@@ -54,7 +52,7 @@ export default class LslWebSocketBridgeTest extends AbstractPackageTest {
|
|
|
54
52
|
await this.activate()
|
|
55
53
|
|
|
56
54
|
assert.isEqual(
|
|
57
|
-
|
|
55
|
+
FakeLslInlet.numCallsToStartPulling,
|
|
58
56
|
1,
|
|
59
57
|
'Did not call startPulling on inlet!'
|
|
60
58
|
)
|
|
@@ -66,7 +64,7 @@ export default class LslWebSocketBridgeTest extends AbstractPackageTest {
|
|
|
66
64
|
this.deactivate()
|
|
67
65
|
|
|
68
66
|
assert.isEqual(
|
|
69
|
-
|
|
67
|
+
FakeLslInlet.numCallsToStopPulling,
|
|
70
68
|
1,
|
|
71
69
|
'Did not call stopPulling on inlet!'
|
|
72
70
|
)
|
|
@@ -77,7 +75,7 @@ export default class LslWebSocketBridgeTest extends AbstractPackageTest {
|
|
|
77
75
|
this.destroy()
|
|
78
76
|
|
|
79
77
|
assert.isEqual(
|
|
80
|
-
|
|
78
|
+
FakeLslInlet.numCallsToDestroy,
|
|
81
79
|
1,
|
|
82
80
|
'Did not call destroy on inlet!'
|
|
83
81
|
)
|
|
@@ -270,7 +268,7 @@ export default class LslWebSocketBridgeTest extends AbstractPackageTest {
|
|
|
270
268
|
const samples = [...new Float32Array([1, 2, 3, 4, 5, 6])]
|
|
271
269
|
const timestamps = [...new Float64Array([7, 8])]
|
|
272
270
|
|
|
273
|
-
|
|
271
|
+
FakeLslInlet.callsToConstructor[0]?.onData!(samples, timestamps)
|
|
274
272
|
return { samples, timestamps }
|
|
275
273
|
}
|
|
276
274
|
|
|
@@ -278,7 +276,7 @@ export default class LslWebSocketBridgeTest extends AbstractPackageTest {
|
|
|
278
276
|
|
|
279
277
|
private static readonly connectUrls = [this.generateId(), this.generateId()]
|
|
280
278
|
|
|
281
|
-
private static readonly inletOptions:
|
|
279
|
+
private static readonly inletOptions: LslInletOptions = {
|
|
282
280
|
sourceId: this.sourceId,
|
|
283
281
|
chunkSize: randomInt(1, 100),
|
|
284
282
|
}
|
|
@@ -289,9 +287,7 @@ export default class LslWebSocketBridgeTest extends AbstractPackageTest {
|
|
|
289
287
|
connectUrls: this.connectUrls,
|
|
290
288
|
}
|
|
291
289
|
|
|
292
|
-
private static LslWebSocketBridge(
|
|
293
|
-
options?: Partial<WebSocketBridgeOptions>
|
|
294
|
-
) {
|
|
290
|
+
private static LslWebSocketBridge(options?: Partial<LslWsBridgeOptions>) {
|
|
295
291
|
return LslWebSocketBridge.Create({ ...this.baseOptions, ...options })
|
|
296
292
|
}
|
|
297
293
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { test, assert } from '@neurodevs/node-tdd'
|
|
2
2
|
|
|
3
3
|
import UsbDeviceController, {
|
|
4
|
-
|
|
4
|
+
UsbDevice,
|
|
5
5
|
} from '../../impl/controllers/UsbDeviceController.js'
|
|
6
6
|
import AbstractPackageTest from '../AbstractPackageTest.js'
|
|
7
7
|
import { FakeLibndx } from '@neurodevs/ndx-native'
|
|
8
8
|
|
|
9
9
|
export default class UsbDeviceControllerTest extends AbstractPackageTest {
|
|
10
|
-
private static instance:
|
|
10
|
+
private static instance: UsbDevice
|
|
11
11
|
|
|
12
12
|
private static readonly serialNumber = this.generateId()
|
|
13
13
|
private static readonly valueToWrite = this.generateId()
|
|
@@ -4,7 +4,7 @@ import { test, assert } from '@neurodevs/node-tdd'
|
|
|
4
4
|
|
|
5
5
|
import WindowedClockRegressor, {
|
|
6
6
|
ClockRegressor,
|
|
7
|
-
} from '../../impl/WindowedClockRegressor.js'
|
|
7
|
+
} from '../../impl/clocks/WindowedClockRegressor.js'
|
|
8
8
|
import AbstractPackageTest from '../AbstractPackageTest.js'
|
|
9
9
|
|
|
10
10
|
export default class WindowedClockRegressorTest extends AbstractPackageTest {
|
package/src/assertions.ts
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
import { generateShortId } from '@neurodevs/generate-id'
|
|
2
2
|
|
|
3
3
|
import LslStreamOutlet, {
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
LslOutletOptions,
|
|
5
|
+
LslOutlet,
|
|
6
6
|
} from './LslStreamOutlet.js'
|
|
7
7
|
|
|
8
|
-
export default class
|
|
9
|
-
public static Class?:
|
|
8
|
+
export default class LslEventMarkerOutlet implements EventMarkerOutlet {
|
|
9
|
+
public static Class?: EventMarkerOutletConstructor
|
|
10
10
|
|
|
11
|
-
protected outlet:
|
|
11
|
+
protected outlet: LslOutlet
|
|
12
12
|
private isRunning = false
|
|
13
13
|
private waitResolve?: () => void
|
|
14
14
|
private timeout?: any
|
|
15
15
|
|
|
16
|
-
protected constructor(outlet:
|
|
16
|
+
protected constructor(outlet: LslOutlet) {
|
|
17
17
|
this.outlet = outlet
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
public static async Create(options?:
|
|
20
|
+
public static async Create(options?: EventMarkerOutletOptions) {
|
|
21
21
|
const outlet = await this.LslStreamOutlet(options)
|
|
22
22
|
return new (this.Class ?? this)(outlet)
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
public async emit(markerName: string, options?:
|
|
25
|
+
public async emit(markerName: string, options?: EmitOptions) {
|
|
26
26
|
this.throwIfAlreadyRunning('emit')
|
|
27
27
|
this.isRunning = true
|
|
28
28
|
|
|
@@ -99,10 +99,10 @@ export default class LslEventMarkerEmitter implements EventMarkerEmitter {
|
|
|
99
99
|
channelFormat: 'string',
|
|
100
100
|
sampleRateHz: 0,
|
|
101
101
|
chunkSize: 1,
|
|
102
|
-
} as
|
|
102
|
+
} as LslOutletOptions
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
-
private static LslStreamOutlet(options?: Partial<
|
|
105
|
+
private static LslStreamOutlet(options?: Partial<LslOutletOptions>) {
|
|
106
106
|
return LslStreamOutlet.Create({
|
|
107
107
|
...this.generateDefaultOutletOptions(),
|
|
108
108
|
...options,
|
|
@@ -110,20 +110,20 @@ export default class LslEventMarkerEmitter implements EventMarkerEmitter {
|
|
|
110
110
|
}
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
-
export interface
|
|
114
|
-
emit(markerName: string, options?:
|
|
113
|
+
export interface EventMarkerOutlet {
|
|
114
|
+
emit(markerName: string, options?: EmitOptions): Promise<void>
|
|
115
115
|
emitMany(markers: TimedEventMarker[]): Promise<void>
|
|
116
116
|
interrupt(): void
|
|
117
117
|
destroy(): void
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
-
export type
|
|
120
|
+
export type EventMarkerOutletOptions = Partial<LslOutletOptions>
|
|
121
121
|
|
|
122
|
-
export type
|
|
123
|
-
outlet:
|
|
124
|
-
) =>
|
|
122
|
+
export type EventMarkerOutletConstructor = new (
|
|
123
|
+
outlet: LslOutlet
|
|
124
|
+
) => EventMarkerOutlet
|
|
125
125
|
|
|
126
|
-
export interface
|
|
126
|
+
export interface EmitOptions {
|
|
127
127
|
waitAfterMs?: number
|
|
128
128
|
}
|
|
129
129
|
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import LslStreamOutlet, { LslOutlet } from './LslStreamOutlet.js'
|
|
2
|
+
|
|
3
|
+
export default class LslJsonOutlet implements JsonOutlet {
|
|
4
|
+
public static Class?: JsonOutletConstructor
|
|
5
|
+
public static backupIdCounter = 0
|
|
6
|
+
|
|
7
|
+
private outlet: LslOutlet
|
|
8
|
+
private maxBytesPerSample?: number
|
|
9
|
+
|
|
10
|
+
protected constructor(outlet: LslOutlet, maxBytesPerSample?: number) {
|
|
11
|
+
this.outlet = outlet
|
|
12
|
+
this.maxBytesPerSample = maxBytesPerSample
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
public static async Create(options?: JsonOutletOptions) {
|
|
16
|
+
const outlet = await this.LslStreamOutlet(options)
|
|
17
|
+
return new (this.Class ?? this)(outlet, options?.maxBytesPerSample)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
public pushJson(data: Json) {
|
|
21
|
+
const json = JSON.stringify(data)
|
|
22
|
+
this.throwIfPayloadTooLarge(json)
|
|
23
|
+
this.outlet.pushSample([json])
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
private throwIfPayloadTooLarge(json: string) {
|
|
27
|
+
const totalBytes = Buffer.byteLength(json)
|
|
28
|
+
|
|
29
|
+
if (this.maxBytesPerSample && totalBytes > this.maxBytesPerSample) {
|
|
30
|
+
throw new Error(
|
|
31
|
+
`Payload of ${totalBytes} bytes exceeds maxBytesPerSample of ${this.maxBytesPerSample}!`
|
|
32
|
+
)
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
public destroy() {
|
|
37
|
+
this.outlet.destroy()
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
private static LslStreamOutlet(options?: JsonOutletOptions) {
|
|
41
|
+
this.backupIdCounter++
|
|
42
|
+
|
|
43
|
+
const { channelName, maxBytesPerSample: _, ...rest } = options ?? {}
|
|
44
|
+
|
|
45
|
+
return LslStreamOutlet.Create({
|
|
46
|
+
name: `JSON (json-${this.backupIdCounter})`,
|
|
47
|
+
type: 'JSON',
|
|
48
|
+
sourceId: `json-${this.backupIdCounter}`,
|
|
49
|
+
channelNames: [channelName ?? 'JSON'],
|
|
50
|
+
channelFormat: 'string',
|
|
51
|
+
sampleRateHz: 0,
|
|
52
|
+
chunkSize: 1,
|
|
53
|
+
...rest,
|
|
54
|
+
})
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface JsonOutlet {
|
|
59
|
+
pushJson(data: Json): void
|
|
60
|
+
destroy(): void
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export type Json = Record<string, unknown>
|
|
64
|
+
|
|
65
|
+
export type JsonOutletConstructor = new (
|
|
66
|
+
outlet: LslOutlet,
|
|
67
|
+
maxBytesPerSample?: number
|
|
68
|
+
) => JsonOutlet
|
|
69
|
+
|
|
70
|
+
export interface JsonOutletOptions {
|
|
71
|
+
name?: string
|
|
72
|
+
type?: string
|
|
73
|
+
sourceId?: string
|
|
74
|
+
channelName?: string
|
|
75
|
+
sampleRateHz?: number
|
|
76
|
+
chunkSize?: number
|
|
77
|
+
maxBufferedMs?: number
|
|
78
|
+
maxBytesPerSample?: number
|
|
79
|
+
manufacturer?: string
|
|
80
|
+
units?: string
|
|
81
|
+
waitAfterConstructionMs?: number
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export type JsonOutletConstructorOptions = Omit<
|
|
85
|
+
JsonOutletOptions,
|
|
86
|
+
'waitAfterConstructionMs'
|
|
87
|
+
>
|