From 79e23dcc566bb56a0dc0570fc17d1acca878652b Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 22 Sep 2020 19:28:47 +0200 Subject: [PATCH 1/8] Initial implementation of handler reregistering --- nodecg-io-core/extension/bundleManager.ts | 8 ++++ nodecg-io-core/extension/instanceManager.ts | 46 ++++++++++++++++++--- nodecg-io-core/extension/serviceBundle.ts | 12 ++++++ nodecg-io-core/extension/types.d.ts | 12 ++++++ 4 files changed, 73 insertions(+), 5 deletions(-) diff --git a/nodecg-io-core/extension/bundleManager.ts b/nodecg-io-core/extension/bundleManager.ts index b0a615b69..206412180 100644 --- a/nodecg-io-core/extension/bundleManager.ts +++ b/nodecg-io-core/extension/bundleManager.ts @@ -81,6 +81,7 @@ export class BundleManager extends EventEmitter { if (svcDependency === undefined) { return error(`Bundle "${bundleName} doesn't depend on the "${instance.serviceType}" service.`); } + const oldInstance = svcDependency.serviceInstance; // Update service instance of service dependency, remove client update callback from old service instance (if applicable) // and add the callback to the new instance. @@ -88,7 +89,9 @@ export class BundleManager extends EventEmitter { // Let the bundle update his reference to the client svcDependency.clientUpdateCallback(instance.client); + this.emit("change"); + this.emit("reregisterInstance", oldInstance); return emptySuccess(); } @@ -105,10 +108,15 @@ export class BundleManager extends EventEmitter { const svcDependency = bundle?.find((svcDep) => svcDep.serviceType === serviceType); if (svcDependency !== undefined) { + const oldInstance = svcDependency.serviceInstance; + // Unset service instance and let the bundle know that it hasn't access to this service anymore. svcDependency.serviceInstance = undefined; svcDependency.clientUpdateCallback(undefined); + this.emit("change"); + this.emit("reregisterInstance", oldInstance); + return true; } diff --git a/nodecg-io-core/extension/instanceManager.ts b/nodecg-io-core/extension/instanceManager.ts index 8c69a266a..ea844b2ee 100644 --- a/nodecg-io-core/extension/instanceManager.ts +++ b/nodecg-io-core/extension/instanceManager.ts @@ -19,6 +19,9 @@ export class InstanceManager extends EventEmitter { private readonly bundles: BundleManager, ) { super(); + bundles.on("reregisterInstance", (serviceInstance?: string) => + this.reregisterHandlersOfInstance(serviceInstance), + ); } /** @@ -176,17 +179,14 @@ export class InstanceManager extends EventEmitter { // Check if a error happened while creating the client if (client.failed) { - this.nodecg.log.error( - `The "${inst.serviceType}" service produced an error while creating a client: ${client.errorMessage}`, - ); - inst.client = undefined; + throw client.errorMessage; // Error logging happens in catch block } else { // Update service instance object inst.client = client.result; } } catch (err) { this.nodecg.log.error( - `The "${inst.serviceType}" service function produced an error while creating a client: ${err}`, + `The "${inst.serviceType}" service produced an error while creating a client: ${err}`, ); inst.client = undefined; } @@ -201,4 +201,40 @@ export class InstanceManager extends EventEmitter { service.stopClient(oldClient); } } + + /** + * Removes all handlers from the service client of the instance and lets bundles readd their handlers. + * @param instanceName the name of the instance which handlers should be re-registred + */ + private reregisterHandlersOfInstance(instanceName?: string): void { + if (!instanceName) return; + + const inst = this.getServiceInstance(instanceName); + if (!inst) { + this.nodecg.log.error(`Can't re-register handlers of instance "${instanceName}": instance not found`); + return; + } + + const svc = this.services.getService(inst.serviceType); + if (svc.failed) { + this.nodecg.log.error( + `Can't reregister handlers of instance "${instanceName}": can't get service: ${svc.errorMessage}`, + ); + return; + } + + if (!svc.result.removeHandlers) return; // Service provides no way to remove handlers, thus this service has no handlers + + // Remove handlers + try { + svc.result.removeHandlers(inst.client); + } catch (err) { + this.nodecg.log.error( + `Can't re-register handlers of instance "${instanceName}": error while removing handlers: ${err.toString()}`, + ); + } + // Readd handlers by running the `onAvailable` function of all bundles + // that are using this service instance. + this.bundles.handleInstanceUpdate(inst, instanceName); + } } diff --git a/nodecg-io-core/extension/serviceBundle.ts b/nodecg-io-core/extension/serviceBundle.ts index d73aa0c56..166a15725 100644 --- a/nodecg-io-core/extension/serviceBundle.ts +++ b/nodecg-io-core/extension/serviceBundle.ts @@ -85,6 +85,18 @@ export abstract class ServiceBundle> impleme */ abstract stopClient(client: C): void; + /** + * Removes all handlers from a service client. + * This is used when a bundle no longer uses a service client it still has its handlers registered. + * Then this function is called that should remove all handlers + * and then all bundles that are still using this client will asked to re-register their handlers + * by running the onAvailable callback of the specific bundle. + * + * Can be left unimplemented if the serivce doesn't has any handlers e.g. a http wrapper + * @param client the client of which all handlers should be removed + */ + abstract removeHandlers?(client: C): void; + private readSchema(pathSegments: string[]): unknown { const joinedPath = path.resolve(...pathSegments); try { diff --git a/nodecg-io-core/extension/types.d.ts b/nodecg-io-core/extension/types.d.ts index 11766d547..b447be960 100644 --- a/nodecg-io-core/extension/types.d.ts +++ b/nodecg-io-core/extension/types.d.ts @@ -60,6 +60,18 @@ export interface Service> { * @param client the client that needs to be stopped. */ readonly stopClient(client: C): void; + + /** + * Removes all handlers from a service client. + * This is used when a bundle no longer uses a service client it still has its handlers registered. + * Then this function is called that should remove all handlers + * and then all bundles that are still using this client will asked to re-register their handlers + * by running the onAvailable callback of the specific bundle. + * + * Can be left unimplemented if the serivce doesn't has any handlers e.g. a http wrapper + * @param client the client of which all handlers should be removed + */ + readonly removeHandlers?(client: C): void; } /** From 841e1b8f3853921ca008b7c4f86d495185c490bd Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 22 Sep 2020 19:33:13 +0200 Subject: [PATCH 2/8] Fix build error --- nodecg-io-core/extension/serviceBundle.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nodecg-io-core/extension/serviceBundle.ts b/nodecg-io-core/extension/serviceBundle.ts index 166a15725..98acee906 100644 --- a/nodecg-io-core/extension/serviceBundle.ts +++ b/nodecg-io-core/extension/serviceBundle.ts @@ -95,7 +95,7 @@ export abstract class ServiceBundle> impleme * Can be left unimplemented if the serivce doesn't has any handlers e.g. a http wrapper * @param client the client of which all handlers should be removed */ - abstract removeHandlers?(client: C): void; + removeHandlers?(client: C): void; private readSchema(pathSegments: string[]): unknown { const joinedPath = path.resolve(...pathSegments); From 7ecef4f5ffd7b9cc98390c34f94e347d7ccc472e Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 22 Sep 2020 19:34:33 +0200 Subject: [PATCH 3/8] Remove unnecessary duplicate removeHandlers definition --- nodecg-io-core/extension/serviceBundle.ts | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/nodecg-io-core/extension/serviceBundle.ts b/nodecg-io-core/extension/serviceBundle.ts index 98acee906..d73aa0c56 100644 --- a/nodecg-io-core/extension/serviceBundle.ts +++ b/nodecg-io-core/extension/serviceBundle.ts @@ -85,18 +85,6 @@ export abstract class ServiceBundle> impleme */ abstract stopClient(client: C): void; - /** - * Removes all handlers from a service client. - * This is used when a bundle no longer uses a service client it still has its handlers registered. - * Then this function is called that should remove all handlers - * and then all bundles that are still using this client will asked to re-register their handlers - * by running the onAvailable callback of the specific bundle. - * - * Can be left unimplemented if the serivce doesn't has any handlers e.g. a http wrapper - * @param client the client of which all handlers should be removed - */ - removeHandlers?(client: C): void; - private readSchema(pathSegments: string[]): unknown { const joinedPath = path.resolve(...pathSegments); try { From 6ab53f7901c22b33d48142429126ff8f98d6f650 Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 1 Oct 2020 19:59:13 +0200 Subject: [PATCH 4/8] Implement removeHandlers in twitch service --- nodecg-io-twitch/extension/index.ts | 5 ++++- nodecg-io-twitch/package.json | 6 +++--- package-lock.json | 32 ++++++++++++++--------------- 3 files changed, 23 insertions(+), 20 deletions(-) diff --git a/nodecg-io-twitch/extension/index.ts b/nodecg-io-twitch/extension/index.ts index 6ed0700ba..7ad66508e 100644 --- a/nodecg-io-twitch/extension/index.ts +++ b/nodecg-io-twitch/extension/index.ts @@ -28,10 +28,13 @@ class TwitchService extends ServiceBundle this.nodecg.log.info("Stopped twitch client successfully.")); } + + removeHandlers(client: TwitchServiceClient): void { + client.getNativeClient().removeListener(); + } } diff --git a/nodecg-io-twitch/package.json b/nodecg-io-twitch/package.json index 464af3682..25bb7e895 100644 --- a/nodecg-io-twitch/package.json +++ b/nodecg-io-twitch/package.json @@ -30,8 +30,8 @@ }, "dependencies": { "nodecg-io-core": "0.1.0", - "twitch": "^4.2.1", - "twitch-auth": "^4.2.1", - "twitch-chat-client": "^4.2.1" + "twitch": "^4.2.5", + "twitch-auth": "^4.2.5", + "twitch-chat-client": "^4.2.5" } } diff --git a/package-lock.json b/package-lock.json index 48e42888e..4661d47cf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13726,9 +13726,9 @@ "integrity": "sha1-WuaBd/GS1EViadEIr6k/+HQ/T2Q=" }, "twitch": { - "version": "4.2.4", - "resolved": "https://registry.npmjs.org/twitch/-/twitch-4.2.4.tgz", - "integrity": "sha512-Al/Wj9581YpHAsBYC7BDIcqhWy8bYQNASgRiz7gKxrIopU7GyJ439qJ6MPWHGYc6DJjww5Anv+3QvMFBsUsSXg==", + "version": "4.2.5", + "resolved": "https://registry.npmjs.org/twitch/-/twitch-4.2.5.tgz", + "integrity": "sha512-VvXsQCmudF+kT7kmukfd1R5ISBni/eKO8DPCHXuD/km+r26s7rikx/MQBGtdfHXFQasZrPPlnk+I3WA4PKNo/g==", "requires": { "@d-fischer/cache-decorators": "^2.0.0", "@d-fischer/deprecate": "^2.0.1", @@ -13737,14 +13737,14 @@ "@d-fischer/shared-utils": "^2.3.2", "top-package": "^1.0.0", "tslib": "^2.0.0", - "twitch-api-call": "^4.2.4", - "twitch-auth": "^4.2.4" + "twitch-api-call": "^4.2.5", + "twitch-auth": "^4.2.5" } }, "twitch-api-call": { - "version": "4.2.4", - "resolved": "https://registry.npmjs.org/twitch-api-call/-/twitch-api-call-4.2.4.tgz", - "integrity": "sha512-riLO068ahkoAjEjHTuDFGQkKHYNKsFdwJInVgE5hYT/SsrOvjWwtf4UlVdmF73IEKWMnoXDXdEhVsQ+DXmzCGQ==", + "version": "4.2.5", + "resolved": "https://registry.npmjs.org/twitch-api-call/-/twitch-api-call-4.2.5.tgz", + "integrity": "sha512-k4xwaaLV6XnuBfVAWOF+Ja+z5ligFht2WKxBfPw4FbiFwLv1tjqc7P9a/kuaLdCSDFmsco07PQjuHOApqXEXhA==", "requires": { "@d-fischer/cross-fetch": "^4.0.1", "@d-fischer/qs": "^7.0.2", @@ -13752,26 +13752,26 @@ } }, "twitch-auth": { - "version": "4.2.4", - "resolved": "https://registry.npmjs.org/twitch-auth/-/twitch-auth-4.2.4.tgz", - "integrity": "sha512-MWoSOf616PgCtBdDNZlloNqZZT02qXAkT6IiZSukPfFkzOtoCTUhZ5wsK1pS1hIm0yq2MjNyKrQVHCqC2psiYQ==", + "version": "4.2.5", + "resolved": "https://registry.npmjs.org/twitch-auth/-/twitch-auth-4.2.5.tgz", + "integrity": "sha512-DCcKp+QZOdgyFKOQw2JGuEtmahFfD0LEJjJSbnY064OzaNr+OwE8Fx8hNJMaH2byx3P514jTawCLp/GLbns/tw==", "requires": { "@d-fischer/deprecate": "^2.0.1", "@d-fischer/shared-utils": "^2.3.2", "tslib": "^2.0.0", - "twitch-api-call": "^4.2.4" + "twitch-api-call": "^4.2.5" } }, "twitch-chat-client": { - "version": "4.2.4", - "resolved": "https://registry.npmjs.org/twitch-chat-client/-/twitch-chat-client-4.2.4.tgz", - "integrity": "sha512-TFlTuGjrnzpP3byoTiMpbqNQXlR5/6aOH+X+pKvOO301u44yWfcGPVa/iQoAa8HTmNX3UCqpUvNYYt5WHxb0hg==", + "version": "4.2.5", + "resolved": "https://registry.npmjs.org/twitch-chat-client/-/twitch-chat-client-4.2.5.tgz", + "integrity": "sha512-SPAf2a7ANIjBUiL8GG5le/588OwVv4RKI1FIGLpTsrb9dMVENkjjsqXUjvkmuuyybJSf4nlF+L+/NQr9XJ/CgA==", "requires": { "@d-fischer/cache-decorators": "^2.0.0", "@d-fischer/deprecate": "^2.0.1", "@d-fischer/logger": "^2.0.0", "@d-fischer/shared-utils": "^2.3.2", - "@d-fischer/typed-event-emitter": "^3.0.0", + "@d-fischer/typed-event-emitter": "^3.0.2", "ircv3": "^0.26.0", "tslib": "^2.0.0" } From 105248758b3d3f05867eb7dad8f6273bc13302bf Mon Sep 17 00:00:00 2001 From: Daniel Date: Sat, 3 Oct 2020 15:09:08 +0200 Subject: [PATCH 5/8] Add removeHandlers method to most services that need it Only telegram is still missing --- nodecg-io-discord/extension/index.ts | 4 ++++ nodecg-io-irc/extension/index.ts | 4 ++++ nodecg-io-midi-input/extension/index.ts | 4 ++++ nodecg-io-obs/extension/index.ts | 10 +++++++++- nodecg-io-sacn-receiver/extension/index.ts | 4 ++++ nodecg-io-slack/extension/index.ts | 4 ++++ nodecg-io-streamelements/extension/index.ts | 4 ++++ nodecg-io-tiane/extension/index.ts | 4 ++++ nodecg-io-websocket-client/extension/index.ts | 4 ++++ nodecg-io-websocket-server/extension/index.ts | 9 +++++++++ 10 files changed, 50 insertions(+), 1 deletion(-) diff --git a/nodecg-io-discord/extension/index.ts b/nodecg-io-discord/extension/index.ts index 9ce7eac57..cbb8da74c 100644 --- a/nodecg-io-discord/extension/index.ts +++ b/nodecg-io-discord/extension/index.ts @@ -38,4 +38,8 @@ class DiscordService extends ServiceBundle { this.nodecg.log.info("Stopped IRC client successfully."); }); } + + removeHandlers(client: IRCServiceClient): void { + client.getNativeClient().removeAllListeners(); + } } function sendMessage(client: IRCClient, target: string, message: string): void { diff --git a/nodecg-io-midi-input/extension/index.ts b/nodecg-io-midi-input/extension/index.ts index f6c13477b..766cac918 100644 --- a/nodecg-io-midi-input/extension/index.ts +++ b/nodecg-io-midi-input/extension/index.ts @@ -59,4 +59,8 @@ class MidiService extends ServiceBundle { async createClient(config: OBSServiceConfig): Promise> { const client = new OBSWebSocket(); - await client.connect({ address: `${config.host}:${config.port}`, password: config.password }); + try { + await client.connect({ address: `${config.host}:${config.port}`, password: config.password }); + } catch (e) { + return error(e.error); + } return success({ getNativeClient() { @@ -43,4 +47,8 @@ class OBSService extends ServiceBundle { stopClient(client: OBSServiceClient) { client.getNativeClient().disconnect(); } + + removeHandlers(client: OBSServiceClient) { + client.getNativeClient().removeAllListeners(); + } } diff --git a/nodecg-io-sacn-receiver/extension/index.ts b/nodecg-io-sacn-receiver/extension/index.ts index 5ce08ff0b..0b9f90636 100644 --- a/nodecg-io-sacn-receiver/extension/index.ts +++ b/nodecg-io-sacn-receiver/extension/index.ts @@ -31,4 +31,8 @@ class SacnReceiverService extends ServiceBundle stopClient(_client: SlackServiceClient): void { // Not supported by the client } + + removeHandlers(client: SlackServiceClient): void { + client.getNativeClient().removeAllListeners(); + } } diff --git a/nodecg-io-streamelements/extension/index.ts b/nodecg-io-streamelements/extension/index.ts index ab30d39d0..045ae962c 100644 --- a/nodecg-io-streamelements/extension/index.ts +++ b/nodecg-io-streamelements/extension/index.ts @@ -31,4 +31,8 @@ class StreamElementsService extends ServiceBundle client.getNativeClient().close(); this.nodecg.log.info("Disconnected from TIANE."); } + + removeHandlers(client: TianeServiceClient): void { + client.getNativeClient().removeAllListeners(); + } } diff --git a/nodecg-io-websocket-client/extension/index.ts b/nodecg-io-websocket-client/extension/index.ts index e066d0961..276e2c932 100644 --- a/nodecg-io-websocket-client/extension/index.ts +++ b/nodecg-io-websocket-client/extension/index.ts @@ -65,4 +65,8 @@ class WSClientService extends ServiceBundle { + client.close(); + }); + } } From 9d2e74a8cfdbe596fbe8ebf5c86fc428c0cd1047 Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 14 Oct 2020 20:15:37 +0200 Subject: [PATCH 6/8] Implement removeHandlers for telegram --- nodecg-io-telegram/extension/index.ts | 27 +++++++++++++++++++++++++-- nodecg-io-telegram/package.json | 2 +- package-lock.json | 6 +++--- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/nodecg-io-telegram/extension/index.ts b/nodecg-io-telegram/extension/index.ts index bd86267a9..50097f9b1 100644 --- a/nodecg-io-telegram/extension/index.ts +++ b/nodecg-io-telegram/extension/index.ts @@ -4,6 +4,23 @@ import { ServiceBundle } from "nodecg-io-core/extension/serviceBundle"; import TelegramBot = require("node-telegram-bot-api"); import { ServiceClient } from "nodecg-io-core/extension/types"; +// TODO: try to upstream these changes to the original package so they can be accessed using public methods +// instead of having to access private variables. +class BetterTelegramBot extends TelegramBot { + private declare _textRegexpCallbacks: Array; + private declare _replyListeners: Array; + + clearTextListeners() { + // The class currently doesn't have a way to reset all regex listeners. + this._textRegexpCallbacks = []; + } + + clearReplyListeners() { + // The class currently also doesn't have a way to reset all reply listeners. + this._replyListeners = []; + } +} + interface TelegramServiceConfig { token: string; polling?: boolean; @@ -13,7 +30,7 @@ interface TelegramServiceConfig { filepath?: boolean; } -export type TelegramServiceClient = ServiceClient; +export type TelegramServiceClient = ServiceClient; module.exports = (nodecg: NodeCG) => { new TelegramService(nodecg, "telegram", __dirname, "../telegram-schema.json").register(); @@ -36,7 +53,7 @@ class TelegramService extends ServiceBundle Date: Thu, 24 Dec 2020 17:07:09 +0100 Subject: [PATCH 7/8] Update removeHandlers in some services and introduce reCreateClientToRemoveHandlers --- nodecg-io-core/extension/instanceManager.ts | 6 ++++++ nodecg-io-core/extension/serviceBundle.ts | 22 +++++++++++++++++++++ nodecg-io-core/extension/types.d.ts | 10 ++++++++++ nodecg-io-serial/extension/index.ts | 4 ++++ nodecg-io-slack/extension/index.ts | 5 +++-- nodecg-io-spotify/extension/index.ts | 2 +- nodecg-io-streamdeck/extension/index.ts | 3 +++ nodecg-io-telegram/extension/index.ts | 3 +-- nodecg-io-telegram/package.json | 2 +- nodecg-io-twitch-pubsub/extension/index.ts | 5 +++++ package-lock.json | 8 ++++---- 11 files changed, 60 insertions(+), 10 deletions(-) diff --git a/nodecg-io-core/extension/instanceManager.ts b/nodecg-io-core/extension/instanceManager.ts index 58b3c7bc8..2d4ae94c1 100644 --- a/nodecg-io-core/extension/instanceManager.ts +++ b/nodecg-io-core/extension/instanceManager.ts @@ -246,6 +246,12 @@ export class InstanceManager extends EventEmitter { return; } + // Client should be recreated because the Service has no way to reset the handlers. + if (svc.result.reCreateClientToRemoveHandlers) { + this.updateInstanceClient(inst, instanceName, svc.result); + return; + } + if (!svc.result.removeHandlers) return; // Service provides no way to remove handlers, thus this service has no handlers // Remove handlers diff --git a/nodecg-io-core/extension/serviceBundle.ts b/nodecg-io-core/extension/serviceBundle.ts index bd3caa64f..a96d048d7 100644 --- a/nodecg-io-core/extension/serviceBundle.ts +++ b/nodecg-io-core/extension/serviceBundle.ts @@ -78,6 +78,28 @@ export abstract class ServiceBundle> impleme */ abstract stopClient(client: C): void; + /** + * Removes all handlers from a service client. + * This is used when a bundle no longer uses a service client it still has its handlers registered. + * Then this function is called that should remove all handlers + * and then all bundles that are still using this client will asked to re-register their handlers + * by running the onAvailable callback of the specific bundle. + * + * Can be left unimplemented if the serivce doesn't has any handlers e.g. a http wrapper + * @param client the client of which all handlers should be removed + */ + removeHandlers?(client: C): void; + + /** + * This flag can be enabled by services if they can't implement removeHandlers but also have some handlers that + * should be reset if a bundleDependency has been changed. + * It gets rid of the handlers by stopping the client and creating a new one, to which then only the + * now wanted handlers get registered (e.g. if a bundle doesn't uses this service anymore but another still does). + * Not ideal, but if your service can't implement removeHandlers for some reason it is still better than + * having dangling handlers that still fire eventho they shouldn't. + */ + reCreateClientToRemoveHandlers = false; + private readSchema(pathSegments: string[]): unknown { const joinedPath = path.resolve(...pathSegments); try { diff --git a/nodecg-io-core/extension/types.d.ts b/nodecg-io-core/extension/types.d.ts index b447be960..bde641d09 100644 --- a/nodecg-io-core/extension/types.d.ts +++ b/nodecg-io-core/extension/types.d.ts @@ -72,6 +72,16 @@ export interface Service> { * @param client the client of which all handlers should be removed */ readonly removeHandlers?(client: C): void; + + /** + * This flag can be enabled by services if they can't implement removeHandlers but also have some handlers that + * should be reset if a bundleDependency has been changed. + * It gets rid of the handlers by stopping the client and creating a new one, to which then only the + * now wanted handlers get registered (e.g. if a bundle doesn't uses this service anymore but another still does). + * Not ideal, but if your service can't implement removeHandlers for some reason it is still better than + * having dangling handlers that still fire eventho they shouldn't. + */ + reCreateClientToRemoveHandlers: boolean; } /** diff --git a/nodecg-io-serial/extension/index.ts b/nodecg-io-serial/extension/index.ts index 2fd49d249..21100b721 100644 --- a/nodecg-io-serial/extension/index.ts +++ b/nodecg-io-serial/extension/index.ts @@ -24,4 +24,8 @@ class SerialService extends ServiceBundle } } - stopClient(_client: SlackServiceClient): void { - // Not supported by the client + stopClient(client: SlackServiceClient): void { + // Not supported by the client, at least remove all listeners + this.removeHandlers(client); } removeHandlers(client: SlackServiceClient): void { diff --git a/nodecg-io-spotify/extension/index.ts b/nodecg-io-spotify/extension/index.ts index 0e01107f5..672284472 100644 --- a/nodecg-io-spotify/extension/index.ts +++ b/nodecg-io-spotify/extension/index.ts @@ -108,6 +108,6 @@ class SpotifyService extends ServiceBundle; private declare _replyListeners: Array; diff --git a/nodecg-io-telegram/package.json b/nodecg-io-telegram/package.json index fc598a567..f45eecaa5 100644 --- a/nodecg-io-telegram/package.json +++ b/nodecg-io-telegram/package.json @@ -37,6 +37,6 @@ }, "dependencies": { "nodecg-io-core": "^0.1.0", - "node-telegram-bot-api": "^0.50.0" + "node-telegram-bot-api": "^0.51.0" } } diff --git a/nodecg-io-twitch-pubsub/extension/index.ts b/nodecg-io-twitch-pubsub/extension/index.ts index 91886cf49..15e58df50 100644 --- a/nodecg-io-twitch-pubsub/extension/index.ts +++ b/nodecg-io-twitch-pubsub/extension/index.ts @@ -28,4 +28,9 @@ class TwitchPubSubService extends ServiceBundle Date: Fri, 1 Jan 2021 13:21:22 +0100 Subject: [PATCH 8/8] Update typings for telegram lib and use upstreamed clear listener methods --- nodecg-io-telegram/extension/index.ts | 20 ++------------------ nodecg-io-telegram/package.json | 2 +- package-lock.json | 6 +++--- 3 files changed, 6 insertions(+), 22 deletions(-) diff --git a/nodecg-io-telegram/extension/index.ts b/nodecg-io-telegram/extension/index.ts index 67d9dc13d..868f89cec 100644 --- a/nodecg-io-telegram/extension/index.ts +++ b/nodecg-io-telegram/extension/index.ts @@ -4,22 +4,6 @@ import { ServiceBundle } from "nodecg-io-core/extension/serviceBundle"; import TelegramBot = require("node-telegram-bot-api"); import { ServiceClient } from "nodecg-io-core/extension/types"; -// TODO: These changes are now upstreamed (https://github.com/yagop/node-telegram-bot-api/commit/ec7e61e041a66a52a90be0849c3d4640a4806873) but typing still need updating -class BetterTelegramBot extends TelegramBot { - private declare _textRegexpCallbacks: Array; - private declare _replyListeners: Array; - - clearTextListeners() { - // The class currently doesn't have a way to reset all regex listeners. - this._textRegexpCallbacks = []; - } - - clearReplyListeners() { - // The class currently also doesn't have a way to reset all reply listeners. - this._replyListeners = []; - } -} - interface TelegramServiceConfig { token: string; polling?: boolean; @@ -29,7 +13,7 @@ interface TelegramServiceConfig { filepath?: boolean; } -export type TelegramServiceClient = ServiceClient; +export type TelegramServiceClient = ServiceClient; module.exports = (nodecg: NodeCG) => { new TelegramService(nodecg, "telegram", __dirname, "../telegram-schema.json").register(); @@ -52,7 +36,7 @@ class TelegramService extends ServiceBundle