summaryrefslogtreecommitdiff
path: root/protocols/Tox/src
diff options
context:
space:
mode:
Diffstat (limited to 'protocols/Tox/src')
-rw-r--r--protocols/Tox/src/api_av.cpp100
-rw-r--r--protocols/Tox/src/common.h6
-rw-r--r--protocols/Tox/src/resource.h8
-rw-r--r--protocols/Tox/src/tox_chatrooms.h2
-rw-r--r--protocols/Tox/src/tox_events.cpp31
-rw-r--r--protocols/Tox/src/tox_icons.cpp3
-rw-r--r--protocols/Tox/src/tox_multimedia.cpp101
-rw-r--r--protocols/Tox/src/tox_multimedia.h24
-rw-r--r--protocols/Tox/src/tox_proto.cpp9
-rw-r--r--protocols/Tox/src/tox_proto.h10
10 files changed, 224 insertions, 70 deletions
diff --git a/protocols/Tox/src/api_av.cpp b/protocols/Tox/src/api_av.cpp
index 4f517187ac..afcf544bbf 100644
--- a/protocols/Tox/src/api_av.cpp
+++ b/protocols/Tox/src/api_av.cpp
@@ -12,99 +12,99 @@ void toxav_kill(ToxAv *av)
CreateFunction<void(*)(ToxAv*)>(__FUNCTION__)(av);
}
-uint32_t toxav_do_interval(ToxAv *av)
-{
- return CreateFunction<uint32_t(*)(ToxAv*)>(__FUNCTION__)(av);
-}
-
-void toxav_do(ToxAv *av)
-{
- CreateFunction<void(*)(ToxAv*)>(__FUNCTION__)(av);
-}
-
-void toxav_register_callstate_callback(ToxAv *av, ToxAVCallback cb, ToxAvCallbackID id, void *userdata)
-{
- CreateFunction<void(*)(ToxAv*, ToxAVCallback, ToxAvCallbackID, void*)>(__FUNCTION__)(av, cb, id, userdata);
-}
-
+uint32_t toxav_do_interval(ToxAv *av)
+{
+ return CreateFunction<uint32_t(*)(ToxAv*)>(__FUNCTION__)(av);
+}
+
+void toxav_do(ToxAv *av)
+{
+ CreateFunction<void(*)(ToxAv*)>(__FUNCTION__)(av);
+}
+
+void toxav_register_callstate_callback(ToxAv *av, ToxAVCallback cb, ToxAvCallbackID id, void *userdata)
+{
+ CreateFunction<void(*)(ToxAv*, ToxAVCallback, ToxAvCallbackID, void*)>(__FUNCTION__)(av, cb, id, userdata);
+}
+
int toxav_call(ToxAv *av, int32_t *call_index, int friend_id, const ToxAvCSettings *csettings, int ringing_seconds)
{
return CreateFunction<int(*)(ToxAv*, int32_t*, int, const ToxAvCSettings*, int)>(__FUNCTION__)(av, call_index, friend_id, csettings, ringing_seconds);
-}
-
+}
+
int toxav_hangup(ToxAv *av, int32_t call_index)
{
return CreateFunction<int(*)(ToxAv*, int32_t)>(__FUNCTION__)(av, call_index);
-}
-
+}
+
int toxav_answer(ToxAv *av, int32_t call_index, const ToxAvCSettings *csettings)
{
return CreateFunction<int(*)(ToxAv*, int32_t, const ToxAvCSettings*)>(__FUNCTION__)(av, call_index, csettings);
-}
-
+}
+
int toxav_reject(ToxAv *av, int32_t call_index, const char *reason)
{
return CreateFunction<int(*)(ToxAv*, int32_t, const char*)>(__FUNCTION__)(av, call_index, reason);
-}
-
+}
+
int toxav_cancel(ToxAv *av, int32_t call_index, int peer_id, const char *reason)
{
return CreateFunction<int(*)(ToxAv*, int32_t, int, const char*)>(__FUNCTION__)(av, call_index, peer_id, reason);
-}
-
+}
+
int toxav_change_settings(ToxAv *av, int32_t call_index, const ToxAvCSettings *csettings)
{
return CreateFunction<int(*)(ToxAv*, int32_t, const ToxAvCSettings*)>(__FUNCTION__)(av, call_index, csettings);
-}
-
+}
+
int toxav_stop_call(ToxAv *av, int32_t call_index)
{
return CreateFunction<int(*)(ToxAv*, int32_t)>(__FUNCTION__)(av, call_index);
-}
-
+}
+
int toxav_prepare_transmission(ToxAv *av, int32_t call_index, int support_video)
{
return CreateFunction<int(*)(ToxAv*, int32_t, int)>(__FUNCTION__)(av, call_index, support_video);
-}
-
+}
+
int toxav_kill_transmission(ToxAv *av, int32_t call_index)
{
return CreateFunction<int(*)(ToxAv*, int32_t)>(__FUNCTION__)(av, call_index);
-}
-
+}
+
int toxav_get_peer_csettings(ToxAv *av, int32_t call_index, int peer, ToxAvCSettings *dest)
{
return CreateFunction<int(*)(ToxAv*, int32_t, int, ToxAvCSettings*)>(__FUNCTION__)(av, call_index, peer, dest);
-}
-
+}
+
int toxav_get_peer_id(ToxAv *av, int32_t call_index, int peer)
{
return CreateFunction<int(*)(ToxAv*, int32_t, int)>(__FUNCTION__)(av, call_index, peer);
-}
-
+}
+
ToxAvCallState toxav_get_call_state(ToxAv *av, int32_t call_index)
{
return CreateFunction<ToxAvCallState(*)(ToxAv*, int32_t)>(__FUNCTION__)(av, call_index);
-}
-
+}
+
int toxav_capability_supported(ToxAv *av, int32_t call_index, ToxAvCapabilities capability)
{
return CreateFunction<int(*)(ToxAv*, int32_t, ToxAvCapabilities)>(__FUNCTION__)(av, call_index, capability);
-}
-
+}
+
Tox *toxav_get_tox(ToxAv *av)
{
return CreateFunction<Tox*(*)(ToxAv*)>(__FUNCTION__)(av);
-}
-
+}
+
int toxav_get_active_count(ToxAv *av)
{
return CreateFunction<int(*)(ToxAv*)>(__FUNCTION__)(av);
-}
-
-/* AUDIO FUNCTIONS */
-
-void toxav_register_audio_callback(ToxAv *av, ToxAvAudioCallback cb, void *userdata)
-{
- CreateFunction<void(*)(ToxAv*, ToxAvAudioCallback, void*)>(__FUNCTION__)(av, cb, userdata);
+}
+
+/* AUDIO FUNCTIONS */
+
+void toxav_register_audio_callback(ToxAv *av, ToxAvAudioCallback cb, void *userdata)
+{
+ CreateFunction<void(*)(ToxAv*, ToxAvAudioCallback, void*)>(__FUNCTION__)(av, cb, userdata);
} \ No newline at end of file
diff --git a/protocols/Tox/src/common.h b/protocols/Tox/src/common.h
index 0c5fa59879..75c1e48f58 100644
--- a/protocols/Tox/src/common.h
+++ b/protocols/Tox/src/common.h
@@ -52,6 +52,7 @@ struct CToxProto;
#include "tox_dialogs.h"
#include "tox_options.h"
#include "tox_transfer.h"
+#include "tox_multimedia.h"
#include "tox_chatrooms.h"
#include "tox_proto.h"
@@ -84,7 +85,10 @@ extern HINSTANCE g_hInstance;
enum TOX_DB_EVENT
{
DB_EVENT_ACTION = 10001,
- DB_EVENT_AUDIO_CALL = 20001
+ DB_EVENT_AUDIO_CALL = 20001,
+ DB_EVENT_AUDIO_RING = 20002,
+ DB_EVENT_AUDIO_START = 20003,
+ DB_EVENT_AUDIO_END = 20004
};
#define PSR_AUDIO "/RecvAudio"
diff --git a/protocols/Tox/src/resource.h b/protocols/Tox/src/resource.h
index 8b06bab10e..5ffc062970 100644
--- a/protocols/Tox/src/resource.h
+++ b/protocols/Tox/src/resource.h
@@ -11,9 +11,13 @@
#define IDD_OPTIONS_NODES 107
#define IDD_ADDNODE 108
#define IDD_NODE_EDITOR 109
-#define IDI_ICON1 109
#define IDI_AUDIO_CALL 109
#define IDD_OPTIONS_AV 110
+#define IDD_AUDIO 111
+#define IDI_AUDIO_END 112
+#define IDI_AUDIO_RING 113
+#define IDI_ICON3 114
+#define IDI_AUDIO_START 114
#define IDD_CHATROOM_INVITE 172
#define IDC_CCLIST 173
#define IDC_EDITSCR 174
@@ -48,7 +52,7 @@
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
-#define _APS_NEXT_RESOURCE_VALUE 110
+#define _APS_NEXT_RESOURCE_VALUE 115
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1025
#define _APS_NEXT_SYMED_VALUE 101
diff --git a/protocols/Tox/src/tox_chatrooms.h b/protocols/Tox/src/tox_chatrooms.h
index 0f51a7391e..419b26bacd 100644
--- a/protocols/Tox/src/tox_chatrooms.h
+++ b/protocols/Tox/src/tox_chatrooms.h
@@ -1,6 +1,8 @@
#ifndef _TOX_CHATROOMS_H_
#define _TOX_CHATROOMS_H_
+#define WM_AUDIO_END (WM_PROTO_LAST + 100)
+
struct ChatRoomInviteParam
{
CToxProto *proto;
diff --git a/protocols/Tox/src/tox_events.cpp b/protocols/Tox/src/tox_events.cpp
index 255358d687..f1e21e955a 100644
--- a/protocols/Tox/src/tox_events.cpp
+++ b/protocols/Tox/src/tox_events.cpp
@@ -25,6 +25,21 @@ void CToxProto::InitCustomDbEvents()
dbEventType.descr = Translate("Audio call");
dbEventType.eventIcon = GetIconHandle("audio_call");
CallService(MS_DB_EVENT_REGISTERTYPE, 0, (LPARAM)&dbEventType);
+
+ dbEventType.eventType = DB_EVENT_AUDIO_RING;
+ dbEventType.descr = Translate("Audio ring");
+ dbEventType.eventIcon = GetIconHandle("audio_ring");
+ CallService(MS_DB_EVENT_REGISTERTYPE, 0, (LPARAM)&dbEventType);
+
+ dbEventType.eventType = DB_EVENT_AUDIO_START;
+ dbEventType.descr = Translate("Audio start");
+ dbEventType.eventIcon = GetIconHandle("audio_start");
+ CallService(MS_DB_EVENT_REGISTERTYPE, 0, (LPARAM)&dbEventType);
+
+ dbEventType.eventType = DB_EVENT_AUDIO_END;
+ dbEventType.descr = Translate("Audio end");
+ dbEventType.eventIcon = GetIconHandle("audio_end");
+ CallService(MS_DB_EVENT_REGISTERTYPE, 0, (LPARAM)&dbEventType);
}
int CToxProto::OnDbEventAdded(WPARAM hContact, LPARAM hEvent)
@@ -56,10 +71,22 @@ int CToxProto::OnDbEventAdded(WPARAM hContact, LPARAM hEvent)
switch (dbei.eventType)
{
case DB_EVENT_AUDIO_CALL:
- mir_snprintf(szService, SIZEOF(szService), "%s/AudioCall", GetContactProto(hContact));
+ mir_snprintf(szService, SIZEOF(szService), "%s/Audio/Call", GetContactProto(hContact));
+ break;
+
+ case DB_EVENT_AUDIO_RING:
+ mir_snprintf(szService, SIZEOF(szService), "%s/Audio/Ring", GetContactProto(hContact));
+ break;
+
+ case DB_EVENT_AUDIO_START:
+ mir_snprintf(szService, SIZEOF(szService), "%s/Audio/Start", GetContactProto(hContact));
+ break;
+
+ case DB_EVENT_AUDIO_END:
+ mir_snprintf(szService, SIZEOF(szService), "%s/Audio/End", GetContactProto(hContact));
break;
- default:
+ default:
return 0;
}
cle.pszService = szService;
diff --git a/protocols/Tox/src/tox_icons.cpp b/protocols/Tox/src/tox_icons.cpp
index 9a62c5069b..5600283ae0 100644
--- a/protocols/Tox/src/tox_icons.cpp
+++ b/protocols/Tox/src/tox_icons.cpp
@@ -4,6 +4,9 @@ IconInfo CToxProto::Icons[] =
{
{ LPGENT("Protocol icon"), "main", IDI_TOX },
{ LPGENT("Audio call"), "audio_call", IDI_AUDIO_CALL },
+ { LPGENT("Audio ring"), "audio_ring", IDI_AUDIO_RING },
+ { LPGENT("Audio start"), "audio_start", IDI_AUDIO_START },
+ { LPGENT("Audio end"), "audio_end", IDI_AUDIO_END },
};
void CToxProto::InitIcons()
diff --git a/protocols/Tox/src/tox_multimedia.cpp b/protocols/Tox/src/tox_multimedia.cpp
index ba795bb0d7..3d6931eedc 100644
--- a/protocols/Tox/src/tox_multimedia.cpp
+++ b/protocols/Tox/src/tox_multimedia.cpp
@@ -1,5 +1,62 @@
#include "common.h"
+/* AUDIO RECEIVING */
+
+CToxAudioCall::CToxAudioCall(CToxProto *proto, int callId) :
+ CToxDlgBase(proto, IDD_AUDIO, false), callId(callId),
+ ok(this, IDOK), cancel(this, IDCANCEL)
+{
+ m_autoClose = CLOSE_ON_CANCEL;
+ ok.OnClick = Callback(this, &CToxAudioCall::OnOk);
+ cancel.OnClick = Callback(this, &CToxAudioCall::OnCancel);
+}
+
+void CToxAudioCall::OnInitDialog()
+{
+ char iconName[100];
+ mir_snprintf(iconName, SIZEOF(iconName), "%s_%s", MODULE, "audio_call");
+ SendMessage(m_hwnd, WM_SETICON, ICON_BIG, (LPARAM)Skin_GetIcon(iconName, 16));
+ SendMessage(m_hwnd, WM_SETICON, ICON_SMALL, (LPARAM)Skin_GetIcon(iconName, 32));
+
+ Utils_RestoreWindowPosition(m_hwnd, NULL, m_proto->m_szModuleName, "AudioCallWindow");
+}
+
+void CToxAudioCall::OnOk(CCtrlBase*)
+{
+ ok.Enable(FALSE);
+ ToxAvCSettings cSettings;// = av_DefaultSettings;
+ //cSettings.call_type = av_TypeAudio;
+ toxav_get_peer_csettings(m_proto->toxAv, callId, 0, &cSettings);
+
+ toxav_answer(m_proto->toxAv, callId, &cSettings);
+}
+
+void CToxAudioCall::OnCancel(CCtrlBase*)
+{
+ if (ok.Enabled())
+ toxav_reject(m_proto->toxAv, callId, NULL);
+ else
+ {
+ int friendNumber = toxav_get_peer_id(m_proto->toxAv, callId, 0);
+ toxav_cancel(m_proto->toxAv, callId, friendNumber, NULL);
+ }
+}
+
+void CToxAudioCall::OnClose()
+{
+ WindowList_Remove(m_proto->hAudioDialogs, m_hwnd);
+ Utils_SaveWindowPosition(m_hwnd, NULL, m_proto->m_szModuleName, "AudioCallWindow");
+}
+
+INT_PTR CToxAudioCall::DlgProc(UINT msg, WPARAM wParam, LPARAM lParam)
+{
+ if (msg == WM_AUDIO_END)
+ Close();
+
+ return CToxDlgBase::DlgProc(msg, wParam, lParam);
+}
+
+// incoming call flow
void CToxProto::OnAvInvite(void*, int32_t callId, void *arg)
{
CToxProto *proto = (CToxProto*)arg;
@@ -37,31 +94,59 @@ void CToxProto::OnAvInvite(void*, int32_t callId, void *arg)
PROTORECVEVENT recv = { 0 };
recv.timestamp = time(NULL);
- recv.flags = PREF_UTF;
- recv.szMessage = mir_utf8encodeT(TranslateT("Incoming call"));
+ recv.lParam = callId;
+ //recv.flags = PREF_UTF;
+ //recv.szMessage = mir_utf8encodeT(TranslateT("Incoming audio call"));
ProtoChainRecv(hContact, PSR_AUDIO, hContact, (LPARAM)&recv);
}
+// save event to db
INT_PTR CToxProto::OnRecvAudioCall(WPARAM hContact, LPARAM lParam)
{
PROTORECVEVENT *pre = (PROTORECVEVENT*)lParam;
+ calls[hContact] = pre->lParam;
+
DBEVENTINFO dbei = { sizeof(dbei) };
dbei.szModule = m_szModuleName;
dbei.timestamp = pre->timestamp;
- dbei.flags = DBEF_UTF;
- dbei.eventType = DB_EVENT_AUDIO_CALL;
- dbei.cbBlob = (DWORD)mir_strlen(pre->szMessage) + 1;
- dbei.pBlob = (PBYTE)pre->szMessage;
+ //dbei.flags = DBEF_UTF;
+ dbei.eventType = DB_EVENT_AUDIO_RING;
+
+ //dbei.cbBlob = (DWORD)mir_strlen(pre->szMessage) + 1;
+ //dbei.pBlob = (PBYTE)pre->szMessage;
return (INT_PTR)db_event_add(hContact, &dbei);
}
+//
+INT_PTR CToxProto::OnAudioRing(WPARAM hContact, LPARAM lParam)
+{
+ CToxAudioCall *audioCall = new CToxAudioCall(this, calls[hContact]);
+ audioCall->Show();
+ WindowList_Add(hAudioDialogs, audioCall->GetHwnd(), hContact);
+ return 0;
+}
+
void CToxProto::OnAvRinging(void*, int32_t callId, void *arg) { }
void CToxProto::OnAvStart(void*, int32_t callId, void *arg) { }
-void CToxProto::OnAvEnd(void*, int32_t callId, void *arg) { }
+
+void CToxProto::OnAvEnd(void*, int32_t callId, void *arg)
+{
+ CToxProto *proto = (CToxProto*)arg;
+
+ WindowList_Broadcast(proto->hAudioDialogs, WM_AUDIO_END, 0, 0);
+}
+
void CToxProto::OnAvReject(void*, int32_t callId, void *arg) { }
-void CToxProto::OnAvCancel(void*, int32_t callId, void *arg) { }
+
+void CToxProto::OnAvCancel(void*, int32_t callId, void *arg)
+{
+ CToxProto *proto = (CToxProto*)arg;
+
+ WindowList_Broadcast(proto->hAudioDialogs, WM_AUDIO_END, 0, 0);
+}
+
void CToxProto::OnAvCsChange(void*, int32_t callId, void *arg) { }
void CToxProto::OnAvRequestTimeout(void*, int32_t callId, void *arg) { }
void CToxProto::OnAvPeerTimeout(void*, int32_t callId, void *arg) { }
diff --git a/protocols/Tox/src/tox_multimedia.h b/protocols/Tox/src/tox_multimedia.h
new file mode 100644
index 0000000000..3dd5ad475b
--- /dev/null
+++ b/protocols/Tox/src/tox_multimedia.h
@@ -0,0 +1,24 @@
+#ifndef _TOX_MULTIMEDIA_H_
+#define _TOX_MULTIMEDIA_H_
+
+class CToxAudioCall : public CToxDlgBase
+{
+private:
+ int callId;
+
+ CCtrlButton ok;
+ CCtrlButton cancel;
+
+protected:
+ void OnInitDialog();
+ void OnOk(CCtrlBase*);
+ void OnCancel(CCtrlBase*);
+ void OnClose();
+
+ INT_PTR DlgProc(UINT msg, WPARAM wParam, LPARAM lParam);
+
+public:
+ CToxAudioCall(CToxProto *proto, int callId);
+};
+
+#endif //_TOX_MULTIMEDIA_H_ \ No newline at end of file
diff --git a/protocols/Tox/src/tox_proto.cpp b/protocols/Tox/src/tox_proto.cpp
index 55285f9b31..0b3947cd74 100644
--- a/protocols/Tox/src/tox_proto.cpp
+++ b/protocols/Tox/src/tox_proto.cpp
@@ -14,6 +14,7 @@ CToxProto::CToxProto(const char* protoName, const TCHAR* userName) :
// services
CreateProtoService(PSR_AUDIO, &CToxProto::OnRecvAudioCall);
+ CreateProtoService("/Audio/Ring", &CToxProto::OnAudioRing);
// avatars
CreateProtoService(PS_GETAVATARCAPS, &CToxProto::GetAvatarCaps);
@@ -23,10 +24,14 @@ CToxProto::CToxProto(const char* protoName, const TCHAR* userName) :
// nick
CreateProtoService(PS_SETMYNICKNAME, &CToxProto::SetMyNickname);
+
+ hAudioDialogs = WindowList_Create();
}
CToxProto::~CToxProto()
{
+ WindowList_Destroy(hAudioDialogs);
+
mir_free(accountName);
UninitNetlib();
}
@@ -213,12 +218,10 @@ int CToxProto::SetAwayMsg(int, const PROTOCHAR *msg)
{
if (IsOnline())
{
- ptrA statusMessage(msg == NULL ? mir_strdup("") : mir_utf8encodeT(msg));
+ ptrA statusMessage(mir_utf8encodeT(msg));
TOX_ERR_SET_INFO error;
if (tox_self_set_status_message(tox, (uint8_t*)(char*)statusMessage, min(TOX_MAX_STATUS_MESSAGE_LENGTH, mir_strlen(statusMessage)), &error))
- {
debugLogA("CToxProto::SetAwayMsg: failed to set status status message %s (%d)", msg, error);
- }
}
return 0;
diff --git a/protocols/Tox/src/tox_proto.h b/protocols/Tox/src/tox_proto.h
index 8d75753713..6fc1dc9c9c 100644
--- a/protocols/Tox/src/tox_proto.h
+++ b/protocols/Tox/src/tox_proto.h
@@ -6,9 +6,9 @@ struct CToxProto : public PROTO<CToxProto>
friend CToxPasswordEditor;
friend CToxOptionsMain;
friend CToxOptionsNodeList;
+ friend CToxAudioCall;
public:
-
//////////////////////////////////////////////////////////////////////////////////////
//Ctors
@@ -241,8 +241,12 @@ private:
void OnGotFriendAvatarInfo(FileTransferParam *transfer, const uint8_t *hash);
// multimedia
- std::map<int, int> calls;
+ HANDLE hAudioDialogs;
+ std::map<MCONTACT, int> calls;
+
static void OnFriendAudio(void *agent, int32_t callId, const int16_t *PCM, uint16_t size, void *arg);
+ INT_PTR __cdecl OnRecvAudioCall(WPARAM wParam, LPARAM lParam);
+ INT_PTR __cdecl OnAudioRing(WPARAM hContact, LPARAM lParam);
static void OnAvInvite(void*, int32_t callId, void *arg);
static void OnAvRinging(void*, int32_t callId, void *arg);
@@ -254,8 +258,6 @@ private:
static void OnAvRequestTimeout(void*, int32_t callId, void *arg);
static void OnAvPeerTimeout(void*, int32_t callId, void *arg);
- INT_PTR __cdecl OnRecvAudioCall(WPARAM wParam, LPARAM lParam);
-
// utils
TOX_USER_STATUS MirandaToToxStatus(int status);
int ToxToMirandaStatus(TOX_USER_STATUS userstatus);