@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 |
---|---|
|
|
|
Defined in#
src/websocketNotification.ts:133
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 |
---|---|
|
|
|
|
Returns#
Promise
<void
>
Defined in#
src/websocketNotification.ts:144
disconnect#
▸ disconnect(): void
Returns#
void
Defined in#
src/websocketNotification.ts:206
off#
▸ off(event
, listener
): WebsocketNotification
Removes a listener for the “connected” event
Parameters#
Name |
Type |
---|---|
|
|
|
() => |
Returns#
Defined in#
src/websocketNotification.ts:44
▸ off(event
, listener
): WebsocketNotification
Removes a listener for the “closed” event
Parameters#
Name |
Type |
---|---|
|
|
|
() => |
Returns#
Defined in#
src/websocketNotification.ts:57
▸ off(event
, listener
): WebsocketNotification
Removes a listener for the “message” event
Parameters#
Name |
Type |
---|---|
|
|
|
( |
Returns#
Defined in#
src/websocketNotification.ts:77
▸ off(event
, listener
): WebsocketNotification
Removes a listener for the “error” event
Parameters#
Name |
Type |
---|---|
|
|
|
( |
Returns#
Defined in#
src/websocketNotification.ts:90
on#
▸ on(event
, listener
): WebsocketNotification
Emitted when the connection is established
Parameters#
Name |
Type |
---|---|
|
|
|
() => |
Returns#
Defined in#
src/websocketNotification.ts:36
▸ on(event
, listener
): WebsocketNotification
Emitted when the connection is closed
Parameters#
Name |
Type |
---|---|
|
|
|
() => |
Returns#
Defined in#
src/websocketNotification.ts:49
▸ on(event
, listener
): WebsocketNotification
Emitted when a valid notification is received, the payload is a activitystreams Activity.
Parameters#
Name |
Type |
---|---|
|
|
|
( |
Returns#
Defined in#
src/websocketNotification.ts:65
▸ on(event
, listener
): WebsocketNotification
Emitted when an error is encountered on the WebSocket
Parameters#
Name |
Type |
---|---|
|
|
|
( |
Returns#
Defined in#
src/websocketNotification.ts:82
once#
▸ once(event
, listener
): WebsocketNotification
Emitted when the next connection is established
Parameters#
Name |
Type |
---|---|
|
|
|
() => |
Returns#
Defined in#
src/websocketNotification.ts:40
▸ once(event
, listener
): WebsocketNotification
Emitted when the next connection is closed
Parameters#
Name |
Type |
---|---|
|
|
|
() => |
Returns#
Defined in#
src/websocketNotification.ts:53
▸ once(event
, listener
): WebsocketNotification
Emitted when the next valid notification is received, the payload is a activitystreams Activity.
Parameters#
Name |
Type |
---|---|
|
|
|
( |
Returns#
Defined in#
src/websocketNotification.ts:72
▸ once(event
, listener
): WebsocketNotification
Emitted when the next error is encountered on the WebSocket
Parameters#
Name |
Type |
---|---|
|
|
|
( |
Returns#
Defined in#
src/websocketNotification.ts:86
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 |
---|---|---|
|
( |
|
Returns#
void
Defined in#
src/notification.ts:132