Skip to content

Commit

Permalink
cytube: add future support for new API
Browse files Browse the repository at this point in the history
  • Loading branch information
Supinic committed Sep 10, 2024
1 parent 734ea6c commit 3f929a8
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions platforms/cytube.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ class CytubeClient {
playlistData = [];
currentlyPlaying = null;
restarting = false;
restartInterval = null;

/** @type {Map<string, CytubeUserPresence>} */
userMap = new Map();
Expand All @@ -26,7 +25,7 @@ class CytubeClient {
this.initialize();
}

initialize () {
async initialize () {
if (this.client) {
console.warn("Attempting to re-initialize a running Cytube client", {
channel: this.channelData.Name
Expand All @@ -45,9 +44,11 @@ class CytubeClient {
});

this.client = client;
if (typeof this.client.connect === "function") {
await this.client.connect();
}

client.on("clientready", () => {
clearInterval(this.restartInterval);
this.restarting = false;
});

Expand Down Expand Up @@ -479,17 +480,20 @@ module.exports = class CytubePlatform extends require("./template.js") {
});
}

connect () {
async connect () {
if (!sb.Config.has("CYTUBE_BOT_PASSWORD", true)) {
throw new sb.Error({
message: "Cytube password has not been configured"
});
}

const eligibleChannels = sb.Channel.getJoinableForPlatform(this);
const promises = [];
for (const channelData of eligibleChannels) {
this.joinChannel(channelData);
promises.push(this.joinChannel(channelData));
}

await Promise.all(promises);
}

/**
Expand Down Expand Up @@ -558,12 +562,14 @@ module.exports = class CytubePlatform extends require("./template.js") {
* @param {Channel} channelData
* @returns {boolean} True if the channel was joined, false if it was joined before.
*/
joinChannel (channelData) {
async joinChannel (channelData) {
if (this.clients.has(channelData)) {
return false;
}

const client = new CytubeClient(channelData, this);
await client.initialize();

this.clients.set(channelData.ID, client);

return true;
Expand Down

0 comments on commit 3f929a8

Please sign in to comment.