From d17eee6ce0345974951a92ffa80c46ef3160aad3 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Wed, 22 Jan 2025 00:40:45 +0200 Subject: [PATCH] feat(peer): support `context` (#110) --- docs/1.guide/3.peer.md | 9 ++++++++- src/peer.ts | 3 +++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/docs/1.guide/3.peer.md b/docs/1.guide/3.peer.md index f9917ce..f3e1316 100644 --- a/docs/1.guide/3.peer.md +++ b/docs/1.guide/3.peer.md @@ -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. > [!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 diff --git a/src/peer.ts b/src/peer.ts index 5619a3e..917af28 100644 --- a/src/peer.ts +++ b/src/peer.ts @@ -14,8 +14,11 @@ export abstract class Peer { #ws?: Partial; + readonly context: Record; + constructor(internal: Internal) { this._topics = new Set(); + this.context = {}; this._internal = internal; }