Skip to content

Commit

Permalink
Fix audience controls and generate stream key logic. (#5148)
Browse files Browse the repository at this point in the history
* Fix audience controls and generate stream key logic.

* fix(build): strict nulls

---------

Co-authored-by: Adrian Perez <[email protected]>
  • Loading branch information
michelinewu and blackxored authored Oct 1, 2024
1 parent f33a1b8 commit 73a7575
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function TikTokEditStreamInfo(p: IPlatformComponentParams<'tiktok'>) {
requiredFields={<div key="empty-tiktok" />}
/>
{approved && <GameSelector key="optional" platform={'tiktok'} {...bind.game} />}
{!controls.disable && (
{approved && !controls.disable && (
<RadioInput
key="audience-ctrl"
options={controls.types}
Expand Down Expand Up @@ -151,11 +151,14 @@ function TikTokButtons(p: { denied: boolean }) {

return (
<>
{!p.denied && (
<Button id="tiktok-locate-key" onClick={openProducer} style={{ marginBottom: '10px' }}>
{$t('Locate my Stream Key')}
</Button>
)}
<Button
id="tiktok-locate-key"
onClick={openProducer}
style={{ marginBottom: '10px', width: '100%' }}
>
{$t('Locate my Stream Key')}
</Button>

<Button
id="tiktok-application"
onClick={() => {
Expand Down
21 changes: 15 additions & 6 deletions app/services/platforms/tiktok.ts
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,13 @@ export class TikTokService
this.setAudienceControls(status.audience_controls_info);
}

if (status?.application_status) {
// show prompt to apply if user has never applied
if (status.application_status.status === 'never-applied') {
return EPlatformCallResult.TikTokStreamScopeMissing;
}
}

if (status?.user) {
const scope = this.convertScope(status.reason);
this.SET_USERNAME(status.user.username);
Expand Down Expand Up @@ -525,11 +532,12 @@ export class TikTokService

// track the first date the user registered as denied so that after 30 days
// they are prompted to reapply
if (status === EPlatformCallResult.TikTokStreamScopeMissing && !this.state.dateDenied) {
this.SET_DENIED_DATE(new Date().toISOString());
} else {
this.SET_DENIED_DATE();
}
// TODO: fix denied date logic
// if (status === EPlatformCallResult.TikTokStreamScopeMissing && !this.state.dateDenied) {
// this.SET_DENIED_DATE(new Date().toISOString());
// } else {
// this.SET_DENIED_DATE();
// }

if (status === EPlatformCallResult.TikTokScopeOutdated) {
throwStreamError('TIKTOK_SCOPE_OUTDATED');
Expand Down Expand Up @@ -749,7 +757,8 @@ export class TikTokService
// convert audience types to match the ListInput component options
const types = audienceControlsInfo.types.map(type => ({
value: type.key.toString(),
label: type.label,
// TODO: revisit as to why cast is needed here, `string|null` on type def
label: type.label as string,
}));
const audienceType = audienceControlsInfo.info_type.toString();

Expand Down
9 changes: 8 additions & 1 deletion app/services/platforms/tiktok/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export enum ETikTokAudienceType {
}

export type TTikTokLiveScopeTypes = 'approved' | 'denied' | 'legacy' | 'relog';
export type TTikTokApplicationStatus = 'approved' | 'rejected' | 'never-applied';

export interface ITikTokLiveScopeResponse {
platform: TPlatform | string;
Expand All @@ -39,6 +40,7 @@ export interface ITikTokLiveScopeResponse {
user?: ITikTokUserData;
info?: any[] | null[] | undefined[] | ITikTokGame[] | ITikTokGamesData | any;
audience_controls_info: ITikTokAudienceControlsInfo;
application_status: ITikTokApplicationStatus;
}

export interface ITikTokGamesData extends ITikTokLiveScopeResponse {
Expand All @@ -63,7 +65,12 @@ export interface ITikTokAudienceControlsInfo {

export interface ITikTokAudienceControlType {
key: ETikTokAudienceType;
label: string;
label: string | null;
}

export interface ITikTokApplicationStatus {
status: string;
timestamp: string | null;
}

export interface ITikTokUserData {
Expand Down

0 comments on commit 73a7575

Please sign in to comment.