From 41d2addc6edc305980251e92a19122e08e96e501 Mon Sep 17 00:00:00 2001 From: Lilian <30466471+hlxid@users.noreply.github.com> Date: Sun, 24 Nov 2024 18:38:48 +0100 Subject: [PATCH] Update twurple from v5 to latest v7 --- nodecg-io-core/dashboard/bundles.ts | 5 +- package-lock.json | 287 ++++++------------ samples/twitch-api/extension/index.ts | 23 +- samples/twitch-chat/extension/index.ts | 4 +- samples/twitch-pubsub/extension/index.ts | 10 +- .../nodecg-io-twitch-api/extension/index.ts | 2 +- services/nodecg-io-twitch-api/package.json | 2 +- .../nodecg-io-twitch-chat/extension/index.ts | 3 +- .../extension/twitchClient.ts | 13 +- services/nodecg-io-twitch-chat/package.json | 2 +- .../extension/pubSubClient.ts | 40 ++- services/nodecg-io-twitch-pubsub/package.json | 4 +- utils/nodecg-io-twitch-auth/package.json | 2 +- 13 files changed, 168 insertions(+), 229 deletions(-) diff --git a/nodecg-io-core/dashboard/bundles.ts b/nodecg-io-core/dashboard/bundles.ts index 08825e4ce..e2530b646 100644 --- a/nodecg-io-core/dashboard/bundles.ts +++ b/nodecg-io-core/dashboard/bundles.ts @@ -77,8 +77,9 @@ export function renderInstanceSelector(): void { return; } - const currentInstance = config.data.bundles[bundle]?.find((dep) => dep.serviceType === serviceType) - ?.serviceInstance; + const currentInstance = config.data.bundles[bundle]?.find( + (dep) => dep.serviceType === serviceType, + )?.serviceInstance; let index = 0; for (let i = 0; i < selectBundleInstance.options.length; i++) { diff --git a/package-lock.json b/package-lock.json index 469db3b4d..437ff4cb2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -802,23 +802,26 @@ } }, "node_modules/@d-fischer/cache-decorators": { - "version": "3.0.3", + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/@d-fischer/cache-decorators/-/cache-decorators-4.0.1.tgz", + "integrity": "sha512-HNYLBLWs/t28GFZZeqdIBqq8f37mqDIFO6xNPof94VjpKvuP6ROqCZGafx88dk5zZUlBfViV9jD8iNNlXfc4CA==", "license": "MIT", "dependencies": { - "@d-fischer/shared-utils": "^3.0.1", - "tslib": "^2.1.0" + "@d-fischer/shared-utils": "^3.6.3", + "tslib": "^2.6.2" } }, "node_modules/@d-fischer/connection": { - "version": "7.0.1", + "version": "9.0.0", + "resolved": "https://registry.npmjs.org/@d-fischer/connection/-/connection-9.0.0.tgz", + "integrity": "sha512-Mljp/EbaE+eYWfsFXUOk+RfpbHgrWGL/60JkAvjYixw6KREfi5r17XdUiXe54ByAQox6jwgdN2vebdmW1BT+nQ==", "license": "MIT", "dependencies": { "@d-fischer/isomorphic-ws": "^7.0.0", - "@d-fischer/logger": "^4.2.0", - "@d-fischer/shared-utils": "^3.3.0", + "@d-fischer/logger": "^4.2.1", + "@d-fischer/shared-utils": "^3.5.0", "@d-fischer/typed-event-emitter": "^3.3.0", - "@types/node": "^16.7.10", - "@types/ws": "^8.5.3", + "@types/ws": "^8.5.4", "tslib": "^2.4.1", "ws": "^8.11.0" }, @@ -826,15 +829,13 @@ "url": "https://github.com/sponsors/d-fischer" } }, - "node_modules/@d-fischer/connection/node_modules/@types/node": { - "version": "16.18.38", - "license": "MIT" - }, "node_modules/@d-fischer/cross-fetch": { - "version": "4.2.1", + "version": "5.0.5", + "resolved": "https://registry.npmjs.org/@d-fischer/cross-fetch/-/cross-fetch-5.0.5.tgz", + "integrity": "sha512-symjDUPInTrkfIsZc2n2mo9hiAJLcTJsZkNICjZajEWnWpJ3s3zn50/FY8xpNUAf5w3eFuQii2wxztTGpvG1Xg==", "license": "MIT", "dependencies": { - "node-fetch": "^2.6.11" + "node-fetch": "^2.6.12" } }, "node_modules/@d-fischer/deprecate": { @@ -847,13 +848,17 @@ }, "node_modules/@d-fischer/escape-string-regexp": { "version": "5.0.0", + "resolved": "https://registry.npmjs.org/@d-fischer/escape-string-regexp/-/escape-string-regexp-5.0.0.tgz", + "integrity": "sha512-7eoxnxcto5eVPW5h1T+ePnVFukmI9f/ZR9nlBLh1t3kyzJDUNor2C+YW9H/Terw3YnbZSDgDYrpCJCHtOtAQHw==", "license": "MIT", "engines": { "node": ">=10" } }, "node_modules/@d-fischer/isomorphic-ws": { - "version": "7.0.0", + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@d-fischer/isomorphic-ws/-/isomorphic-ws-7.0.2.tgz", + "integrity": "sha512-xK+qIJUF0ne3dsjq5Y3BviQ4M+gx9dzkN+dPP7abBMje4YRfow+X9jBgeEoTe5e+Q6+8hI9R0b37Okkk8Vf0hQ==", "license": "MIT", "peerDependencies": { "ws": "^8.2.0" @@ -871,26 +876,10 @@ "url": "https://github.com/sponsors/d-fischer" } }, - "node_modules/@d-fischer/promise.allsettled": { - "version": "2.0.2", - "license": "MIT", - "dependencies": { - "array.prototype.map": "^1.0.3", - "call-bind": "^1.0.2", - "define-properties": "^1.1.3", - "es-abstract": "^1.18.0-next.2", - "get-intrinsic": "^1.0.2", - "iterate-value": "^1.0.2" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/d-fischer" - } - }, "node_modules/@d-fischer/qs": { "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@d-fischer/qs/-/qs-7.0.2.tgz", + "integrity": "sha512-yAu3xDooiL+ef84Jo8nLjDjWBRk7RXk163Y6aTvRB7FauYd3spQD/dWvgT7R4CrN54Juhrrc3dMY7mc+jZGurQ==", "license": "BSD-3-Clause", "engines": { "node": ">=0.6" @@ -900,20 +889,19 @@ } }, "node_modules/@d-fischer/rate-limiter": { - "version": "0.6.2", + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@d-fischer/rate-limiter/-/rate-limiter-1.0.1.tgz", + "integrity": "sha512-Mq+0pAJsx92hP83cjmsrXQZVQJ+/+u1JFT6fjH8pj3yfUrbT3eDBsA+6J63eat+QaC+Mci78HdiBfpsdBkdwog==", "license": "MIT", "dependencies": { - "@d-fischer/logger": "^4.0.0", - "@d-fischer/promise.allsettled": "^2.0.2", - "@d-fischer/shared-utils": "^3.2.0", - "@types/node": "^12.12.5", - "tslib": "^2.0.3" + "@d-fischer/logger": "^4.2.3", + "@d-fischer/shared-utils": "^3.6.3", + "tslib": "^2.6.2" + }, + "funding": { + "url": "https://github.com/sponsors/d-fischer" } }, - "node_modules/@d-fischer/rate-limiter/node_modules/@types/node": { - "version": "12.20.55", - "license": "MIT" - }, "node_modules/@d-fischer/shared-utils": { "version": "3.6.3", "license": "MIT", @@ -2807,34 +2795,40 @@ "license": "MIT" }, "node_modules/@twurple/api": { - "version": "5.3.4", + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/@twurple/api/-/api-7.2.0.tgz", + "integrity": "sha512-nUIZkZ2szty/NDebEd6ggNks5s0+mVyKM+d8VSFEi2v/qpT5fu34fYtm5aAIvSJ5WglaP7l+dmGvHrcafDxNoA==", "license": "MIT", "dependencies": { - "@d-fischer/cache-decorators": "^3.0.0", + "@d-fischer/cache-decorators": "^4.0.0", + "@d-fischer/cross-fetch": "^5.0.1", "@d-fischer/detect-node": "^3.0.1", - "@d-fischer/logger": "^4.0.0", - "@d-fischer/rate-limiter": "^0.6.1", - "@d-fischer/shared-utils": "^3.4.0", - "@twurple/api-call": "5.3.4", - "@twurple/common": "5.3.4", + "@d-fischer/logger": "^4.2.1", + "@d-fischer/rate-limiter": "^1.0.0", + "@d-fischer/shared-utils": "^3.6.1", + "@d-fischer/typed-event-emitter": "^3.3.1", + "@twurple/api-call": "7.2.0", + "@twurple/common": "7.2.0", + "retry": "^0.13.1", "tslib": "^2.0.3" }, "funding": { "url": "https://github.com/sponsors/d-fischer" }, "peerDependencies": { - "@twurple/auth": "5.3.4" + "@twurple/auth": "7.2.0" } }, "node_modules/@twurple/api-call": { - "version": "5.3.4", + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/@twurple/api-call/-/api-call-7.2.0.tgz", + "integrity": "sha512-xMIaNdFpJNzwm961USGIzhaT6i+ZNr+gkDImvkWexGztyeB7icIXaT8U2I0gm3b4QvK9eT9megY9N/Xbn9lumQ==", "license": "MIT", "dependencies": { - "@d-fischer/cross-fetch": "^4.0.2", + "@d-fischer/cross-fetch": "^5.0.1", "@d-fischer/qs": "^7.0.2", - "@d-fischer/shared-utils": "^3.4.0", - "@twurple/common": "5.3.4", - "@types/node-fetch": "^2.5.7", + "@d-fischer/shared-utils": "^3.6.1", + "@twurple/common": "7.2.0", "tslib": "^2.0.3" }, "funding": { @@ -2842,13 +2836,16 @@ } }, "node_modules/@twurple/auth": { - "version": "5.3.4", + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/@twurple/auth/-/auth-7.2.0.tgz", + "integrity": "sha512-rcqoU3TtLm7UICEcefg+NIaSi7ry7nBlIuUQEzDC09A/mfy/R5D6u8uqt+V2ybZChu1Pue2wRGycOTFseHYE5g==", "license": "MIT", "dependencies": { - "@d-fischer/logger": "^4.0.0", - "@d-fischer/shared-utils": "^3.4.0", - "@twurple/api-call": "5.3.4", - "@twurple/common": "5.3.4", + "@d-fischer/logger": "^4.2.1", + "@d-fischer/shared-utils": "^3.6.1", + "@d-fischer/typed-event-emitter": "^3.3.1", + "@twurple/api-call": "7.2.0", + "@twurple/common": "7.2.0", "tslib": "^2.0.3" }, "funding": { @@ -2856,31 +2853,35 @@ } }, "node_modules/@twurple/chat": { - "version": "5.3.4", + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/@twurple/chat/-/chat-7.2.0.tgz", + "integrity": "sha512-iSkOBG1i3sMexo0yKWHF0qXfgozwNPCpDbl66/mNtzsxTPZvnJfyP/eci2t/MF5shk8NfiyykwBMIliD9mXQ5Q==", "license": "MIT", "dependencies": { - "@d-fischer/cache-decorators": "^3.0.0", + "@d-fischer/cache-decorators": "^4.0.0", "@d-fischer/deprecate": "^2.0.2", - "@d-fischer/logger": "^4.0.0", - "@d-fischer/rate-limiter": "^0.6.1", - "@d-fischer/shared-utils": "^3.4.0", + "@d-fischer/logger": "^4.2.1", + "@d-fischer/rate-limiter": "^1.0.0", + "@d-fischer/shared-utils": "^3.6.1", "@d-fischer/typed-event-emitter": "^3.3.0", - "@twurple/common": "5.3.4", - "ircv3": "^0.29.8", + "@twurple/common": "7.2.0", + "ircv3": "^0.33.0", "tslib": "^2.0.3" }, "funding": { "url": "https://github.com/sponsors/d-fischer" }, "peerDependencies": { - "@twurple/auth": "5.3.4" + "@twurple/auth": "7.2.0" } }, "node_modules/@twurple/common": { - "version": "5.3.4", + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/@twurple/common/-/common-7.2.0.tgz", + "integrity": "sha512-bfUWDDxvpzWztEQnMWa2ivwSncnz0UE5ToWUnsCDNlujTPJvrFTm4eU9FCYgSwCQ8o+9LCiuA4pNF20HhKzhOw==", "license": "MIT", "dependencies": { - "@d-fischer/shared-utils": "^3.4.0", + "@d-fischer/shared-utils": "^3.6.1", "klona": "^2.0.4", "tslib": "^2.0.3" }, @@ -2889,21 +2890,23 @@ } }, "node_modules/@twurple/pubsub": { - "version": "5.3.4", + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/@twurple/pubsub/-/pubsub-7.2.0.tgz", + "integrity": "sha512-CiTizIlekwp+yHXSWoK+aT8ba5AD8MzDLtUqVgJWF55/8rZ+H1Q6/OsXGZIsmRM7N/QEOO1+3QPEe+QhBFsUAg==", "license": "MIT", "dependencies": { - "@d-fischer/connection": "^7.0.0", - "@d-fischer/logger": "^4.0.0", - "@d-fischer/shared-utils": "^3.4.0", + "@d-fischer/connection": "^9.0.0", + "@d-fischer/logger": "^4.2.1", + "@d-fischer/shared-utils": "^3.6.1", "@d-fischer/typed-event-emitter": "^3.3.0", - "@twurple/common": "5.3.4", + "@twurple/common": "7.2.0", "tslib": "^2.0.3" }, "funding": { "url": "https://github.com/sponsors/d-fischer" }, "peerDependencies": { - "@twurple/auth": "5.3.4" + "@twurple/auth": "7.2.0" } }, "node_modules/@types/babel__core": { @@ -3939,23 +3942,6 @@ "es-shim-unscopables": "^1.0.0" } }, - "node_modules/array.prototype.map": { - "version": "1.0.5", - "license": "MIT", - "dependencies": { - "call-bind": "^1.0.2", - "define-properties": "^1.1.4", - "es-abstract": "^1.20.4", - "es-array-method-boxes-properly": "^1.0.0", - "is-string": "^1.0.7" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, "node_modules/arraybuffer.slice": { "version": "0.0.7", "license": "MIT" @@ -5530,32 +5516,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/es-array-method-boxes-properly": { - "version": "1.0.0", - "license": "MIT" - }, - "node_modules/es-get-iterator": { - "version": "1.1.3", - "license": "MIT", - "dependencies": { - "call-bind": "^1.0.2", - "get-intrinsic": "^1.1.3", - "has-symbols": "^1.0.3", - "is-arguments": "^1.1.1", - "is-map": "^2.0.2", - "is-set": "^2.0.2", - "is-string": "^1.0.7", - "isarray": "^2.0.5", - "stop-iteration-iterator": "^1.0.0" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/es-get-iterator/node_modules/isarray": { - "version": "2.0.5", - "license": "MIT" - }, "node_modules/es-set-tostringtag": { "version": "2.0.1", "license": "MIT", @@ -7080,40 +7040,23 @@ } }, "node_modules/ircv3": { - "version": "0.29.10", + "version": "0.33.0", + "resolved": "https://registry.npmjs.org/ircv3/-/ircv3-0.33.0.tgz", + "integrity": "sha512-7rK1Aial3LBiFycE8w3MHiBBFb41/2GG2Ll/fR2IJj1vx0pLpn1s+78K+z/I4PZTqCCSp/Sb4QgKMh3NMhx0Kg==", "license": "MIT", "dependencies": { - "@d-fischer/connection": "^7.0.0", + "@d-fischer/connection": "^9.0.0", "@d-fischer/escape-string-regexp": "^5.0.0", - "@d-fischer/logger": "^4.0.0", - "@d-fischer/shared-utils": "^3.0.1", + "@d-fischer/logger": "^4.2.1", + "@d-fischer/shared-utils": "^3.5.0", "@d-fischer/typed-event-emitter": "^3.3.0", - "@types/node": "^14.14.19", - "klona": "^2.0.4", - "tslib": "^2.0.3" + "klona": "^2.0.5", + "tslib": "^2.4.1" }, "funding": { "url": "https://github.com/sponsors/d-fischer" } }, - "node_modules/ircv3/node_modules/@types/node": { - "version": "14.18.53", - "license": "MIT" - }, - "node_modules/is-arguments": { - "version": "1.1.1", - "license": "MIT", - "dependencies": { - "call-bind": "^1.0.2", - "has-tostringtag": "^1.0.0" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, "node_modules/is-array-buffer": { "version": "3.0.2", "license": "MIT", @@ -7260,13 +7203,6 @@ "node": ">=8" } }, - "node_modules/is-map": { - "version": "2.0.2", - "license": "MIT", - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, "node_modules/is-negative-zero": { "version": "2.0.2", "license": "MIT", @@ -7331,13 +7267,6 @@ "version": "2.1.0", "license": "BSD" }, - "node_modules/is-set": { - "version": "2.0.2", - "license": "MIT", - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, "node_modules/is-shared-array-buffer": { "version": "1.0.2", "license": "MIT", @@ -7545,24 +7474,6 @@ "node": ">=8" } }, - "node_modules/iterate-iterator": { - "version": "1.0.2", - "license": "MIT", - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/iterate-value": { - "version": "1.0.2", - "license": "MIT", - "dependencies": { - "es-get-iterator": "^1.0.2", - "iterate-iterator": "^1.0.1" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, "node_modules/jest": { "version": "28.1.3", "dev": true, @@ -8214,6 +8125,8 @@ }, "node_modules/klona": { "version": "2.0.6", + "resolved": "https://registry.npmjs.org/klona/-/klona-2.0.6.tgz", + "integrity": "sha512-dhG34DXATL5hSxJbIexCft8FChFXtmskoZYnoPWjXQuebWYCNkVeV3KkGegCK9CP1oswI/vQibS2GY7Em/sJJA==", "license": "MIT", "engines": { "node": ">= 8" @@ -11472,16 +11385,6 @@ "node": ">=0.10.0" } }, - "node_modules/stop-iteration-iterator": { - "version": "1.0.0", - "license": "MIT", - "dependencies": { - "internal-slot": "^1.0.4" - }, - "engines": { - "node": ">= 0.4" - } - }, "node_modules/stream-combiner": { "version": "0.0.4", "license": "MIT", @@ -14018,7 +13921,7 @@ "version": "0.3.0", "license": "MIT", "dependencies": { - "@twurple/api": "^5.3.4", + "@twurple/api": "^7.2.0", "nodecg-io-core": "^0.3.0", "nodecg-io-twitch-auth": "^0.3.0" }, @@ -14033,7 +13936,7 @@ "version": "0.3.0", "license": "MIT", "dependencies": { - "@twurple/chat": "^5.3.4", + "@twurple/chat": "^7.2.0", "nodecg-io-core": "^0.3.0", "nodecg-io-twitch-auth": "^0.3.0" }, @@ -14048,8 +13951,8 @@ "version": "0.3.0", "license": "MIT", "dependencies": { - "@twurple/api": "^5.3.4", - "@twurple/pubsub": "^5.3.4", + "@twurple/api": "^7.2.0", + "@twurple/pubsub": "^7.2.0", "nodecg-io-core": "^0.3.0", "nodecg-io-twitch-auth": "^0.3.0" }, @@ -14182,7 +14085,7 @@ "version": "0.3.0", "license": "MIT", "dependencies": { - "@twurple/auth": "^5.3.4" + "@twurple/auth": "^7.2.0" }, "devDependencies": { "@types/node": "^20.12.2", diff --git a/samples/twitch-api/extension/index.ts b/samples/twitch-api/extension/index.ts index c255aa372..62886ccfb 100644 --- a/samples/twitch-api/extension/index.ts +++ b/samples/twitch-api/extension/index.ts @@ -9,13 +9,24 @@ module.exports = function (nodecg: NodeCG.ServerAPI) { twitchApi?.onAvailable(async (client) => { nodecg.log.info("Twitch api client has been updated, getting user info."); - const user = await client.helix.users.getMe(); - const follows = await user.getFollows(); - const stream = await user.getStream(); + const tokenInfo = await client.getTokenInfo(); + const userId = tokenInfo.userId; + + if (!userId) { + nodecg.log.info("Unable to determine authenticated user"); + return; + } + + const user = await client.users.getUserById(userId); + if (!user) { + nodecg.log.info("Unable to get user info"); + return; + } + + const follows = await user?.getFollowedChannels(); + const stream = await user?.getStream(); nodecg.log.info( - `You are user "${user.name}", follow ${follows.total} people and are${ - stream === null ? " not" : "" - } streaming.`, + `You are user "${user.name}", follow ${follows.total} people and are${stream === null ? " not" : ""} streaming.`, ); }); diff --git a/samples/twitch-chat/extension/index.ts b/samples/twitch-chat/extension/index.ts index fea8dec2c..bd6379bdd 100644 --- a/samples/twitch-chat/extension/index.ts +++ b/samples/twitch-chat/extension/index.ts @@ -9,8 +9,8 @@ module.exports = function (nodecg: NodeCG.ServerAPI) { const twitch = requireService(nodecg, "twitch-chat"); // Hardcoded channels for testing purposes. - // Note that this does need a # before the channel name and is case-insensitive. - const twitchChannels = ["#skate702", "#daniel0611"]; + // Note that this is case-insensitive. + const twitchChannels = ["skate702", "hlxid"]; // Once the service instance has been set we add listeners for messages in the corresponding channels. twitch?.onAvailable((client) => { diff --git a/samples/twitch-pubsub/extension/index.ts b/samples/twitch-pubsub/extension/index.ts index 3b256c0d7..8edac3ee1 100644 --- a/samples/twitch-pubsub/extension/index.ts +++ b/samples/twitch-pubsub/extension/index.ts @@ -8,17 +8,19 @@ module.exports = function (nodecg: NodeCG.ServerAPI) { const pubsub = requireService(nodecg, "twitch-pubsub"); pubsub?.onAvailable((client) => { + const channelName = "skate702"; + nodecg.log.info("PubSub client has been updated, adding handlers for messages."); - client.onSubscription((message) => { + client.onSubscription(channelName, (message) => { nodecg.log.info(`${message.userDisplayName} just subscribed (${message.cumulativeMonths} months)`); }); - client.onBits((message) => { + client.onBits(channelName, (message) => { nodecg.log.info(`${message.userName} cheered ${message.bits} Bits`); }); - client.onBitsBadgeUnlock((message) => { + client.onBitsBadgeUnlock(channelName, (message) => { nodecg.log.info(`${message.userName} just unlocked the ${message.badgeTier} Badge`); }); - client.onRedemption((message) => { + client.onRedemption(channelName, (message) => { nodecg.log.info(`${message.userDisplayName} redeemed ${message.rewardTitle} (${message.message})`); }); }); diff --git a/services/nodecg-io-twitch-api/extension/index.ts b/services/nodecg-io-twitch-api/extension/index.ts index 642cc663c..7ba13f082 100644 --- a/services/nodecg-io-twitch-api/extension/index.ts +++ b/services/nodecg-io-twitch-api/extension/index.ts @@ -1,6 +1,6 @@ import NodeCG from "@nodecg/types"; -import { Result, emptySuccess, success, ServiceBundle, Logger } from "nodecg-io-core"; import { ApiClient } from "@twurple/api"; +import { Result, emptySuccess, success, ServiceBundle, Logger } from "nodecg-io-core"; import { createAuthProvider, getTokenInfo, TwitchServiceConfig } from "nodecg-io-twitch-auth"; export type TwitchApiServiceClient = ApiClient; diff --git a/services/nodecg-io-twitch-api/package.json b/services/nodecg-io-twitch-api/package.json index dae85f65c..4e5aff1f9 100644 --- a/services/nodecg-io-twitch-api/package.json +++ b/services/nodecg-io-twitch-api/package.json @@ -39,6 +39,6 @@ "dependencies": { "nodecg-io-core": "^0.3.0", "nodecg-io-twitch-auth": "^0.3.0", - "@twurple/api": "^5.3.4" + "@twurple/api": "^7.2.0" } } diff --git a/services/nodecg-io-twitch-chat/extension/index.ts b/services/nodecg-io-twitch-chat/extension/index.ts index 001f51f22..cbd629c94 100644 --- a/services/nodecg-io-twitch-chat/extension/index.ts +++ b/services/nodecg-io-twitch-chat/extension/index.ts @@ -24,7 +24,8 @@ class TwitchService extends ServiceBundle logger.info("Successfully stopped twitch client.")); + client.quit(); + logger.info("Successfully stopped twitch client."); } removeHandlers(client: TwitchChatServiceClient): void { diff --git a/services/nodecg-io-twitch-chat/extension/twitchClient.ts b/services/nodecg-io-twitch-chat/extension/twitchClient.ts index aaf3492be..25f24d040 100644 --- a/services/nodecg-io-twitch-chat/extension/twitchClient.ts +++ b/services/nodecg-io-twitch-chat/extension/twitchClient.ts @@ -11,11 +11,14 @@ export class TwitchChatServiceClient extends ChatClient { // Create the actual chat client and connect const chatClient = new TwitchChatServiceClient({ authProvider }); - await chatClient.connect(); + chatClient.connect(); - // This also waits till it has registered itself at the IRC server, which is needed to do anything. - await new Promise((resolve, _reject) => { - chatClient.onRegister(() => resolve(undefined)); + // This also waits till it has connected and registered itself at the IRC server, which is needed to do anything. + await new Promise((resolve, reject) => { + chatClient.onConnect(() => resolve(undefined)); + chatClient.onAuthenticationFailure(() => { + reject("Authentication failed"); + }); }); return chatClient; @@ -31,7 +34,7 @@ export class TwitchChatServiceClient extends ChatClient { * @param channel the channel to join */ join(channel: string): Promise { - this.onRegister(() => { + this.onConnect(() => { this.join(channel); }); diff --git a/services/nodecg-io-twitch-chat/package.json b/services/nodecg-io-twitch-chat/package.json index 8dcb252b3..307bd8ca9 100644 --- a/services/nodecg-io-twitch-chat/package.json +++ b/services/nodecg-io-twitch-chat/package.json @@ -39,6 +39,6 @@ "dependencies": { "nodecg-io-core": "^0.3.0", "nodecg-io-twitch-auth": "^0.3.0", - "@twurple/chat": "^5.3.4" + "@twurple/chat": "^7.2.0" } } diff --git a/services/nodecg-io-twitch-pubsub/extension/pubSubClient.ts b/services/nodecg-io-twitch-pubsub/extension/pubSubClient.ts index 218d3bde5..77c84dca6 100644 --- a/services/nodecg-io-twitch-pubsub/extension/pubSubClient.ts +++ b/services/nodecg-io-twitch-pubsub/extension/pubSubClient.ts @@ -1,12 +1,21 @@ -import { BasicPubSubClient, SingleUserPubSubClient } from "@twurple/pubsub"; +import { BasicPubSubClient, PubSubClient } from "@twurple/pubsub"; import { createAuthProvider, TwitchServiceConfig } from "nodecg-io-twitch-auth"; -import { AuthProvider } from "@twurple/auth"; +import { PubSubClientConfig } from "@twurple/pubsub/lib/PubSubClient"; -export class TwitchPubSubServiceClient extends SingleUserPubSubClient { +export class TwitchPubSubServiceClient extends PubSubClient { private basicClient: BasicPubSubClient; - constructor(auth: AuthProvider, basicClient: BasicPubSubClient) { - super({ authProvider: auth, pubSubClient: basicClient }); - this.basicClient = basicClient; + + constructor(config: PubSubClientConfig) { + super(config); + + // Get reference to underlying client. + // Very ugly but not possible differently. + // This is a private field and may change but we need it + // to add listeners for disconnect/connection failures + // to the underlying basic client and force connection to + // ensure valid credentials. + //@ts-expect-error private field + this.basicClient = this._basicClient; } /** @@ -17,14 +26,23 @@ export class TwitchPubSubServiceClient extends SingleUserPubSubClient { const authProvider = await createAuthProvider(cfg); // Create the actual pubsub client and connect - const basicClient = new BasicPubSubClient(); - const pubSubClient = new TwitchPubSubServiceClient(authProvider, basicClient); + const pubSubClient = new TwitchPubSubServiceClient({ authProvider }); - await basicClient.connect(); + pubSubClient.basicClient.connect(); + await new Promise((resolve, reject) => { + pubSubClient.basicClient.onConnect(() => resolve(null)); + // 15 second timeout + setTimeout(() => reject("Timeout for PubSub connection was exceeded"), 15000); + }); return pubSubClient; } - disconnect(): Promise { - return this.basicClient.disconnect(); + async disconnect(): Promise { + this.basicClient.disconnect(); + await new Promise((resolve, reject) => { + this.basicClient.onDisconnect(() => resolve(null)); + // 15 second timeout + setTimeout(() => reject("Timeout for PubSub disconnection was exceeded"), 15000); + }); } } diff --git a/services/nodecg-io-twitch-pubsub/package.json b/services/nodecg-io-twitch-pubsub/package.json index b44a4973a..324fd5ab1 100644 --- a/services/nodecg-io-twitch-pubsub/package.json +++ b/services/nodecg-io-twitch-pubsub/package.json @@ -39,7 +39,7 @@ "dependencies": { "nodecg-io-core": "^0.3.0", "nodecg-io-twitch-auth": "^0.3.0", - "@twurple/api": "^5.3.4", - "@twurple/pubsub": "^5.3.4" + "@twurple/api": "^7.2.0", + "@twurple/pubsub": "^7.2.0" } } diff --git a/utils/nodecg-io-twitch-auth/package.json b/utils/nodecg-io-twitch-auth/package.json index 475b73018..28d7a2000 100644 --- a/utils/nodecg-io-twitch-auth/package.json +++ b/utils/nodecg-io-twitch-auth/package.json @@ -21,6 +21,6 @@ "typescript": "^5.4.3" }, "dependencies": { - "@twurple/auth": "^5.3.4" + "@twurple/auth": "^7.2.0" } }