BREAKING CHANGE(socketconnection): Stricter typings, smartserve hooks, connection fixes, and tag API change

This commit is contained in:
2025-12-04 07:59:44 +00:00
parent 5b21955e04
commit 0499db71b8
12 changed files with 1039 additions and 2864 deletions

View File

@@ -143,20 +143,24 @@ await socketConnection.addTag({
Use smartsocket with `@push.rocks/smartserve` for advanced HTTP/WebSocket handling:
```typescript
import { Smartserve } from '@push.rocks/smartserve';
import { SmartServe } from '@push.rocks/smartserve';
import { Smartsocket } from '@push.rocks/smartsocket';
const smartserve = new Smartserve({ port: 3000 });
// Create smartsocket without a port (hooks mode)
const smartsocket = new Smartsocket({ alias: 'myServer' });
// Set smartserve as external server
await smartsocket.setExternalServer('smartserve', smartserve);
// Get WebSocket hooks and pass them to SmartServe
const wsHooks = smartsocket.getSmartserveWebSocketHooks();
const smartserve = new SmartServe({
port: 3000,
websocket: wsHooks
});
// Get WebSocket hooks for smartserve
const wsHooks = smartsocket.socketServer.getSmartserveWebSocketHooks();
// Add socket functions as usual
smartsocket.addSocketFunction(myFunction);
// Configure smartserve with the hooks
// (see smartserve documentation for integration details)
// Start smartserve (smartsocket hooks mode doesn't need start())
await smartserve.start();
```
### Handling Disconnections
@@ -223,11 +227,11 @@ const response = await client.serverCall<IGreetRequest>('greet', { name: 'Bob' }
| Method | Description |
|--------|-------------|
| `start()` | Start the WebSocket server |
| `start()` | Start the WebSocket server (not needed in hooks mode) |
| `stop()` | Stop the server and close all connections |
| `addSocketFunction(fn)` | Register a function that clients can call |
| `clientCall(funcName, data, connection)` | Call a function on a specific client |
| `setExternalServer(type, server)` | Use an external server (smartserve) |
| `getSmartserveWebSocketHooks()` | Get hooks for smartserve integration |
### SmartsocketClient