Skip to content

Commit

Permalink
add commercial & stream key API methods
Browse files Browse the repository at this point in the history
  • Loading branch information
d-fischer committed Nov 16, 2020
1 parent 6021b7e commit e1dd435
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 7 deletions.
4 changes: 4 additions & 0 deletions packages/twitch/src/API/CommercialLength.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/**
* The possible lengths of a channel commercial.
*/
export type CommercialLength = 30 | 60 | 90 | 120 | 150 | 180;
19 changes: 19 additions & 0 deletions packages/twitch/src/API/Helix/Channel/HelixChannelApi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { TwitchApiCallType } from 'twitch-api-call';
import type { CommercialLength } from '../../CommercialLength';
import type { UserIdResolvable } from '../../../Toolkit/UserTools';
import { extractUserId } from '../../../Toolkit/UserTools';
import { BaseApi } from '../../BaseApi';
Expand Down Expand Up @@ -79,4 +80,22 @@ export class HelixChannelApi extends BaseApi {
}
});
}

/**
* Starts a commercial on a channel.
*
* @param broadcaster The broadcaster on whose channel the commercial is started.
* @param length The length of the commercial, in seconds.
*/
async startChannelCommercial(broadcaster: UserIdResolvable, length: CommercialLength): Promise<void> {
await this._client.callApi({
type: TwitchApiCallType.Helix,
url: 'channels/commercial',
scope: 'channel:edit:commercial',
jsonBody: {
broadcaster_id: extractUserId(broadcaster),
length: length
}
});
}
}
18 changes: 18 additions & 0 deletions packages/twitch/src/API/Helix/Stream/HelixStreamApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,24 @@ export class HelixStreamApi extends BaseApi {
});
}

/**
* Retrieves the stream key of a stream.
*
* @param broadcaster The broadcaster to retrieve the stream key for.
*/
async getStreamKey(broadcaster: UserIdResolvable): Promise<string> {
const result = await this._client.callApi<HelixResponse<{ stream_key: string }>>({
type: TwitchApiCallType.Helix,
url: 'streams/key',
scope: 'channel:read:stream_key',
query: {
broadcaster_id: extractUserId(broadcaster)
}
});

return result.data[0].stream_key;
}

private async _getStreamMarkers(
queryType: string,
id: string
Expand Down
6 changes: 1 addition & 5 deletions packages/twitch/src/API/Kraken/Channel/ChannelApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { NoSubscriptionProgramError } from '../../../Errors/NoSubscriptionProgra
import type { UserIdResolvable } from '../../../Toolkit/UserTools';
import { extractUserId } from '../../../Toolkit/UserTools';
import { BaseApi } from '../../BaseApi';
import type { CommercialLength } from '../../CommercialLength';
import type { TeamData } from '../Team/Team';
import { Team } from '../Team/Team';
import type { UserData } from '../User/User';
Expand Down Expand Up @@ -41,11 +42,6 @@ export interface ChannelUpdateData {
channel_feed_enabled?: boolean;
}

/**
* The possible lengths of a channel commercial.
*/
export type CommercialLength = 30 | 60 | 90 | 120 | 150 | 180;

/**
* The API methods that deal with channels.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { CommercialLength } from '../../CommercialLength';
import type { User } from '../User/User';
import type { ChannelData } from './Channel';
import { Channel } from './Channel';
import type { CommercialLength } from './ChannelApi';

/** @private */
export interface PrivilegedChannelData extends ChannelData {
Expand Down
2 changes: 1 addition & 1 deletion packages/twitch/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export { ChannelPlaceholder } from './API/Kraken/Channel/ChannelPlaceholder';
export { ChannelSubscription } from './API/Kraken/Channel/ChannelSubscription';
export { EmoteSetList } from './API/Kraken/Channel/EmoteSetList';
export { PrivilegedChannel } from './API/Kraken/Channel/PrivilegedChannel';
export { CommercialLength } from './API/Kraken/Channel/ChannelApi';

export { Stream, StreamType } from './API/Kraken/Stream/Stream';

Expand Down Expand Up @@ -114,3 +113,4 @@ export {
RefreshConfig,
TokenInfo
} from 'twitch-auth';
export { CommercialLength } from './API/CommercialLength';

0 comments on commit e1dd435

Please sign in to comment.