GithubHelp home page GithubHelp logo

ichigowalker / twitchps Goto Github PK

View Code? Open in Web Editor NEW

This project forked from thehamsti/twitchps

0.0 1.0 0.0 52 KB

Neat little library which lets you easily listen/unlisten to different events on the Twitch.tv PubSub service.

License: MIT License

JavaScript 100.00%

twitchps's Introduction

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

twitchps's People

Contributors

thehamsti avatar dbkynd avatar ichigowalker avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.