@neurodevs/node-lsl 16.0.3 → 16.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 (30) hide show
  1. package/build/__tests__/AbstractPackageTest.js +0 -2
  2. package/build/__tests__/AbstractPackageTest.js.map +1 -1
  3. package/build/__tests__/impl/LiblslAdapter.test.d.ts +13 -0
  4. package/build/__tests__/impl/LiblslAdapter.test.js +87 -1
  5. package/build/__tests__/impl/LiblslAdapter.test.js.map +1 -1
  6. package/build/__tests__/impl/LslStreamInfo.test.d.ts +2 -1
  7. package/build/__tests__/impl/LslStreamInfo.test.js +16 -6
  8. package/build/__tests__/impl/LslStreamInfo.test.js.map +1 -1
  9. package/build/__tests__/impl/LslStreamInlet.test.js +2 -1
  10. package/build/__tests__/impl/LslStreamInlet.test.js.map +1 -1
  11. package/build/__tests__/impl/LslWebSocketBridge.test.js +1 -0
  12. package/build/__tests__/impl/LslWebSocketBridge.test.js.map +1 -1
  13. package/build/impl/LiblslAdapter.d.ts +14 -4
  14. package/build/impl/LiblslAdapter.js +49 -5
  15. package/build/impl/LiblslAdapter.js.map +1 -1
  16. package/build/impl/LslStreamInfo.d.ts +1 -1
  17. package/build/impl/LslStreamInfo.js +9 -20
  18. package/build/impl/LslStreamInfo.js.map +1 -1
  19. package/build/testDoubles/Liblsl/FakeLiblsl.d.ts +8 -4
  20. package/build/testDoubles/Liblsl/FakeLiblsl.js +12 -4
  21. package/build/testDoubles/Liblsl/FakeLiblsl.js.map +1 -1
  22. package/package.json +1 -1
  23. package/src/__tests__/AbstractPackageTest.ts +0 -4
  24. package/src/__tests__/impl/LiblslAdapter.test.ts +118 -2
  25. package/src/__tests__/impl/LslStreamInfo.test.ts +20 -6
  26. package/src/__tests__/impl/LslStreamInlet.test.ts +2 -1
  27. package/src/__tests__/impl/LslWebSocketBridge.test.ts +1 -0
  28. package/src/impl/LiblslAdapter.ts +84 -11
  29. package/src/impl/LslStreamInfo.ts +9 -31
  30. package/src/testDoubles/Liblsl/FakeLiblsl.ts +18 -6
@@ -7,8 +7,6 @@ import LiblslAdapter from './LiblslAdapter.js'
7
7
  export default class LslStreamInfo implements StreamInfo {
8
8
  public static Class?: StreamInfoConstructor
9
9
 
10
- private static instanceCache: Record<string, StreamInfo> = {}
11
-
12
10
  public readonly name: string
13
11
  public readonly type: string
14
12
  public readonly sourceId: string
@@ -36,6 +34,7 @@ export default class LslStreamInfo implements StreamInfo {
36
34
  channelFormat,
37
35
  sampleRateHz,
38
36
  units = this.defaultUnits,
37
+ boundStreamInfo,
39
38
  } = options
40
39
 
41
40
  this.name = name
@@ -47,38 +46,16 @@ export default class LslStreamInfo implements StreamInfo {
47
46
  this.sampleRateHz = sampleRateHz
48
47
  this.units = units
49
48
 
50
- this.createStreamInfo()
51
- this.appendChannelsToStreamInfo()
49
+ if (!boundStreamInfo) {
50
+ this.createStreamInfo()
51
+ this.appendChannelsToStreamInfo()
52
+ } else {
53
+ this.boundInfo = boundStreamInfo
54
+ }
52
55
  }
53
56
 
54
57
  public static Create(options: StreamInfoOptions) {
55
- const {
56
- name,
57
- type,
58
- sourceId,
59
- channelNames,
60
- channelFormat,
61
- sampleRateHz,
62
- } = options
63
-
64
- const channelCount = channelNames.length
65
-
66
- const key = JSON.stringify({
67
- name,
68
- type,
69
- sourceId,
70
- channelCount,
71
- channelFormat,
72
- sampleRateHz,
73
- })
74
-
75
- let instance = this.instanceCache[key]
76
-
77
- if (instance === undefined) {
78
- instance = new (this.Class ?? this)(options)
79
- this.instanceCache[key] = instance
80
- }
81
- return instance
58
+ return new (this.Class ?? this)(options)
82
59
  }
83
60
 
84
61
  private createStreamInfo() {
@@ -139,4 +116,5 @@ export interface StreamInfoOptions {
139
116
  type?: string
140
117
  sourceId?: string
141
118
  units?: string
119
+ boundStreamInfo?: BoundStreamInfo
142
120
  }
@@ -16,9 +16,13 @@ import {
16
16
  PullChunkOptions,
17
17
  PullSampleOptions,
18
18
  DestroyStreamInfoOptions,
19
+ ResolveByPropOptions,
20
+ DestroyOutletOptions,
19
21
  } from 'impl/LiblslAdapter.js'
20
22
 
21
23
  export default class FakeLiblsl implements Liblsl {
24
+ public static fakeResolveHandles: bigint[] = []
25
+
22
26
  public static fakeSamples: Float32Array[] = [
23
27
  new Float32Array([1, 2, 3]),
24
28
  new Float32Array([4, 5, 6]),
@@ -46,12 +50,14 @@ export default class FakeLiblsl implements Liblsl {
46
50
  public streamInfo: BoundStreamInfo = {} as BoundStreamInfo
47
51
 
48
52
  public lastCreateStreamInfoOptions?: CreateStreamInfoOptions
49
- public lastDestroyStreamInfoOptions?: DestroyStreamInfoOptions
50
53
  public lastAppendChannelsToStreamInfoOptions?: AppendChannelsToStreamInfoOptions
54
+ public lastDestroyStreamInfoOptions?: DestroyStreamInfoOptions
55
+ public lastResolveByPropOptions?: ResolveByPropOptions
51
56
  public lastCreateOutletOptions?: CreateOutletOptions
52
57
  public lastPushSampleFloatTimestampOptions?: PushSampleFloatTimestampOptions
53
58
  public lastPushSampleStringTimestampOptions?: PushSampleStringTimestampOptions
54
59
  public lastCreateInletOptions?: CreateInletOptions
60
+ public lastDestroyOutletOptions?: DestroyOutletOptions
55
61
  public lastPullSampleOptions?: PullSampleOptions
56
62
  public lastPullChunkOptions?: PullChunkOptions
57
63
  public lastFlushInletOptions?: FlushInletOptions
@@ -72,16 +78,21 @@ export default class FakeLiblsl implements Liblsl {
72
78
  return this.streamInfo
73
79
  }
74
80
 
75
- public destroyStreamInfo(options: DestroyStreamInfoOptions) {
76
- this.lastDestroyStreamInfoOptions = options
77
- }
78
-
79
81
  public appendChannelsToStreamInfo(
80
82
  options: AppendChannelsToStreamInfoOptions
81
83
  ) {
82
84
  this.lastAppendChannelsToStreamInfoOptions = options
83
85
  }
84
86
 
87
+ public destroyStreamInfo(options: DestroyStreamInfoOptions) {
88
+ this.lastDestroyStreamInfoOptions = options
89
+ }
90
+
91
+ public async resolveByProp(options: ResolveByPropOptions) {
92
+ this.lastResolveByPropOptions = options
93
+ return FakeLiblsl.fakeResolveHandles
94
+ }
95
+
85
96
  public pushSampleFloatTimestamp(options: PushSampleFloatTimestampOptions) {
86
97
  this.lastPushSampleFloatTimestampOptions = options
87
98
  return FakeLiblsl.fakeErrorCode
@@ -101,8 +112,9 @@ export default class FakeLiblsl implements Liblsl {
101
112
  return this.outlet
102
113
  }
103
114
 
104
- public destroyOutlet() {
115
+ public destroyOutlet(options: DestroyOutletOptions) {
105
116
  this.destroyOutletHitCount++
117
+ this.lastDestroyOutletOptions = options
106
118
  }
107
119
 
108
120
  public createInlet(options: CreateInletOptions) {