Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

twitchonlinetracker

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

twitchonlinetracker - npm Package Compare versions

Comparing version 1.1.2 to 1.1.5

dev.env

16

lib/index.d.ts

@@ -28,9 +28,2 @@ /// <reference types="node" />

/**
* Gets the version number.
*
* @returns {string} The version number
* @memberof TwitchOnlineTracker
*/
version(): any;
/**
* Make a request on the Twitch Helix API. Used internally but can be used for something custom.

@@ -92,3 +85,3 @@ *

*/
_loop(): Promise<void>;
_loop(): Promise<StreamData[]>;
/**

@@ -100,2 +93,9 @@ * Emit an event when a stream starts

_announce(streamData: StreamData): void;
/**
* Emit an event when a stream stops
* @fires TwitchOnlineTracker#offline
* @param {string} channelName the channel name of the stream that has stopped
* @memberof TwitchOnlineTracker
*/
_offline(channelName: string): void;
}

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

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

@@ -106,14 +104,5 @@ /**

if (this.options.debug)
console.log.apply(console, rest);
console.log.apply(console, ['[twitchonlinetracker]'].concat(rest));
};
/**
* Gets the version number.
*
* @returns {string} The version number
* @memberof TwitchOnlineTracker
*/
TwitchOnlineTracker.prototype.version = function () {
return require('./package.json').version;
};
/**
* Make a request on the Twitch Helix API. Used internally but can be used for something custom.

@@ -276,3 +265,3 @@ *

TwitchOnlineTracker.prototype.stop = function () {
this.log('[tot] forcefully stopping polling');
this.log('forcefully stopping polling');
clearInterval(this._loopIntervalId);

@@ -288,3 +277,4 @@ this._loopIntervalId = 0;

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

@@ -298,12 +288,25 @@ switch (_a.label) {

_streamDataJson = _a.sent();
streamRequestData = _streamDataJson;
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;
_a.label = 2;
streamRequestData_1 = _streamDataJson;
started = streamRequestData_1.data
.filter(function (current) {
return _this._cachedStreamData.filter(function (other) {
return other.user_name === current.user_name;
}).length == 0;
});
stopped = this._cachedStreamData
.filter(function (current) {
return streamRequestData_1.data.filter(function (other) {
return other.user_name === current.user_name;
}).length == 0;
});
if (started.length) {
this.log(started.length + " new streams");
started.forEach(function (startedStream) { return _this._announce(startedStream); });
}
if (stopped.length) {
this.log(stopped.length + " stopped streams");
stopped.forEach(function (stoppedStream) { return _this._offline(stoppedStream.user_name); });
}
this._cachedStreamData = streamRequestData_1.data;
return [2 /*return*/, started];
case 2: return [3 /*break*/, 4];

@@ -334,8 +337,21 @@ case 3:

* @event TwitchOnlineTracker#live
* @param {StreamData} channel The stream that has started
* @param {StreamData} The stream that has started
*/
this.emit('live', streamData);
};
/**
* Emit an event when a stream stops
* @fires TwitchOnlineTracker#offline
* @param {string} channelName the channel name of the stream that has stopped
* @memberof TwitchOnlineTracker
*/
TwitchOnlineTracker.prototype._offline = function (channelName) {
/**
* @event TwitchOnlineTracker#offline
* @param {string} The stream that has stopped
*/
this.emit('offline', channelName);
};
return TwitchOnlineTracker;
}(EventEmitter));
exports.TwitchOnlineTracker = TwitchOnlineTracker;
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
var _this = this;
Object.defineProperty(exports, "__esModule", { value: true });
require("mocha");
var chai_1 = require("chai");
require("mocha");
var dotenv = require("dotenv");
var index_1 = require("../index");
var twitchApi_1 = require("./twitchApi");
dotenv.config();
var tracker = new index_1.TwitchOnlineTracker({
'debug': Boolean(process.env.TEST_DEBUG) || false,
'debug': false,
'pollInterval': 5,
'client_id': process.env.TEST_CLIENT_ID || null,
'track': process.env.TEST_STREAMS.split(',')
'track': process.env.TEST_STREAMS.split(',') || []
});
describe('TwitchOnlineTracker', function () {
it('should be tracking at least 1 stream', function () {
chai_1.expect(tracker.tracked.size).to.be.greaterThan(0);
});
it('will start polling with an _loopIntervalId', function () {

@@ -20,2 +60,40 @@ tracker.start();

});
it('should return empty array, no new streams', function () { return __awaiter(_this, void 0, void 0, function () {
var streamsRequestData, newStreams;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
streamsRequestData = twitchApi_1.streams;
return [4 /*yield*/, tracker._loop()]; // cache current results
case 1:
_a.sent(); // cache current results
return [4 /*yield*/, tracker._loop()];
case 2:
newStreams = _a.sent();
chai_1.expect(newStreams.length).to.equal(0);
return [2 /*return*/];
}
});
}); });
it('should return an array with 1 element, 1 new stream', function () { return __awaiter(_this, void 0, void 0, function () {
var streamsRequestData, newStreams;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
streamsRequestData = twitchApi_1.streams;
return [4 /*yield*/, tracker._loop()
// pop one off
]; // cache current results
case 1:
_a.sent(); // cache current results
// pop one off
tracker._cachedStreamData.pop();
return [4 /*yield*/, tracker._loop()];
case 2:
newStreams = _a.sent();
chai_1.expect(newStreams.length).to.equal(1);
return [2 /*return*/];
}
});
}); });
});
{
"name": "twitchonlinetracker",
"version": "1.1.2",
"version": "1.1.5",
"description": "A library to help track streamers and fires an event if they go online.",

@@ -5,0 +5,0 @@ "main": "lib/",

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc