@neurodevs/node-lsl 12.0.6 → 13.0.1

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 (122) hide show
  1. package/README.md +2 -5
  2. package/build/__tests__/AbstractPackageTest.d.ts +9 -3
  3. package/build/__tests__/AbstractPackageTest.js +37 -3
  4. package/build/__tests__/AbstractPackageTest.js.map +1 -1
  5. package/build/__tests__/impl/LiblslAdapter.test.d.ts +6 -0
  6. package/build/__tests__/impl/LiblslAdapter.test.js +133 -12
  7. package/build/__tests__/impl/LiblslAdapter.test.js.map +1 -1
  8. package/build/__tests__/impl/LslEventMarkerOutlet.test.js +5 -5
  9. package/build/__tests__/impl/LslEventMarkerOutlet.test.js.map +1 -1
  10. package/build/__tests__/impl/LslStreamInfo.test.js +3 -3
  11. package/build/__tests__/impl/LslStreamInfo.test.js.map +1 -1
  12. package/build/__tests__/impl/LslStreamInlet.test.d.ts +30 -2
  13. package/build/__tests__/impl/LslStreamInlet.test.js +181 -18
  14. package/build/__tests__/impl/LslStreamInlet.test.js.map +1 -1
  15. package/build/__tests__/impl/LslStreamOutlet.test.d.ts +16 -7
  16. package/build/__tests__/impl/LslStreamOutlet.test.js +84 -23
  17. package/build/__tests__/impl/LslStreamOutlet.test.js.map +1 -1
  18. package/build/__tests__/impl/LslWebSocketBridge.test.d.ts +15 -0
  19. package/build/__tests__/impl/LslWebSocketBridge.test.js +112 -2
  20. package/build/__tests__/impl/LslWebSocketBridge.test.js.map +1 -1
  21. package/build/assertions.d.ts +3 -3
  22. package/build/assertions.js +6 -6
  23. package/build/assertions.js.map +1 -1
  24. package/build/handleError.d.ts +8 -0
  25. package/build/handleError.js +25 -0
  26. package/build/handleError.js.map +1 -0
  27. package/build/impl/LiblslAdapter.d.ts +128 -13
  28. package/build/impl/LiblslAdapter.js +149 -71
  29. package/build/impl/LiblslAdapter.js.map +1 -1
  30. package/build/impl/LslEventMarkerOutlet.d.ts +4 -1
  31. package/build/impl/LslEventMarkerOutlet.js +3 -3
  32. package/build/impl/LslEventMarkerOutlet.js.map +1 -1
  33. package/build/impl/LslStreamInfo.d.ts +3 -3
  34. package/build/impl/LslStreamInfo.js +5 -5
  35. package/build/impl/LslStreamInfo.js.map +1 -1
  36. package/build/impl/LslStreamInlet.d.ts +52 -14
  37. package/build/impl/LslStreamInlet.js +157 -20
  38. package/build/impl/LslStreamInlet.js.map +1 -1
  39. package/build/impl/LslStreamOutlet.d.ts +13 -13
  40. package/build/impl/LslStreamOutlet.js +22 -21
  41. package/build/impl/LslStreamOutlet.js.map +1 -1
  42. package/build/impl/LslWebSocketBridge.d.ts +35 -3
  43. package/build/impl/LslWebSocketBridge.js +66 -3
  44. package/build/impl/LslWebSocketBridge.js.map +1 -1
  45. package/build/index.d.ts +4 -1
  46. package/build/index.js +5 -1
  47. package/build/index.js.map +1 -1
  48. package/build/scripts/runLslStreamOutlet.js +2 -3
  49. package/build/scripts/runLslStreamOutlet.js.map +1 -1
  50. package/build/scripts/runOutletToInlet.d.ts +1 -0
  51. package/build/scripts/runOutletToInlet.js +45 -0
  52. package/build/scripts/runOutletToInlet.js.map +1 -0
  53. package/build/testDoubles/EventMarkerOutlet/FakeEventMarkerOutlet.d.ts +1 -2
  54. package/build/testDoubles/EventMarkerOutlet/FakeEventMarkerOutlet.js.map +1 -1
  55. package/build/testDoubles/EventMarkerOutlet/MockEventMarkerOutlet.d.ts +2 -2
  56. package/build/testDoubles/EventMarkerOutlet/MockEventMarkerOutlet.js.map +1 -1
  57. package/build/testDoubles/EventMarkerOutlet/ThrowingEventMarkerOutlet.d.ts +1 -2
  58. package/build/testDoubles/EventMarkerOutlet/ThrowingEventMarkerOutlet.js.map +1 -1
  59. package/build/testDoubles/Liblsl/FakeLiblsl.d.ts +15 -3
  60. package/build/testDoubles/Liblsl/FakeLiblsl.js +42 -0
  61. package/build/testDoubles/Liblsl/FakeLiblsl.js.map +1 -1
  62. package/build/testDoubles/StreamInfo/FakeStreamInfo.d.ts +1 -1
  63. package/build/testDoubles/StreamInfo/SpyStreamInfo.d.ts +1 -1
  64. package/build/testDoubles/StreamInlet/FakeStreamInlet.d.ts +12 -3
  65. package/build/testDoubles/StreamInlet/FakeStreamInlet.js +25 -5
  66. package/build/testDoubles/StreamInlet/FakeStreamInlet.js.map +1 -1
  67. package/build/testDoubles/StreamInlet/SpyStreamInlet.d.ts +3 -3
  68. package/build/testDoubles/StreamInlet/SpyStreamInlet.js +2 -2
  69. package/build/testDoubles/StreamInlet/SpyStreamInlet.js.map +1 -1
  70. package/build/testDoubles/StreamOutlet/FakeStreamOutlet.d.ts +4 -4
  71. package/build/testDoubles/StreamOutlet/FakeStreamOutlet.js +6 -6
  72. package/build/testDoubles/StreamOutlet/FakeStreamOutlet.js.map +1 -1
  73. package/build/testDoubles/StreamTransportBridge/FakeStreamTransportBridge.d.ts +6 -0
  74. package/build/testDoubles/StreamTransportBridge/FakeStreamTransportBridge.js +15 -0
  75. package/build/testDoubles/StreamTransportBridge/FakeStreamTransportBridge.js.map +1 -1
  76. package/build/testDoubles/StreamTransportBridge/SpyLslWebSocketBridge.d.ts +4 -0
  77. package/build/testDoubles/StreamTransportBridge/SpyLslWebSocketBridge.js +7 -0
  78. package/build/testDoubles/StreamTransportBridge/SpyLslWebSocketBridge.js.map +1 -0
  79. package/build/testDoubles/WebSockets/FakeWebSocket.d.ts +10 -0
  80. package/build/testDoubles/WebSockets/FakeWebSocket.js +14 -0
  81. package/build/testDoubles/WebSockets/FakeWebSocket.js.map +1 -0
  82. package/build/testDoubles/WebSockets/FakeWebSocketServer.d.ts +13 -0
  83. package/build/testDoubles/WebSockets/FakeWebSocketServer.js +22 -0
  84. package/build/testDoubles/WebSockets/FakeWebSocketServer.js.map +1 -0
  85. package/build/testDoubles/generateRandomOutletOptions.js +3 -3
  86. package/build/testDoubles/generateRandomOutletOptions.js.map +1 -1
  87. package/package.json +5 -3
  88. package/src/__tests__/AbstractPackageTest.ts +52 -4
  89. package/src/__tests__/impl/LiblslAdapter.test.ts +181 -16
  90. package/src/__tests__/impl/LslEventMarkerOutlet.test.ts +5 -5
  91. package/src/__tests__/impl/LslStreamInfo.test.ts +3 -3
  92. package/src/__tests__/impl/LslStreamInlet.test.ts +253 -20
  93. package/src/__tests__/impl/LslStreamOutlet.test.ts +111 -24
  94. package/src/__tests__/impl/LslWebSocketBridge.test.ts +163 -5
  95. package/src/assertions.ts +7 -7
  96. package/src/handleError.ts +24 -0
  97. package/src/impl/LiblslAdapter.ts +322 -97
  98. package/src/impl/LslEventMarkerOutlet.ts +8 -4
  99. package/src/impl/LslStreamInfo.ts +9 -9
  100. package/src/impl/LslStreamInlet.ts +233 -25
  101. package/src/impl/LslStreamOutlet.ts +43 -33
  102. package/src/impl/LslWebSocketBridge.ts +115 -5
  103. package/src/index.ts +8 -2
  104. package/src/scripts/runLslStreamOutlet.ts +2 -3
  105. package/src/scripts/runOutletToInlet.ts +53 -0
  106. package/src/testDoubles/EventMarkerOutlet/FakeEventMarkerOutlet.ts +4 -2
  107. package/src/testDoubles/EventMarkerOutlet/MockEventMarkerOutlet.ts +5 -2
  108. package/src/testDoubles/EventMarkerOutlet/ThrowingEventMarkerOutlet.ts +4 -2
  109. package/src/testDoubles/Liblsl/FakeLiblsl.ts +61 -1
  110. package/src/testDoubles/StreamInfo/FakeStreamInfo.ts +1 -1
  111. package/src/testDoubles/StreamInlet/FakeStreamInlet.ts +36 -5
  112. package/src/testDoubles/StreamInlet/SpyStreamInlet.ts +7 -2
  113. package/src/testDoubles/StreamOutlet/FakeStreamOutlet.ts +7 -7
  114. package/src/testDoubles/StreamTransportBridge/FakeStreamTransportBridge.ts +18 -0
  115. package/src/testDoubles/StreamTransportBridge/SpyLslWebSocketBridge.ts +9 -0
  116. package/src/testDoubles/WebSockets/FakeWebSocket.ts +17 -0
  117. package/src/testDoubles/WebSockets/FakeWebSocketServer.ts +32 -0
  118. package/src/testDoubles/generateRandomOutletOptions.ts +3 -3
  119. package/build/types.d.ts +0 -95
  120. package/build/types.js +0 -2
  121. package/build/types.js.map +0 -1
  122. package/src/types.ts +0 -111
@@ -0,0 +1,53 @@
1
+ import LslStreamInlet from '../impl/LslStreamInlet.js'
2
+ import LslStreamOutlet from '../impl/LslStreamOutlet.js'
3
+
4
+ console.log('Creating outlet...')
5
+ const outlet = await LslStreamOutlet.Create({
6
+ name: 'TestOutlet',
7
+ type: 'TEST',
8
+ sourceId: 'TestOutletID',
9
+ sampleRateHz: 100,
10
+ channelNames: ['Ch1', 'Ch2', 'Ch3'],
11
+ channelFormat: 'float32',
12
+ chunkSize: 1,
13
+ units: 'test',
14
+ manufacturer: 'test',
15
+ })
16
+
17
+ console.log('Creating inlet...')
18
+
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,
26
+ chunkSize: 1,
27
+ }
28
+
29
+ const inlet = LslStreamInlet.Create(inletOptions, (samples, timestamps) => {
30
+ console.log('Received samples:', samples, 'at timestamps:', timestamps)
31
+ })
32
+
33
+ console.log('Start pulling...')
34
+ inlet.startPulling()
35
+
36
+ console.log('Waiting for 100 ms...')
37
+ await new Promise((resolve) => setTimeout(resolve, 100))
38
+
39
+ console.log('Pushing samples...')
40
+ for (let i = 0; i < 300; i++) {
41
+ const sample = [i, i, i]
42
+ outlet.pushSample(sample)
43
+ await new Promise((resolve) => setTimeout(resolve, 10))
44
+ }
45
+
46
+ await new Promise((resolve) => setTimeout(resolve, 1000))
47
+
48
+ console.log('Pushing more samples...')
49
+ for (let i = 0; i < 30; i++) {
50
+ const sample = [i, i, i]
51
+ outlet.pushSample(sample)
52
+ await new Promise((resolve) => setTimeout(resolve, 100))
53
+ }
@@ -1,5 +1,7 @@
1
- import { EventMarkerOutlet } from '../../impl/LslEventMarkerOutlet.js'
2
- import { DurationMarker } from '../../types.js'
1
+ import {
2
+ DurationMarker,
3
+ EventMarkerOutlet,
4
+ } from '../../impl/LslEventMarkerOutlet.js'
3
5
 
4
6
  export default class FakeEventMarkerOutlet implements EventMarkerOutlet {
5
7
  public static callsToPushMarker: string[] = []
@@ -1,7 +1,10 @@
1
1
  import { assert } from '@neurodevs/node-tdd'
2
2
 
3
- import { EventMarkerOutlet } from '../../impl/LslEventMarkerOutlet.js'
4
- import { DurationMarker, LslSample } from '../../types.js'
3
+ import { LslSample } from 'impl/LiblslAdapter.js'
4
+ import {
5
+ DurationMarker,
6
+ EventMarkerOutlet,
7
+ } from '../../impl/LslEventMarkerOutlet.js'
5
8
 
6
9
  export default class MockEventMarkerOutlet implements EventMarkerOutlet {
7
10
  private didPushMarkers = false
@@ -1,5 +1,7 @@
1
- import { EventMarkerOutlet } from '../../impl/LslEventMarkerOutlet.js'
2
- import { DurationMarker } from '../../types.js'
1
+ import {
2
+ DurationMarker,
3
+ EventMarkerOutlet,
4
+ } from '../../impl/LslEventMarkerOutlet.js'
3
5
 
4
6
  export default class ThrowingEventMarkerOutlet implements EventMarkerOutlet {
5
7
  private errorMsg = 'Intentional throwing: '
@@ -1,3 +1,5 @@
1
+ import generateId from '@neurodevs/generate-id'
2
+
1
3
  import {
2
4
  BoundOutlet,
3
5
  BoundStreamInfo,
@@ -11,9 +13,34 @@ import {
11
13
  DestroyInletOptions,
12
14
  BoundInlet,
13
15
  FlushInletOptions,
14
- } from '../../types.js'
16
+ PullChunkOptions,
17
+ PullSampleOptions,
18
+ } from 'impl/LiblslAdapter.js'
15
19
 
16
20
  export default class FakeLiblsl implements Liblsl {
21
+ public static fakeSamples: Float32Array[] = [
22
+ new Float32Array([1, 2, 3]),
23
+ new Float32Array([4, 5, 6]),
24
+ ]
25
+
26
+ public static fakeChunks: Float32Array[] = [
27
+ new Float32Array([1, 2, 3, 4, 5, 6]),
28
+ new Float32Array([1, 2, 3, 4, 5, 6]),
29
+ ]
30
+
31
+ public static fakeTimestamps: Float64Array[] = [
32
+ new Float64Array([7, 8]),
33
+ new Float64Array([7, 8]),
34
+ ]
35
+
36
+ public static fakeErrorCode = 0
37
+
38
+ public liblslPath: string = generateId()
39
+
40
+ public fakeSamples = FakeLiblsl.fakeSamples.slice()
41
+ public fakeChunks = FakeLiblsl.fakeChunks.slice()
42
+ public fakeTimestamps = FakeLiblsl.fakeTimestamps.slice()
43
+
17
44
  public outlet: BoundOutlet = {} as BoundOutlet
18
45
  public streamInfo: BoundStreamInfo = {} as BoundStreamInfo
19
46
 
@@ -23,6 +50,8 @@ export default class FakeLiblsl implements Liblsl {
23
50
  public lastPushSampleFloatTimestampOptions?: PushSampleFloatTimestampOptions
24
51
  public lastPushSampleStringTimestampOptions?: PushSampleStringTimestampOptions
25
52
  public lastCreateInletOptions?: CreateInletOptions
53
+ public lastPullSampleOptions?: PullSampleOptions
54
+ public lastPullChunkOptions?: PullChunkOptions
26
55
  public lastFlushInletOptions?: FlushInletOptions
27
56
  public lastDestroyInletOptions?: DestroyInletOptions
28
57
 
@@ -49,6 +78,7 @@ export default class FakeLiblsl implements Liblsl {
49
78
 
50
79
  public pushSampleFloatTimestamp(options: PushSampleFloatTimestampOptions) {
51
80
  this.lastPushSampleFloatTimestampOptions = options
81
+ return FakeLiblsl.fakeErrorCode
52
82
  }
53
83
 
54
84
  public pushSampleStringTimestamp(
@@ -56,6 +86,7 @@ export default class FakeLiblsl implements Liblsl {
56
86
  ) {
57
87
  this.lastPushSampleStringTimestampOptions = options
58
88
  this.pushSampleStringTimestampHitCount++
89
+ return FakeLiblsl.fakeErrorCode
59
90
  }
60
91
 
61
92
  public createOutlet(options: CreateOutletOptions) {
@@ -74,6 +105,31 @@ export default class FakeLiblsl implements Liblsl {
74
105
  return {} as BoundInlet
75
106
  }
76
107
 
108
+ public pullSample(options: PullSampleOptions) {
109
+ this.lastPullSampleOptions = options
110
+
111
+ const sample = this.fakeSamples.shift()
112
+
113
+ if (sample) {
114
+ return 1
115
+ }
116
+
117
+ return 0
118
+ }
119
+
120
+ public pullChunk(options: PullChunkOptions) {
121
+ this.lastPullChunkOptions = options
122
+
123
+ const chunk = this.fakeChunks.shift()
124
+ const timestamps = this.fakeTimestamps.shift()
125
+
126
+ if (chunk && timestamps) {
127
+ return 1
128
+ }
129
+
130
+ return 0
131
+ }
132
+
77
133
  public flushInlet(options: FlushInletOptions) {
78
134
  this.flushInletHitCount++
79
135
  this.lastFlushInletOptions = options
@@ -100,5 +156,9 @@ export default class FakeLiblsl implements Liblsl {
100
156
  this.destroyOutletHitCount = 0
101
157
  this.localClockHitCount = 0
102
158
  this.pushSampleStringTimestampHitCount = 0
159
+
160
+ this.fakeSamples = FakeLiblsl.fakeSamples.slice()
161
+ this.fakeChunks = FakeLiblsl.fakeChunks.slice()
162
+ this.fakeTimestamps = FakeLiblsl.fakeTimestamps.slice()
103
163
  }
104
164
  }
@@ -1,5 +1,5 @@
1
+ import { BoundStreamInfo } from 'impl/LiblslAdapter.js'
1
2
  import { StreamInfo, StreamInfoOptions } from '../../impl/LslStreamInfo.js'
2
- import { BoundStreamInfo } from '../../types.js'
3
3
 
4
4
  export default class FakeStreamInfo implements StreamInfo {
5
5
  public static callsToConstructor: StreamInfoOptions[] = []
@@ -5,23 +5,54 @@ export default class FakeStreamInlet implements StreamInlet {
5
5
  public static callsToConstructor: {
6
6
  info?: StreamInfo
7
7
  options?: StreamInletOptions
8
+ onData?: (samples: Float32Array, timestamps: Float64Array) => void
8
9
  }[] = []
9
10
 
10
- public static numCallsToFlushSamples = 0
11
+ public static numCallsToStartPulling = 0
12
+ public static numCallsToStopPulling = 0
13
+ public static numCallsToFlushQueue = 0
14
+ public static numCallsToDestroy = 0
15
+
16
+ public isRunning = false
17
+
18
+ protected onData!: (samples: Float32Array, timestamps: Float64Array) => void
19
+
20
+ public constructor(
21
+ info?: StreamInfo,
22
+ options?: StreamInletOptions,
23
+ onData?: (samples: Float32Array, timestamps: Float64Array) => void
24
+ ) {
25
+ this.onData = onData ?? (() => {})
11
26
 
12
- public constructor(info?: StreamInfo, options?: StreamInletOptions) {
13
27
  FakeStreamInlet.callsToConstructor.push({
14
28
  info,
15
29
  options,
30
+ onData: this.onData,
16
31
  })
17
32
  }
18
33
 
19
- public flushSamples() {
20
- FakeStreamInlet.numCallsToFlushSamples++
34
+ public startPulling() {
35
+ FakeStreamInlet.numCallsToStartPulling++
36
+ this.isRunning = true
37
+ }
38
+
39
+ public stopPulling() {
40
+ FakeStreamInlet.numCallsToStopPulling++
41
+ this.isRunning = false
42
+ }
43
+
44
+ public flushQueue() {
45
+ FakeStreamInlet.numCallsToFlushQueue++
46
+ }
47
+
48
+ public destroy() {
49
+ FakeStreamInlet.numCallsToDestroy++
21
50
  }
22
51
 
23
52
  public static resetTestDouble() {
24
53
  FakeStreamInlet.callsToConstructor = []
25
- FakeStreamInlet.numCallsToFlushSamples = 0
54
+ FakeStreamInlet.numCallsToStartPulling = 0
55
+ FakeStreamInlet.numCallsToFlushQueue = 0
56
+ FakeStreamInlet.numCallsToDestroy = 0
26
57
  }
27
58
  }
@@ -1,11 +1,16 @@
1
1
  import { StreamInfo } from '../../impl/LslStreamInfo.js'
2
2
  import LslStreamInlet, {
3
+ OnDataCallback,
3
4
  StreamInletOptions,
4
5
  } from '../../impl/LslStreamInlet.js'
5
6
 
6
7
  export class SpyStreamInlet extends LslStreamInlet {
7
- public constructor(info: StreamInfo, options: StreamInletOptions) {
8
- super(info, options)
8
+ public constructor(
9
+ info: StreamInfo,
10
+ options: StreamInletOptions,
11
+ onData: OnDataCallback
12
+ ) {
13
+ super(info, options, onData)
9
14
  }
10
15
 
11
16
  public getName() {
@@ -1,12 +1,12 @@
1
1
  import { randomInt } from 'crypto'
2
2
  import generateId from '@neurodevs/generate-id'
3
3
 
4
+ import { LslSample } from 'impl/LiblslAdapter.js'
4
5
  import { StreamInfo } from '../../impl/LslStreamInfo.js'
5
6
  import {
6
7
  StreamOutlet,
7
8
  StreamOutletOptions,
8
9
  } from '../../impl/LslStreamOutlet.js'
9
- import { LslSample } from '../../types.js'
10
10
 
11
11
  export default class FakeStreamOutlet implements StreamOutlet {
12
12
  public static callsToConstructor: {
@@ -56,24 +56,24 @@ export default class FakeStreamOutlet implements StreamOutlet {
56
56
  return this.options?.channelFormat ?? 'float32'
57
57
  }
58
58
 
59
- public get sampleRate() {
60
- return this.options?.sampleRate ?? randomInt(1, 1000)
59
+ public get sampleRateHz() {
60
+ return this.options?.sampleRateHz ?? randomInt(1, 1000)
61
61
  }
62
62
 
63
63
  public get chunkSize() {
64
64
  return this.options?.chunkSize ?? randomInt(1, 1000)
65
65
  }
66
66
 
67
- public get maxBuffered() {
68
- return this.options?.maxBuffered ?? randomInt(1, 1000)
67
+ public get maxBufferedMs() {
68
+ return this.options?.maxBufferedMs ?? randomInt(1, 1000)
69
69
  }
70
70
 
71
71
  public get manufacturer() {
72
72
  return this.options?.manufacturer ?? generateId()
73
73
  }
74
74
 
75
- public get unit() {
76
- return this.options?.unit ?? generateId()
75
+ public get units() {
76
+ return this.options?.units ?? generateId()
77
77
  }
78
78
 
79
79
  public static resetTestDouble() {
@@ -4,12 +4,30 @@ export default class FakeStreamTransportBridge
4
4
  implements StreamTransportBridge
5
5
  {
6
6
  public static numCallsToConstructor = 0
7
+ public static numCallsToActivate = 0
8
+ public static numCallsToDeactivate = 0
9
+ public static numCallsToDestroy = 0
7
10
 
8
11
  public constructor() {
9
12
  FakeStreamTransportBridge.numCallsToConstructor++
10
13
  }
11
14
 
15
+ public activate() {
16
+ FakeStreamTransportBridge.numCallsToActivate++
17
+ }
18
+
19
+ public deactivate() {
20
+ FakeStreamTransportBridge.numCallsToDeactivate++
21
+ }
22
+
23
+ public destroy() {
24
+ FakeStreamTransportBridge.numCallsToDestroy++
25
+ }
26
+
12
27
  public static resetTestDouble() {
13
28
  FakeStreamTransportBridge.numCallsToConstructor = 0
29
+ FakeStreamTransportBridge.numCallsToActivate = 0
30
+ FakeStreamTransportBridge.numCallsToDeactivate = 0
31
+ FakeStreamTransportBridge.numCallsToDestroy = 0
14
32
  }
15
33
  }
@@ -0,0 +1,9 @@
1
+ import LslWebSocketBridge, {
2
+ StreamTransportBridgeConstructorOptions,
3
+ } from '../../impl/LslWebSocketBridge.js'
4
+
5
+ export default class SpyLslWebSocketBridge extends LslWebSocketBridge {
6
+ public constructor(options: StreamTransportBridgeConstructorOptions) {
7
+ super(options)
8
+ }
9
+ }
@@ -0,0 +1,17 @@
1
+ import generateId from '@neurodevs/generate-id'
2
+ import WebSocket from 'ws'
3
+
4
+ export default class FakeWebSocket {
5
+ public static callsToSend: { id: string; data: unknown }[] = []
6
+
7
+ public readyState: number = WebSocket.OPEN
8
+ public id = generateId()
9
+
10
+ public send(data: unknown) {
11
+ FakeWebSocket.callsToSend.push({ id: this.id, data })
12
+ }
13
+
14
+ public static resetTestDouble() {
15
+ FakeWebSocket.callsToSend = []
16
+ }
17
+ }
@@ -0,0 +1,32 @@
1
+ import FakeWebSocket from './FakeWebSocket.js'
2
+
3
+ export default class FakeWebSocketServer {
4
+ public static callsToConstructor: FakeWSSConstructorOptions[] = []
5
+ public static numCallsToClose = 0
6
+
7
+ public static clients = new Set<FakeWebSocket>([
8
+ new FakeWebSocket(),
9
+ new FakeWebSocket(),
10
+ ])
11
+
12
+ public clients = FakeWebSocketServer.clients
13
+
14
+ public constructor(options: FakeWSSConstructorOptions) {
15
+ FakeWebSocketServer.callsToConstructor.push(options)
16
+ }
17
+
18
+ public close() {
19
+ FakeWebSocketServer.numCallsToClose += 1
20
+ }
21
+
22
+ public static resetTestDouble() {
23
+ FakeWebSocketServer.callsToConstructor = []
24
+ FakeWebSocketServer.numCallsToClose = 0
25
+
26
+ FakeWebSocket.resetTestDouble()
27
+ }
28
+ }
29
+
30
+ export interface FakeWSSConstructorOptions {
31
+ port: number
32
+ }
@@ -11,12 +11,12 @@ export default function generateRandomOutletOptions() {
11
11
  name: generateId(),
12
12
  type: generateId(),
13
13
  channelNames: new Array(randomInt(1, 10)).fill(generateId()),
14
- sampleRate: Math.random() * 10,
14
+ sampleRateHz: Math.random() * 10,
15
15
  channelFormat: TEST_SUPPORTED_CHANNEL_FORMATS[randomChannelIdx],
16
16
  sourceId: generateId(),
17
17
  manufacturer: generateId(),
18
- unit: generateId(),
18
+ units: generateId(),
19
19
  chunkSize: randomInt(0, 10),
20
- maxBuffered: randomInt(0, 10),
20
+ maxBufferedMs: randomInt(0, 10),
21
21
  } as StreamOutletOptions
22
22
  }
package/build/types.d.ts DELETED
@@ -1,95 +0,0 @@
1
- import { FuncObj, FieldType } from 'ffi-rs';
2
- import { CHANNEL_FORMATS } from './consts.js';
3
- import { StreamInlet } from './impl/LslStreamInlet.js';
4
- import { StreamOutlet } from './impl/LslStreamOutlet.js';
5
- export type StreamFixuture = StreamOutlet | StreamInlet;
6
- export type ChannelFormat = (typeof CHANNEL_FORMATS)[number];
7
- export interface DurationMarker {
8
- name: string;
9
- durationMs: number;
10
- }
11
- export interface Liblsl {
12
- createStreamInfo(options: CreateStreamInfoOptions): BoundStreamInfo;
13
- appendChannelsToStreamInfo(options: AppendChannelsToStreamInfoOptions): void;
14
- createOutlet(options: CreateOutletOptions): BoundOutlet;
15
- pushSampleFloatTimestamp(options: PushSampleFloatTimestampOptions): void;
16
- pushSampleStringTimestamp(options: PushSampleStringTimestampOptions): void;
17
- destroyOutlet(options: DestroyOutletOptions): void;
18
- createInlet(options: CreateInletOptions): BoundInlet;
19
- flushInlet(options: FlushInletOptions): void;
20
- destroyInlet(options: DestroyInletOptions): void;
21
- localClock(): number;
22
- }
23
- export interface CreateStreamInfoOptions {
24
- name: string;
25
- type: string;
26
- channelCount: number;
27
- sampleRate: number;
28
- channelFormat: number;
29
- sourceId: string;
30
- manufacturer?: string;
31
- unit?: string;
32
- }
33
- export interface AppendChannelsToStreamInfoOptions {
34
- info: BoundStreamInfo;
35
- channels: LslChannel[];
36
- }
37
- export interface LslChannel {
38
- label: string;
39
- unit: string;
40
- type: string;
41
- }
42
- export type LslSample = (number | string | undefined)[];
43
- export interface CreateOutletOptions {
44
- info: BoundStreamInfo;
45
- chunkSize: number;
46
- maxBuffered: number;
47
- }
48
- export interface PushSampleFloatTimestampOptions {
49
- outlet: BoundOutlet;
50
- sample: number[];
51
- timestamp: number;
52
- }
53
- export interface PushSampleStringTimestampOptions {
54
- outlet: BoundOutlet;
55
- sample: string[];
56
- timestamp: number;
57
- }
58
- export interface DestroyOutletOptions {
59
- outlet: BoundOutlet;
60
- }
61
- export interface CreateInletOptions {
62
- info: BoundStreamInfo;
63
- chunkSize: number;
64
- maxBuffered: number;
65
- }
66
- export interface FlushInletOptions {
67
- inlet: BoundInlet;
68
- }
69
- export interface DestroyInletOptions {
70
- }
71
- export interface LiblslBindings {
72
- lsl_create_streaminfo(args: [string, string, number, number, number, string]): BoundStreamInfo;
73
- lsl_create_outlet(args: [BoundStreamInfo, number, number]): BoundOutlet;
74
- lsl_push_sample_ft(args: [BoundOutlet, LslSample, number]): void;
75
- lsl_push_sample_strt(args: [BoundOutlet, LslSample, number]): void;
76
- lsl_destroy_outlet(args: [BoundOutlet]): void;
77
- lsl_create_inlet(args: any): BoundInlet;
78
- lsl_flush_inlet(args: [BoundInlet]): void;
79
- lsl_destroy_inlet(args: any): void;
80
- lsl_local_clock(args: []): number;
81
- lsl_get_desc(args: [BoundStreamInfo]): BoundDescription;
82
- lsl_append_child(args: [BoundDescription, string]): BoundChild;
83
- lsl_append_child_value(args: [BoundChild, string, string]): void;
84
- }
85
- export interface BoundStreamInfo {
86
- }
87
- export interface BoundOutlet {
88
- }
89
- export interface BoundInlet {
90
- }
91
- export interface BoundDescription {
92
- }
93
- export interface BoundChild {
94
- }
95
- export type FfiRsDefineOptions = FuncObj<FieldType, boolean | undefined>;
package/build/types.js DELETED
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/src/types.ts DELETED
@@ -1,111 +0,0 @@
1
- import { FuncObj, FieldType } from 'ffi-rs'
2
-
3
- import { CHANNEL_FORMATS } from './consts.js'
4
- import { StreamInlet } from './impl/LslStreamInlet.js'
5
- import { StreamOutlet } from './impl/LslStreamOutlet.js'
6
-
7
- export type StreamFixuture = StreamOutlet | StreamInlet
8
-
9
- export type ChannelFormat = (typeof CHANNEL_FORMATS)[number]
10
-
11
- export interface DurationMarker {
12
- name: string
13
- durationMs: number
14
- }
15
-
16
- export interface Liblsl {
17
- createStreamInfo(options: CreateStreamInfoOptions): BoundStreamInfo
18
- appendChannelsToStreamInfo(options: AppendChannelsToStreamInfoOptions): void
19
- createOutlet(options: CreateOutletOptions): BoundOutlet
20
- pushSampleFloatTimestamp(options: PushSampleFloatTimestampOptions): void
21
- pushSampleStringTimestamp(options: PushSampleStringTimestampOptions): void
22
- destroyOutlet(options: DestroyOutletOptions): void
23
- createInlet(options: CreateInletOptions): BoundInlet
24
- flushInlet(options: FlushInletOptions): void
25
- destroyInlet(options: DestroyInletOptions): void
26
- localClock(): number
27
- }
28
-
29
- export interface CreateStreamInfoOptions {
30
- name: string
31
- type: string
32
- channelCount: number
33
- sampleRate: number
34
- channelFormat: number
35
- sourceId: string
36
- manufacturer?: string
37
- unit?: string
38
- }
39
-
40
- export interface AppendChannelsToStreamInfoOptions {
41
- info: BoundStreamInfo
42
- channels: LslChannel[]
43
- }
44
-
45
- export interface LslChannel {
46
- label: string
47
- unit: string
48
- type: string
49
- }
50
-
51
- export type LslSample = (number | string | undefined)[]
52
-
53
- export interface CreateOutletOptions {
54
- info: BoundStreamInfo
55
- chunkSize: number
56
- maxBuffered: number
57
- }
58
-
59
- export interface PushSampleFloatTimestampOptions {
60
- outlet: BoundOutlet
61
- sample: number[]
62
- timestamp: number
63
- }
64
-
65
- export interface PushSampleStringTimestampOptions {
66
- outlet: BoundOutlet
67
- sample: string[]
68
- timestamp: number
69
- }
70
-
71
- export interface DestroyOutletOptions {
72
- outlet: BoundOutlet
73
- }
74
-
75
- export interface CreateInletOptions {
76
- info: BoundStreamInfo
77
- chunkSize: number
78
- maxBuffered: number
79
- }
80
-
81
- export interface FlushInletOptions {
82
- inlet: BoundInlet
83
- }
84
-
85
- export interface DestroyInletOptions {}
86
-
87
- export interface LiblslBindings {
88
- lsl_create_streaminfo(
89
- args: [string, string, number, number, number, string]
90
- ): BoundStreamInfo
91
-
92
- lsl_create_outlet(args: [BoundStreamInfo, number, number]): BoundOutlet
93
- lsl_push_sample_ft(args: [BoundOutlet, LslSample, number]): void
94
- lsl_push_sample_strt(args: [BoundOutlet, LslSample, number]): void
95
- lsl_destroy_outlet(args: [BoundOutlet]): void
96
- lsl_create_inlet(args: any): BoundInlet
97
- lsl_flush_inlet(args: [BoundInlet]): void
98
- lsl_destroy_inlet(args: any): void
99
- lsl_local_clock(args: []): number
100
- lsl_get_desc(args: [BoundStreamInfo]): BoundDescription
101
- lsl_append_child(args: [BoundDescription, string]): BoundChild
102
- lsl_append_child_value(args: [BoundChild, string, string]): void
103
- }
104
-
105
- export interface BoundStreamInfo {}
106
- export interface BoundOutlet {}
107
- export interface BoundInlet {}
108
- export interface BoundDescription {}
109
- export interface BoundChild {}
110
-
111
- export type FfiRsDefineOptions = FuncObj<FieldType, boolean | undefined>