diff --git a/apps/desktop/src/App.tsx b/apps/desktop/src/App.tsx
index 1cca81e1..402c50dd 100644
--- a/apps/desktop/src/App.tsx
+++ b/apps/desktop/src/App.tsx
@@ -1,4 +1,3 @@
-import { useSocket } from "./rpc/manager";
import { Routes, Route } from "react-router-dom";
import { MainView } from "./views/main";
import { ChannelView } from "./views/channel";
@@ -15,7 +14,6 @@ import { Toaster } from "./components/ui/toaster";
import { useEffect } from "react";
function App() {
- useSocket();
useDisableWebFeatures();
useEffect(() => {
@@ -41,7 +39,6 @@ function App() {
setAlignDirection={setHorizontalDirection}
/>
)}
-
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..74dd6bfe 100644
--- a/apps/desktop/src/rpc/event.ts
+++ b/apps/desktop/src/rpc/event.ts
@@ -17,6 +17,12 @@ 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",
+ /** sent when the you get a message that tags your or a dm */
+ NOTIFICATION_CREATE = "NOTIFICATION_CREATE",
}
// TODO: move this somewhere
diff --git a/apps/desktop/src/rpc/manager.ts b/apps/desktop/src/rpc/manager.ts
index 45f508b8..fb68fae3 100644
--- a/apps/desktop/src/rpc/manager.ts
+++ b/apps/desktop/src/rpc/manager.ts
@@ -91,6 +91,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 +153,21 @@ class SocketManager {
this.send({
args: {
client_id: APP_ID,
- scopes: ["rpc", "identify"],
+ scopes: [
+ "identify",
+ "rpc",
+ // TODO: when we need soundboard we can enable these scopes
+ // "guilds",
+ // "rpc.notifications.read",
+ // TODO: how do you use other scopes 🤔
+ // "rpc.activities.write",
+ // "rpc.voice.read",
+ // "rpc.voice.write",
+ // "rpc.video.read",
+ // "rpc.video.write",
+ // "rpc.screenshare.read",
+ // "rpc.screenshare.write",
+ ],
},
cmd: RPCCommand.AUTHORIZE,
});
@@ -193,6 +209,7 @@ class SocketManager {
}
const payload: DiscordPayload = JSON.parse(event.data);
+ console.log(payload);
// either the token is good and valid and we can login otherwise prompt them approve
if (payload.evt === RPCEvent.READY) {
@@ -241,6 +258,11 @@ class SocketManager {
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) {
if (payload.data.channel_id === null) {
@@ -338,10 +360,10 @@ class SocketManager {
// try to find the user
this.requestUserChannel();
- // subscribe to get notified when the user changes channels
+ // sub to any otifs
this.send({
cmd: RPCCommand.SUBSCRIBE,
- evt: RPCEvent.VOICE_CHANNEL_SELECT,
+ evt: RPCEvent.NOTIFICATION_CREATE,
});
this.userdataStore.setAccessTokenExpiry(payload.data.expires);
@@ -376,12 +398,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(),
@@ -401,7 +432,6 @@ class SocketManager {
cmd,
args: { channel_id: channelId },
evt: eventName,
- nonce: uuid.v4(),
})
);
}