Meteor and listening to events from another package (tmi.js)

Hey reader, I’m trying to build an app using tmi.js (,

The code I need to find a place for is the following:

// Initialize a client and connect it to Twitch.
clientOptions = {} // not important for example
client = new tmi.client(clientOptions);

I’ve put this in server.js before the Meteor.startup and it loads up fine (terminal shows it connecting and joining a channel). But then I want to define a listener, for example (

// Listen to the 'chat' event on the client.
client.on("chat", function (channel, userstate, message, self) {
    // Do stuff.

I can’t figure out where in Meteor structure such a thing would go. I’ve tried putting it in the server.js as well, just to test, and added a Messages.insert (figured I’d just save it somewhere so I can read it from the db in another component) but then I get a Fiber error and rightly so.

I reckon I need to put the entire client in a component so it is scoped properly but I’m just spitballing here.

Can anyone show me where to look/what to try? I’ve done the todos tutorial etc. but I can’t find any use cases related to what I’m trying to accomplish, although I reckon it should be peanuts since in plain js it works easily enough (but I want to use the nice framework for all the UI capabilities I need to add).

Any pointers, tips, directions…?