diff --git a/Telegram/Resources/art/newmsg.wav b/Telegram/Resources/art/newmsg.wav
deleted file mode 100644
index ca7508e1b..000000000
Binary files a/Telegram/Resources/art/newmsg.wav and /dev/null differ
diff --git a/Telegram/Resources/qrc/telegram.qrc b/Telegram/Resources/qrc/telegram.qrc
index bd68d3b96..6b9c6d9a0 100644
--- a/Telegram/Resources/qrc/telegram.qrc
+++ b/Telegram/Resources/qrc/telegram.qrc
@@ -3,13 +3,20 @@
../fonts/OpenSans-Regular.ttf
../fonts/OpenSans-Bold.ttf
../fonts/OpenSans-Semibold.ttf
- ../art/newmsg.wav
../art/bg.jpg
../art/bg_initial.jpg
../art/icon256.png
../art/iconbig256.png
../art/sunrise.jpg
+
+ ../sounds/msg_incoming.mp3
+ ../sounds/call_incoming.mp3
+ ../sounds/call_outgoing.mp3
+ ../sounds/call_busy.mp3
+ ../sounds/call_connect.mp3
+ ../sounds/call_end.mp3
+
qmime/freedesktop.org.xml
diff --git a/Telegram/Resources/sounds/call_busy.mp3 b/Telegram/Resources/sounds/call_busy.mp3
new file mode 100644
index 000000000..968279215
Binary files /dev/null and b/Telegram/Resources/sounds/call_busy.mp3 differ
diff --git a/Telegram/Resources/sounds/call_connect.mp3 b/Telegram/Resources/sounds/call_connect.mp3
new file mode 100644
index 000000000..5db9355ea
Binary files /dev/null and b/Telegram/Resources/sounds/call_connect.mp3 differ
diff --git a/Telegram/Resources/sounds/call_end.mp3 b/Telegram/Resources/sounds/call_end.mp3
new file mode 100644
index 000000000..177373e77
Binary files /dev/null and b/Telegram/Resources/sounds/call_end.mp3 differ
diff --git a/Telegram/Resources/sounds/call_incoming.mp3 b/Telegram/Resources/sounds/call_incoming.mp3
new file mode 100644
index 000000000..932a00b2d
Binary files /dev/null and b/Telegram/Resources/sounds/call_incoming.mp3 differ
diff --git a/Telegram/Resources/sounds/call_outgoing.mp3 b/Telegram/Resources/sounds/call_outgoing.mp3
new file mode 100644
index 000000000..16125a945
Binary files /dev/null and b/Telegram/Resources/sounds/call_outgoing.mp3 differ
diff --git a/Telegram/Resources/sounds/msg_incoming.mp3 b/Telegram/Resources/sounds/msg_incoming.mp3
new file mode 100644
index 000000000..97a035320
Binary files /dev/null and b/Telegram/Resources/sounds/msg_incoming.mp3 differ
diff --git a/Telegram/SourceFiles/calls/calls_call.cpp b/Telegram/SourceFiles/calls/calls_call.cpp
index 6c94e154b..e81c8377b 100644
--- a/Telegram/SourceFiles/calls/calls_call.cpp
+++ b/Telegram/SourceFiles/calls/calls_call.cpp
@@ -28,6 +28,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
#include "calls/calls_instance.h"
#include "base/openssl_help.h"
#include "mtproto/connection.h"
+#include "media/media_audio_track.h"
#ifdef slots
#undef slots
@@ -84,6 +85,7 @@ Call::Call(gsl::not_null delegate, gsl::not_null user, Typ
if (_type == Type::Outgoing) {
setState(State::Requesting);
}
+ startWaitingTrack();
}
void Call::generateModExpFirst(base::const_byte_span randomSeed) {
@@ -219,9 +221,17 @@ void Call::redial() {
t_assert(_controller == nullptr);
_type = Type::Outgoing;
setState(State::Requesting);
+ startWaitingTrack();
_delegate->callRedial(this);
}
+void Call::startWaitingTrack() {
+ _waitingTrack = Media::Audio::Current().createTrack();
+ auto trackFileName = (_type == Type::Outgoing) ? qsl(":/sounds/call_outgoing.mp3") : qsl(":/sounds/call_incoming.mp3");
+ _waitingTrack->fillFromFile(trackFileName);
+ _waitingTrack->playInLoop();
+}
+
bool Call::isKeyShaForFingerprintReady() const {
return (_keyFingerprint != 0);
}
@@ -494,24 +504,41 @@ bool Call::checkCallFields(const MTPDphoneCallAccepted &call) {
void Call::setState(State state) {
if (_state != state) {
+ auto wasBusy = (_state == State::Busy);
+
_state = state;
_stateChanged.notify(state, true);
+ if (true
+ && _state != State::Starting
+ && _state != State::Requesting
+ && _state != State::Waiting
+ && _state != State::WaitingIncoming
+ && _state != State::Ringing) {
+ _waitingTrack.reset();
+ }
switch (_state) {
- case State::WaitingInit:
- case State::WaitingInitAck:
case State::Established:
_startTime = getms(true);
break;
+ case State::ExchangingKeys:
+ _delegate->playSound(Delegate::Sound::Connecting);
+ break;
case State::Ended:
+ if (!wasBusy) {
+ _delegate->playSound(Delegate::Sound::Ended);
+ }
_delegate->callFinished(this);
break;
case State::Failed:
+ if (!wasBusy) {
+ _delegate->playSound(Delegate::Sound::Ended);
+ }
_delegate->callFailed(this);
break;
case State::Busy:
destroyController();
- // TODO play sound
+ _delegate->playSound(Delegate::Sound::Busy);
break;
}
}
diff --git a/Telegram/SourceFiles/calls/calls_call.h b/Telegram/SourceFiles/calls/calls_call.h
index 8fecf0cd1..88bd7e954 100644
--- a/Telegram/SourceFiles/calls/calls_call.h
+++ b/Telegram/SourceFiles/calls/calls_call.h
@@ -25,6 +25,12 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
#include "mtproto/sender.h"
#include "mtproto/auth_key.h"
+namespace Media {
+namespace Audio {
+class Track;
+} // namespace Audio
+} // namespace Media
+
namespace tgvoip {
class VoIPController;
} // namespace tgvoip
@@ -46,6 +52,13 @@ public:
virtual void callFailed(gsl::not_null call) = 0;
virtual void callRedial(gsl::not_null call) = 0;
+ enum class Sound {
+ Connecting,
+ Busy,
+ Ended,
+ };
+ virtual void playSound(Sound sound) = 0;
+
};
static constexpr auto kRandomPowerSize = 256;
@@ -114,6 +127,7 @@ private:
void finish(const MTPPhoneCallDiscardReason &reason);
void startOutgoing();
void startIncoming();
+ void startWaitingTrack();
void generateModExpFirst(base::const_byte_span randomSeed);
void handleControllerStateChange(tgvoip::VoIPController *controller, int state);
@@ -158,6 +172,8 @@ private:
std::unique_ptr _controller;
+ std::unique_ptr _waitingTrack;
+
};
void UpdateConfig(const std::map &data);
diff --git a/Telegram/SourceFiles/calls/calls_instance.cpp b/Telegram/SourceFiles/calls/calls_instance.cpp
index b453b2d79..536ab37e8 100644
--- a/Telegram/SourceFiles/calls/calls_instance.cpp
+++ b/Telegram/SourceFiles/calls/calls_instance.cpp
@@ -28,7 +28,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
#include "boxes/confirm_box.h"
#include "calls/calls_call.h"
#include "calls/calls_panel.h"
-
+#include "media/media_audio_track.h"
#include "boxes/rate_call_box.h"
namespace Calls {
@@ -41,9 +41,10 @@ constexpr auto kServerConfigUpdateTimeoutMs = 24 * 3600 * TimeMs(1000);
Instance::Instance() = default;
void Instance::startOutgoingCall(gsl::not_null user) {
- if (_currentCall) {
+ finishCurrentBusyCall();
+ if (_currentCall) { // Already in a call.
_currentCallPanel->showAndActivate();
- return; // Already in a call.
+ return;
}
if (user->callsStatus() == UserData::CallsStatus::Private) {
// Request full user once more to refresh the setting in case it was changed.
@@ -68,6 +69,34 @@ void Instance::callRedial(gsl::not_null call) {
}
}
+void Instance::playSound(Sound sound) {
+ switch (sound) {
+ case Sound::Busy: {
+ if (!_callBusyTrack) {
+ _callBusyTrack = Media::Audio::Current().createTrack();
+ _callBusyTrack->fillFromFile(qsl(":/sounds/call_busy.mp3"));
+ }
+ _callBusyTrack->playOnce();
+ } break;
+
+ case Sound::Ended: {
+ if (!_callEndedTrack) {
+ _callEndedTrack = Media::Audio::Current().createTrack();
+ _callEndedTrack->fillFromFile(qsl(":/sounds/call_end.mp3"));
+ }
+ _callEndedTrack->playOnce();
+ } break;
+
+ case Sound::Connecting: {
+ if (!_callConnectingTrack) {
+ _callConnectingTrack = Media::Audio::Current().createTrack();
+ _callConnectingTrack->fillFromFile(qsl(":/sounds/call_connect.mp3"));
+ }
+ _callConnectingTrack->playOnce();
+ } break;
+ }
+}
+
void Instance::destroyCall(gsl::not_null call) {
if (_currentCall.get() == call) {
_currentCallPanel.reset();
@@ -230,6 +259,7 @@ void Instance::handleCallUpdate(const MTPPhoneCall &call) {
} else if (user->isSelf()) {
LOG(("API Error: Self found in phoneCallRequested."));
}
+ finishCurrentBusyCall();
if (_currentCall || !user || user->isSelf()) {
request(MTPphone_DiscardCall(MTP_inputPhoneCall(phoneCall.vid, phoneCall.vaccess_hash), MTP_int(0), MTP_phoneCallDiscardReasonBusy(), MTP_long(0))).send();
} else if (phoneCall.vdate.v + Global::CallRingTimeoutMs() / 1000 < unixtime()) {
@@ -243,6 +273,12 @@ void Instance::handleCallUpdate(const MTPPhoneCall &call) {
}
}
+void Instance::finishCurrentBusyCall() {
+ if (_currentCall && _currentCall->state() == Call::State::Busy) {
+ _currentCall->hangup();
+ }
+}
+
Instance::~Instance() = default;
Instance &Current() {
diff --git a/Telegram/SourceFiles/calls/calls_instance.h b/Telegram/SourceFiles/calls/calls_instance.h
index ba0be1c9d..bde38bfd0 100644
--- a/Telegram/SourceFiles/calls/calls_instance.h
+++ b/Telegram/SourceFiles/calls/calls_instance.h
@@ -23,6 +23,12 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
#include "mtproto/sender.h"
#include "calls/calls_call.h"
+namespace Media {
+namespace Audio {
+class Track;
+} // namespace Audio
+} // namespace Media
+
namespace Calls {
class Panel;
@@ -57,12 +63,15 @@ private:
void callFinished(gsl::not_null call) override;
void callFailed(gsl::not_null call) override;
void callRedial(gsl::not_null call) override;
+ using Sound = Call::Delegate::Sound;
+ void playSound(Sound sound) override;
void createCall(gsl::not_null user, Call::Type type);
void destroyCall(gsl::not_null call);
void refreshDhConfig();
void refreshServerConfig();
+ void finishCurrentBusyCall();
void handleCallUpdate(const MTPPhoneCall &call);
DhConfig _dhConfig;
@@ -75,6 +84,10 @@ private:
base::Observable _currentCallChanged;
base::Observable _newServiceMessage;
+ std::unique_ptr _callConnectingTrack;
+ std::unique_ptr _callEndedTrack;
+ std::unique_ptr _callBusyTrack;
+
};
Instance &Current();
diff --git a/Telegram/SourceFiles/window/notifications_manager.cpp b/Telegram/SourceFiles/window/notifications_manager.cpp
index d26ce6c49..288ecfbeb 100644
--- a/Telegram/SourceFiles/window/notifications_manager.cpp
+++ b/Telegram/SourceFiles/window/notifications_manager.cpp
@@ -362,7 +362,7 @@ void System::ensureSoundCreated() {
}
_soundTrack = Media::Audio::Current().createTrack();
- _soundTrack->fillFromFile(qsl(":/gui/art/newmsg.wav"));
+ _soundTrack->fillFromFile(qsl(":/sounds/msg_incoming.mp3"));
}
void System::updateAll() {