Skip to content

Commit

Permalink
client: remove updateEmoteset timers and options
Browse files Browse the repository at this point in the history
  • Loading branch information
AlcaDesign committed Jun 15, 2024
1 parent cef6988 commit 3edc540
Showing 1 changed file with 2 additions and 58 deletions.
60 changes: 2 additions & 58 deletions lib/client.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const _global = typeof global !== 'undefined' ? global : typeof window !== 'undefined' ? window : {};
const _WebSocket = _global.WebSocket || require('ws');
const _fetch = _global.fetch || require('node-fetch');
const commands = require('./commands');
const EventEmitter = require('./events').EventEmitter;
const logger = require('./logger');
Expand All @@ -20,9 +19,6 @@ const client = function client(opts) {
this.clientId = _.get(this.opts.options.clientId, null);
this._globalDefaultChannel = _.channel(_.get(this.opts.options.globalDefaultChannel, '#tmijs'));
this._skipMembership = _.get(this.opts.options.skipMembership, false);
this._skipUpdatingEmotesets = _.get(this.opts.options.skipUpdatingEmotesets, false);
this._updateEmotesetsTimer = null;
this._updateEmotesetsTimerDelay = _.get(this.opts.options.updateEmotesetsTimer, 60000);

this.maxReconnectAttempts = _.get(this.opts.connection.maxReconnectAttempts, Infinity);
this.maxReconnectInterval = _.get(this.opts.connection.maxReconnectInterval, 30000);
Expand Down Expand Up @@ -184,7 +180,6 @@ client.prototype.handleMessage = function handleMessage(message) {

clearInterval(this.pingLoop);
clearTimeout(this.pingTimeout);
clearTimeout(this._updateEmotesetsTimer);
}
}, _.get(this.opts.connection.timeout, 9999));
}, 60000);
Expand Down Expand Up @@ -811,7 +806,7 @@ client.prototype.handleMessage = function handleMessage(message) {

// Emote-sets has changed, update it..
if(message.tags['emote-sets'] !== this.emotes) {
this._updateEmoteset(message.tags['emote-sets']);
this.emit('emotesets', message.tags['emote-sets'], {});
}

this.userstate[channel] = tags;
Expand All @@ -824,7 +819,7 @@ client.prototype.handleMessage = function handleMessage(message) {

// Received emote-sets..
if(typeof message.tags['emote-sets'] !== 'undefined') {
this._updateEmoteset(message.tags['emote-sets']);
this.emit('emotesets', message.tags['emote-sets'], {});
}
break;

Expand Down Expand Up @@ -1155,7 +1150,6 @@ client.prototype._onError = function _onError() {
// Stop the internal ping timeout check interval..
clearInterval(this.pingLoop);
clearTimeout(this.pingTimeout);
clearTimeout(this._updateEmotesetsTimer);

this.reason = this.ws === null ? 'Connection closed.' : 'Unable to connect.';

Expand Down Expand Up @@ -1188,7 +1182,6 @@ client.prototype._onClose = function _onClose() {
// Stop the internal ping timeout check interval..
clearInterval(this.pingLoop);
clearTimeout(this.pingTimeout);
clearTimeout(this._updateEmotesetsTimer);

// User called .disconnect(), don't try to reconnect.
if(this.wasCloseCalled) {
Expand Down Expand Up @@ -1331,55 +1324,6 @@ client.prototype._sendMessage = function _sendMessage(delay, channel, message, f
}
});
};
// Grab the emote-sets object from the API..
client.prototype._updateEmoteset = function _updateEmoteset(sets) {
let setsChanges = sets !== undefined;
if(setsChanges) {
if(sets === this.emotes) {
setsChanges = false;
}
else {
this.emotes = sets;
}
}
if(this._skipUpdatingEmotesets) {
if(setsChanges) {
this.emit('emotesets', sets, {});
}
return;
}
const setEmotesetTimer = () => {
if(this._updateEmotesetsTimerDelay > 0) {
clearTimeout(this._updateEmotesetsTimer);
this._updateEmotesetsTimer = setTimeout(() => this._updateEmoteset(sets), this._updateEmotesetsTimerDelay);
}
};
this._getToken()
.then(token => {
const url = `https://api.twitch.tv/kraken/chat/emoticon_images?emotesets=${sets}`;
/** @type {import('node-fetch').RequestInit} */
const fetchOptions = {};
if('fetchAgent' in this.opts.connection) {
fetchOptions.agent = this.opts.connection.fetchAgent;
}
/** @type {import('node-fetch').Response} */
return _fetch(url, {
...fetchOptions,
headers: {
'Accept': 'application/vnd.twitchtv.v5+json',
'Authorization': `OAuth ${_.token(token)}`,
'Client-ID': this.clientId
}
});
})
.then(res => res.json())
.then(data => {
this.emotesets = data.emoticon_sets || {};
this.emit('emotesets', sets, this.emotesets);
setEmotesetTimer();
})
.catch(() => setEmotesetTimer());
};
// Get current username..
client.prototype.getUsername = function getUsername() {
return this.username;
Expand Down

0 comments on commit 3edc540

Please sign in to comment.