-
Notifications
You must be signed in to change notification settings - Fork 30.3k
/
Copy pathindex.d.ts
626 lines (541 loc) · 21.5 KB
/
index.d.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
/**
* The Twitch extensions JavaScript Helper.
*
* @see https://dev.twitch.tv/docs/extensions/reference/#javascript-helper
*/
declare namespace Twitch.ext {
/**
* This encodes the Helper version in 1.1.1 (semantic versioning) format.
*/
const version: string;
/**
* This encodes the environment. For external users, this is always production.
*/
const environment: "production";
/**
* @see https://dev.twitch.tv/docs/extensions/reference/#helper-actions
*/
namespace actions {
/**
* This function prompts users to follow the specified channel, with a dialog controlled by Twitch.
*
* @see https://dev.twitch.tv/docs/extensions/reference/#followchannel
*/
function followChannel(channelName: string): void;
/**
* This function causes your video-component or video-overlay extension to be minimized.
*
* @see https://dev.twitch.tv/docs/extensions/reference/#minimize
*/
function minimize(): void;
/**
* This function registers a callback that is invoked whenever a user completes an interaction prompted by the followChannel action.
*
* @see https://dev.twitch.tv/docs/extensions/reference/#onfollow
*/
function onFollow(callback: (didFollow: boolean, channelName: string) => void): void;
/**
* This function opens a prompt for users to share their identity.
* After a successful identity link, the Twitch.ext.onAuthorized callback is invoked with the user’s ID.
*
* @see https://dev.twitch.tv/docs/extensions/reference/#requestidshare
*/
function requestIdShare(): void;
}
/**
* @see https://dev.twitch.tv/docs/extensions/reference/#helper-configuration
*/
namespace configuration {
/**
* This property returns the record for the broadcaster segment if one is found; otherwise, undefined.
*/
const broadcaster: { version: string; content: string } | undefined;
/**
* This property returns the record for the developer segment if one is found; otherwise, undefined.
*/
const developer: { version: string; content: string } | undefined;
/**
* This property returns the record for the global segment if one is found; otherwise, undefined.
*/
const global: { version: string; content: string } | undefined;
/**
* This function registers a callback that is called whenever an extension configuration is received.
* The callback function takes no input and returns nothing. After this is called for the first time,
* the records for the global, developer and broadcaster segments will be set if the data is available.
* @param callback The callback that is fired.
*/
function onChanged(callback: () => void): void;
/**
* This function can be called by the front end to set an extension configuration.
* @param segment The configuration segment to set. Valid value. "broadcaster".
* @param version The version of configuration with which the segment is stored.
* @param content The string-encoded configuration.
*/
function set(segment: "broadcaster", version: string, content: string): void;
}
/**
* @see https://dev.twitch.tv/docs/extensions/reference/#twitch-extension-feature-flags
*/
namespace features {
type ChangedKey = "isBitsEnabled" | "isChatEnabled" | "isSubscriptionStatusAvailable";
/**
* If this flag is true, Bits in Extensions features will work in your extension on the current channel.
* If this flag is false, disable or hide the Bits in Extensions features in your extension.
*/
const isBitsEnabled: boolean;
/**
* If this flag is true, you can send a chat message to the current channel using Send Extension Chat Message
* (subject to the authentication requirements documented for that endpoint).
*/
const isChatEnabled: boolean;
/**
* If this flag is true, your extension has the ability to get the subscription status of identity-linked viewers
* from both the helper in the twitch.ext.viewer.subscriptionStatus object and via the Twitch API.
*/
const isSubscriptionStatusAvailable: boolean;
/**
* This function enables you to receive real-time updates to changes of the features object.
* If this callback is invoked, you should re-check the Twitch.ext.features object for a change
* to any feature flag your extension cares about.
*
* @param callback The callback is called with an array of feature flags which were updated.
*/
function onChanged(callback: (changed: readonly ChangedKey[]) => void): void;
}
/**
* @see https://dev.twitch.tv/docs/extensions/reference#helper-bits
*/
namespace bits {
/**
* This function returns a promise which resolves to an array of products available for Bits,
* for the extension, if the context supports Bits in Extensions actions. Otherwise, the
* promise rejects with an error; this can occur, for instance, if the extension is running in
* an older version of the developer rig or the mobile app, which does not support Bits in
* Extensions actions.
*
* @see https://dev.twitch.tv/docs/extensions/bits/#getproducts
*/
function getProducts(): Promise<readonly BitsProduct[]>;
/**
* This function takes a callback that is fired whenever a transaction is cancelled.
* @param callback The callback that is fired whenever a transaction is cancelled.
*
* @see https://dev.twitch.tv/docs/extensions/bits/#ontransactioncancelledcallback
*/
function onTransactionCancelled(callback: () => void): void;
/**
* This function registers a callback that is fired whenever a Bits in Extensions transaction
* is completed.
* @param callback The callback that is fired.
*
* @see https://dev.twitch.tv/docs/extensions/bits/#ontransactioncompletecallbacktransactionobject
*/
function onTransactionComplete(callback: (transaction: BitsTransaction) => void): void;
/**
* This function sets the state of the extension helper, so it does not call live services for
* usage of Bits. Instead, it does a local loopback to the completion handler, after a fixed
* delay to simulate user approval and process latency.
* @param useLoopback Whether to use local looback.
*
* @see https://dev.twitch.tv/docs/extensions/bits/#setuseloopbackboolean
*/
function setUseLoopback(useLoopback: boolean): void;
/**
* Call this function when the viewer hovers over a product in your extension UI, to cause the
* Twitch UI to display a dialog showing the viewer’s Bits balance.
* The dialog displays for 1.5 seconds, unless your extension calls showBitsBalance again, in
* which case the 1.5-second timer resets.
*
* This is a “fire-and-forget” function: the extension developer does not need to tell Twitch
* when the viewer stops hovering over the product.
*
* On mobile, this function is ignored.
*
* @see https://dev.twitch.tv/docs/extensions/bits/#showbitsbalance
*/
function showBitsBalance(): void;
/**
* This function redeems a product with the specified SKU for the number of Bits specified in
* the catalog entry of that product.
* @param sku
*
* @see https://dev.twitch.tv/docs/extensions/bits/#usebitssku
* @see https://dev.twitch.tv/docs/extensions/bits/#exchanging-bits-for-a-product
*/
function useBits(sku: string): void;
}
/**
* @see https://dev.twitch.tv/docs/extensions/reference#helper-viewer
*/
const viewer: Viewer;
/**
* Helper methods for the Twitch Extension rig.
* @see https://github.com/twitchdev/developer-rig
*/
const rig: Rig;
/**
* This function binds the callback to the initial values and changes to the authorization data.
*
* @param authCallback This callback is fired each time the JWT is refreshed.
* @see https://dev.twitch.tv/docs/extensions/reference/#onauthorized
*/
function onAuthorized(authCallback: (auth: Authorized) => void): void;
/**
* This function binds the callback to the initial values and changes to the context.
*
* @param contextCallback This callback is fired when the context of an extension is fired.
* @see https://dev.twitch.tv/docs/extensions/reference/#oncontext
*/
function onContext(
contextCallback: <T extends Partial<Context>>(context: T, changed: ReadonlyArray<keyof T>) => void,
): void;
/**
* This function binds the callback to any internal error.
*
* @param errorCallback This callback is fired if any errors are generated by the extension helper.
* @see https://dev.twitch.tv/docs/extensions/reference/#onerror
*/
function onError(errorCallback: (errorValue: any) => void): void;
/**
* This function allows an extension to adjust its visibility when the viewer highlights the extension by hovering
* over the extension’s menu icon or open menu, in the video player. The function applies only to video-overlay and
* component Extensions.
*
* @param callback This callback is called whenever the extension is or is no longer highlighted by the user.
* @see https://dev.twitch.tv/docs/extensions/reference/#onhighlightchanged
*/
function onHighlightChanged(callback: (isHighlighted: boolean) => void): void;
/**
* This function registers a callback that gets called whenever an extension changes position in the player. This
* occurs only for video-component extensions. This also is triggered as the extension loads.
*
* @param callback This callback is called whenever an extension changes position in the player.
* @see https://dev.twitch.tv/docs/extensions/reference/#onpositionchanged
*/
function onPositionChanged(callback: (position: { x: number; y: number }) => void): void;
/**
* This function registers a callback that gets called whenever an extension is hidden/re-shown. (This occurs only
* for mobile or component extensions.) When an extension is not visible in the mobile app, it does not receive
* onContext updates and must perform only minimal work in the background.
*
* @param callback This callback is called whenever an extension is hidden/re-shown.
* @see https://dev.twitch.tv/docs/extensions/reference/#onvisibilitychanged
*/
function onVisibilityChanged(
callback: ((isVisible: false) => void) | ((isVisible: true, context: Partial<Context>) => void),
): void;
/**
* This function can be called by the front end to send directly to PubSub.
*
* @param target Target topic. Often this is "broadcast" but it might be "whisper-<userId>".
* @param contentType type of the serialized message; for example, "application/json".
* @param message Either an object that will be automatically serialized as JSON or a string.
* @see https://dev.twitch.tv/docs/extensions/reference/#send
*/
function send(target: string, contentType: string, message: object | string): void;
/**
* This function binds the callback to listen to the target topic.
*
* @param target Target topic. Often this is "broadcast" but it might be "whisper-<userId>".
* @param callback These fields correspond to the values in the send() message, except the message is always a string.
* @see https://dev.twitch.tv/docs/extensions/reference/#listen
*/
function listen(target: string, callback: (target: string, contentType: string, message: string) => void): void;
/**
* This function unbinds the listen callback from the target.
*
* @param target Target topic. Often this is "broadcast" but it might be "whisper-<userId>".
* @param callback These fields correspond to the values in the send() message, except the message is always a string.
* @see https://dev.twitch.tv/docs/extensions/reference/#unlisten
*/
function unlisten(target: string, callback: (target: string, contentType: string, message: string) => void): void;
interface BitsProductCost {
/**
* Number of Bits required for the product.
*/
amount: string;
/**
* Always the string "bits". Reserved for future use.
*/
type: "bits";
}
interface BitsProduct {
/**
* Cost object.
*/
cost: BitsProductCost;
/**
* Registered display name for the SKU.
*/
displayName: string;
/**
* This field is returned only for extension versions that are not in the Released state.
*/
inDevelopment?: boolean | undefined;
/**
* Unique ID for the product.
*/
sku: string;
}
interface BitsTransaction {
/**
* Display name of the user who executed the Bits in Extensions transaction.
*/
displayName: string;
// The documentation says that the type of this field is `"CURRENT_USER" | "OTHER"`,
// but in reality it is lowercase.
// https://github.com/DefinitelyTyped/DefinitelyTyped/discussions/67555
initiator: "current_user" | "other";
/**
* Full product object from getProducts call
*/
product: BitsProduct;
/**
* Will be "twitch.ext" + your extension ID.
*/
domainID: string;
/**
* ID of the transaction.
*/
transactionID: string;
/**
* JWT containing the following transaction information in the payload.
* The JWT is a large, base64-encoded string. It can be verified using your developer secret.
*/
transactionReceipt: string;
/**
* Twitch ID of the user who executed the transaction.
*/
userId: string;
}
interface ViewerSubscriptionStatus {
/**
* This tier of the subscription.
* Possible values are 1000, 200 and 300 for tier one, two and three subscriptions respectively.
*/
tier: string;
}
/**
* @see viewer
*/
interface Viewer {
/**
* The opaque id of the viewer.
*/
opaqueId: string;
/**
* The Twitch ID of a linked viewer. null if the viewer has not opted to share their identity with the extension.
*/
id: string | null;
/**
* The role of the user. See the JWT schema for possible values.
*/
role: string;
/**
* Provided as a convenience to check whether or not a user has shared their identity with their extension
*/
isLinked: boolean;
/**
* The encoded JWT. This is the same as the token property of the authData parameter that currently gets passed to
* the onAuthorized callback.
*/
sessionToken: string;
/**
* A token to use with the Twitch API. This is the same as the helixToken property of the authData parameter
* that currently gets passed to the onAuthorized callback.
*/
helixToken: string;
/**
* An object containing information about the viewer’s subscription. The value of subscriptionStatus will be null if
* the user is either not a subscriber, or opting not to share their identity. The value will also be null if the
* extension otherwise doesn't have subscription capabilities.
*/
subscriptionStatus: ViewerSubscriptionStatus | null;
/**
* This function binds a callback will be invoked when the viewer’s status changes (e.g. if a viewer subscribes and
* changes their subscription status).
* @param callback The callback that is called whenever the viewer's status changes
*/
onChanged(callback: () => void): void;
}
/**
* The developer rig object as available under window.Twitch.ext.rig.
*
* @see rig
*/
interface Rig {
/**
* Print a message to the developer rig console.
*
* @param message The message to print.
* @see https://github.com/twitchdev/developer-rig#rig-console
*/
log(message: string): void;
}
/**
* The result object as passed to the onAuthorized callback.
*
* @see onAuthorized
*/
interface Authorized {
/**
* Channel ID of the page where the extension is iframe embedded.
*/
channelId: string;
/**
* Client ID of the extension.
*/
clientId: string;
/**
* JWT that should be passed to any EBS call for authentication.
*/
token: string;
/**
* JWT that can be used for front end API requests.
*/
helixToken: string;
/**
* Opaque user ID.
*/
userId: string;
}
/**
* The result object as passed to the onContext callback.
*
* @see onContext
*/
interface Context {
/**
* If true, player controls are visible (e.g., due to mouseover).
* Do not use this for mobile extensions; it is not sent for mobile.
*/
arePlayerControlsVisible: boolean;
/**
* Bitrate of the broadcast.
*/
bitrate: number;
/**
* Buffer size of the broadcast.
*/
bufferSize: number;
/**
* Display size of the player.
*/
displayResolution: string;
/**
* Game being broadcast.
*/
game: string;
/**
* Number of seconds of latency between the broadcaster and viewer.
*/
hlsLatencyBroadcaster: number;
/**
* Information about the current channel’s hosting status, or undefined if the channel is not currently hosting.
*/
hostingInfo?:
| {
/**
* Numeric ID of the channel being hosted by the currently visible channel
*/
hostedChannelId: string;
/**
* Numeric ID of the host channel
*/
hostingChannelId: string;
}
| undefined;
/**
* If true, the viewer is watching in fullscreen mode.
* Do not use this for mobile extensions; it is not sent for mobile.
*/
isFullScreen: boolean;
/**
* If true, the viewer has muted the stream.
*/
isMuted: boolean;
/**
* If true, the viewer has paused the stream.
*/
isPaused: boolean;
/**
* If true, the viewer is watching in theater mode.
* Do not use this for mobile extensions; it is not sent for mobile.
*/
isTheatreMode: boolean;
/**
* Language of the broadcast (e.g., "en").
*/
language: string;
/**
* The mode the extension is currently run in.
*/
mode: "viewer" | "dashboard" | "config";
/**
* Indicates how the stream is being played.
*/
playbackMode: "video" | "audio" | "remote" | "chat-only";
/**
* The user’s theme setting on the Twitch website.
*/
theme: "light" | "dark";
/**
* Resolution of the broadcast.
*/
videoResolution: string;
/**
* Currently selected player volume. Valid values: between 0 and 1.
*/
volume: number;
}
/**
* The extension window receives the following query parameters, which indicate
* information about the extension environment that isn’t subject to change over
* the frame’s life cycle. Note that all parameters are encoded as strings here,
* because they are always part of the URL.
*
* @see https://dev.twitch.tv/docs/extensions/reference/#client-query-parameters
*/
interface ClientQueryParams {
/**
* The type of the anchor in which the extension is activated.
*/
anchor: "component" | "panel" | "video_overlay";
/**
* The user’s language setting.
*
* @example "en"
*/
language: string;
/**
* The user’s language locale.
*
* @example "en-US"
*/
locale: string;
/**
* The extension’s mode.
*/
mode: "config" | "dashboard" | "viewer";
/**
* The platform on which the Twitch client is running.
*/
platform: "mobile" | "web";
/**
* Indicates whether the extension is popped out.
*/
popout: "true" | "false";
/**
* The release state of the extension.
*/
state:
| "testing"
| "hosted_test"
| "approved"
| "released"
| "ready_for_review"
| "in_review"
| "pending_action"
| "uploading";
}
}