@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

Implements#

Table of contents#

Constructors#

Methods#

Constructors#

constructor#

new WebsocketNotification(topic, options?)

Parameters#

Name

Type

topic

string

options?

NotificationOptions

Overrides#

LiveNotification.constructor

Defined in#

src/websocketNotification.ts:136

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>

Overrides#

LiveNotification.connect

Defined in#

src/websocketNotification.ts:147


disconnect#

disconnect(): void

Returns#

void

Overrides#

LiveNotification.disconnect

Defined in#

src/websocketNotification.ts:209


off#

off(eventName, listener): WebsocketNotification

Removes a listener for the “connected” event

Parameters#

Name

Type

eventName

string

listener

(…args: any[]) => void

Returns#

WebsocketNotification

Implementation of#

IWebsocketNotification.off

Inherited from#

LiveNotification.off

Defined in#

src/liveNotification.ts:80


on#

on(eventName, listener): WebsocketNotification

Emitted when the connection is established

Parameters#

Name

Type

eventName

string

listener

(…args: any[]) => void

Returns#

WebsocketNotification

Implementation of#

IWebsocketNotification.on

Inherited from#

LiveNotification.on

Defined in#

src/liveNotification.ts:68


once#

once(eventName, listener): WebsocketNotification

Emitted when the next connection is established

Parameters#

Name

Type

eventName

string | symbol

listener

(…args: any[]) => void

Returns#

WebsocketNotification

Implementation of#

IWebsocketNotification.once

Inherited from#

LiveNotification.once

Defined in#

src/liveNotification.ts:74


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

Deprecated

In future versions of this library the fetch function MUST be set in the constructor, and the fetch function will always be unathenticated if no fetch function is provided in the constructor.

Inherited from#

LiveNotification.setSessionFetch

Defined in#

src/notification.ts:138