@neurodevs/node-lsl 14.0.0 → 14.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.
@@ -2,36 +2,35 @@ import { ChannelFormat, LslSample } from './LiblslAdapter.js';
2
2
  import { StreamInfo } from './LslStreamInfo.js';
3
3
  export default class LslStreamOutlet implements StreamOutlet {
4
4
  static Class?: StreamOutletConstructor;
5
+ readonly name: string;
6
+ readonly type: string;
7
+ readonly sourceId: string;
8
+ readonly channelNames: string[];
9
+ readonly channelFormat: ChannelFormat;
10
+ readonly channelCount: number;
11
+ readonly sampleRateHz: number;
12
+ readonly chunkSize: number;
13
+ readonly maxBufferedMs: number;
14
+ readonly manufacturer: string;
15
+ readonly units: string;
5
16
  private info;
6
- private options;
7
17
  private outlet;
8
18
  private pushSampleMethod;
9
19
  protected constructor(info: StreamInfo, options: StreamOutletOptions);
10
20
  static Create(options: StreamOutletOptions): Promise<StreamOutlet>;
11
21
  private validateOptions;
12
- private createStreamOutlet;
13
- private setPushSampleMethod;
14
22
  private validateChannelFormat;
23
+ private get isChannelFormatSupported();
15
24
  private throwUnsupportedChannelFormat;
16
- private get unsupportedChannelMessage();
25
+ private createStreamOutlet;
26
+ private get boundStreamInfo();
27
+ private setPushSampleMethod;
17
28
  private get pushMethod();
18
29
  private readonly methodMap;
19
30
  pushSample(sample: LslSample): void;
20
31
  destroy(): void;
21
- get name(): string;
22
- get type(): string;
23
- get sourceId(): string;
24
- get channelNames(): string[];
25
- get channelCount(): number;
26
- get channelFormat(): "string" | "undefined" | "float32" | "double64" | "int32" | "int16" | "int8" | "int64";
27
- get sampleRateHz(): number;
28
- get chunkSize(): number;
29
- get maxBufferedMs(): number;
30
- get manufacturer(): string;
31
- get units(): string;
32
- private get boundStreamInfo();
33
32
  private get lsl();
34
- private static wait;
33
+ private static waitToAllowSetup;
35
34
  private static LslStreamInfo;
36
35
  }
37
36
  export interface StreamOutlet {
@@ -4,31 +4,43 @@ import LiblslAdapter from './LiblslAdapter.js';
4
4
  import LslStreamInfo from './LslStreamInfo.js';
5
5
  export default class LslStreamOutlet {
6
6
  static Class;
7
+ name;
8
+ type;
9
+ sourceId;
10
+ channelNames;
11
+ channelFormat;
12
+ channelCount;
13
+ sampleRateHz;
14
+ chunkSize;
15
+ maxBufferedMs = 360 * 1000;
16
+ manufacturer = 'N/A';
17
+ units = 'N/A';
7
18
  info;
8
- options;
9
19
  outlet;
10
20
  pushSampleMethod;
11
21
  constructor(info, options) {
22
+ const { name, type, sourceId, channelNames, channelFormat, sampleRateHz, chunkSize, maxBufferedMs, manufacturer, units, } = options;
12
23
  this.info = info;
13
- this.options = options;
24
+ this.name = name;
25
+ this.type = type;
26
+ this.sourceId = sourceId;
27
+ this.channelNames = channelNames;
28
+ this.channelFormat = channelFormat;
29
+ this.channelCount = channelNames.length;
30
+ this.sampleRateHz = sampleRateHz;
31
+ this.chunkSize = chunkSize;
32
+ this.maxBufferedMs = maxBufferedMs ?? this.maxBufferedMs;
33
+ this.manufacturer = manufacturer ?? this.manufacturer;
34
+ this.units = units ?? this.units;
14
35
  this.validateOptions();
15
36
  this.createStreamOutlet();
16
37
  this.setPushSampleMethod();
17
38
  }
18
39
  static async Create(options) {
19
40
  const { waitAfterConstructionMs = 10 } = options ?? {};
20
- const infoOptions = {
21
- channelNames: options.channelNames,
22
- channelFormat: options.channelFormat,
23
- sampleRateHz: options.sampleRateHz,
24
- name: options.name,
25
- type: options.type,
26
- sourceId: options.sourceId,
27
- units: options.units,
28
- };
29
- const info = this.LslStreamInfo(infoOptions);
41
+ const info = this.LslStreamInfo(options);
30
42
  const instance = new (this.Class ?? this)(info, options);
31
- await this.wait(waitAfterConstructionMs);
43
+ await this.waitToAllowSetup(waitAfterConstructionMs);
32
44
  return instance;
33
45
  }
34
46
  validateOptions() {
@@ -37,6 +49,18 @@ export default class LslStreamOutlet {
37
49
  assertValidChannelFormat(this.channelFormat);
38
50
  assertValidChunkSize(this.chunkSize);
39
51
  assertValidMaxBufferedMs(this.maxBufferedMs);
52
+ this.validateChannelFormat();
53
+ }
54
+ validateChannelFormat() {
55
+ if (!this.isChannelFormatSupported) {
56
+ this.throwUnsupportedChannelFormat();
57
+ }
58
+ }
59
+ get isChannelFormatSupported() {
60
+ return this.channelFormat in this.methodMap;
61
+ }
62
+ throwUnsupportedChannelFormat() {
63
+ throw new Error(`This method currently does not support the ${this.channelFormat} type! Please implement it.`);
40
64
  }
41
65
  createStreamOutlet() {
42
66
  this.outlet = this.lsl.createOutlet({
@@ -45,21 +69,12 @@ export default class LslStreamOutlet {
45
69
  maxBufferedMs: this.maxBufferedMs,
46
70
  });
47
71
  }
72
+ get boundStreamInfo() {
73
+ return this.info.boundStreamInfo;
74
+ }
48
75
  setPushSampleMethod() {
49
- this.validateChannelFormat();
50
76
  this.pushSampleMethod = this.lsl[this.pushMethod].bind(this.lsl);
51
77
  }
52
- validateChannelFormat() {
53
- if (!(this.channelFormat in this.methodMap)) {
54
- this.throwUnsupportedChannelFormat();
55
- }
56
- }
57
- throwUnsupportedChannelFormat() {
58
- throw new Error(this.unsupportedChannelMessage);
59
- }
60
- get unsupportedChannelMessage() {
61
- return `This method currently does not support the ${this.channelFormat} type! Please implement it.`;
62
- }
63
78
  get pushMethod() {
64
79
  return this.methodMap[this.channelFormat];
65
80
  }
@@ -69,59 +84,33 @@ export default class LslStreamOutlet {
69
84
  };
70
85
  pushSample(sample) {
71
86
  const timestamp = this.lsl.localClock();
72
- handleError(this.pushSampleMethod({
87
+ const err = this.pushSampleMethod({
73
88
  outlet: this.outlet,
74
89
  sample,
75
90
  timestamp,
76
- }));
91
+ });
92
+ handleError(err);
77
93
  }
78
94
  destroy() {
79
95
  this.lsl.destroyOutlet({ outlet: this.outlet });
80
96
  }
81
- get name() {
82
- return this.options.name;
83
- }
84
- get type() {
85
- return this.options.type;
86
- }
87
- get sourceId() {
88
- return this.options.sourceId;
89
- }
90
- get channelNames() {
91
- return this.options.channelNames;
92
- }
93
- get channelCount() {
94
- return this.channelNames.length;
95
- }
96
- get channelFormat() {
97
- return this.options.channelFormat;
98
- }
99
- get sampleRateHz() {
100
- return this.options.sampleRateHz;
101
- }
102
- get chunkSize() {
103
- return this.options.chunkSize;
104
- }
105
- get maxBufferedMs() {
106
- return this.options.maxBufferedMs ?? 360 * 1000;
107
- }
108
- get manufacturer() {
109
- return this.options.manufacturer ?? 'N/A';
110
- }
111
- get units() {
112
- return this.options.units ?? 'N/A';
113
- }
114
- get boundStreamInfo() {
115
- return this.info.boundStreamInfo;
116
- }
117
97
  get lsl() {
118
98
  return LiblslAdapter.getInstance();
119
99
  }
120
- static async wait(waitMs) {
121
- return new Promise((resolve) => setTimeout(resolve, waitMs));
100
+ static async waitToAllowSetup(waitAfterConstructionMs) {
101
+ await new Promise((resolve) => setTimeout(resolve, waitAfterConstructionMs));
122
102
  }
123
103
  static LslStreamInfo(options) {
124
- return LslStreamInfo.Create(options);
104
+ const { channelNames, channelFormat, sampleRateHz, name, type, sourceId, units, } = options;
105
+ return LslStreamInfo.Create({
106
+ name,
107
+ type,
108
+ sourceId,
109
+ channelNames,
110
+ channelFormat,
111
+ sampleRateHz,
112
+ units,
113
+ });
125
114
  }
126
115
  }
127
116
  //# sourceMappingURL=LslStreamOutlet.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"LslStreamOutlet.js","sourceRoot":"","sources":["../../src/impl/LslStreamOutlet.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,uBAAuB,EACvB,wBAAwB,EACxB,oBAAoB,EACpB,wBAAwB,EACxB,uBAAuB,GAC1B,MAAM,kBAAkB,CAAA;AACzB,OAAO,WAA6B,MAAM,mBAAmB,CAAA;AAO7D,OAAO,aAAa,MAAM,oBAAoB,CAAA;AAC9C,OAAO,aAGN,MAAM,oBAAoB,CAAA;AAE3B,MAAM,CAAC,OAAO,OAAO,eAAe;IACzB,MAAM,CAAC,KAAK,CAA0B;IAErC,IAAI,CAAY;IAChB,OAAO,CAAqB;IAC5B,MAAM,C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AC;IAEM,OAAO;QACV,IAAI,CAAC,GAAG,CAAC,aAAa,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAA;IACnD,CAAC;IAED,IAAY,GAAG;QACX,OAAO,aAAa,CAAC,WAAW,EAAE,CAAA;IACtC,CAAC;IAEO,MAAM,CAAC,KAAK,CAAC,gBAAgB,CAAC,uBAA+B;QACjE,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAC1B,UAAU,CAAC,OAAO,EAAE,uBAAuB,CAAC,CAC/C,CAAA;IACL,CAAC;IAEO,MAAM,CAAC,aAAa,CAAC,OAA0B;QACnD,MAAM,EACF,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,IAAI,EACJ,IAAI,EACJ,QAAQ,EACR,KAAK,GACR,GAAG,OAAO,CAAA;QAEX,OAAO,aAAa,CAAC,MAAM,CAAC;YACxB,IAAI;YACJ,IAAI;YACJ,QAAQ;YACR,YAAY;YACZ,aAAa;YACb,YAAY;YACZ,KAAK;SACR,CAAC,CAAA;IACN,CAAC;CACJ"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neurodevs/node-lsl",
3
- "version": "14.0.0",
3
+ "version": "14.0.1",
4
4
  "description": "Lab Streaming Layer (LSL) bindings for Node",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -21,14 +21,48 @@ import LslStreamInfo, {
21
21
  export default class LslStreamOutlet implements StreamOutlet {
22
22
  public static Class?: StreamOutletConstructor
23
23
 
24
+ public readonly name: string
25
+ public readonly type: string
26
+ public readonly sourceId: string
27
+ public readonly channelNames: string[]
28
+ public readonly channelFormat: ChannelFormat
29
+ public readonly channelCount: number
30
+ public readonly sampleRateHz: number
31
+ public readonly chunkSize: number
32
+ public readonly maxBufferedMs = 360 * 1000
33
+ public readonly manufacturer: string = 'N/A'
34
+ public readonly units: string = 'N/A'
35
+
24
36
  private info: StreamInfo
25
- private options: StreamOutletOptions
26
37
  private outlet!: BoundOutlet
27
38
  private pushSampleMethod!: (options: unknown) => LslErrorCode
28
39
 
29
40
  protected constructor(info: StreamInfo, options: StreamOutletOptions) {
41
+ const {
42
+ name,
43
+ type,
44
+ sourceId,
45
+ channelNames,
46
+ channelFormat,
47
+ sampleRateHz,
48
+ chunkSize,
49
+ maxBufferedMs,
50
+ manufacturer,
51
+ units,
52
+ } = options
53
+
30
54
  this.info = info
31
- this.options = options
55
+ this.name = name
56
+ this.type = type
57
+ this.sourceId = sourceId
58
+ this.channelNames = channelNames
59
+ this.channelFormat = channelFormat
60
+ this.channelCount = channelNames.length
61
+ this.sampleRateHz = sampleRateHz
62
+ this.chunkSize = chunkSize
63
+ this.maxBufferedMs = maxBufferedMs ?? this.maxBufferedMs
64
+ this.manufacturer = manufacturer ?? this.manufacturer
65
+ this.units = units ?? this.units
32
66
 
33
67
  this.validateOptions()
34
68
  this.createStreamOutlet()
@@ -38,20 +72,10 @@ export default class LslStreamOutlet implements StreamOutlet {
38
72
  public static async Create(options: StreamOutletOptions) {
39
73
  const { waitAfterConstructionMs = 10 } = options ?? {}
40
74
 
41
- const infoOptions = {
42
- channelNames: options.channelNames,
43
- channelFormat: options.channelFormat,
44
- sampleRateHz: options.sampleRateHz,
45
- name: options.name,
46
- type: options.type,
47
- sourceId: options.sourceId,
48
- units: options.units,
49
- }
50
-
51
- const info = this.LslStreamInfo(infoOptions)
75
+ const info = this.LslStreamInfo(options)
52
76
  const instance = new (this.Class ?? this)(info, options)
53
77
 
54
- await this.wait(waitAfterConstructionMs)
78
+ await this.waitToAllowSetup(waitAfterConstructionMs)
55
79
 
56
80
  return instance
57
81
  }
@@ -62,6 +86,23 @@ export default class LslStreamOutlet implements StreamOutlet {
62
86
  assertValidChannelFormat(this.channelFormat)
63
87
  assertValidChunkSize(this.chunkSize)
64
88
  assertValidMaxBufferedMs(this.maxBufferedMs)
89
+ this.validateChannelFormat()
90
+ }
91
+
92
+ private validateChannelFormat() {
93
+ if (!this.isChannelFormatSupported) {
94
+ this.throwUnsupportedChannelFormat()
95
+ }
96
+ }
97
+
98
+ private get isChannelFormatSupported() {
99
+ return this.channelFormat in this.methodMap
100
+ }
101
+
102
+ private throwUnsupportedChannelFormat() {
103
+ throw new Error(
104
+ `This method currently does not support the ${this.channelFormat} type! Please implement it.`
105
+ )
65
106
  }
66
107
 
67
108
  private createStreamOutlet() {
@@ -72,28 +113,16 @@ export default class LslStreamOutlet implements StreamOutlet {
72
113
  })
73
114
  }
74
115
 
75
- private setPushSampleMethod() {
76
- this.validateChannelFormat()
116
+ private get boundStreamInfo() {
117
+ return this.info.boundStreamInfo
118
+ }
77
119
 
120
+ private setPushSampleMethod() {
78
121
  this.pushSampleMethod = (
79
122
  this.lsl[this.pushMethod] as (options: unknown) => LslErrorCode
80
123
  ).bind(this.lsl)
81
124
  }
82
125
 
83
- private validateChannelFormat() {
84
- if (!(this.channelFormat in this.methodMap)) {
85
- this.throwUnsupportedChannelFormat()
86
- }
87
- }
88
-
89
- private throwUnsupportedChannelFormat() {
90
- throw new Error(this.unsupportedChannelMessage)
91
- }
92
-
93
- private get unsupportedChannelMessage() {
94
- return `This method currently does not support the ${this.channelFormat} type! Please implement it.`
95
- }
96
-
97
126
  private get pushMethod() {
98
127
  return this.methodMap[this.channelFormat]
99
128
  }
@@ -106,77 +135,48 @@ export default class LslStreamOutlet implements StreamOutlet {
106
135
  public pushSample(sample: LslSample) {
107
136
  const timestamp = this.lsl.localClock()
108
137
 
109
- handleError(
110
- this.pushSampleMethod({
111
- outlet: this.outlet,
112
- sample,
113
- timestamp,
114
- })
115
- )
138
+ const err = this.pushSampleMethod({
139
+ outlet: this.outlet,
140
+ sample,
141
+ timestamp,
142
+ })
143
+ handleError(err)
116
144
  }
117
145
 
118
146
  public destroy() {
119
147
  this.lsl.destroyOutlet({ outlet: this.outlet })
120
148
  }
121
149
 
122
- public get name() {
123
- return this.options.name
124
- }
125
-
126
- public get type() {
127
- return this.options.type
128
- }
129
-
130
- public get sourceId() {
131
- return this.options.sourceId
132
- }
133
-
134
- public get channelNames() {
135
- return this.options.channelNames
136
- }
137
-
138
- public get channelCount() {
139
- return this.channelNames.length
140
- }
141
-
142
- public get channelFormat() {
143
- return this.options.channelFormat
144
- }
145
-
146
- public get sampleRateHz() {
147
- return this.options.sampleRateHz
148
- }
149
-
150
- public get chunkSize() {
151
- return this.options.chunkSize
152
- }
153
-
154
- public get maxBufferedMs() {
155
- return this.options.maxBufferedMs ?? 360 * 1000
156
- }
157
-
158
- public get manufacturer() {
159
- return this.options.manufacturer ?? 'N/A'
160
- }
161
-
162
- public get units() {
163
- return this.options.units ?? 'N/A'
164
- }
165
-
166
- private get boundStreamInfo() {
167
- return this.info.boundStreamInfo
168
- }
169
-
170
150
  private get lsl() {
171
151
  return LiblslAdapter.getInstance()
172
152
  }
173
153
 
174
- private static async wait(waitMs: number) {
175
- return new Promise((resolve) => setTimeout(resolve, waitMs))
154
+ private static async waitToAllowSetup(waitAfterConstructionMs: number) {
155
+ await new Promise((resolve) =>
156
+ setTimeout(resolve, waitAfterConstructionMs)
157
+ )
176
158
  }
177
159
 
178
160
  private static LslStreamInfo(options: StreamInfoOptions) {
179
- return LslStreamInfo.Create(options)
161
+ const {
162
+ channelNames,
163
+ channelFormat,
164
+ sampleRateHz,
165
+ name,
166
+ type,
167
+ sourceId,
168
+ units,
169
+ } = options
170
+
171
+ return LslStreamInfo.Create({
172
+ name,
173
+ type,
174
+ sourceId,
175
+ channelNames,
176
+ channelFormat,
177
+ sampleRateHz,
178
+ units,
179
+ })
180
180
  }
181
181
  }
182
182