summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2022-09-05 07:01:30 -0700
committerGeorge Hazan <ghazan@miranda.im>2022-09-05 07:01:30 -0700
commitaf7ec319f30cf0968d4dca762614d2ef5cc8de6f (patch)
tree355822a07267828ba3d6b4a3ab9885bf732353e3
parent49a9d26f6a67dd4f0bade379402dd459baf9200e (diff)
fixes for Voip
-rw-r--r--plugins/VoiceService/src/VoiceCall.cpp110
-rw-r--r--plugins/VoiceService/src/stdafx.h14
-rw-r--r--protocols/JabberG/src/jabber_proto.h1
-rw-r--r--protocols/JabberG/src/jabber_thread.cpp2
-rw-r--r--protocols/JabberG/src/jabber_voip.cpp55
5 files changed, 60 insertions, 122 deletions
diff --git a/plugins/VoiceService/src/VoiceCall.cpp b/plugins/VoiceService/src/VoiceCall.cpp
index 972d8e0ce0..40ea12aedf 100644
--- a/plugins/VoiceService/src/VoiceCall.cpp
+++ b/plugins/VoiceService/src/VoiceCall.cpp
@@ -19,7 +19,7 @@ Boston, MA 02111-1307, USA.
#include "stdafx.h"
-static wchar_t *popupTitles[] = {
+static wchar_t *popupTexts[] = {
LPGENW("Voice call started"),
LPGENW("Voice call ringing"),
LPGENW("Voice call"),
@@ -29,14 +29,19 @@ static wchar_t *popupTitles[] = {
LPGENW("Voice call ready"),
};
-static wchar_t *stateTexts[] = {
- LPGENW("Call from %s has started"),
- LPGENW("Call from %s is ringing"),
- LPGENW("Calling %s"),
- LPGENW("Call from %s is on hold"),
- LPGENW("Call from %s has ended"),
- LPGENW("%s is busy"),
- LPGENW("Ready to call %s"),
+struct {
+ wchar_t *status;
+ wchar_t *btn1text;
+ wchar_t *btn2text;
+}
+static stateTexts[NUM_STATES] = {
+ { L"0:00", L"Hold", L"Drop" },
+ { L"Ringing", L"Answer", L"Drop" },
+ { L"Calling", nullptr, L"Drop" },
+ { L"Holded", L"Resume", L"Drop" },
+ { nullptr, nullptr, L"Close" },
+ { L"Callee is busy", nullptr, L"Close" },
+ { L"Ready", L"Call", L"Cancel" },
};
/////////////////////////////////////////////////////////////////////////////////////////
@@ -53,17 +58,9 @@ VoiceCall::VoiceCall(VoiceProvider *module, const char *id) :
m_lblContactName(this, IDC_DESCR),
m_lblAddress(this, IDC_ADDRESS)
{
- hContact = NULL;
name[0] = 0;
number[0] = 0;
displayName[0] = 0;
- state = -1;
- end_time = 0;
- clistBlinking = false;
- incoming = false;
- secure = false;
- hwnd = NULL;
- m_nsec = 0;
m_btnAnswer.OnClick = Callback(this, &VoiceCall::OnCommand_Answer);
m_btnDrop.OnClick = Callback(this, &VoiceCall::OnCommand_Drop);
@@ -77,7 +74,7 @@ VoiceCall::~VoiceCall()
{
RemoveNotifications();
mir_free(id);
- id = NULL;
+ id = 0;
DeleteObject(hContactNameFont);
}
@@ -116,8 +113,6 @@ void VoiceCall::OnCommand_Drop(CCtrlButton *)
Close();
else
Drop();
- if (state == VOICE_STATE_READY)
- Close();
}
void VoiceCall::OnCallTimer(CTimer *)
@@ -197,11 +192,6 @@ void VoiceCall::CreateDisplayName()
void VoiceCall::RemoveNotifications()
{
- if (hwnd != NULL) {
- DestroyWindow(hwnd);
- hwnd = NULL;
- }
-
if (clistBlinking) {
g_clistApi.pfnRemoveEvent(hContact, MEVENT(1001));
clistBlinking = false;
@@ -219,61 +209,41 @@ void VoiceCall::SetState(int aState)
switch (state) {
case VOICE_STATE_TALKING:
m_calltimer.Start(1000);
- m_lblStatus.SetText(L"0:00");
- m_btnAnswer.Enable(false);
break;
case VOICE_STATE_RINGING:
incoming = true;
- SetCaption(TranslateT("Incoming call"));
- m_btnAnswer.Enable(true);
- m_lblStatus.SetText(TranslateT("Ringing"));
if(opts.opt_bImmDialog) {
- Show(opts.opt_bImmDialogFocus ? SW_SHOWNORMAL : SW_SHOWNOACTIVATE);
- SetWindowPos(GetHwnd(), HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
+ SetWindowPos(GetHwnd(), HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
SetWindowPos(GetHwnd(), HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
+ Show(opts.opt_bImmDialogFocus ? SW_SHOWNORMAL : SW_SHOWNOACTIVATE);
}
break;
case VOICE_STATE_CALLING:
incoming = false;
- SetCaption(TranslateT("Outgoing call"));
- m_lblStatus.SetText(TranslateT("Calling"));
- m_btnAnswer.Enable(false);
- break;
- case VOICE_STATE_ON_HOLD:
- m_lblStatus.SetText(TranslateT("Holded"));
- m_btnAnswer.Enable(true);
- m_btnAnswer.SetText(TranslateT("Unhold"));
break;
case VOICE_STATE_ENDED:
m_calltimer.Stop();
- m_lblStatus.SetText(TranslateT("Call ended"));
- m_btnAnswer.Enable(false);
- m_btnDrop.SetText(TranslateT("Close"));
- break;
- case VOICE_STATE_BUSY:
- m_lblStatus.SetText(TranslateT("Busy"));
- m_btnAnswer.Enable(false);
- m_btnDrop.SetText(TranslateT("Close"));
+ wchar_t text[100];
+ mir_snwprintf(text, TranslateT("Call is over %s"), m_nsec ? m_lblStatus.GetText() : L"");
+ m_lblStatus.SetText(text);
break;
case VOICE_STATE_READY:
- m_lblStatus.SetText(TranslateT("Ready"));
- m_btnAnswer.Enable(true);
- m_btnAnswer.SetText(TranslateT("Call"));
- m_btnDrop.SetText(TranslateT("Close"));
Show();
break;
- default:
- m_lblStatus.SetText(TranslateT("Unknown state"));
- break;
}
+
+ if(stateTexts[state].status)
+ m_lblStatus.SetText(stateTexts[state].status);
+ if(stateTexts[state].btn1text)
+ m_btnAnswer.SetText(stateTexts[state].btn1text);
+ m_btnDrop.SetText(stateTexts[state].btn2text);
+
+ m_btnAnswer.Enable(state == VOICE_STATE_TALKING ? CanHold() : (bool)stateTexts[state].btn1text);
if (state != VOICE_STATE_ON_HOLD)
m_nsec = 0;
if (IsFinished()) {
- if (end_time == 0)
- end_time = GetTickCount();
-
// Remove id because providers can re-use them
mir_free(id);
id = NULL;
@@ -289,19 +259,15 @@ void VoiceCall::SetStatus(const wchar_t *text)
void VoiceCall::Notify(bool popup, bool sound, bool clist)
{
- if(opts.opt_bImmDialog)
- return;
-
- if (popup) {
- wchar_t text[512];
- mir_snwprintf(text, TranslateW(stateTexts[state]), displayName);
-
- ShowPopup(NULL, TranslateW(popupTitles[state]), text);
- }
-
if (sound)
Skin_PlaySound(g_sounds[state].szName);
+ if(IsWindowVisible(GetHwnd()))
+ return;
+
+ if (popup)
+ ShowPopup(NULL, displayName, TranslateW(popupTexts[state]));
+
if (clist && state == VOICE_STATE_RINGING) {
CLISTEVENT ce = {};
ce.hContact = hContact;
@@ -379,11 +345,3 @@ void VoiceCall::SendDTMF(wchar_t c)
CallProtoService(module->name, PS_VOICE_SEND_DTMF, (WPARAM)id, (LPARAM)c);
}
-
-void VoiceCall::SetNewCallHWND(HWND _h)
-{
- if (_h != NULL)
- RemoveNotifications();
-
- hwnd = _h;
-}
diff --git a/plugins/VoiceService/src/stdafx.h b/plugins/VoiceService/src/stdafx.h
index 47f002cba6..4233afc08c 100644
--- a/plugins/VoiceService/src/stdafx.h
+++ b/plugins/VoiceService/src/stdafx.h
@@ -120,14 +120,12 @@ class VoiceCall : public CDlgBase
public:
VoiceProvider *module;
char *id; // Protocol especific ID for this call
- MCONTACT hContact;
+ MCONTACT hContact = 0;
wchar_t name[256];
wchar_t number[256];
wchar_t displayName[256];
- int state;
- DWORD end_time;
- bool incoming;
- bool secure;
+ int state = -1;
+ bool incoming = false, secure = false, clistBlinking = false;
VoiceCall(VoiceProvider *module, const char *id);
~VoiceCall();
@@ -151,12 +149,8 @@ public:
bool IsFinished();
void Notify(bool popup = true, bool sound = true, bool clist = true);
- void SetNewCallHWND(HWND hwnd);
private:
- HWND hwnd;
- bool clistBlinking;
-
void RemoveNotifications();
void CreateDisplayName();
void OnCommand_Answer(CCtrlButton*);
@@ -168,7 +162,7 @@ private:
CCtrlButton m_btnAnswer;
CCtrlButton m_btnDrop;
CCtrlLabel m_lblStatus, m_lblContactName, m_lblAddress;
- int m_nsec;
+ int m_nsec = 0;
CTimer m_calltimer;
HFONT hContactNameFont;
};
diff --git a/protocols/JabberG/src/jabber_proto.h b/protocols/JabberG/src/jabber_proto.h
index daed6fa219..0df9ff5ffc 100644
--- a/protocols/JabberG/src/jabber_proto.h
+++ b/protocols/JabberG/src/jabber_proto.h
@@ -900,7 +900,6 @@ struct CJabberProto : public PROTO<CJabberProto>, public IJabberInterface
bool OnRTPDescription(const TiXmlElement *Node);
bool VOIPCreatePipeline();
bool VOIPTerminateSession(const char *reason = "cancel");
- bool VOIPCallAccept(const TiXmlElement *jingleNode, const char *from);
bool VOIPCallIinitiate(MCONTACT hContact);
CMStringA m_voipSession, m_voipPeerJid;
diff --git a/protocols/JabberG/src/jabber_thread.cpp b/protocols/JabberG/src/jabber_thread.cpp
index 0ee2fcabab..80ff33e370 100644
--- a/protocols/JabberG/src/jabber_thread.cpp
+++ b/protocols/JabberG/src/jabber_thread.cpp
@@ -1808,6 +1808,7 @@ bool CJabberProto::OnProcessJingle(const TiXmlElement *node)
if (m_voipSession.IsEmpty()) {
m_voipSession = szSid;
m_voipPeerJid = from;
+ m_isOutgoing = false;
m_offerNode = child->DeepClone(&m_offerDoc)->ToElement();
//Make call GUI
@@ -1817,6 +1818,7 @@ bool CJabberProto::OnProcessJingle(const TiXmlElement *node)
vc.id = szSid; // Protocol specific ID for this call
vc.hContact = HContactFromJID(from); // Contact associated with the call (can be NULL)
vc.state = VOICE_STATE_RINGING;
+ vc.szNumber.a = m_voipPeerJid;
NotifyEventHooks(m_hVoiceEvent, WPARAM(&vc), 0);
// ringing message
diff --git a/protocols/JabberG/src/jabber_voip.cpp b/protocols/JabberG/src/jabber_voip.cpp
index f83c9f4270..5b65fb269e 100644
--- a/protocols/JabberG/src/jabber_voip.cpp
+++ b/protocols/JabberG/src/jabber_voip.cpp
@@ -377,6 +377,9 @@ bool CJabberProto::VOIPTerminateSession(const char *reason)
bool CJabberProto::OnRTPDescription(const TiXmlElement *jingleNode)
{
+ if (!jingleNode)
+ return false;
+
// process remote offer
auto *content = XmlGetChildByTag(jingleNode, "content", "creator", "initiator");
auto *transport = XmlGetChildByTag(content, "transport", "xmlns", "urn:xmpp:jingle:transports:ice-udp:1");
@@ -472,7 +475,7 @@ bool CJabberProto::VOIPCallIinitiate(MCONTACT hContact)
{
if (!m_voipSession.IsEmpty()) {
VOIPTerminateSession();
- MessageBoxA(0, "Terminated", NULL, 0);
+ MessageBoxA(0, "Something went wrong\r\nOld session terminated", NULL, 0);
return false;
}
@@ -480,17 +483,12 @@ bool CJabberProto::VOIPCallIinitiate(MCONTACT hContact)
return false;
CMStringA jid(ptrA(getUStringA(hContact, "jid")));
- if (jid == "")
+ if (jid.IsEmpty())
return false;
ptrA szResource(GetBestResourceName(jid));
if (szResource)
jid = MakeJid(jid, szResource);
- CMStringA question(FORMAT, "Call %s?\r\n"
- "It will disclose IP address to the peer and his server", jid.c_str());
- if (MessageBoxA(0, question.c_str(), "Outgoing call", MB_YESNO | MB_ICONQUESTION) != IDYES)
- return false;
-
unsigned char tmp[16];
Utils_GetRandom(tmp, sizeof(tmp));
@@ -498,26 +496,6 @@ bool CJabberProto::VOIPCallIinitiate(MCONTACT hContact)
m_voipSession = ptrA(mir_base64_encode(tmp, sizeof(tmp)));
m_voipPeerJid = jid.c_str();
-
-
- return true;
-}
-
-bool CJabberProto::VOIPCallAccept(const TiXmlElement *jingleNode, const char *from)
-{
- if (!from || !jingleNode)
- return false;
-
- CMStringW question(FORMAT, TranslateT("Accept call from %S?\r\nIt will disclose IP address to the peer and his server"), from);
- if (MessageBoxW(0, question, TranslateT("Incoming call"), MB_YESNO | MB_ICONQUESTION) != IDYES)
- return false;
-
- m_isOutgoing = false;
-
- if (!VOIPCreatePipeline())
- return false;
-
- OnRTPDescription(jingleNode);
return true;
}
@@ -542,22 +520,29 @@ INT_PTR CJabberProto::JabberVOIP_answercall(WPARAM id, LPARAM)
if(strcmp((const char *)id, m_voipSession))
return 0;
+/* CMStringA question(FORMAT, "Proceed call with %s?\r\n"
+ "It will disclose IP address to the peer and his server", m_voipPeerJid.c_str());
+ if (MessageBoxA(0, question.c_str(), "Outgoing call", MB_YESNO | MB_ICONQUESTION) != IDYES)
+ return 0;*/
+
VOICE_CALL vc = {};
vc.cbSize = sizeof(VOICE_CALL);
vc.moduleName = m_szModuleName;
vc.hContact = HContactFromJID(m_voipPeerJid);// Contact associated with the call (can be NULL)
vc.szNumber.a = m_voipPeerJid;
+ vc.id = m_voipSession;
+ vc.state = VOICE_STATE_ENDED;
- if (m_isOutgoing) {
- VOIPCreatePipeline();
- vc.id = m_voipSession; // Protocol especific ID for this call
- vc.state = VOICE_STATE_CALLING;
- }
- else {
- vc.id = (char *)id;
- vc.state = VOIPCallAccept(m_offerNode, m_voipPeerJid) ? VOICE_STATE_TALKING : VOICE_STATE_ENDED;
+ if (VOIPCreatePipeline()) {
+ if (m_isOutgoing)
+ vc.state = VOICE_STATE_CALLING;
+ else if (OnRTPDescription(m_offerNode))
+ vc.state = VOICE_STATE_TALKING;
+ else
+ VOIPTerminateSession();
}
NotifyEventHooks(m_hVoiceEvent, WPARAM(&vc), 0);
+
return 0;
}