@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?): WebsocketNotification

Parameters#

Name

Type

topic

string

options?

NotificationOptions

Returns#

WebsocketNotification

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): this

Removes a listener for the “connected” event

Parameters#

Name

Type

eventName

string

listener

(…args: any[]) => void

Returns#

this

Implementation of#

IWebsocketNotification.off

Inherited from#

LiveNotification.off

Defined in#

src/liveNotification.ts:80


on#

on(eventName, listener): this

Emitted when the connection is established

Parameters#

Name

Type

eventName

string

listener

(…args: any[]) => void

Returns#

this

Implementation of#

IWebsocketNotification.on

Inherited from#

LiveNotification.on

Defined in#

src/liveNotification.ts:68


once#

once(eventName, listener): this

Emitted when the next connection is established

Parameters#

Name

Type

eventName

string | symbol

listener

(…args: any[]) => void

Returns#

this

Implementation of#

IWebsocketNotification.once

Inherited from#

LiveNotification.once

Defined in#

src/liveNotification.ts:74