Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add functionality to turn on/off Running lights for faders based on user in-call status #6

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"devDependencies": {
"@semantic-release/exec": "^5.0.0",
"@semantic-release/git": "^9.0.0",
"@types/discord-rpc": "^3.0.5",
"@types/discord-rpc": "^4",
"@types/node": "^15.12.1",
"@typescript-eslint/eslint-plugin": "^4.14.2",
"@typescript-eslint/parser": "^4.14.2",
Expand All @@ -34,7 +34,7 @@
},
"dependencies": {
"conf": "^10.0.1",
"discord-rpc": "^3.2.0",
"discord-rpc": "^4.0.1",
"midi-mixer-plugin": "^0.3.0"
},
"bundledDependencies": [
Expand Down
39 changes: 38 additions & 1 deletion src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export class DiscordApi {
"rpc.activities.write",
"rpc.voice.read",
"rpc.voice.write",
"rpc.notifications.read",
];
private static syncGap = 1000 * 30;

Expand Down Expand Up @@ -115,9 +116,25 @@ export class DiscordApi {
}
}

this.rpc.subscribe("VOICE_SETTINGS_UPDATE", (data: VoiceSettings) => {
/**
* our own libs are well-typed. the 4.x TotallyTyped declarations have lagged (at least for .on and .subscribe signatures)
* so to force compilation (until fixed upstream), let ts ignore the .on and .subscribe lines (badbadnotgood)
*/
// @ts-ignore
this.rpc.on("VOICE_CONNECTION_STATUS", (data: any) => {
console.log("VOICE_CONNECTION_STATUS event triggered");
this.syncRunning(data);
});
// @ts-ignore
this.rpc.on("VOICE_SETTINGS_UPDATE", (data: VoiceSettings) => {
console.log("VOICE_SETTINGS_UPDATE event triggered");
this.sync(data);
});

// @ts-ignore
this.rpc.subscribe("VOICE_CONNECTION_STATUS", {});
// @ts-ignore
this.rpc.subscribe("VOICE_SETTINGS_UPDATE", {});

$MM.setSettingsStatus("status", "Syncing voice settings...");
this.settings = await this.rpc.getVoiceSettings();
Expand Down Expand Up @@ -329,6 +346,26 @@ export class DiscordApi {
config.set(Keys.AuthToken, accessToken);
}

private async syncRunning(data?: any) {
/**
* RPC client ain't really best at getting current connection status, so just
* wait for subs to tell us state
*/
console.log("Syncing voice connection status from: ", data);
if (!this.faders) return;

if (!data.state) {
console.log("No state given!?")
return;
};

const connected = data.state == "VOICE_CONNECTED";
this.faders[DiscordFader.InputVolume].running = connected;
this.faders[DiscordFader.OutputVolume].running = connected;

console.log("Finished syncing voice connection status from: ", data);
};

private async sync(settings?: VoiceSettings) {
this.settings = settings ?? (await this.rpc.getVoiceSettings());
const boolSettings = this.normaliseSettings(this.settings);
Expand Down