feat(peer): support context (#110)

This commit is contained in:
Pooya Parsa
2025-01-22 00:40:45 +02:00
committed by GitHub
parent e3c2cf5a4d
commit d17eee6ce0
2 changed files with 11 additions and 1 deletions

View File

@@ -33,7 +33,14 @@ The IP address of the client.
Direct access to the [`WebSocket`](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket) instance. Direct access to the [`WebSocket`](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket) instance.
> [!NOTE] > [!NOTE]
> WebSocket properties vary across runtimes. When accessing `peer.websocket`, a lightweight proxy increases stablity. Refer to the [compatibility table](#compatibility) for more info. > WebSocket properties vary across runtimes. When accessing `peer.websocket`, a lightweight proxy increases stability. Refer to the [compatibility table](#compatibility) for more info.
### `peer.context`
The context is an object that contains arbitrary information about the request.
> [!NOTE]
> context data can be volatile in some runtimes.
## Instance methods ## Instance methods

View File

@@ -14,8 +14,11 @@ export abstract class Peer<Internal extends AdapterInternal = AdapterInternal> {
#ws?: Partial<web.WebSocket>; #ws?: Partial<web.WebSocket>;
readonly context: Record<string, unknown>;
constructor(internal: Internal) { constructor(internal: Internal) {
this._topics = new Set(); this._topics = new Set();
this.context = {};
this._internal = internal; this._internal = internal;
} }