UNPKG

twitch-toolkit

Version:

A set of tools to integrate with Twitch API, Twitch Chat and Twitch WebHooks.

1,422 lines (417 loc) 21.2 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width,initial-scale=1"> <title>TwitchWebSub - Documentation</title> <script src="scripts/prettify/prettify.js"></script> <script src="scripts/prettify/lang-css.js"></script> <!--[if lt IE 9]> <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <link type="text/css" rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css"> <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css"> <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css"> </head> <body> <input type="checkbox" id="nav-trigger" class="nav-trigger" /> <label for="nav-trigger" class="navicon-button x"> <div class="navicon"></div> </label> <label for="nav-trigger" class="overlay"></label> <nav> <li class="nav-link nav-home-link"><a href="index.html">Home</a></li><li class="nav-heading">Classes</li><li class="nav-heading"><span class="nav-item-type type-class">C</span><span class="nav-item-name"><a href="TwitchApi.html">TwitchApi</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="TwitchApi.html#auth">auth</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="TwitchApi.html#getGames">getGames</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="TwitchApi.html#getStreams">getStreams</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="TwitchApi.html#getStreamsMetadata">getStreamsMetadata</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="TwitchApi.html#getUsers">getUsers</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="TwitchApi.html#getUsersFollows">getUsersFollows</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="TwitchApi.html#getVideos">getVideos</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="TwitchApi.html#updateUser">updateUser</a></span></li><li class="nav-heading"><span class="nav-item-type type-class">C</span><span class="nav-item-name"><a href="TwitchChatEmitter.html">TwitchChatEmitter</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="TwitchChatEmitter.html#connect">connect</a></span></li><li class="nav-heading"><span class="nav-item-type type-class">C</span><span class="nav-item-name"><a href="TwitchWebSub.html">TwitchWebSub</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="TwitchWebSub.html#destroy">destroy</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="TwitchWebSub.html#subscribe">subscribe</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="TwitchWebSub.html#topicStreamUpDownSubscribe">topicStreamUpDownSubscribe</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="TwitchWebSub.html#topicUserFollowsSubscribe">topicUserFollowsSubscribe</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="TwitchWebSub.html#unsubscribe">unsubscribe</a></span></li><li class="nav-heading">Events</li><li class="nav-heading"><span class="nav-item-type type-event">E</span><span class="nav-item-name"><a href="TwitchChatEmitter.html#event:Chat:chat_cmd_COMMAND">Chat:chat_cmd_COMMAND</a></span></li><li class="nav-heading"><span class="nav-item-type type-event">E</span><span class="nav-item-name"><a href="TwitchChatEmitter.html#event:Chat:chat_parsed">Chat:chat_parsed</a></span></li><li class="nav-heading"><span class="nav-item-type type-event">E</span><span class="nav-item-name"><a href="TwitchChatEmitter.html#event:Chat:whisper_cmd_COMMAND">Chat:whisper_cmd_COMMAND</a></span></li><li class="nav-heading"><span class="nav-item-type type-event">E</span><span class="nav-item-name"><a href="TwitchWebSub.html#event:WebSub:stream_up_down">WebSub:stream_up_down</a></span></li><li class="nav-heading"><span class="nav-item-type type-event">E</span><span class="nav-item-name"><a href="TwitchWebSub.html#event:WebSub:user_follows">WebSub:user_follows</a></span></li> </nav> <div id="main"> <h1 class="page-title">TwitchWebSub</h1> <section> <header> <h2> TwitchWebSub </h2> <div class="class-description"><p>TwitchWebSub The Twitch Webhooks implementation, as described in https://dev.twitch.tv/docs/api/webhooks-guide/ . The Webhook/WebSub requires a public endpoint on the running express server/application to receive the data from the hub. Without this, its impossible to make this work.</p></div> </header> <article> <div class="container-overview"> <div class="section-method"> <h2>Constructor</h2> <h4 class="name" id="TwitchWebSub"><span class="type-signature"></span>new TwitchWebSub<span class="signature">(config, logger)</span><span class="type-signature"></span></h4> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="twitchWebSub.js.html">twitchWebSub.js</a>, <a href="twitchWebSub.js.html#line20">line 20</a> </li></ul></dd> </dl> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>config</code></td> <td class="type"> <span class="param-type"><code>object</code></span> </td> <td class="description last"> <p>The config object.</p> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>client_id</code></td> <td class="type"> <span class="param-type"><code>string</code></span> </td> <td class="description last"> <p>The client ID of the user to be passed to the Hub (un)subscribe requests.</p> </td> </tr> <tr> <td class="name"><code>callbackUrl</code></td> <td class="type"> <span class="param-type"><code>string</code></span> </td> <td class="description last"> <p>The callback URL that will receive the Hub requests. These requests should be forwarded to the handleRequest method to properly handle these data.</p> </td> </tr> </tbody> </table> </td> </tr> <tr> <td class="name"><code>logger</code></td> <td class="type"> <span class="param-type"><code>object</code></span> </td> <td class="description last"> <p>The logger object.</p> </td> </tr> </tbody> </table> </div> </div> <h3 class="subsection-title">Methods</h3> <div class="section-method"> <h4 class="name" id="destroy"><span class="type-signature"></span>destroy<span class="signature">()</span><span class="type-signature"></span></h4> <div class="description"> <p>Destroy the WebSub, unsubscribing every active subscription.</p> </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="twitchWebSub.js.html">twitchWebSub.js</a>, <a href="twitchWebSub.js.html#line193">line 193</a> </li></ul></dd> </dl> </div> <div class="section-method"> <h4 class="name" id="subscribe"><span class="type-signature"></span>subscribe<span class="signature">(topic, eventName)</span><span class="type-signature"> &rarr; {string}</span></h4> <div class="description"> <p>Subscribe to a specific topic that will fires an event when new data is received from the hub. The event handler will receive the data object and the subscription ID.</p> </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="twitchWebSub.js.html">twitchWebSub.js</a>, <a href="twitchWebSub.js.html#line91">line 91</a> </li></ul></dd> </dl> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>topic</code></td> <td class="type"> <span class="param-type"><code>string</code></span> </td> <td class="description last"> <p>The topic name/URL.</p> </td> </tr> <tr> <td class="name"><code>eventName</code></td> <td class="type"> <span class="param-type"><code>string</code></span> </td> <td class="description last"> <p>The event name that will be fired when new data is received.</p> </td> </tr> </tbody> </table> <div class="section-returns"> <h5>Returns:</h5> <dl class="param-type"> <dt> Type: </dt> <dd> <span class="param-type"><code>string</code></span> </dd> </dl> <div class="param-desc"> <p>The subscription ID, used to identify the active topic.</p> </div> </div> </div> <div class="section-method"> <h4 class="name" id="topicStreamUpDownSubscribe"><span class="type-signature"></span>topicStreamUpDownSubscribe<span class="signature">(streamUserId)</span><span class="type-signature"> &rarr; {string}</span></h4> <div class="description"> <p>Notifies when a stream goes online or offline. The response mimics the Get Streams endpoint. (https://dev.twitch.tv/docs/api/reference/#get-streams)</p> </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="twitchWebSub.js.html">twitchWebSub.js</a>, <a href="twitchWebSub.js.html#line67">line 67</a> </li></ul></dd> </dl> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>streamUserId</code></td> <td class="type"> <span class="param-type"><code>number</code></span> </td> <td class="description last"> <p>The ID of the user whose stream is monitored.</p> </td> </tr> </tbody> </table> <h5>Fires:</h5> <ul> <li><a href="TwitchWebSub.html#event:WebSub:stream_up_down">TwitchWebSub#WebSub:stream_up_down</a></li> </ul> <div class="section-returns"> <h5>Returns:</h5> <dl class="param-type"> <dt> Type: </dt> <dd> <span class="param-type"><code>string</code></span> </dd> </dl> <div class="param-desc"> <p>The subscription ID, used to identify the active topic.</p> </div> </div> </div> <div class="section-method"> <h4 class="name" id="topicUserFollowsSubscribe"><span class="type-signature"></span>topicUserFollowsSubscribe<span class="signature">(fromId, toId)</span><span class="type-signature"> &rarr; {string}</span></h4> <div class="description"> <p>Notifies when a follows event occurs. The response mimics the Get Users Follows endpoint. (https://dev.twitch.tv/docs/api/reference/#get-users-follows)</p> </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="twitchWebSub.js.html">twitchWebSub.js</a>, <a href="twitchWebSub.js.html#line37">line 37</a> </li></ul></dd> </dl> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>fromId</code></td> <td class="type"> <span class="param-type"><code>number</code></span> </td> <td class="description last"> <p>The ID of the user who starts following someone.</p> </td> </tr> <tr> <td class="name"><code>toId</code></td> <td class="type"> <span class="param-type"><code>number</code></span> </td> <td class="description last"> <p>The ID of the user who has a new follower.</p> </td> </tr> </tbody> </table> <h5>Fires:</h5> <ul> <li><a href="TwitchWebSub.html#event:WebSub:user_follows">TwitchWebSub#WebSub:user_follows</a></li> </ul> <div class="section-returns"> <h5>Returns:</h5> <dl class="param-type"> <dt> Type: </dt> <dd> <span class="param-type"><code>string</code></span> </dd> </dl> <div class="param-desc"> <p>The subscription ID, used to identify the active topic.</p> </div> </div> </div> <div class="section-method"> <h4 class="name" id="unsubscribe"><span class="type-signature"></span>unsubscribe<span class="signature">(id)</span><span class="type-signature"></span></h4> <div class="description"> <p>Unsubscribe from a topic by its ID.</p> </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="twitchWebSub.js.html">twitchWebSub.js</a>, <a href="twitchWebSub.js.html#line160">line 160</a> </li></ul></dd> </dl> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>id</code></td> <td class="type"> <span class="param-type"><code>string</code></span> </td> <td class="description last"> <p>The subscription ID.</p> </td> </tr> </tbody> </table> </div> <h3 class="subsection-title">Events</h3> <div class="section-method"> <h4 class="name" id="event:WebSub:stream_up_down">WebSub:stream_up_down</h4> <div class="description"> <p>Stream Up/Down Event</p> </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="twitchWebSub.js.html">twitchWebSub.js</a>, <a href="twitchWebSub.js.html#line70">line 70</a> </li></ul></dd> </dl> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>data</code></td> <td class="type"> <span class="param-type"><code>object</code></span> </td> <td class="description last"> <p>The data object received from the Hub.</p> </td> </tr> <tr> <td class="name"><code>id</code></td> <td class="type"> <span class="param-type"><code>string</code></span> </td> <td class="description last"> <p>The subscription ID.</p> </td> </tr> </tbody> </table> </div> <div class="section-method"> <h4 class="name" id="event:WebSub:user_follows">WebSub:user_follows</h4> <div class="description"> <p>Stream User Follows Event</p> </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="twitchWebSub.js.html">twitchWebSub.js</a>, <a href="twitchWebSub.js.html#line41">line 41</a> </li></ul></dd> </dl> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>data</code></td> <td class="type"> <span class="param-type"><code>object</code></span> </td> <td class="description last"> <p>The data object received from the Hub.</p> </td> </tr> <tr> <td class="name"><code>id</code></td> <td class="type"> <span class="param-type"><code>string</code></span> </td> <td class="description last"> <p>The subscription ID.</p> </td> </tr> </tbody> </table> </div> </article> </section> </div> <br class="clear"> <footer> Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Tue Jun 05 2018 22:52:28 GMT-0300 (E. South America Standard Time) using the Minami theme. </footer> <script>prettyPrint();</script> <script src="scripts/linenumber.js"></script> </body> </html>