jmri-client 3.7.0 → 4.0.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.
package/README.md CHANGED
@@ -19,6 +19,7 @@ WebSocket client for [JMRI](http://jmri.sourceforge.net/) with real-time updates
19
19
  - ✅ **Heartbeat monitoring** - Automatic ping/pong keepalive
20
20
  - ✅ **TypeScript** - Full type definitions included
21
21
  - ✅ **Dual module support** - ESM and CommonJS
22
+ - ✅ **Extensible** - Subclass `JmriClient` to add support for additional JMRI object types
22
23
 
23
24
  ## Installation
24
25
 
@@ -105,6 +106,37 @@ client.on('reconnecting', (attempt, delay) => {
105
106
  });
106
107
  ```
107
108
 
109
+ ### Extending JmriClient
110
+
111
+ `JmriClient` exposes its `wsClient` as `protected`, so you can subclass it to add support for JMRI object types not yet built in (e.g., sensors, lights, routes, blocks):
112
+
113
+ ```typescript
114
+ import { JmriClient } from 'jmri-client';
115
+ import type { PartialClientOptions } from 'jmri-client';
116
+
117
+ class MyExtendedClient extends JmriClient {
118
+ constructor(options?: PartialClientOptions) {
119
+ super(options);
120
+
121
+ // this.wsClient is available — use it to send/receive JMRI JSON messages
122
+ this.wsClient.on('update', (message: any) => {
123
+ if (message.type === 'sensor') {
124
+ this.emit('sensor:changed', message.data.name, message.data.state);
125
+ }
126
+ });
127
+ }
128
+
129
+ async listSensors() {
130
+ const response = await this.wsClient.request({ type: 'sensor', method: 'list' });
131
+ return Array.isArray(response?.data)
132
+ ? response.data.map((r: any) => r.data ?? r)
133
+ : [];
134
+ }
135
+ }
136
+ ```
137
+
138
+ `WebSocketClient` is also exported for direct use if you need it. See its `send()`, `request()`, and `on('update', ...)` API for low-level messaging.
139
+
108
140
  ## Testing
109
141
 
110
142
  **Unit Tests** (no hardware required):
@@ -2242,6 +2242,7 @@ export {
2242
2242
  MockResponseManager,
2243
2243
  PowerState,
2244
2244
  TurnoutState,
2245
+ WebSocketClient,
2245
2246
  isThrottleFunctionKey,
2246
2247
  isValidSpeed,
2247
2248
  mockData,
package/dist/cjs/index.js CHANGED
@@ -4,9 +4,11 @@
4
4
  * WebSocket client for JMRI with real-time updates and throttle control
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.mockData = exports.mockResponseManager = exports.MockResponseManager = exports.turnoutStateToString = exports.powerStateToString = exports.isValidSpeed = exports.isThrottleFunctionKey = exports.ConnectionState = exports.TurnoutState = exports.PowerState = exports.JmriClient = void 0;
7
+ exports.mockData = exports.mockResponseManager = exports.MockResponseManager = exports.turnoutStateToString = exports.powerStateToString = exports.isValidSpeed = exports.isThrottleFunctionKey = exports.ConnectionState = exports.TurnoutState = exports.PowerState = exports.WebSocketClient = exports.JmriClient = void 0;
8
8
  var client_js_1 = require("./client.js");
9
9
  Object.defineProperty(exports, "JmriClient", { enumerable: true, get: function () { return client_js_1.JmriClient; } });
10
+ var websocket_client_js_1 = require("./core/websocket-client.js");
11
+ Object.defineProperty(exports, "WebSocketClient", { enumerable: true, get: function () { return websocket_client_js_1.WebSocketClient; } });
10
12
  // Export types
11
13
  var index_js_1 = require("./types/index.js");
12
14
  // JMRI message types
package/dist/esm/index.js CHANGED
@@ -3,6 +3,7 @@
3
3
  * WebSocket client for JMRI with real-time updates and throttle control
4
4
  */
5
5
  export { JmriClient } from './client.js';
6
+ export { WebSocketClient } from './core/websocket-client.js';
6
7
  // Export types
7
8
  export {
8
9
  // JMRI message types
@@ -2,6 +2,7 @@
2
2
  * Main JMRI client class
3
3
  */
4
4
  import { EventEmitter } from 'eventemitter3';
5
+ import { WebSocketClient } from './core/websocket-client.js';
5
6
  import { PartialClientOptions } from './types/client-options.js';
6
7
  import { PowerState, RosterEntryWrapper, TurnoutState, TurnoutData } from './types/jmri-messages.js';
7
8
  import { ConnectionState } from './types/events.js';
@@ -12,7 +13,7 @@ import { ThrottleAcquireOptions, ThrottleFunctionKey, ThrottleState } from './ty
12
13
  */
13
14
  export declare class JmriClient extends EventEmitter {
14
15
  private options;
15
- private wsClient;
16
+ protected wsClient: WebSocketClient;
16
17
  private powerManager;
17
18
  private rosterManager;
18
19
  private throttleManager;
@@ -3,6 +3,7 @@
3
3
  * WebSocket client for JMRI with real-time updates and throttle control
4
4
  */
5
5
  export { JmriClient } from './client.js';
6
+ export { WebSocketClient } from './core/websocket-client.js';
6
7
  export { JmriClientOptions, PartialClientOptions, ReconnectionOptions, HeartbeatOptions, MockOptions, PowerState, TurnoutState, RosterEntry, TurnoutData, JmriMessage, PowerMessage, TurnoutMessage, ThrottleMessage, RosterMessage, ConnectionState, EventPayloads, ThrottleAcquireOptions, ThrottleFunctionKey, ThrottleState } from './types/index.js';
7
8
  export { isThrottleFunctionKey, isValidSpeed } from './types/throttle.js';
8
9
  export { powerStateToString, turnoutStateToString } from './types/jmri-messages.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jmri-client",
3
- "version": "3.7.0",
3
+ "version": "4.0.0",
4
4
  "description": "WebSocket client for JMRI with real-time updates and throttle control - works in both Node.js and browsers",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/esm/index.js",