From af4fcef3bf8b374638827f1a4ae5ce6e970150cd Mon Sep 17 00:00:00 2001 From: Federico Della Rovere Date: Thu, 28 Feb 2019 17:50:59 +0100 Subject: [PATCH 1/9] Update twitch ext definitions with configuration feature --- types/twitch-ext/index.d.ts | 45 +++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/types/twitch-ext/index.d.ts b/types/twitch-ext/index.d.ts index 4cac514539..fac7ccaad4 100644 --- a/types/twitch-ext/index.d.ts +++ b/types/twitch-ext/index.d.ts @@ -29,6 +29,11 @@ interface TwitchExt { */ actions: TwitchExtActions; + /** + * @see https://dev.twitch.tv/docs/extensions/reference/#helper-configuration + */ + configuration: TwitchExtConfiguration; + /** * @see https://dev.twitch.tv/docs/extensions/reference/#twitch-extension-feature-flags */ @@ -170,6 +175,46 @@ interface TwitchExtActions { requestIdShare(): void; } +/** + * @see TwitchExt.configuration + */ +interface TwitchExtConfiguration { + /** + * This property returns the record for the broadcaster segment if one is found; otherwise, undefined. + */ + broadcaster: { version: string; content: string } | undefined; + + /** + * This property returns the record for the developer segment if one is found; otherwise, undefined. + */ + developer: { version: string; content: string } | undefined; + + /** + * This property returns the record for the global segment if one is found; otherwise, undefined. + */ + global: { version: string; content: string } | undefined; + + /** + * This function registers a callback that is called whenever an extension configuration is received. + * The callback function takes no input and returns nothing. After this is called for the first time, + * the records for the global, developer and broadcaster segments will be set if the data is available. + * @param callback The callback that is fired. + */ + onChanged( + callback: () => void + ): void + + + /** + * This function can be called by the front end to set an extension configuration. + * @param segment The string-encoded configuration. + * @param version The configuration segment to set. + * @param content The version of configuration with which the segment is stored. + */ + set(segment: string, version: string, content: string): void; +} + + interface TwitchExtFeatureFlags { /** * If this flag is true, you can send a chat message to the current channel using Send Extension Chat Message From 80b5ecb0821f57cb96890431dd31d8fd1d7ce2aa Mon Sep 17 00:00:00 2001 From: Federico Della Rovere Date: Fri, 1 Mar 2019 09:23:11 +0100 Subject: [PATCH 2/9] fix linting issues --- types/twitch-ext/index.d.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/types/twitch-ext/index.d.ts b/types/twitch-ext/index.d.ts index fac7ccaad4..2aa518fb43 100644 --- a/types/twitch-ext/index.d.ts +++ b/types/twitch-ext/index.d.ts @@ -186,7 +186,7 @@ interface TwitchExtConfiguration { /** * This property returns the record for the developer segment if one is found; otherwise, undefined. - */ + */ developer: { version: string; content: string } | undefined; /** @@ -199,11 +199,10 @@ interface TwitchExtConfiguration { * The callback function takes no input and returns nothing. After this is called for the first time, * the records for the global, developer and broadcaster segments will be set if the data is available. * @param callback The callback that is fired. - */ + */ onChanged( callback: () => void - ): void - + ): void; /** * This function can be called by the front end to set an extension configuration. @@ -214,7 +213,6 @@ interface TwitchExtConfiguration { set(segment: string, version: string, content: string): void; } - interface TwitchExtFeatureFlags { /** * If this flag is true, you can send a chat message to the current channel using Send Extension Chat Message From 4853a9065b484a47c33a56eb3cc29c48ab144f39 Mon Sep 17 00:00:00 2001 From: Federico Della Rovere Date: Fri, 1 Mar 2019 10:04:20 +0100 Subject: [PATCH 3/9] add twitch-ext configuration test --- types/twitch-ext/twitch-ext-tests.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/types/twitch-ext/twitch-ext-tests.ts b/types/twitch-ext/twitch-ext-tests.ts index f6a70f86cb..f3b16517d2 100644 --- a/types/twitch-ext/twitch-ext-tests.ts +++ b/types/twitch-ext/twitch-ext-tests.ts @@ -36,6 +36,28 @@ window.Twitch.ext.actions.minimize(); window.Twitch.ext.actions.followChannel("hearthsim"); window.Twitch.ext.actions.requestIdShare(); +// Twitch Extension Configuration +window.Twitch.ext.configuration.onChanged(() => { + console.log('Configuration changed'); + if (window.Twitch.ext.configuration.broadcaster) { + console.log('Caster configuration'); + console.log('version: ', window.Twitch.ext.configuration.broadcaster.version); + console.log('content: ', window.Twitch.ext.configuration.broadcaster.content); + } + if (window.Twitch.ext.configuration.developer) { + console.log('Developer configuration'); + console.log('version:', window.Twitch.ext.configuration.developer.version); + console.log('content: ', window.Twitch.ext.configuration.developer.content); + } + if (window.Twitch.ext.configuration.global) { + console.log('Global configuration'); + console.log('version: ', window.Twitch.ext.configuration.global.version); + console.log('content: ', window.Twitch.ext.configuration.global.content); + } +}); + +window.Twitch.ext.configuration.set('broadcaster', '0.0.1', '{"test": "test"}'); + // Twitch Extension Feature flags window.Twitch.ext.features.onChanged(changed => { if (changed.indexOf("isChatEnabled") !== -1) { From 129237bb3c8098e4b013233ea2ce9484d9d3e37d Mon Sep 17 00:00:00 2001 From: Federico Della Rovere Date: Fri, 1 Mar 2019 10:23:01 +0100 Subject: [PATCH 4/9] add contribution sign --- types/twitch-ext/index.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/types/twitch-ext/index.d.ts b/types/twitch-ext/index.d.ts index 2aa518fb43..cb02f14538 100644 --- a/types/twitch-ext/index.d.ts +++ b/types/twitch-ext/index.d.ts @@ -1,6 +1,7 @@ // Type definitions for non-npm package twitch-ext 1.15 // Project: https://dev.twitch.tv/docs/extensions/reference/#javascript-helper // Definitions by: Benedict Etzel +// Federico Della Rovere // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.4 From 3796d81ce2f6df3e1dcc839245881086c8d10c1a Mon Sep 17 00:00:00 2001 From: Federico Della Rovere Date: Fri, 1 Mar 2019 10:33:24 +0100 Subject: [PATCH 5/9] increase twitch-ext version --- types/twitch-ext/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/twitch-ext/index.d.ts b/types/twitch-ext/index.d.ts index cb02f14538..a9e2a648d9 100644 --- a/types/twitch-ext/index.d.ts +++ b/types/twitch-ext/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for non-npm package twitch-ext 1.15 +// Type definitions for non-npm package twitch-ext 1.16 // Project: https://dev.twitch.tv/docs/extensions/reference/#javascript-helper // Definitions by: Benedict Etzel // Federico Della Rovere From b269c7cfcb6ead375fc10a8a165f151dfa936da3 Mon Sep 17 00:00:00 2001 From: Federico Della Rovere Date: Fri, 1 Mar 2019 15:07:44 +0100 Subject: [PATCH 6/9] fix with more natural syntax --- types/twitch-ext/index.d.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/types/twitch-ext/index.d.ts b/types/twitch-ext/index.d.ts index a9e2a648d9..5e1c9bfc74 100644 --- a/types/twitch-ext/index.d.ts +++ b/types/twitch-ext/index.d.ts @@ -183,17 +183,17 @@ interface TwitchExtConfiguration { /** * This property returns the record for the broadcaster segment if one is found; otherwise, undefined. */ - broadcaster: { version: string; content: string } | undefined; + broadcaster?: { version: string; content: string }; /** * This property returns the record for the developer segment if one is found; otherwise, undefined. */ - developer: { version: string; content: string } | undefined; + developer?: { version: string; content: string }; /** * This property returns the record for the global segment if one is found; otherwise, undefined. */ - global: { version: string; content: string } | undefined; + global?: { version: string; content: string }; /** * This function registers a callback that is called whenever an extension configuration is received. From b98bcdf2e2be48ded1d34f2c9007bb92acd0071e Mon Sep 17 00:00:00 2001 From: Federico Della Rovere Date: Fri, 1 Mar 2019 15:11:03 +0100 Subject: [PATCH 7/9] enforce segment's only valid value --- types/twitch-ext/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/twitch-ext/index.d.ts b/types/twitch-ext/index.d.ts index 5e1c9bfc74..b603c8aa92 100644 --- a/types/twitch-ext/index.d.ts +++ b/types/twitch-ext/index.d.ts @@ -211,7 +211,7 @@ interface TwitchExtConfiguration { * @param version The configuration segment to set. * @param content The version of configuration with which the segment is stored. */ - set(segment: string, version: string, content: string): void; + set(segment: "broadcaster", version: string, content: string): void; } interface TwitchExtFeatureFlags { From b48449e7839db521b06deb9a2ff579440ab35ecf Mon Sep 17 00:00:00 2001 From: Federico Della Rovere Date: Fri, 1 Mar 2019 15:14:53 +0100 Subject: [PATCH 8/9] update version according to twitch-ext javascript helper --- types/twitch-ext/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/twitch-ext/index.d.ts b/types/twitch-ext/index.d.ts index b603c8aa92..b8d29c5818 100644 --- a/types/twitch-ext/index.d.ts +++ b/types/twitch-ext/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for non-npm package twitch-ext 1.16 +// Type definitions for non-npm package twitch-ext 1.20 // Project: https://dev.twitch.tv/docs/extensions/reference/#javascript-helper // Definitions by: Benedict Etzel // Federico Della Rovere From c9bb0dc4f70dc428be05b67079dbda3bd3e47f77 Mon Sep 17 00:00:00 2001 From: Federico Della Rovere Date: Mon, 4 Mar 2019 09:47:28 +0100 Subject: [PATCH 9/9] fix descrition issue --- types/twitch-ext/index.d.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/types/twitch-ext/index.d.ts b/types/twitch-ext/index.d.ts index b8d29c5818..6c3126c049 100644 --- a/types/twitch-ext/index.d.ts +++ b/types/twitch-ext/index.d.ts @@ -207,9 +207,9 @@ interface TwitchExtConfiguration { /** * This function can be called by the front end to set an extension configuration. - * @param segment The string-encoded configuration. - * @param version The configuration segment to set. - * @param content The version of configuration with which the segment is stored. + * @param segment The configuration segment to set. Valid value. "broadcaster". + * @param version The version of configuration with which the segment is stored. + * @param content The string-encoded configuration. */ set(segment: "broadcaster", version: string, content: string): void; }