Get unlimited public & private packages + package-based permissions with npm Pro.Get started »

twitchps

1.2.0 • Public • Published

TwitchPS

dependency status Downloads Version GitHub issues Build Status

Neat little Node library which lets you easily interact with the Twitch.tv PubSub service.

CAUTION Not updated since Twitch changed API. Broken at the moment. Will fix in near future.

#### Supported Topics

Feature Topic and Example Required Scope You are notified when …
Bits channel-bits-events-v1.<channel ID>

Example: channel-bits-events-v1.44322889
Any scope Anyone cheers on a specified channel.
Channel Subscriptions channel-subscribe-events-v1.<channel ID>

Example: channel-subscribe-events-v1.44322889
channel_subscriptions Anyone subscribes (first month, gift sub) or resubscribes (subsequent months) to a channel.
Whispers whispers.<user ID>

Example: whispers.44322889
chat_login Anyone whispers the specified user.
Stream Status video-playback.<channel name>

Example: video-playback.summit1g
No scope needed Status on stream going up, down, and viewer count. Not officially supported by Twitch
Moderator Action chat_moderator_actions.<user_id_of_moderator>.<room_id>

Example: video-playback.summit1g
Any scope Sends event when moderator you are listening too bans, or unbans chat user. Not officially supported by Twitch

Installation

Node

Install via NPM

npm i twitchps --save

Usage

Include the Component

Options
Name Type Optional Default Description
init_topics JSON object False *NONE JSON Object array of initial topics with tokens. See below.
reconnect boolean True True Reconnect when disconnected from Pubsub servers.
debug boolean True False Turns debug console output on and off.
const TwitchPS = require('twitchps');
 
// Initial topics are required
let init_topics = [{topic: 'video-playback.bajheera'}, {topic: 'whispers.44322889', token: 'nkuaf7ur3trg7ju37md1y3u5p52s3q'}];
// Optional reconnect, debug options (Defaults: reconnect: true, debug: false)
// var ps = new TwitchPS({init_topics: init_topics});
var ps = new TwitchPS({init_topics: init_topics, reconnect: false, debug: true});
 
ps.on('stream-up', (data) => {
  console.log(data.time , data.channel_name);
  // Use data here
});

Token changed for security reasons. You can generate a token here.
In order to find the userID/channelID follow the instructions here.
For more detailed usage see example application.

Connection Events

Event Name You are notified when …
'connected' A successful connection has been established
'disconnected' The connection has been terminated
'reconnect' An attempt will be made to reconnect

Events emitted after subscribing/adding topics

Event Name List of fields
'bits' bits_used - {integer}
channel_id - {string}
channel_name - {string}
chat_message - {string}
context - {string}
message_id - {string}
message_type - {string}
time - {string}
total_bits_used - {integer}
user_id - {string}
user_name - {string}
version - {string}
'subscribe' user_name - {string}
display_name - {string}
channel_name - {string}
user_id - {string}
channel_id- {string}
time- {string}
sub_plan- {string}
sub_plan_name - {string}
months - {integer}
cumulative_months - {integer}
context - {string}
sub_message - {object}
sub_message.message - {string}
sub_message.emotes - {array}
recipient_id - {integer}
recipient_user_name - {string}
recipient_display_name - {string}
'whisper_sent' & 'whisper_received' id - {integer}
body - {string}
thread_id - {string}
sender - {JSON}
sender.id - {integer}
sender.username - {string}
sender.display_name - {string}
sender.color - {string}
sender.badges - {Array}
sender.emotes - {Array}
recipient - {JSON}
recipient.id - {integer}
recipient.username - {string}
recipient.display_name - {string}
recipient.color - {string}
recipient.badges - {Array}
sent_ts - {integer}
nonce - {string}
'stream-up' time - {integer}
channel_name- {string}
play_delay - {string}
'stream-down' time - {integer}
channel_name- {string}
'viewcount' time - {integer}
channel_name- {string}
viewers - {integer}

Listen to new topics

ps.addTopic([{topic: "video-playback.starladder_cs_en"}]);
ps.addTopic([{topic: 'whispers.38290946', token: 'nkuaf7ur3trg7ju37md1y3u5p52s3q'}]);

Token changed for security reasons.

Un-listen (remove) to existing topics

ps.removeTopic([{topic: "video-playback.starladder_cs_en"}]);

Token not required.

Community

Install

npm i twitchps

DownloadsWeekly Downloads

14

Version

1.2.0

License

MIT

Unpacked Size

37.5 kB

Total Files

6

Last publish

Collaborators

  • avatar