From 1c83c786d7b47843316da3e467ac887b1e86f3be Mon Sep 17 00:00:00 2001
From: Sean Boult <996134+Hacksore@users.noreply.github.com>
Date: Sun, 28 Jul 2024 17:28:19 -0500
Subject: [PATCH 1/7] =?UTF-8?q?Add=20new=20RPC=20methods,=20at=20least=20s?=
=?UTF-8?q?oundboard=20works=20=E2=9D=A4=EF=B8=8F=20@spdermn02?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
apps/desktop/src/App.tsx | 23 ++++++++++++++++++++++-
apps/desktop/src/rpc/command.ts | 2 ++
apps/desktop/src/rpc/event.ts | 4 ++++
apps/desktop/src/rpc/manager.ts | 25 ++++++++++++++++++++++---
4 files changed, 50 insertions(+), 4 deletions(-)
diff --git a/apps/desktop/src/App.tsx b/apps/desktop/src/App.tsx
index 1cca81e1..afd2dbd2 100644
--- a/apps/desktop/src/App.tsx
+++ b/apps/desktop/src/App.tsx
@@ -13,9 +13,11 @@ import { useUpdate } from "./hooks/use-update";
import { useAppStore } from "./store";
import { Toaster } from "./components/ui/toaster";
import { useEffect } from "react";
+import { Button } from "./components/ui/button";
+import { RPCCommand } from "./rpc/command";
function App() {
- useSocket();
+ const socket = useSocket();
useDisableWebFeatures();
useEffect(() => {
@@ -42,6 +44,25 @@ function App() {
/>
)}
+
diff --git a/apps/desktop/src/rpc/command.ts b/apps/desktop/src/rpc/command.ts
index 2bd7cd3a..e63615d4 100644
--- a/apps/desktop/src/rpc/command.ts
+++ b/apps/desktop/src/rpc/command.ts
@@ -17,4 +17,6 @@ export enum RPCCommand {
GET_VOICE_SETTINGS = "GET_VOICE_SETTINGS",
SET_VOICE_SETTINGS_2 = "SET_VOICE_SETTINGS_2",
SET_VOICE_SETTINGS = "SET_VOICE_SETTINGS",
+ PLAY_SOUNDBOARD_SOUND = "PLAY_SOUNDBOARD_SOUND",
+ GET_SOUNDBOARD_SOUNDS = "GET_SOUNDBOARD_SOUNDS",
}
diff --git a/apps/desktop/src/rpc/event.ts b/apps/desktop/src/rpc/event.ts
index f8bcb9fa..3094836c 100644
--- a/apps/desktop/src/rpc/event.ts
+++ b/apps/desktop/src/rpc/event.ts
@@ -17,6 +17,10 @@ export enum RPCEvent {
VOICE_CHANNEL_SELECT = "VOICE_CHANNEL_SELECT",
/** sent when the client's voice connection status changes */
VOICE_CONNECTION_STATUS = "VOICE_CONNECTION_STATUS",
+ /** not quite sure */
+ VIDEO_STATE_UPDATE = "VIDEO_STATE_UPDATE",
+ /** not quite sure */
+ SCREENSHARE_STATE_UPDATE = "SCREENSHARE_STATE_UPDATE",
}
// TODO: move this somewhere
diff --git a/apps/desktop/src/rpc/manager.ts b/apps/desktop/src/rpc/manager.ts
index 45f508b8..52eb6270 100644
--- a/apps/desktop/src/rpc/manager.ts
+++ b/apps/desktop/src/rpc/manager.ts
@@ -63,6 +63,9 @@ const SUBSCRIBABLE_EVENTS = [
RPCEvent.VOICE_STATE_CREATE,
RPCEvent.VOICE_STATE_DELETE,
RPCEvent.VOICE_STATE_UPDATE,
+ // NOTE: these dont work or im using them wrong?
+ // RPCEvent.SCREENSHARE_STATE_UPDATE,
+ // RPCEvent.VIDEO_STATE_UPDATE,
];
export const APP_ID = "905987126099836938";
@@ -91,6 +94,8 @@ class SocketManager {
public _navigate: NavigateFunction | null = null;
public isConnected = false;
public version: string | undefined;
+ // @ts-expect-error need better types
+ public soundBoardItemsResolver = Promise.withResolvers();
private navigate(url: string) {
if (window.location.hash.includes("#settings")) return;
@@ -151,7 +156,7 @@ class SocketManager {
this.send({
args: {
client_id: APP_ID,
- scopes: ["rpc", "identify"],
+ scopes: ["identify", "rpc", "rpc.voice.read", "rpc.video.read", "rpc.screenshare.read"],
},
cmd: RPCCommand.AUTHORIZE,
});
@@ -240,6 +245,11 @@ class SocketManager {
if (payload.evt === RPCEvent.VOICE_STATE_UPDATE) {
this.store.updateUser(payload.data);
}
+
+ if (payload.cmd === RPCCommand.GET_SOUNDBOARD_SOUNDS) {
+ // update the Promise
+ this.soundBoardItemsResolver.resolve(payload.data);
+ }
// VOICE_CHANNEL_SELECT sent when the client joins a voice channel
if (payload.evt === RPCEvent.VOICE_CHANNEL_SELECT) {
@@ -376,12 +386,21 @@ class SocketManager {
});
}
+ /** Get the soundboard items */
+ public async getSoundBoardItems() {
+ await this.send({
+ cmd: RPCCommand.GET_SOUNDBOARD_SOUNDS,
+ });
+
+ return this.soundBoardItemsResolver.promise;
+ }
+
/**
* Send a message to discord
* @param payload {DiscordPayload} the payload to send
*/
- private send(payload: DiscordPayload) {
- this.socket?.send(
+ public send(payload: DiscordPayload) {
+ return this.socket?.send(
JSON.stringify({
...payload,
nonce: uuid.v4(),
From 88459af75133ce44b25af95c4009d0091241f83a Mon Sep 17 00:00:00 2001
From: Sean Boult <996134+Hacksore@users.noreply.github.com>
Date: Sun, 28 Jul 2024 17:31:39 -0500
Subject: [PATCH 2/7] Format
---
apps/desktop/src/App.tsx | 3 +--
apps/desktop/src/rpc/manager.ts | 2 +-
2 files changed, 2 insertions(+), 3 deletions(-)
diff --git a/apps/desktop/src/App.tsx b/apps/desktop/src/App.tsx
index afd2dbd2..21ccde14 100644
--- a/apps/desktop/src/App.tsx
+++ b/apps/desktop/src/App.tsx
@@ -46,9 +46,8 @@ function App() {