subscriptions
Types from PocketBase's Go package subscriptions, as JavaScript sees them: you get these objects from $app and the other globals and from hook events, and call their methods by their JS names (Go's FindRecordById is findRecordById). The same package in Go: subscriptions.
subscriptions.Broker
Broker defines a struct for managing subscriptions clients.
| Member | Type | |
|---|---|---|
clients() |
(): { [key: string]: any } |
Clients returns a shallow copy of all registered clients indexed with their connection id. |
chunkedClients() |
(chunkSize: number): Array<Array<Client>> |
ChunkedClients splits the current clients into a chunked slice. |
totalClients() |
(): number |
TotalClients returns the total number of registered clients. |
clientById() |
(clientId: string): Client |
ClientById finds a registered client by its id. |
register() |
(client: Client): void |
Register adds a new client to the broker instance. |
unregister() |
(clientId: string): void |
Unregister removes a single client by its id and marks it as discarded. |
subscriptions.Client
Client is an interface for a generic subscription client.
| Member | Type | |
|---|---|---|
id() |
(): string |
Id Returns the unique id of the client. |
channel() |
(): undefined |
Channel returns the client's communication channel. |
subscriptions() |
(...prefixes: string[]): { [key: string]: any } |
Subscriptions returns a shallow copy of the client subscriptions matching the prefixes. If no prefix is specified, returns all subscriptions. |
subscribe() |
(...subs: string[]): void |
Subscribe subscribes the client to the provided subscriptions list. |
unsubscribe() |
(...subs: string[]): void |
Unsubscribe unsubscribes the client from the provided subscriptions list. |
hasSubscription() |
(sub: string): boolean |
HasSubscription checks if the client is subscribed to sub. |
set() |
(key: string, value: any): void |
Set stores any value to the client's context. |
unset() |
(key: string): void |
Unset removes a single value from the client's context. |
get() |
(key: string): any |
Get retrieves the key value from the client's context. |
discard() |
(): void |
Discard marks the client as "discarded" (and closes its channel), meaning that it shouldn't be used anymore for sending new messages. |
isDiscarded() |
(): boolean |
IsDiscarded indicates whether the client has been "discarded" and should no longer be used. |
send() |
(m: Message): void |
Send sends the specified message to the client's channel (if not discarded). |
subscriptions.Message
Message defines a client's channel data.
| Member | Type | |
|---|---|---|
name |
string |
|
data |
string|Array<number> |
|
writeSSE() |
(w: io.Writer, eventId: string): void |
WriteSSE writes the current message in a SSE format into the provided writer. |
Questions and comments
Comments are a GitHub Discussions thread; sign in with GitHub to post.