|
|
@ -1,4 +1,4 @@ |
|
|
|
import type { ConnectedContext } from "@ldo/connected"; |
|
|
|
import type { ConnectedContext, SubscriptionCallbacks } from "@ldo/connected"; |
|
|
|
import type { NotificationCallbackError } from "./results/NotificationErrors"; |
|
|
|
import type { NotificationCallbackError } from "./results/NotificationErrors"; |
|
|
|
import { v4 } from "uuid"; |
|
|
|
import { v4 } from "uuid"; |
|
|
|
import type { SolidContainer } from "../resources/SolidContainer"; |
|
|
|
import type { SolidContainer } from "../resources/SolidContainer"; |
|
|
@ -6,12 +6,6 @@ import type { SolidLeaf } from "../resources/SolidLeaf"; |
|
|
|
import type { SolidNotificationMessage } from "./SolidNotificationMessage"; |
|
|
|
import type { SolidNotificationMessage } from "./SolidNotificationMessage"; |
|
|
|
import type { SolidConnectedPlugin } from "../SolidConnectedPlugin"; |
|
|
|
import type { SolidConnectedPlugin } from "../SolidConnectedPlugin"; |
|
|
|
|
|
|
|
|
|
|
|
export interface SubscriptionCallbacks { |
|
|
|
|
|
|
|
onNotification?: (message: SolidNotificationMessage) => void; |
|
|
|
|
|
|
|
// TODO: make notification errors more specific
|
|
|
|
|
|
|
|
onNotificationError?: (error: Error) => void; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* @internal |
|
|
|
* @internal |
|
|
|
* Abstract class for notification subscription methods. |
|
|
|
* Abstract class for notification subscription methods. |
|
|
@ -20,7 +14,10 @@ export abstract class SolidNotificationSubscription { |
|
|
|
protected resource: SolidContainer | SolidLeaf; |
|
|
|
protected resource: SolidContainer | SolidLeaf; |
|
|
|
protected parentSubscription: (message: SolidNotificationMessage) => void; |
|
|
|
protected parentSubscription: (message: SolidNotificationMessage) => void; |
|
|
|
protected context: ConnectedContext<SolidConnectedPlugin[]>; |
|
|
|
protected context: ConnectedContext<SolidConnectedPlugin[]>; |
|
|
|
protected subscriptions: Record<string, SubscriptionCallbacks> = {}; |
|
|
|
protected subscriptions: Record< |
|
|
|
|
|
|
|
string, |
|
|
|
|
|
|
|
SubscriptionCallbacks<SolidNotificationMessage> |
|
|
|
|
|
|
|
> = {}; |
|
|
|
private isOpen: boolean = false; |
|
|
|
private isOpen: boolean = false; |
|
|
|
|
|
|
|
|
|
|
|
constructor( |
|
|
|
constructor( |
|
|
@ -48,7 +45,7 @@ export abstract class SolidNotificationSubscription { |
|
|
|
* subscribeToNotifications |
|
|
|
* subscribeToNotifications |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
async subscribeToNotifications( |
|
|
|
async subscribeToNotifications( |
|
|
|
subscriptionCallbacks?: SubscriptionCallbacks, |
|
|
|
subscriptionCallbacks?: SubscriptionCallbacks<SolidNotificationMessage>, |
|
|
|
): Promise<string> { |
|
|
|
): Promise<string> { |
|
|
|
const subscriptionId = v4(); |
|
|
|
const subscriptionId = v4(); |
|
|
|
this.subscriptions[subscriptionId] = subscriptionCallbacks ?? {}; |
|
|
|
this.subscriptions[subscriptionId] = subscriptionCallbacks ?? {}; |
|
|
|