mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
feat: Replace WebSocketSubscription2021 with WebSocketChannel2023
This commit is contained in:
16
src/index.ts
16
src/index.ts
@@ -326,14 +326,14 @@ export * from './server/notifications/WebHookSubscription2021/WebHookSubscriptio
|
||||
export * from './server/notifications/WebHookSubscription2021/WebHookUnsubscriber';
|
||||
export * from './server/notifications/WebHookSubscription2021/WebHookWebId';
|
||||
|
||||
// Server/Notifications/WebSocketSubscription2021
|
||||
export * from './server/notifications/WebSocketSubscription2021/WebSocket2021Emitter';
|
||||
export * from './server/notifications/WebSocketSubscription2021/WebSocket2021Handler';
|
||||
export * from './server/notifications/WebSocketSubscription2021/WebSocket2021Listener';
|
||||
export * from './server/notifications/WebSocketSubscription2021/WebSocket2021Storer';
|
||||
export * from './server/notifications/WebSocketSubscription2021/WebSocket2021Util';
|
||||
export * from './server/notifications/WebSocketSubscription2021/WebSocketMap';
|
||||
export * from './server/notifications/WebSocketSubscription2021/WebSocketSubscription2021';
|
||||
// Server/Notifications/WebSocketChannel2023
|
||||
export * from './server/notifications/WebSocketChannel2023/WebSocket2023Emitter';
|
||||
export * from './server/notifications/WebSocketChannel2023/WebSocket2023Handler';
|
||||
export * from './server/notifications/WebSocketChannel2023/WebSocket2023Listener';
|
||||
export * from './server/notifications/WebSocketChannel2023/WebSocket2023Storer';
|
||||
export * from './server/notifications/WebSocketChannel2023/WebSocket2023Util';
|
||||
export * from './server/notifications/WebSocketChannel2023/WebSocketMap';
|
||||
export * from './server/notifications/WebSocketChannel2023/WebSocketChannel2023Type';
|
||||
|
||||
// Server/Notifications
|
||||
export * from './server/notifications/ActivityEmitter';
|
||||
|
||||
@@ -6,11 +6,11 @@ import { NotificationEmitter } from '../NotificationEmitter';
|
||||
import type { NotificationEmitterInput } from '../NotificationEmitter';
|
||||
|
||||
/**
|
||||
* Emits notifications on WebSocketSubscription2021 subscription.
|
||||
* Emits notifications on WebSocketChannel2023 subscription.
|
||||
* Uses the WebSockets found in the provided map.
|
||||
* The key should be the identifier of the matching channel.
|
||||
*/
|
||||
export class WebSocket2021Emitter extends NotificationEmitter {
|
||||
export class WebSocket2023Emitter extends NotificationEmitter {
|
||||
protected readonly logger = getLoggerFor(this);
|
||||
|
||||
private readonly socketMap: SetMultiMap<string, WebSocket>;
|
||||
@@ -2,12 +2,12 @@ import type { WebSocket } from 'ws';
|
||||
import { AsyncHandler } from '../../../util/handlers/AsyncHandler';
|
||||
import type { NotificationChannel } from '../NotificationChannel';
|
||||
|
||||
export interface WebSocket2021HandlerInput {
|
||||
export interface WebSocket2023HandlerInput {
|
||||
channel: NotificationChannel;
|
||||
webSocket: WebSocket;
|
||||
}
|
||||
|
||||
/**
|
||||
* A handler that is called when a valid WebSocketSubscription2021 connection has been made.
|
||||
* A handler that is called when a valid WebSocketChannel2023 connection has been made.
|
||||
*/
|
||||
export abstract class WebSocket2021Handler extends AsyncHandler<WebSocket2021HandlerInput> {}
|
||||
export abstract class WebSocket2023Handler extends AsyncHandler<WebSocket2023HandlerInput> {}
|
||||
@@ -4,21 +4,21 @@ import type { InteractionRoute } from '../../../identity/interaction/routing/Int
|
||||
import { getLoggerFor } from '../../../logging/LogUtil';
|
||||
import { WebSocketServerConfigurator } from '../../WebSocketServerConfigurator';
|
||||
import type { NotificationChannelStorage } from '../NotificationChannelStorage';
|
||||
import type { WebSocket2021Handler } from './WebSocket2021Handler';
|
||||
import { parseWebSocketRequest } from './WebSocket2021Util';
|
||||
import type { WebSocket2023Handler } from './WebSocket2023Handler';
|
||||
import { parseWebSocketRequest } from './WebSocket2023Util';
|
||||
|
||||
/**
|
||||
* Listens for WebSocket connections and verifies if they are valid WebSocketSubscription2021 connections,
|
||||
* in which case its {@link WebSocket2021Handler} will be alerted.
|
||||
* Listens for WebSocket connections and verifies if they are valid WebSocketChannel2023 connections,
|
||||
* in which case its {@link WebSocket2023Handler} will be alerted.
|
||||
*/
|
||||
export class WebSocket2021Listener extends WebSocketServerConfigurator {
|
||||
export class WebSocket2023Listener extends WebSocketServerConfigurator {
|
||||
protected readonly logger = getLoggerFor(this);
|
||||
|
||||
private readonly storage: NotificationChannelStorage;
|
||||
private readonly handler: WebSocket2021Handler;
|
||||
private readonly handler: WebSocket2023Handler;
|
||||
private readonly path: string;
|
||||
|
||||
public constructor(storage: NotificationChannelStorage, handler: WebSocket2021Handler, route: InteractionRoute) {
|
||||
public constructor(storage: NotificationChannelStorage, handler: WebSocket2023Handler, route: InteractionRoute) {
|
||||
super();
|
||||
this.storage = storage;
|
||||
this.handler = handler;
|
||||
@@ -3,11 +3,11 @@ import { getLoggerFor } from '../../../logging/LogUtil';
|
||||
import type { SetMultiMap } from '../../../util/map/SetMultiMap';
|
||||
import { setSafeInterval } from '../../../util/TimerUtil';
|
||||
import type { NotificationChannelStorage } from '../NotificationChannelStorage';
|
||||
import type { WebSocket2021HandlerInput } from './WebSocket2021Handler';
|
||||
import { WebSocket2021Handler } from './WebSocket2021Handler';
|
||||
import type { WebSocket2023HandlerInput } from './WebSocket2023Handler';
|
||||
import { WebSocket2023Handler } from './WebSocket2023Handler';
|
||||
|
||||
/**
|
||||
* Keeps track of the WebSockets that were opened for a WebSocketSubscription2021 channel.
|
||||
* Keeps track of the WebSockets that were opened for a WebSocketChannel2023 channel.
|
||||
* The WebSockets are stored in the map using the identifier of the matching channel.
|
||||
*
|
||||
* `cleanupTimer` defines in minutes how often the stored WebSockets are closed
|
||||
@@ -15,7 +15,7 @@ import { WebSocket2021Handler } from './WebSocket2021Handler';
|
||||
* Defaults to 60 minutes.
|
||||
* Open WebSockets will not receive notifications if their channel expired.
|
||||
*/
|
||||
export class WebSocket2021Storer extends WebSocket2021Handler {
|
||||
export class WebSocket2023Storer extends WebSocket2023Handler {
|
||||
protected readonly logger = getLoggerFor(this);
|
||||
|
||||
private readonly storage: NotificationChannelStorage;
|
||||
@@ -34,7 +34,7 @@ export class WebSocket2021Storer extends WebSocket2021Handler {
|
||||
timer.unref();
|
||||
}
|
||||
|
||||
public async handle({ webSocket, channel }: WebSocket2021HandlerInput): Promise<void> {
|
||||
public async handle({ webSocket, channel }: WebSocket2023HandlerInput): Promise<void> {
|
||||
this.socketMap.add(channel.id, webSocket);
|
||||
webSocket.on('error', (): boolean => this.socketMap.deleteEntry(channel.id, webSocket));
|
||||
webSocket.on('close', (): boolean => this.socketMap.deleteEntry(channel.id, webSocket));
|
||||
@@ -5,45 +5,45 @@ import { getLoggerFor } from '../../../logging/LogUtil';
|
||||
import { NOTIFY } from '../../../util/Vocabularies';
|
||||
import { BaseChannelType } from '../BaseChannelType';
|
||||
import type { NotificationChannel } from '../NotificationChannel';
|
||||
import { generateWebSocketUrl } from './WebSocket2021Util';
|
||||
import { generateWebSocketUrl } from './WebSocket2023Util';
|
||||
|
||||
/**
|
||||
* A {@link NotificationChannel} containing the necessary fields for a WebSocketSubscription2021 channel.
|
||||
* A {@link NotificationChannel} containing the necessary fields for a WebSocketChannel2023 channel.
|
||||
*/
|
||||
export interface WebSocketSubscription2021Channel extends NotificationChannel {
|
||||
export interface WebSocketChannel2023 extends NotificationChannel {
|
||||
/**
|
||||
* The "notify:WebSocketSubscription2021" type.
|
||||
* The "notify:WebSocketChannel2023" type.
|
||||
*/
|
||||
type: typeof NOTIFY.WebSocketSubscription2021;
|
||||
type: typeof NOTIFY.WebSocketChannel2023;
|
||||
/**
|
||||
* The WebSocket through which the channel will send notifications.
|
||||
*/
|
||||
source: string;
|
||||
receiveFrom: string;
|
||||
}
|
||||
|
||||
export function isWebSocket2021Channel(channel: NotificationChannel): channel is WebSocketSubscription2021Channel {
|
||||
return channel.type === NOTIFY.WebSocketSubscription2021;
|
||||
export function isWebSocket2023Channel(channel: NotificationChannel): channel is WebSocketChannel2023 {
|
||||
return channel.type === NOTIFY.WebSocketChannel2023;
|
||||
}
|
||||
|
||||
/**
|
||||
* The notification channel type WebSocketSubscription2021 as described in
|
||||
* The notification channel type WebSocketChannel2023 as described in
|
||||
* https://solidproject.org/TR/websocket-subscription-2021
|
||||
*
|
||||
* Requires read permissions on a resource to be able to receive notifications.
|
||||
*/
|
||||
export class WebSocketSubscription2021 extends BaseChannelType {
|
||||
export class WebSocketChannel2023Type extends BaseChannelType {
|
||||
protected readonly logger = getLoggerFor(this);
|
||||
|
||||
public constructor(route: InteractionRoute, features?: string[]) {
|
||||
super(NOTIFY.terms.WebSocketSubscription2021, route, features);
|
||||
super(NOTIFY.terms.WebSocketChannel2023, route, features);
|
||||
}
|
||||
|
||||
public async initChannel(data: Store, credentials: Credentials): Promise<WebSocketSubscription2021Channel> {
|
||||
public async initChannel(data: Store, credentials: Credentials): Promise<WebSocketChannel2023> {
|
||||
const channel = await super.initChannel(data, credentials);
|
||||
return {
|
||||
...channel,
|
||||
type: NOTIFY.WebSocketSubscription2021,
|
||||
source: generateWebSocketUrl(this.path, channel.id),
|
||||
type: NOTIFY.WebSocketChannel2023,
|
||||
receiveFrom: generateWebSocketUrl(this.path, channel.id),
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -197,6 +197,7 @@ export const NOTIFY = createVocabulary('http://www.w3.org/ns/solid/notifications
|
||||
'endAt',
|
||||
'feature',
|
||||
'rate',
|
||||
'receiveFrom',
|
||||
'startAt',
|
||||
'state',
|
||||
'subscription',
|
||||
@@ -206,7 +207,7 @@ export const NOTIFY = createVocabulary('http://www.w3.org/ns/solid/notifications
|
||||
'webid',
|
||||
|
||||
'WebHookSubscription2021',
|
||||
'WebSocketSubscription2021',
|
||||
'WebSocketChannel2023',
|
||||
);
|
||||
|
||||
export const OIDC = createVocabulary('http://www.w3.org/ns/solid/oidc#',
|
||||
|
||||
Reference in New Issue
Block a user