twurple / twurple

Interact with Twitch's API, chat and subscribe to events via PubSub and EventSub.
MIT License
649 stars 101 forks source link

onHost can return NaN for number of viewers #35

Closed lafiosca closed 5 years ago

lafiosca commented 5 years ago

Bug Report

When connecting to a channel that is already hosting another channel, the onHost callback returns a value of NaN for the number of viewers rather than undefined.

This is due to a possible change in the notices that Twitch sends. Specifically, when connecting to a channel that is already hosting another channel, Twitch sends a notice in the form of targetchannel -, with a hyphen in the viewer count position.

Code

const twitchChat = await TwitchChatClient.forTwitchClient(twitchClient);
twitchChat.onHost((channel, target, viewers) => {
    console.log(`viewers ${isNaN(viewers) ? 'isNaN' : 'is a number'}`);
});

Expected behavior

When connecting to a channel that is already hosting another channel, onHost should receive an undefined value for viewers.

Actual Behavior

When connecting to a channel that is already hosting another channel, onHost receives NaN for viewers.

Environment

n/a

d-fischer commented 5 years ago

The fix was published in twitch-chat-client@2.3.2.