@inrupt/solid-client-notifications / websocketNotification / WebsocketNotification

Class: WebsocketNotification#

websocketNotification.WebsocketNotification

Constructor for a WebSocket Notification instance, which allows subscribing to resources in the solid ecosystem. See the Solid Notifications Protocol Specification for more details.

import { getDefaultSession } from '@inrupt/solid-authn-browser';
// or for node.js:
//   import { Session } from '@inrupt/solid-authn-node';

const session = getDefaultSession();
// for node.js:
//   const session = new Session();
//   await session.login({
//     oidcIssuer,
//     clientId,
//     clientSecret,
//   });

const socket = new WebsocketNotification(parentContainerUrl, {
  fetch: session.fetch,
});

socket.on("message", (notification) => {
  console.log("Change:", notification);
});

// Connect for receiving notifications:
await socket.connect();

// later:
socket.disconnect();

Hierarchy#

  • LiveNotification

    WebsocketNotification

Table of contents#

Constructors#

Methods#

Constructors#

constructor#

new WebsocketNotification(topic, options?)

Parameters#

Name

Type

topic

string

options?

NotificationOptions

Defined in#

src/websocketNotification.ts:132

Methods#

connect#

connect(providedEndpoint?, providedSubprotocol?): Promise<void>

Connects the websocket to start receiving notifications. If no providedEndpoint or providedSubprotocol parameter is present, then those will automatically be discovered based on the capabilities of the host of the resource that you’re subscribing to notifications for.

Parameters#

Name

Type

providedEndpoint?

string

providedSubprotocol?

string

Returns#

Promise<void>

Defined in#

src/websocketNotification.ts:143


disconnect#

disconnect(): void

Returns#

void

Defined in#

src/websocketNotification.ts:205


off#

off(event, listener): WebsocketNotification

Removes a listener for the “connected” event

Parameters#

Name

Type

event

"connected"

listener

() => void

Returns#

WebsocketNotification

Defined in#

src/websocketNotification.ts:43

off(event, listener): WebsocketNotification

Removes a listener for the “closed” event

Parameters#

Name

Type

event

"closed"

listener

() => void

Returns#

WebsocketNotification

Defined in#

src/websocketNotification.ts:56

off(event, listener): WebsocketNotification

Removes a listener for the “message” event

Parameters#

Name

Type

event

"message"

listener

(notification: object) => void

Returns#

WebsocketNotification

Defined in#

src/websocketNotification.ts:76

off(event, listener): WebsocketNotification

Removes a listener for the “error” event

Parameters#

Name

Type

event

"error"

listener

(error: ErrorEvent) => void

Returns#

WebsocketNotification

Defined in#

src/websocketNotification.ts:89


on#

on(event, listener): WebsocketNotification

Emitted when the connection is established

Parameters#

Name

Type

event

"connected"

listener

() => void

Returns#

WebsocketNotification

Defined in#

src/websocketNotification.ts:35

on(event, listener): WebsocketNotification

Emitted when the connection is closed

Parameters#

Name

Type

event

"closed"

listener

() => void

Returns#

WebsocketNotification

Defined in#

src/websocketNotification.ts:48

on(event, listener): WebsocketNotification

Emitted when a valid notification is received, the payload is a activitystreams Activity.

Parameters#

Name

Type

event

"message"

listener

(notification: object) => void

Returns#

WebsocketNotification

Defined in#

src/websocketNotification.ts:64

on(event, listener): WebsocketNotification

Emitted when an error is encountered on the WebSocket

Parameters#

Name

Type

event

"error"

listener

(error: ErrorEvent) => void

Returns#

WebsocketNotification

Defined in#

src/websocketNotification.ts:81


once#

once(event, listener): WebsocketNotification

Emitted when the next connection is established

Parameters#

Name

Type

event

"connected"

listener

() => void

Returns#

WebsocketNotification

Defined in#

src/websocketNotification.ts:39

once(event, listener): WebsocketNotification

Emitted when the next connection is closed

Parameters#

Name

Type

event

"closed"

listener

() => void

Returns#

WebsocketNotification

Defined in#

src/websocketNotification.ts:52

once(event, listener): WebsocketNotification

Emitted when the next valid notification is received, the payload is a activitystreams Activity.

Parameters#

Name

Type

event

"message"

listener

(notification: object) => void

Returns#

WebsocketNotification

Defined in#

src/websocketNotification.ts:71

once(event, listener): WebsocketNotification

Emitted when the next error is encountered on the WebSocket

Parameters#

Name

Type

event

"error"

listener

(error: ErrorEvent) => void

Returns#

WebsocketNotification

Defined in#

src/websocketNotification.ts:85


setSessionFetch#

setSessionFetch(sessionFetch?): void

Allows setting a WHATWG Fetch API compatible function for making HTTP requests. When @inrupt/solid-client-authn-browser is available and this property is not set, fetch will be imported from there. Otherwise, the HTTP requests will be unauthenticated.

Parameters#

Name

Type

Default value

sessionFetch

(input: RequestInfo | URL, init?: RequestInit) => Promise<Response>

crossFetch

Returns#

void

Defined in#

src/notification.ts:132