Skip to content

Commit

Permalink
Update README, add some comments. (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
aidenwallis authored Jul 16, 2023
1 parent 8d4c2ac commit 45cc8f5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# team-members-extension

A Twitch extension to display all users who are in a Twitch stream in a panel, and their viewership (if they're live).
![Example screenshot](extension-assets/screenshot.png)

> A Twitch extension to display all users who are in a Twitch stream in a panel, and their viewership (if they're live).
**[This extension is live on Twitch!](https://dashboard.twitch.tv/extensions/3ot63weux43j9va0jy0th37wm2yjlz)**

This extension is written in Web Components using [Lit](https://lit.dev), and makes all of its data calls through the [public Twitch API](https://dev.twitch.tv/docs/api).

Expand Down
3 changes: 3 additions & 0 deletions src/teams/team-select-menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ export class ExtSelectTeamMenu extends TwElement {
}

private switchFocus(down: boolean) {
// turns out *good* keyboard navigation is pretty hard to do right
// - this is mostly shared with the sort-dropdown code, i'll consolidate these later

const activeElement = this.shadowRoot?.activeElement || document.activeElement;
if (!activeElement) return;

Expand Down
9 changes: 9 additions & 0 deletions src/teams/team-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,10 @@ export class ExtTeamView extends TwElement {
protected updated(changed: Map<string, string>): void {
if (!changed.has("teamId") || !this.teamId) return;

// never said this shit was pretty, enjoy this mess of a data fetch/poll spiral.
// - it's worth noting that this is deliberately complex, it's trying to optimise
// the polling rate the best it can, and cache as optimally as possible.

if (teamDataCache.has(this.teamId)) {
// already cached data, skip
this.teamData = teamDataCache.get(this.teamId) || null;
Expand Down Expand Up @@ -292,6 +296,11 @@ export class ExtTeamView extends TwElement {
}

private requestLiveStatusHydration() {
// this is also deliberately complex, it's doing a bunch of things:
// - ensuring we only ever call twitch if we *really need to*
// - ensuring that the poll rate from old caches is always respected.
// - ensuring state from old timers is gracefully cleared up

if (!this.authContext.value || !this.teamData?.users) return;
if (this.streamCache && this.streamCache.nextUpdateDue > Date.now()) {
this.setupNextLivePoll();
Expand Down

0 comments on commit 45cc8f5

Please sign in to comment.