Skip to content

Commit

Permalink
implement X viewer count (#4795)
Browse files Browse the repository at this point in the history
  • Loading branch information
avacreeth authored Nov 17, 2023
1 parent 0e50f48 commit 04332f0
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion app/services/platforms/twitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class TwitterPlatformService
ingest: '',
};

readonly capabilities = new Set<TPlatformCapability>(['title']);
readonly capabilities = new Set<TPlatformCapability>(['title', 'viewerCount']);
readonly apiBase = 'https://api.twitter.com/2';
readonly platform = 'twitter';
readonly displayName = 'X (Twitter)';
Expand Down Expand Up @@ -139,6 +139,19 @@ export class TwitterPlatformService
return jfetch<{}>(request);
}

async fetchViewerCount(): Promise<number> {
if (!this.state.broadcastId) return 0;

const host = this.hostsService.streamlabs;
const url = `https://${host}/api/v5/slobs/twitter/stream/${this.state.broadcastId}/info`;
const headers = authorizedHeaders(this.userService.apiToken!);
const request = new Request(url, { headers });

const result = await jfetch<{ viewers: string }>(request);

return parseInt(result.viewers, 10);
}

/**
* prepopulate channel info and save it to the store
*/
Expand Down

0 comments on commit 04332f0

Please sign in to comment.