/
HelixChannel.ts
115 lines (100 loc) · 2.72 KB
/
HelixChannel.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import { Enumerable } from '@d-fischer/shared-utils';
import { checkRelationAssertion, DataObject, rawDataSymbol, rtfm } from '@twurple/common';
import { type BaseApiClient } from '../../client/BaseApiClient';
import { type HelixChannelData } from '../../interfaces/endpoints/channel.external';
import type { HelixGame } from '../game/HelixGame';
import type { HelixUser } from '../user/HelixUser';
/**
* A Twitch channel.
*/
@rtfm<HelixChannel>('api', 'HelixChannel', 'id')
export class HelixChannel extends DataObject<HelixChannelData> {
/** @internal */ @Enumerable(false) private readonly _client: BaseApiClient;
/** @internal */
constructor(data: HelixChannelData, client: BaseApiClient) {
super(data);
this._client = client;
}
/**
* The ID of the channel.
*/
get id(): string {
return this[rawDataSymbol].broadcaster_id;
}
/**
* The name of the channel.
*/
get name(): string {
return this[rawDataSymbol].broadcaster_login;
}
/**
* The display name of the channel.
*/
get displayName(): string {
return this[rawDataSymbol].broadcaster_name;
}
/**
* Gets more information about the broadcaster of the channel.
*/
async getBroadcaster(): Promise<HelixUser> {
return checkRelationAssertion(await this._client.users.getUserById(this[rawDataSymbol].broadcaster_id));
}
/**
* The language of the channel.
*/
get language(): string {
return this[rawDataSymbol].broadcaster_language;
}
/**
* The ID of the game currently played on the channel.
*/
get gameId(): string {
return this[rawDataSymbol].game_id;
}
/**
* The name of the game currently played on the channel.
*/
get gameName(): string {
return this[rawDataSymbol].game_name;
}
/**
* Gets information about the game that is being played on the stream.
*/
async getGame(): Promise<HelixGame | null> {
return this[rawDataSymbol].game_id
? checkRelationAssertion(await this._client.games.getGameById(this[rawDataSymbol].game_id))
: null;
}
/**
* The title of the channel.
*/
get title(): string {
return this[rawDataSymbol].title;
}
/**
* The stream delay of the channel, in seconds.
*
* If you didn't request this with broadcaster access, this is always zero.
*/
get delay(): number {
return this[rawDataSymbol].delay;
}
/**
* The tags applied to the channel.
*/
get tags(): string[] {
return this[rawDataSymbol].tags;
}
/**
* The content classification labels applied to the channel.
*/
get contentClassificationLabels(): string[] {
return this[rawDataSymbol].content_classification_labels;
}
/**
* Whether the channel currently displays branded content (as specified by the broadcaster).
*/
get isBrandedContent(): boolean {
return this[rawDataSymbol].is_branded_content;
}
}