feat(streaming): add global activity watchers, client-side buffering, and improved real-time streaming UX
This commit is contained in:
@@ -106,6 +106,28 @@ IReq_PushS3Change: { event: IS3ChangeEvent } -> { received }
|
||||
IReq_PushActivityEvent: { event: IActivityEvent } -> { received }
|
||||
```
|
||||
|
||||
### WebSocket Context Pattern
|
||||
|
||||
When a TypedHandler receives a WebSocket request, the transport context is available via the second argument (`TypedTools` instance). SmartServe attaches the WebSocket peer to `localData.peer`:
|
||||
|
||||
```typescript
|
||||
// In a TypedHandler callback:
|
||||
async (reqData, context) => {
|
||||
// context is a TypedTools instance
|
||||
const peerId = context.localData?.peer?.id; // unique WebSocket connection ID
|
||||
}
|
||||
```
|
||||
|
||||
To push events back to a specific client, use `findTargetConnection`:
|
||||
|
||||
```typescript
|
||||
const conn = await typedSocket.findTargetConnection(async (c: any) => {
|
||||
return c.peer?.id === connectionId;
|
||||
});
|
||||
const request = typedSocket.createTypedRequest<IReq_Push>('pushEvent', conn);
|
||||
await request.fire({ event });
|
||||
```
|
||||
|
||||
### Dependencies Added
|
||||
|
||||
- `@api.global/typedsocket` - WebSocket client/server
|
||||
|
||||
Reference in New Issue
Block a user