Socket
Socket
Sign inDemoInstall

twitchonlinetracker

Package Overview
Dependencies
5
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.5 to 1.1.0

.env.EXAMPLE

34

lib/index.js

@@ -54,2 +54,4 @@ 'use strict';

var EventEmitter = require("events");
from;
'../package.json';
dotenv.config({ path: "./" + process.env.NODE_ENV + ".env" });

@@ -130,3 +132,3 @@ /**

twitchApiBase = 'https://api.twitch.tv/helix/';
this.log("[tot] making a request: " + twitchApiBase + endpoint);
this.log("making a request: " + twitchApiBase + endpoint);
return [4 /*yield*/, axios_1.default(twitchApiBase + endpoint, {

@@ -169,3 +171,3 @@ headers: {

if (!params.id && !params.login) {
throw new Error("[tot] Need login or id for Users endpoint.");
throw new Error("Need login or id for Users endpoint.");
}

@@ -238,3 +240,3 @@ paramString_1 = '';

var _this = this;
this.log("[tot] tracking " + loginNames.join(', '));
this.log("tracking " + loginNames.join(', '));
loginNames.forEach(function (login) {

@@ -252,3 +254,3 @@ _this.tracked.add(login.toLowerCase());

var _this = this;
this.log("[tot] untracking " + loginNames.join(', '));
this.log("untracking " + loginNames.join(', '));
loginNames.forEach(function (login) {

@@ -265,3 +267,3 @@ _this.tracked.delete(login.toLowerCase());

var _this = this;
this.log("[tot] starting to poll at " + this.options.pollInterval + "s intervals");
this.log("starting to poll at " + this.options.pollInterval + "s intervals");
this._loopIntervalId = setInterval(function () {

@@ -289,4 +291,3 @@ _this._loop();

return __awaiter(this, void 0, void 0, function () {
var _streamDataJson, streamRequestData, started_1, e_3;
var _this = this;
var _streamDataJson, streamRequestData, difference, newStreams, e_3;
return __generator(this, function (_a) {

@@ -301,14 +302,9 @@ switch (_a.label) {

streamRequestData = _streamDataJson;
started_1 = [];
streamRequestData.data.forEach(function (stream) {
// for each stream, check if it's cached already. if not, it is a new stream.
var isCached = _this._cachedStreamData.filter(function (cached) { return cached.user_id === stream.user_id; }).length > 0;
if (!isCached) {
// announce
_this._announce(stream);
started_1.push(stream.user_name);
}
});
if (started_1.length)
this.log(started_1.length + " new streams");
difference = function (a, b) {
var s = new Set(b);
return a.filter(function (x) { return !s.has(x); });
};
newStreams = difference(streamRequestData.data, this._cachedStreamData);
console.log(newStreams);
// if (started.length) this.log(`${started.length} new streams`)
this._cachedStreamData = streamRequestData.data;

@@ -315,0 +311,0 @@ _a.label = 2;

{
"name": "twitchonlinetracker",
"version": "1.0.5",
"version": "1.1.0",
"description": "A library to help track streamers and fires an event if they go online.",

@@ -16,3 +16,3 @@ "main": "lib/",

"watch": "tsc --watch -p tsconfig.json",
"test": "echo \"Error: no test specified\" && exit 1"
"test": "mocha -r ts-node/register src/**/*.test.ts"
},

@@ -27,8 +27,14 @@ "keywords": [

"dependencies": {
"axios": "^0.18.0",
"dotenv": "^6.2.0"
"axios": "^0.18.0"
},
"devDependencies": {
"@types/chai": "^4.1.7",
"@types/dotenv": "^6.1.0",
"@types/mocha": "^5.2.5",
"chai": "^4.2.0",
"dotenv": "^6.2.0",
"mocha": "^5.2.0",
"ts-node": "^7.0.1",
"typescript": "^3.2.2"
}
}

@@ -7,2 +7,4 @@ 'use strict'

import * as pkg from '../package.json'
import {

@@ -17,2 +19,3 @@ UserData,

} from './interfaces'
import { start } from 'repl';

@@ -74,3 +77,3 @@ dotenv.config({path: `./${process.env.NODE_ENV}.env`})

log (...rest) {
if (this.options.debug) console.log(...rest)
if (this.options.debug) console.log(`[${pkg.name}]`, ...rest)
}

@@ -98,3 +101,3 @@

const twitchApiBase: string = 'https://api.twitch.tv/helix/'
this.log(`[tot] making a request: ${twitchApiBase}${endpoint}`)
this.log(`making a request: ${twitchApiBase}${endpoint}`)
const response = await axios(twitchApiBase + endpoint, {

@@ -127,3 +130,3 @@ headers: {

if (!params.id && !params.login) {
throw new Error(`[tot] Need login or id for Users endpoint.`)
throw new Error(`Need login or id for Users endpoint.`)
}

@@ -186,3 +189,3 @@

track (loginNames: string[]) {
this.log(`[tot] tracking ${loginNames.join(', ')}`)
this.log(`tracking ${loginNames.join(', ')}`)
loginNames.forEach(login => {

@@ -200,3 +203,3 @@ this.tracked.add(login.toLowerCase())

untrack (loginNames: string[]) {
this.log(`[tot] untracking ${loginNames.join(', ')}`)
this.log(`untracking ${loginNames.join(', ')}`)
loginNames.forEach(login => {

@@ -213,3 +216,3 @@ this.tracked.delete(login.toLowerCase())

start () {
this.log(`[tot] starting to poll at ${this.options.pollInterval}s intervals`)
this.log(`starting to poll at ${this.options.pollInterval}s intervals`)
this._loopIntervalId = setInterval(() => {

@@ -242,19 +245,15 @@ this._loop()

const streamRequestData: StreamRequestData = _streamDataJson
const started = streamRequestData.data
.filter((current) => {
return this._cachedStreamData.filter((other) => {
return other.user_name === current.user_name
}).length == 0;
})
// has a stream started? check on cached
const started = []
streamRequestData.data.forEach(stream => {
// for each stream, check if it's cached already. if not, it is a new stream.
const isCached = this._cachedStreamData.filter(cached => cached.user_id === stream.user_id).length > 0
if (!isCached) {
// announce
this._announce(stream)
started.push(stream.user_name)
}
})
if (started.length) this.log(`${started.length} new streams`)
this._cachedStreamData = streamRequestData.data
return started
}

@@ -261,0 +260,0 @@ } catch (e) {

@@ -8,2 +8,3 @@ {

"outDir": "./lib",
"resolveJsonModule": true,
"target": "es5",

@@ -10,0 +11,0 @@ "types": ["node"]

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc