summaryrefslogtreecommitdiff
path: root/protocols
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2024-05-30 17:50:29 +0300
committerGeorge Hazan <george.hazan@gmail.com>2024-05-30 17:50:29 +0300
commit7d0cf97af1a12fa2541107cf63b3070f3713d8cd (patch)
treebd688abe1f6e459e74bbf82d035afa3fbc5123b6 /protocols
parent48409fcaea4cda67ce0642bf6c39ffd636a1294d (diff)
Discord: stubs for voice services (#4404)
Diffstat (limited to 'protocols')
-rw-r--r--protocols/Discord/src/main.cpp10
-rw-r--r--protocols/Discord/src/proto.cpp7
-rw-r--r--protocols/Discord/src/proto.h16
-rw-r--r--protocols/Discord/src/voice.cpp39
4 files changed, 65 insertions, 7 deletions
diff --git a/protocols/Discord/src/main.cpp b/protocols/Discord/src/main.cpp
index 98f0b120de..17a10bf78e 100644
--- a/protocols/Discord/src/main.cpp
+++ b/protocols/Discord/src/main.cpp
@@ -56,12 +56,20 @@ IconItem g_iconList[] =
{ LPGEN("Call ended"), "voiceend", IDI_VOICE_ENDED }
};
-static int OnModulesLoaded(WPARAM, LPARAM)
+static int OnModuleLoaded(WPARAM, LPARAM)
{
g_plugin.bVoiceService = ServiceExists(MS_VOICESERVICE_REGISTER);
return 0;
}
+static int OnModulesLoaded(WPARAM, LPARAM)
+{
+ HookEvent(ME_SYSTEM_MODULELOAD, &OnModuleLoaded);
+ HookEvent(ME_SYSTEM_MODULEUNLOAD, &OnModuleLoaded);
+ OnModuleLoaded(0, 0);
+ return 0;
+}
+
int CMPlugin::Load()
{
HookEvent(ME_SYSTEM_MODULESLOADED, &OnModulesLoaded);
diff --git a/protocols/Discord/src/proto.cpp b/protocols/Discord/src/proto.cpp
index 5056282794..22f6f35e05 100644
--- a/protocols/Discord/src/proto.cpp
+++ b/protocols/Discord/src/proto.cpp
@@ -63,6 +63,10 @@ CDiscordProto::CDiscordProto(const char *proto_name, const wchar_t *username) :
CreateProtoService(PS_GETMYAVATAR, &CDiscordProto::GetMyAvatar);
CreateProtoService(PS_SETMYAVATAR, &CDiscordProto::SetMyAvatar);
+ CreateProtoService(PS_VOICE_CALL, &CDiscordProto::VoiceCallCreate);
+ CreateProtoService(PS_VOICE_DROPCALL, &CDiscordProto::VoiceCallCancel);
+ CreateProtoService(PS_VOICE_ANSWERCALL, &CDiscordProto::VoiceCallAnswer);
+
CreateProtoService(PS_MENU_REQAUTH, &CDiscordProto::RequestFriendship);
CreateProtoService(PS_MENU_LOADHISTORY, &CDiscordProto::OnMenuLoadHistory);
@@ -185,6 +189,7 @@ void CDiscordProto::OnModulesLoaded()
HookProtoEvent(ME_GC_BUILDMENU, &CDiscordProto::GroupchatMenuHook);
InitMenus();
+ InitVoip(true);
// Voice support
if (g_plugin.bVoiceService) {
@@ -205,6 +210,8 @@ void CDiscordProto::OnShutdown()
m_bTerminated = true;
SetEvent(m_evRequestsQueue);
+ InitVoip(false);
+
for (auto &it : arGuilds)
it->SaveToFile();
diff --git a/protocols/Discord/src/proto.h b/protocols/Discord/src/proto.h
index aaa00c0cd5..31fda24fd3 100644
--- a/protocols/Discord/src/proto.h
+++ b/protocols/Discord/src/proto.h
@@ -411,6 +411,18 @@ class CDiscordProto : public PROTO<CDiscordProto>
void OnSendTotp(MHttpResponse *, struct AsyncHttpRequest *);
//////////////////////////////////////////////////////////////////////////////////////
+ // voice
+
+ void InitVoip(bool bEnable);
+
+ INT_PTR __cdecl VoiceCaps(WPARAM, LPARAM);
+ INT_PTR __cdecl VoiceCallCreate(WPARAM, LPARAM);
+ INT_PTR __cdecl VoiceCallAnswer(WPARAM, LPARAM);
+ INT_PTR __cdecl VoiceCallCancel(WPARAM, LPARAM);
+
+ int __cdecl OnVoiceState(WPARAM, LPARAM);
+
+ //////////////////////////////////////////////////////////////////////////////////////
// misc methods
SnowFlake getId(const char *szName);
@@ -472,16 +484,12 @@ public:
INT_PTR __cdecl GetMyAvatar(WPARAM, LPARAM);
INT_PTR __cdecl SetMyAvatar(WPARAM, LPARAM);
- INT_PTR __cdecl VoiceCaps(WPARAM, LPARAM);
-
//////////////////////////////////////////////////////////////////////////////////////
// Events
int __cdecl OnOptionsInit(WPARAM, LPARAM);
int __cdecl OnAccountChanged(WPARAM, LPARAM);
- int __cdecl OnVoiceState(WPARAM, LPARAM);
-
//////////////////////////////////////////////////////////////////////////////////////
// dispatch commands
diff --git a/protocols/Discord/src/voice.cpp b/protocols/Discord/src/voice.cpp
index 48e5290c23..ee6369777b 100644
--- a/protocols/Discord/src/voice.cpp
+++ b/protocols/Discord/src/voice.cpp
@@ -88,12 +88,27 @@ void CDiscordProto::OnCommandCallUpdated(const JSONNode&)
/////////////////////////////////////////////////////////////////////////////////////////
// Events & services
-INT_PTR __cdecl CDiscordProto::VoiceCaps(WPARAM, LPARAM)
+INT_PTR CDiscordProto::VoiceCaps(WPARAM, LPARAM)
{
return VOICE_CAPS_VOICE | VOICE_CAPS_CALL_CONTACT;
}
-int __cdecl CDiscordProto::OnVoiceState(WPARAM wParam, LPARAM)
+INT_PTR CDiscordProto::VoiceCallCreate(WPARAM, LPARAM)
+{
+ return 0;
+}
+
+INT_PTR CDiscordProto::VoiceCallAnswer(WPARAM, LPARAM)
+{
+ return 0;
+}
+
+INT_PTR CDiscordProto::VoiceCallCancel(WPARAM, LPARAM)
+{
+ return 0;
+}
+
+int CDiscordProto::OnVoiceState(WPARAM wParam, LPARAM)
{
auto *pVoice = (VOICE_CALL *)wParam;
if (mir_strcmp(pVoice->moduleName, m_szModuleName))
@@ -114,3 +129,23 @@ int __cdecl CDiscordProto::OnVoiceState(WPARAM wParam, LPARAM)
debugLogA("Call %s state changed to %d", pVoice->id, pVoice->state);
return 0;
}
+
+void CDiscordProto::InitVoip(bool bEnable)
+{
+ if (!g_plugin.bVoiceService)
+ return;
+
+ if (bEnable) {
+ VOICE_MODULE vsr = {};
+ vsr.cbSize = sizeof(VOICE_MODULE);
+ vsr.description = m_tszUserName;
+ vsr.name = m_szModuleName;
+ vsr.icon = g_plugin.getIconHandle(IDI_MAIN);
+ vsr.flags = VOICE_CAPS_VOICE | VOICE_CAPS_CALL_CONTACT;
+ CallService(MS_VOICESERVICE_REGISTER, (WPARAM)&vsr, 0);
+ }
+ else {
+ // TerminateSession();
+ CallService(MS_VOICESERVICE_UNREGISTER, (WPARAM)m_szModuleName, 0);
+ }
+}