mirror of
https://github.com/LukeHagar/crossws.git
synced 2025-12-06 04:19:26 +00:00
feat(peer): support context (#110)
This commit is contained in:
@@ -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
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user