@momo2555/koppeliajs 0.0.162 → 0.0.163

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.
@@ -11,7 +11,8 @@ export type AnyRequestCallback = (request: string, params: {
11
11
  }, from: string, address: string) => void;
12
12
  export type MediaResponseData = string | Blob | ArrayBuffer | any;
13
13
  /**
14
- * This class defines the Koppelia console to send and receive requests.
14
+ * Handles the Koppelia console connection, facilitating the sending and receiving of requests
15
+ * and managing event subscriptions for state changes, device data, and custom logic.
15
16
  */
16
17
  export declare class Console {
17
18
  consoleHostname: string;
@@ -27,85 +28,110 @@ export declare class Console {
27
28
  private _mediaApiUrl;
28
29
  constructor();
29
30
  /**
30
- * Generates a unique random ID for callback registration.
31
+ * Generates a unique random ID used for registering and tracking callbacks.
32
+ * @returns A randomly generated string ID.
31
33
  */
32
34
  private _generateId;
33
35
  /**
34
- * Unsubscribes a previously registered callback using its ID.
35
- * @param id The identifier returned by the "on..." functions.
36
- * @returns true if the ID was found and deleted, false otherwise.
36
+ * Unsubscribes a previously registered callback using its unique ID.
37
+ * @param id The subscription identifier returned by any "on..." listener function.
38
+ * @returns True if the ID was found and successfully removed, false otherwise.
37
39
  */
38
40
  unsubscribeCallback(id: string): boolean;
39
41
  /**
40
- * Sends a message to the console. Set header.to to dispatch the message.
41
- * @param message The message to send.
42
- * @param callback The callback triggered when the websocket receives a response.
42
+ * Dispatches a message through the console socket.
43
+ * The routing source is automatically appended based on the current application state.
44
+ * @param message The message payload to send.
45
+ * @param callback Optional callback triggered when the WebSocket receives a specific response.
43
46
  */
44
47
  sendMessage(message: Message, callback?: Callback): void;
45
48
  /**
46
- * Identifies the page (controller or monitor) to the console.
49
+ * Identifies the current client application (controller or monitor) to the console.
47
50
  * @param peer The peer type to identify as.
48
51
  */
49
52
  identify(peer: PeerType): void;
53
+ /**
54
+ * Retrieves the list of connected devices.
55
+ * @todo Implementation pending.
56
+ */
50
57
  getConnectedDevices(): void;
51
58
  /**
52
- * Sends data to a specific peer.
53
- * @param receiver The peer type receiving the data.
54
- * @param data The data payload.
59
+ * Transmits data payload directly to a specific peer type.
60
+ * @param receiver The target peer intended to receive the data.
61
+ * @param data The data payload to transmit.
55
62
  */
56
63
  sendDataTo(receiver: PeerType, data: MessageData): void;
57
64
  /**
58
- * Adds a callback to be executed when a new state is received from the console.
59
- * @param callback Function to execute on state change.
60
- * @returns The subscription ID.
65
+ * Registers a callback to execute whenever a new state is received from the console.
66
+ * @param callback The function to execute on state change.
67
+ * @returns The unique subscription ID used for unsubscribing.
61
68
  */
62
69
  onStateChange(callback: ChangeStateCallback): string;
63
70
  /**
64
- * Adds a callback to be executed when the current stage changes.
65
- * @param callback Function to execute on stage change.
66
- * @returns The subscription ID.
71
+ * Registers a callback to execute whenever the current application stage changes.
72
+ * @param callback The function to execute on stage change.
73
+ * @returns The unique subscription ID used for unsubscribing.
67
74
  */
68
75
  onStageChange(callback: ChangeStageCallback): string;
69
76
  /**
70
- * Adds a callback to be executed when the console is ready.
71
- * If the console is already ready, the function is called immediately.
72
- * @param callback Function to execute.
73
- * @returns The subscription ID.
77
+ * Registers a callback to execute when the console connection is fully established and ready.
78
+ * If the console is already ready at the time of calling, the callback is executed immediately.
79
+ * @param callback The function to execute upon readiness.
80
+ * @returns The unique subscription ID used for unsubscribing.
74
81
  */
75
82
  onReady(callback: () => void): string;
76
83
  /**
77
- * Adds a callback to listen for device events.
78
- * @param callback Function to execute on device event.
79
- * @returns The subscription ID.
84
+ * Registers a callback to listen for specific device events.
85
+ * @param callback The function to execute when a device event occurs.
86
+ * @returns The unique subscription ID used for unsubscribing.
80
87
  */
81
88
  onDeviceEvent(callback: DeviceEventCallback): string;
82
89
  /**
83
- * Adds a callback to listen for data exchanges.
84
- * @param callback Function to execute on data exchange.
85
- * @returns The subscription ID.
90
+ * Registers a callback to listen for raw data exchanges between peers.
91
+ * @param callback The function to execute upon receiving exchanged data.
92
+ * @returns The unique subscription ID used for unsubscribing.
86
93
  */
87
94
  onDataExchange(callback: DataExchangeCallback): string;
88
95
  /**
89
- * Adds a callback to listen for generic requests.
90
- * @param callback Function to execute on request.
91
- * @returns The subscription ID.
96
+ * Registers a generic callback to intercept and handle custom or unrecognized requests.
97
+ * @param callback The function to execute for generic requests.
98
+ * @returns The unique subscription ID used for unsubscribing.
92
99
  */
93
100
  onRequest(callback: AnyRequestCallback): string;
94
101
  /**
95
- * Gets the current readiness state of the console connection.
102
+ * Gets the current readiness state of the console WebSocket connection.
96
103
  */
97
104
  get ready(): boolean;
105
+ /**
106
+ * Constructs the full URL for a media asset based on the API port and hostname.
107
+ * @param path The relative path to the media asset.
108
+ * @returns The fully qualified URL string.
109
+ */
98
110
  getMediaUrl(path: string): string;
99
111
  /**
100
- * Normalizes the media URL to ensure it works for both the controller and the monitor.
101
- * Sometimes, a link retrieved from one client is saved as a game state, but fails
102
- * when accessed by the other client. Wrapping all media URLs with this function is best practice.
103
- * @param mediaUrl The original media URL.
104
- * @returns The corrected URL string.
112
+ * Normalizes a media URL to ensure cross-client compatibility.
113
+ * Corrects edge cases where media links cached in game states by one client (e.g., controller)
114
+ * fail when accessed by another (e.g., monitor).
115
+ * @param mediaUrl The raw URL string to fix.
116
+ * @returns The corrected and standardized URL string.
105
117
  */
106
118
  fixMediaUrl(mediaUrl: string): string;
119
+ /**
120
+ * Fetches a media asset from the API and automatically parses it based on its Content-Type.
121
+ * @param path The relative path to the media asset.
122
+ * @returns A promise resolving to the parsed data (JSON, Text, Blob, or ArrayBuffer).
123
+ * @throws Will throw an error if the HTTP request fails.
124
+ */
107
125
  getMedia(path: string): Promise<MediaResponseData>;
126
+ /**
127
+ * Initializes core WebSocket event listeners and maps them to the internal handlers.
128
+ */
108
129
  private _initEvents;
130
+ /**
131
+ * Core router for incoming WebSocket data. Decodes the message type and
132
+ * dispatches it to the corresponding internal execution loops.
133
+ * @param request The parsed Message object received from the socket.
134
+ */
109
135
  private _processReceivedData;
110
136
  private _execDeviceDataHandlers;
111
137
  private _execDeviceEventHandlers;
@@ -114,7 +140,7 @@ export declare class Console {
114
140
  private _execDataExchangeHandlers;
115
141
  private _execAnyRequestHandlers;
116
142
  /**
117
- * Clears all registered event handlers.
143
+ * Hard-resets the application by clearing all registered event handlers.
118
144
  */
119
145
  destroyEvents(): void;
120
146
  }
@@ -7,12 +7,12 @@ import { logger } from "./logger.js";
7
7
  const PORT = 2225;
8
8
  const API_PORT = 8000;
9
9
  /**
10
- * This class defines the Koppelia console to send and receive requests.
10
+ * Handles the Koppelia console connection, facilitating the sending and receiving of requests
11
+ * and managing event subscriptions for state changes, device data, and custom logic.
11
12
  */
12
13
  export class Console {
13
14
  consoleHostname = "";
14
15
  consoleSocket;
15
- // Event handlers stored as dictionaries (Record) for ID-based subscription management
16
16
  _changeStateHandlers;
17
17
  _changeStageHandlers;
18
18
  _deviceEventHandlers;
@@ -31,7 +31,6 @@ export class Console {
31
31
  this.consoleSocket = new KoppeliaWebsocket(consoleUrl);
32
32
  this._mediaApiUrl = "http://" + this.consoleHostname + ":" + API_PORT;
33
33
  this._ready = false;
34
- // Initialize dictionaries
35
34
  this._changeStateHandlers = {};
36
35
  this._changeStageHandlers = {};
37
36
  this._deviceEventHandlers = {};
@@ -42,16 +41,17 @@ export class Console {
42
41
  this._initEvents();
43
42
  }
44
43
  /**
45
- * Generates a unique random ID for callback registration.
44
+ * Generates a unique random ID used for registering and tracking callbacks.
45
+ * @returns A randomly generated string ID.
46
46
  */
47
47
  _generateId() {
48
48
  return Math.random().toString(36).substring(2, 15) +
49
49
  Math.random().toString(36).substring(2, 15);
50
50
  }
51
51
  /**
52
- * Unsubscribes a previously registered callback using its ID.
53
- * @param id The identifier returned by the "on..." functions.
54
- * @returns true if the ID was found and deleted, false otherwise.
52
+ * Unsubscribes a previously registered callback using its unique ID.
53
+ * @param id The subscription identifier returned by any "on..." listener function.
54
+ * @returns True if the ID was found and successfully removed, false otherwise.
55
55
  */
56
56
  unsubscribeCallback(id) {
57
57
  let deleted = false;
@@ -86,9 +86,10 @@ export class Console {
86
86
  return deleted;
87
87
  }
88
88
  /**
89
- * Sends a message to the console. Set header.to to dispatch the message.
90
- * @param message The message to send.
91
- * @param callback The callback triggered when the websocket receives a response.
89
+ * Dispatches a message through the console socket.
90
+ * The routing source is automatically appended based on the current application state.
91
+ * @param message The message payload to send.
92
+ * @param callback Optional callback triggered when the WebSocket receives a specific response.
92
93
  */
93
94
  sendMessage(message, callback) {
94
95
  let route = PeerType.NONE;
@@ -102,7 +103,7 @@ export class Console {
102
103
  this.consoleSocket.send(message, callback);
103
104
  }
104
105
  /**
105
- * Identifies the page (controller or monitor) to the console.
106
+ * Identifies the current client application (controller or monitor) to the console.
106
107
  * @param peer The peer type to identify as.
107
108
  */
108
109
  identify(peer) {
@@ -110,12 +111,16 @@ export class Console {
110
111
  req.setIdentification(peer);
111
112
  this.consoleSocket.send(req);
112
113
  }
114
+ /**
115
+ * Retrieves the list of connected devices.
116
+ * @todo Implementation pending.
117
+ */
113
118
  getConnectedDevices() {
114
119
  }
115
120
  /**
116
- * Sends data to a specific peer.
117
- * @param receiver The peer type receiving the data.
118
- * @param data The data payload.
121
+ * Transmits data payload directly to a specific peer type.
122
+ * @param receiver The target peer intended to receive the data.
123
+ * @param data The data payload to transmit.
119
124
  */
120
125
  sendDataTo(receiver, data) {
121
126
  let req = new Message();
@@ -123,9 +128,9 @@ export class Console {
123
128
  req.setDestination(receiver);
124
129
  }
125
130
  /**
126
- * Adds a callback to be executed when a new state is received from the console.
127
- * @param callback Function to execute on state change.
128
- * @returns The subscription ID.
131
+ * Registers a callback to execute whenever a new state is received from the console.
132
+ * @param callback The function to execute on state change.
133
+ * @returns The unique subscription ID used for unsubscribing.
129
134
  */
130
135
  onStateChange(callback) {
131
136
  const id = this._generateId();
@@ -133,9 +138,9 @@ export class Console {
133
138
  return id;
134
139
  }
135
140
  /**
136
- * Adds a callback to be executed when the current stage changes.
137
- * @param callback Function to execute on stage change.
138
- * @returns The subscription ID.
141
+ * Registers a callback to execute whenever the current application stage changes.
142
+ * @param callback The function to execute on stage change.
143
+ * @returns The unique subscription ID used for unsubscribing.
139
144
  */
140
145
  onStageChange(callback) {
141
146
  const id = this._generateId();
@@ -143,10 +148,10 @@ export class Console {
143
148
  return id;
144
149
  }
145
150
  /**
146
- * Adds a callback to be executed when the console is ready.
147
- * If the console is already ready, the function is called immediately.
148
- * @param callback Function to execute.
149
- * @returns The subscription ID.
151
+ * Registers a callback to execute when the console connection is fully established and ready.
152
+ * If the console is already ready at the time of calling, the callback is executed immediately.
153
+ * @param callback The function to execute upon readiness.
154
+ * @returns The unique subscription ID used for unsubscribing.
150
155
  */
151
156
  onReady(callback) {
152
157
  const id = this._generateId();
@@ -159,9 +164,9 @@ export class Console {
159
164
  return id;
160
165
  }
161
166
  /**
162
- * Adds a callback to listen for device events.
163
- * @param callback Function to execute on device event.
164
- * @returns The subscription ID.
167
+ * Registers a callback to listen for specific device events.
168
+ * @param callback The function to execute when a device event occurs.
169
+ * @returns The unique subscription ID used for unsubscribing.
165
170
  */
166
171
  onDeviceEvent(callback) {
167
172
  const id = this._generateId();
@@ -169,9 +174,9 @@ export class Console {
169
174
  return id;
170
175
  }
171
176
  /**
172
- * Adds a callback to listen for data exchanges.
173
- * @param callback Function to execute on data exchange.
174
- * @returns The subscription ID.
177
+ * Registers a callback to listen for raw data exchanges between peers.
178
+ * @param callback The function to execute upon receiving exchanged data.
179
+ * @returns The unique subscription ID used for unsubscribing.
175
180
  */
176
181
  onDataExchange(callback) {
177
182
  const id = this._generateId();
@@ -179,9 +184,9 @@ export class Console {
179
184
  return id;
180
185
  }
181
186
  /**
182
- * Adds a callback to listen for generic requests.
183
- * @param callback Function to execute on request.
184
- * @returns The subscription ID.
187
+ * Registers a generic callback to intercept and handle custom or unrecognized requests.
188
+ * @param callback The function to execute for generic requests.
189
+ * @returns The unique subscription ID used for unsubscribing.
185
190
  */
186
191
  onRequest(callback) {
187
192
  const id = this._generateId();
@@ -189,22 +194,27 @@ export class Console {
189
194
  return id;
190
195
  }
191
196
  /**
192
- * Gets the current readiness state of the console connection.
197
+ * Gets the current readiness state of the console WebSocket connection.
193
198
  */
194
199
  get ready() {
195
200
  return this._ready;
196
201
  }
202
+ /**
203
+ * Constructs the full URL for a media asset based on the API port and hostname.
204
+ * @param path The relative path to the media asset.
205
+ * @returns The fully qualified URL string.
206
+ */
197
207
  getMediaUrl(path) {
198
208
  if (!path.startsWith("/"))
199
209
  path = "/" + path;
200
210
  return this._mediaApiUrl + path;
201
211
  }
202
212
  /**
203
- * Normalizes the media URL to ensure it works for both the controller and the monitor.
204
- * Sometimes, a link retrieved from one client is saved as a game state, but fails
205
- * when accessed by the other client. Wrapping all media URLs with this function is best practice.
206
- * @param mediaUrl The original media URL.
207
- * @returns The corrected URL string.
213
+ * Normalizes a media URL to ensure cross-client compatibility.
214
+ * Corrects edge cases where media links cached in game states by one client (e.g., controller)
215
+ * fail when accessed by another (e.g., monitor).
216
+ * @param mediaUrl The raw URL string to fix.
217
+ * @returns The corrected and standardized URL string.
208
218
  */
209
219
  fixMediaUrl(mediaUrl) {
210
220
  let url = new URL(mediaUrl);
@@ -213,6 +223,12 @@ export class Console {
213
223
  fixedurl.search = url.search;
214
224
  return fixedurl.toString();
215
225
  }
226
+ /**
227
+ * Fetches a media asset from the API and automatically parses it based on its Content-Type.
228
+ * @param path The relative path to the media asset.
229
+ * @returns A promise resolving to the parsed data (JSON, Text, Blob, or ArrayBuffer).
230
+ * @throws Will throw an error if the HTTP request fails.
231
+ */
216
232
  async getMedia(path) {
217
233
  const response = await fetch(this.getMediaUrl(path));
218
234
  if (!response.ok) {
@@ -220,19 +236,22 @@ export class Console {
220
236
  }
221
237
  const contentType = response.headers.get("Content-Type") || "";
222
238
  if (contentType.includes("application/json")) {
223
- return await response.json(); // Returns an Object
239
+ return await response.json();
224
240
  }
225
241
  else if (contentType.startsWith("text/")) {
226
- return await response.text(); // Returns a String
242
+ return await response.text();
227
243
  }
228
244
  else if (contentType.startsWith("image/") ||
229
245
  contentType.includes("application/octet-stream")) {
230
- return await response.blob(); // Returns a Blob (images, downloads, etc.)
246
+ return await response.blob();
231
247
  }
232
248
  else {
233
- return await response.arrayBuffer(); // Returns a Generic binary buffer
249
+ return await response.arrayBuffer();
234
250
  }
235
251
  }
252
+ /**
253
+ * Initializes core WebSocket event listeners and maps them to the internal handlers.
254
+ */
236
255
  _initEvents() {
237
256
  this.consoleSocket.onOpen(() => {
238
257
  this._ready = true;
@@ -244,13 +263,17 @@ export class Console {
244
263
  this._processReceivedData(request);
245
264
  });
246
265
  }
266
+ /**
267
+ * Core router for incoming WebSocket data. Decodes the message type and
268
+ * dispatches it to the corresponding internal execution loops.
269
+ * @param request The parsed Message object received from the socket.
270
+ */
247
271
  _processReceivedData(request) {
248
272
  logger.log("Received new data from console", request);
249
273
  if (request.header.type === undefined) {
250
274
  return;
251
275
  }
252
276
  let type = request.header.type;
253
- /* Handle specific requests */
254
277
  if (type == MessageType.REQUEST) {
255
278
  switch (request.request.exec) {
256
279
  case "changeState":
@@ -264,18 +287,18 @@ export class Console {
264
287
  this._execAnyRequestHandlers(request.request.exec, request.request.params, request.header.from, request.header.from_addr);
265
288
  break;
266
289
  }
267
- } /* Handle data exchange */
290
+ }
268
291
  else if (type == MessageType.DATA_EXCHANGE) {
269
292
  this._execDataExchangeHandlers(request.header.from, request.data);
270
- } /* Handle device event */
293
+ }
271
294
  else if (type == MessageType.DEVICE_EVENT) {
272
295
  this._execDeviceEventHandlers(request.header.device, request.header.from_addr, request.event);
273
- } /* Handle device data */
296
+ }
274
297
  else if (type == MessageType.DEVICE_DATA) {
275
298
  this._execDeviceDataHandlers(request.header.from_addr, request.data);
276
299
  }
277
300
  }
278
- // Handler execution methods iterating over dictionary values
301
+ // --- Dictionary execution methods below ---
279
302
  _execDeviceDataHandlers(from_addr, data) {
280
303
  for (let handler of Object.values(this._deviceDataHandlers)) {
281
304
  handler(from_addr, data);
@@ -307,10 +330,9 @@ export class Console {
307
330
  }
308
331
  }
309
332
  /**
310
- * Clears all registered event handlers.
333
+ * Hard-resets the application by clearing all registered event handlers.
311
334
  */
312
335
  destroyEvents() {
313
- // Reset dictionaries to empty objects
314
336
  this._deviceEventHandlers = {};
315
337
  this._deviceDataHandlers = {};
316
338
  this._anyRequestHandlers = {};
@@ -1,13 +1,31 @@
1
1
  import type { Console } from "./console.js";
2
+ /**
3
+ * Manages the registration and network-wide execution of custom callbacks.
4
+ * Allows different nodes in the system to broadcast and react to custom function calls.
5
+ */
2
6
  export declare class CustomCallbacks {
3
7
  private _console;
4
8
  private _customCallbacks;
5
9
  constructor(console: Console);
10
+ /**
11
+ * Broadcasts a request across the network to execute a registered custom callback.
12
+ * @param name The registered name of the custom callback to trigger.
13
+ * @param args A dictionary of arguments to pass to the callback function.
14
+ */
6
15
  runCustomCallback(name: string, args: {
7
16
  [key: string]: any;
8
17
  }): void;
18
+ /**
19
+ * Registers a local function to be executed when a specific custom callback request is received.
20
+ * @param name The identifier name for this callback.
21
+ * @param callback The function to execute when triggered by the network.
22
+ */
9
23
  registerCustomCallback(name: string, callback: (args: {
10
24
  [key: string]: any;
11
25
  }) => void): void;
26
+ /**
27
+ * Removes a previously registered custom callback from the local listener registry.
28
+ * @param name The identifier name of the callback to remove.
29
+ */
12
30
  unregisterCustomCallback(name: string): void;
13
31
  }
@@ -1,5 +1,9 @@
1
1
  import { logger } from "./logger.js";
2
2
  import { Message, MessageType, PeerType } from "./message.js";
3
+ /**
4
+ * Manages the registration and network-wide execution of custom callbacks.
5
+ * Allows different nodes in the system to broadcast and react to custom function calls.
6
+ */
3
7
  export class CustomCallbacks {
4
8
  _console;
5
9
  _customCallbacks;
@@ -9,25 +13,39 @@ export class CustomCallbacks {
9
13
  });
10
14
  this._customCallbacks = {};
11
15
  this._console.onDataExchange((from, data) => {
12
- if (data.custumCallbackName != undefined &&
16
+ if (data.customCallbackName != undefined &&
13
17
  data.customCallbackArgs != undefined) {
14
- if (Object.hasOwn(this._customCallbacks, data.custumCallbackName)) {
15
- this._customCallbacks[data.custumCallbackName](data.customCallbackArgs);
18
+ if (Object.hasOwn(this._customCallbacks, data.customCallbackName)) {
19
+ this._customCallbacks[data.customCallbackName](data.customCallbackArgs);
16
20
  }
17
21
  }
18
22
  });
19
23
  }
24
+ /**
25
+ * Broadcasts a request across the network to execute a registered custom callback.
26
+ * @param name The registered name of the custom callback to trigger.
27
+ * @param args A dictionary of arguments to pass to the callback function.
28
+ */
20
29
  runCustomCallback(name, args) {
21
30
  let customCallbackRequest = new Message();
22
31
  customCallbackRequest.setType(MessageType.DATA_EXCHANGE);
23
- customCallbackRequest.addData("custumCallbackName", name);
32
+ customCallbackRequest.addData("customCallbackName", name);
24
33
  customCallbackRequest.addData("customCallbackArgs", args);
25
34
  customCallbackRequest.setDestination(PeerType.BROADCAST, "");
26
35
  this._console.sendMessage(customCallbackRequest);
27
36
  }
37
+ /**
38
+ * Registers a local function to be executed when a specific custom callback request is received.
39
+ * @param name The identifier name for this callback.
40
+ * @param callback The function to execute when triggered by the network.
41
+ */
28
42
  registerCustomCallback(name, callback) {
29
43
  this._customCallbacks[name] = callback;
30
44
  }
45
+ /**
46
+ * Removes a previously registered custom callback from the local listener registry.
47
+ * @param name The identifier name of the callback to remove.
48
+ */
31
49
  unregisterCustomCallback(name) {
32
50
  if (Object.hasOwn(this._customCallbacks, name)) {
33
51
  delete this._customCallbacks[name];
@@ -1,8 +1,5 @@
1
1
  import { Console } from "./console.js";
2
2
  import { Resident } from "./resident.js";
3
- /**
4
- * This class reprensts a device
5
- */
6
3
  type Color = {
7
4
  r: number;
8
5
  g: number;
@@ -10,6 +7,10 @@ type Color = {
10
7
  lon?: number;
11
8
  loff?: number;
12
9
  };
10
+ /**
11
+ * Represents a physical or logical device connected to the console.
12
+ * Handles device-specific commands like LEDs, vibrations, and hardware module subscriptions.
13
+ */
13
14
  export declare class Device {
14
15
  private _address;
15
16
  private _color;
@@ -21,32 +22,66 @@ export declare class Device {
21
22
  constructor(console: Console, address?: string);
22
23
  get color(): Color;
23
24
  get name(): string;
25
+ /**
26
+ * Subscribes to a specific hardware event for this device.
27
+ * @param eventName The name of the event to listen to.
28
+ * @param callback Function to execute when the event is triggered.
29
+ */
24
30
  onEvent(eventName: string, callback: () => void): void;
31
+ /**
32
+ * Enables the cursor module and listens for coordinate updates.
33
+ * @param callback Function to execute with the incoming (x, y) coordinates.
34
+ */
25
35
  onCursor(callback: (x: number, y: number) => void): void;
36
+ /**
37
+ * Enables the biking module and listens for speed updates.
38
+ * @param callback Function to execute with the incoming speed data.
39
+ */
26
40
  onBiking(callback: (speed: number) => void): void;
41
+ /**
42
+ * Enables the vertical detector module and listens for orientation updates.
43
+ * @param callback Function to execute with the boolean vertical state.
44
+ */
27
45
  onVerticalDetector(callback: (vertical: boolean) => void): void;
46
+ /**
47
+ * Sends a request to the device to attach a specific event listener on the hardware side.
48
+ * @param event The event name to attach.
49
+ */
28
50
  private _attachEvent;
51
+ /**
52
+ * Sends a request to the device to enable a specific hardware module.
53
+ * @param moduleName The name of the module to enable (Note: retains original code spelling).
54
+ */
29
55
  private _enableModule;
56
+ /**
57
+ * Changes the current LED color of the device.
58
+ * @param color The RGB color configuration to apply.
59
+ */
30
60
  setColor(color: Color): void;
61
+ /**
62
+ * Sends a predefined sequence of colors to the device.
63
+ * @param sequence Array of color sequence identifiers or configurations.
64
+ * @param reset Whether to interrupt the current sequence before starting the new one.
65
+ */
31
66
  setColorSequence(sequence: string[], reset?: boolean): void;
32
67
  /**
33
- * Vibrate the device (use the motor vibrator)
34
- * @param time
35
- * @param blink
36
- * @param blinkOff
37
- * @param blinkCount
68
+ * Triggers the device's vibration motor.
69
+ * @param time Total vibration time in milliseconds.
70
+ * @param blink Enables pulsating/intermittent vibration.
71
+ * @param blinkOff The duration of the pause between pulses in milliseconds.
72
+ * @param blinkCount The number of pulsing cycles to execute.
38
73
  */
39
74
  vibrate(time: number, blink?: boolean, blinkOff?: number, blinkCount?: number): void;
40
75
  /**
41
- * Convert this device object to a json object
42
- * @returns
76
+ * Serializes the Device object into a generic dictionary.
77
+ * @returns A plain object representing the device's current state.
43
78
  */
44
79
  toObject(): {
45
80
  [key: string]: any;
46
81
  };
47
82
  /**
48
- * set the device object from a json object
49
- * @param object
83
+ * Hydrates the Device instance using properties from a provided object.
84
+ * @param object The plain object containing device properties.
50
85
  */
51
86
  fromObject(object: {
52
87
  [key: string]: any;