diff --git a/src/examples/asyncEngine/asyncGlobalState.ts b/src/examples/asyncEngine/asyncGlobalState.ts index 1c0aeaffee..c552e697d0 100644 --- a/src/examples/asyncEngine/asyncGlobalState.ts +++ b/src/examples/asyncEngine/asyncGlobalState.ts @@ -154,7 +154,11 @@ function setSubscriptions(params) { const instanceState = getInstanceState(); Object.keys(params.subscriptions).forEach((subscription) => { - instanceState.subscriptions[subscription] = params.subscriptions[subscription]; + if (typeof params.subscriptions[subscription] === 'function') { + instanceState.subscriptions[subscription] = params.subscriptions[subscription]; + } else { + delete instanceState.subscriptions[subscription]; + } }); return { ...SUCCESS }; } diff --git a/src/global/state/globalState.ts b/src/global/state/globalState.ts index 22ed944d60..96240aa90a 100644 --- a/src/global/state/globalState.ts +++ b/src/global/state/globalState.ts @@ -321,6 +321,10 @@ export function getTopics() { return _globalStateProvider.getTopics(); } +export function hasTopic(topic) { + return getTopics()?.topics?.includes(topic); +} + export type CallListenerArgs = { notices: Notice[]; topic: string; diff --git a/src/global/state/syncGlobalState.ts b/src/global/state/syncGlobalState.ts index 44735e56f4..d848583d0f 100644 --- a/src/global/state/syncGlobalState.ts +++ b/src/global/state/syncGlobalState.ts @@ -121,7 +121,11 @@ export function setSubscriptions(params: any) { if (typeof params.subscriptions !== 'object') return { error: INVALID_VALUES }; Object.keys(params.subscriptions).forEach((subscription) => { - syncGlobalState.subscriptions[subscription] = params.subscriptions[subscription]; + if (typeof params.subscriptions[subscription] === 'function') { + syncGlobalState.subscriptions[subscription] = params.subscriptions[subscription]; + } else { + delete syncGlobalState.subscriptions[subscription]; + } }); return { ...SUCCESS }; diff --git a/src/server/providers/factory/engines/asyncGlobalState.ts b/src/server/providers/factory/engines/asyncGlobalState.ts index 5da37f55e5..0bc70932d3 100644 --- a/src/server/providers/factory/engines/asyncGlobalState.ts +++ b/src/server/providers/factory/engines/asyncGlobalState.ts @@ -160,7 +160,11 @@ function setSubscriptions(params) { const instanceState = getInstanceState(); Object.keys(params.subscriptions).forEach((subscription) => { - instanceState.subscriptions[subscription] = params.subscriptions[subscription]; + if (typeof params.subscriptions[subscription] === 'function') { + instanceState.subscriptions[subscription] = params.subscriptions[subscription]; + } else { + delete instanceState.subscriptions[subscription]; + } }); return { ...SUCCESS }; }