Skip to content

Commit

Permalink
fix(webhooks): set stream id after going live (#2843)
Browse files Browse the repository at this point in the history
* fix(webhooks): set stream id after going live

[skip-tests]

* add webhooks
  • Loading branch information
sogehige committed Oct 22, 2019
1 parent fab9eff commit ce997e5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
9 changes: 4 additions & 5 deletions src/bot/api.ts
Expand Up @@ -1037,6 +1037,10 @@ class API extends Core {
this.stats.currentBits = 0;
this.stats.currentTips = 0;

this.streamStatusChangeSince = new Date(stream.started_at).getTime();
this.streamId = stream.id;
this.streamType = stream.type;

global.events.fire('stream-started', {});
global.events.fire('command-send-x-times', { reset: true });
global.events.fire('keyword-send-x-times', { reset: true });
Expand Down Expand Up @@ -1065,11 +1069,6 @@ class API extends Core {
}
}

// Always keep this updated
this.streamStatusChangeSince = new Date(stream.started_at).getTime();
this.streamId = stream.id;
this.streamType = stream.type;

this.curRetries = 0;
this.saveStreamData(stream);
this.isStreamOnline = true;
Expand Down
20 changes: 10 additions & 10 deletions src/bot/webhooks.ts
Expand Up @@ -303,22 +303,14 @@ class Webhooks {
if (aEvent.data.length > 0) {
const stream = aEvent.data[0];

if (parseInt(stream.user_id, 10) !== parseInt(cid, 10) || Number(stream.id) === Number(global.api.streamId)) {
if (parseInt(stream.user_id, 10) !== parseInt(cid, 10)) {
return;
}

// Always keep this updated
global.api.streamStatusChangeSince = (new Date(stream.started_at)).getTime();
global.api.streamId = stream.id;
global.api.streamType = stream.type;

global.api.stats.currentTitle = stream.title;
global.api.stats.currentGame = await global.api.getGameFromId(stream.game_id);

if (Number(global.api.streamId) !== Number(stream.id)) {
debug('webhooks.stream', 'WEBHOOKS: ' + JSON.stringify(aEvent));
start(
`id: ${stream.id} | startedAt: ${stream.started_at} | title: ${stream.title} | game: ${await global.api.getGameFromId(stream.game_id)} | type: ${stream.type} | channel ID: ${cid}`
`id: ${stream.id} | webhooks | startedAt: ${stream.started_at} | title: ${stream.title} | game: ${await global.api.getGameFromId(stream.game_id)} | type: ${stream.type} | channel ID: ${cid}`
);

// reset quick stats on stream start
Expand All @@ -338,6 +330,14 @@ class Webhooks {
global.events.fire('every-x-minutes-of-stream', { reset: true });
}

// Always keep this updated
global.api.streamStatusChangeSince = (new Date(stream.started_at)).getTime();
global.api.streamId = stream.id;
global.api.streamType = stream.type;

global.api.stats.currentTitle = stream.title;
global.api.stats.currentGame = await global.api.getGameFromId(stream.game_id);

global.api.curRetries = 0;
global.api.saveStreamData(stream);
global.api.streamId = stream.id;
Expand Down

0 comments on commit ce997e5

Please sign in to comment.