@neurodevs/node-lsl 16.1.0 → 17.1.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.
Files changed (61) hide show
  1. package/build/__tests__/AbstractPackageTest.d.ts +3 -1
  2. package/build/__tests__/AbstractPackageTest.js +3 -7
  3. package/build/__tests__/AbstractPackageTest.js.map +1 -1
  4. package/build/__tests__/impl/LslStreamInfo.test.d.ts +3 -2
  5. package/build/__tests__/impl/LslStreamInfo.test.js +19 -12
  6. package/build/__tests__/impl/LslStreamInfo.test.js.map +1 -1
  7. package/build/__tests__/impl/LslStreamInlet.test.d.ts +1 -3
  8. package/build/__tests__/impl/LslStreamInlet.test.js +6 -27
  9. package/build/__tests__/impl/LslStreamInlet.test.js.map +1 -1
  10. package/build/__tests__/impl/LslWebSocketBridge.test.js +10 -16
  11. package/build/__tests__/impl/LslWebSocketBridge.test.js.map +1 -1
  12. package/build/impl/LslStreamInfo.d.ts +5 -8
  13. package/build/impl/LslStreamInfo.js +13 -13
  14. package/build/impl/LslStreamInfo.js.map +1 -1
  15. package/build/impl/LslStreamInlet.d.ts +6 -17
  16. package/build/impl/LslStreamInlet.js +5 -21
  17. package/build/impl/LslStreamInlet.js.map +1 -1
  18. package/build/impl/LslStreamOutlet.d.ts +3 -3
  19. package/build/impl/LslStreamOutlet.js +5 -8
  20. package/build/impl/LslStreamOutlet.js.map +1 -1
  21. package/build/impl/LslWebSocketBridge.d.ts +3 -8
  22. package/build/impl/LslWebSocketBridge.js +3 -3
  23. package/build/impl/LslWebSocketBridge.js.map +1 -1
  24. package/build/scripts/runLslStreamOutlet.js +15 -10
  25. package/build/scripts/runLslStreamOutlet.js.map +1 -1
  26. package/build/scripts/runOutletToInlet.js +2 -7
  27. package/build/scripts/runOutletToInlet.js.map +1 -1
  28. package/build/testDoubles/Liblsl/FakeLiblsl.d.ts +1 -1
  29. package/build/testDoubles/Liblsl/FakeLiblsl.js +2 -2
  30. package/build/testDoubles/Liblsl/FakeLiblsl.js.map +1 -1
  31. package/build/testDoubles/StreamInfo/FakeStreamInfo.d.ts +4 -4
  32. package/build/testDoubles/StreamInfo/FakeStreamInfo.js +4 -4
  33. package/build/testDoubles/StreamInfo/FakeStreamInfo.js.map +1 -1
  34. package/build/testDoubles/StreamInfo/SpyStreamInfo.d.ts +0 -1
  35. package/build/testDoubles/StreamInfo/SpyStreamInfo.js +0 -3
  36. package/build/testDoubles/StreamInfo/SpyStreamInfo.js.map +1 -1
  37. package/build/testDoubles/StreamInlet/FakeStreamInlet.d.ts +3 -3
  38. package/build/testDoubles/StreamInlet/FakeStreamInlet.js.map +1 -1
  39. package/build/testDoubles/StreamInlet/SpyStreamInlet.d.ts +2 -3
  40. package/build/testDoubles/StreamInlet/SpyStreamInlet.js +0 -3
  41. package/build/testDoubles/StreamInlet/SpyStreamInlet.js.map +1 -1
  42. package/build/testDoubles/StreamOutlet/FakeStreamOutlet.d.ts +1 -0
  43. package/build/testDoubles/StreamOutlet/FakeStreamOutlet.js +3 -0
  44. package/build/testDoubles/StreamOutlet/FakeStreamOutlet.js.map +1 -1
  45. package/package.json +11 -11
  46. package/src/__tests__/AbstractPackageTest.ts +3 -7
  47. package/src/__tests__/impl/LslStreamInfo.test.ts +22 -11
  48. package/src/__tests__/impl/LslStreamInlet.test.ts +9 -34
  49. package/src/__tests__/impl/LslWebSocketBridge.test.ts +11 -25
  50. package/src/impl/LslStreamInfo.ts +24 -23
  51. package/src/impl/LslStreamInlet.ts +15 -46
  52. package/src/impl/LslStreamOutlet.ts +6 -9
  53. package/src/impl/LslWebSocketBridge.ts +6 -12
  54. package/src/scripts/runLslStreamOutlet.ts +16 -10
  55. package/src/scripts/runOutletToInlet.ts +7 -9
  56. package/src/testDoubles/Liblsl/FakeLiblsl.ts +2 -2
  57. package/src/testDoubles/StreamInfo/FakeStreamInfo.ts +6 -6
  58. package/src/testDoubles/StreamInfo/SpyStreamInfo.ts +0 -4
  59. package/src/testDoubles/StreamInlet/FakeStreamInlet.ts +6 -3
  60. package/src/testDoubles/StreamInlet/SpyStreamInlet.ts +2 -6
  61. package/src/testDoubles/StreamOutlet/FakeStreamOutlet.ts +4 -0
@@ -1,19 +1,25 @@
1
1
  import LslStreamOutlet from '../impl/LslStreamOutlet.js'
2
2
 
3
3
  async function main() {
4
- const instance = await LslStreamOutlet.Create({
5
- name: 'Muse S (2nd gen)',
6
- type: 'EEG',
7
- channelNames: ['TP9', 'AF7', 'AF8', 'TP10', 'AUX'],
8
- sampleRateHz: 256,
4
+ const outlet = await LslStreamOutlet.Create({
5
+ name: '10 Hz Pulse',
6
+ type: 'HZ',
7
+ sourceId: '10-hz-pulse',
8
+ channelNames: ['Ch1', 'Ch2', 'Ch3'],
9
9
  channelFormat: 'float32',
10
- sourceId: 'muse-s-eeg',
11
- manufacturer: 'Interaxon Inc.',
12
- units: 'microvolt',
13
- chunkSize: 12,
10
+ sampleRateHz: 10,
11
+ chunkSize: 1,
14
12
  })
15
13
 
16
- instance.pushSample([1, 2, 3, 4, 5])
14
+ for (let i = 0; i < 100; i++) {
15
+ await new Promise((resolve) => setTimeout(resolve, 100))
16
+
17
+ outlet.pushSample([
18
+ Math.random() * 100,
19
+ Math.random() * 100,
20
+ Math.random() * 100,
21
+ ])
22
+ }
17
23
  }
18
24
 
19
25
  main().catch((error) => {
@@ -17,18 +17,16 @@ const outlet = await LslStreamOutlet.Create({
17
17
  console.log('Creating inlet...')
18
18
 
19
19
  const inletOptions = {
20
- name: 'TestOutlet',
21
- type: 'TEST',
22
- sourceId: 'TestOutletID',
23
- sampleRateHz: 100,
24
- channelNames: ['Ch1', 'Ch2', 'Ch3'],
25
- channelFormat: 'float32' as const,
20
+ info: outlet.info,
26
21
  chunkSize: 1,
27
22
  }
28
23
 
29
- const inlet = LslStreamInlet.Create(inletOptions, (samples, timestamps) => {
30
- console.log('Received samples:', samples, 'at timestamps:', timestamps)
31
- })
24
+ const inlet = await LslStreamInlet.Create(
25
+ inletOptions,
26
+ (samples, timestamps) => {
27
+ console.log('Received samples:', samples, 'at timestamps:', timestamps)
28
+ }
29
+ )
32
30
 
33
31
  console.log('Start pulling...')
34
32
  inlet.startPulling()
@@ -21,7 +21,7 @@ import {
21
21
  } from 'impl/LiblslAdapter.js'
22
22
 
23
23
  export default class FakeLiblsl implements Liblsl {
24
- public static fakeResolveHandles: bigint[] = []
24
+ public static fakeStreamInfoHandles: BoundStreamInfo[] = []
25
25
 
26
26
  public static fakeSamples: Float32Array[] = [
27
27
  new Float32Array([1, 2, 3]),
@@ -90,7 +90,7 @@ export default class FakeLiblsl implements Liblsl {
90
90
 
91
91
  public async resolveByProp(options: ResolveByPropOptions) {
92
92
  this.lastResolveByPropOptions = options
93
- return FakeLiblsl.fakeResolveHandles
93
+ return FakeLiblsl.fakeStreamInfoHandles as bigint[]
94
94
  }
95
95
 
96
96
  public pushSampleFloatTimestamp(options: PushSampleFloatTimestampOptions) {
@@ -4,20 +4,20 @@ import { BoundStreamInfo } from 'impl/LiblslAdapter.js'
4
4
  import { StreamInfo, StreamInfoOptions } from '../../impl/LslStreamInfo.js'
5
5
 
6
6
  export default class FakeStreamInfo implements StreamInfo {
7
- public static callsToConstructor: StreamInfoOptions[] = []
7
+ public static callsToConstructor: (StreamInfoOptions | undefined)[] = []
8
8
  public static numCallsToDestroy = 0
9
9
 
10
- public static boundStreamInfo = {} as BoundStreamInfo
10
+ public static boundInfo = {} as BoundStreamInfo
11
11
 
12
12
  public name = generateId()
13
13
  public type = generateId()
14
14
  public sourceId = generateId()
15
- public channelNames: string[] = [generateId(), generateId()]
15
+ public channelNames: string[] = [generateId(), generateId(), generateId()]
16
16
  public channelFormat = 'float32' as const
17
17
  public sampleRateHz = 0
18
18
  public units = 'N/A'
19
19
 
20
- public constructor(options: StreamInfoOptions) {
20
+ public constructor(options?: StreamInfoOptions) {
21
21
  FakeStreamInfo.callsToConstructor.push(options)
22
22
  }
23
23
 
@@ -29,8 +29,8 @@ export default class FakeStreamInfo implements StreamInfo {
29
29
  return this.channelNames.length
30
30
  }
31
31
 
32
- public get boundStreamInfo() {
33
- return FakeStreamInfo.boundStreamInfo
32
+ public get boundInfo() {
33
+ return FakeStreamInfo.boundInfo
34
34
  }
35
35
 
36
36
  public static resetTestDouble() {
@@ -8,10 +8,6 @@ export default class SpyStreamInfo extends LslStreamInfo {
8
8
  SpyStreamInfo.numCallsToConstructor++
9
9
  }
10
10
 
11
- public getBoundInfo() {
12
- return this.boundInfo
13
- }
14
-
15
11
  public getName() {
16
12
  return this.name
17
13
  }
@@ -1,10 +1,13 @@
1
1
  import { StreamInfo } from '../../impl/LslStreamInfo.js'
2
- import { StreamInlet, StreamInletOptions } from '../../impl/LslStreamInlet.js'
2
+ import {
3
+ StreamInlet,
4
+ StreamInletConstructorOptions,
5
+ } from '../../impl/LslStreamInlet.js'
3
6
 
4
7
  export default class FakeStreamInlet implements StreamInlet {
5
8
  public static callsToConstructor: {
6
9
  info?: StreamInfo
7
- options?: StreamInletOptions
10
+ options?: StreamInletConstructorOptions
8
11
  onData?: (samples: Float32Array, timestamps: Float64Array) => void
9
12
  }[] = []
10
13
 
@@ -19,7 +22,7 @@ export default class FakeStreamInlet implements StreamInlet {
19
22
 
20
23
  public constructor(
21
24
  info?: StreamInfo,
22
- options?: StreamInletOptions,
25
+ options?: StreamInletConstructorOptions,
23
26
  onData?: (samples: Float32Array, timestamps: Float64Array) => void
24
27
  ) {
25
28
  this.onData = onData ?? (() => {})
@@ -1,22 +1,18 @@
1
1
  import { StreamInfo } from '../../impl/LslStreamInfo.js'
2
2
  import LslStreamInlet, {
3
3
  OnDataCallback,
4
- StreamInletOptions,
4
+ StreamInletConstructorOptions,
5
5
  } from '../../impl/LslStreamInlet.js'
6
6
 
7
7
  export class SpyStreamInlet extends LslStreamInlet {
8
8
  public constructor(
9
9
  info: StreamInfo,
10
- options: StreamInletOptions,
10
+ options: StreamInletConstructorOptions,
11
11
  onData: OnDataCallback
12
12
  ) {
13
13
  super(info, options, onData)
14
14
  }
15
15
 
16
- public getName() {
17
- return this.name
18
- }
19
-
20
16
  public getStreamInfo() {
21
17
  return this.info
22
18
  }
@@ -7,6 +7,7 @@ import {
7
7
  StreamOutlet,
8
8
  StreamOutletOptions,
9
9
  } from '../../impl/LslStreamOutlet.js'
10
+ import FakeStreamInfo from '../StreamInfo/FakeStreamInfo.js'
10
11
 
11
12
  export default class FakeStreamOutlet implements StreamOutlet {
12
13
  public static callsToConstructor: {
@@ -17,10 +18,13 @@ export default class FakeStreamOutlet implements StreamOutlet {
17
18
  public static callsToPushSample: LslSample[] = []
18
19
  public static numCallsToDestroy = 0
19
20
 
21
+ public info: StreamInfo
20
22
  public options?: StreamOutletOptions
21
23
 
22
24
  public constructor(info?: StreamInfo, options?: StreamOutletOptions) {
23
25
  FakeStreamOutlet.callsToConstructor.push({ info, options })
26
+
27
+ this.info = info ?? new FakeStreamInfo()
24
28
  this.options = options
25
29
  }
26
30