Commit d6437ed0 authored by Gabriel Margiani's avatar Gabriel Margiani

muteringing and literally toggle muteall

Add muteringing command to toggle ringing globally.
"fix" muteall to toggle mute on each active call.
parent 546a0a33
......@@ -160,7 +160,6 @@ void p3::call::mute_toggle() {
mute = false;
} else {
if (aud_med != nullptr) {
std::cout << "mutetx" << std::endl;
aud_med->adjustRxLevel(0);
}
mute = true;
......
......@@ -34,6 +34,7 @@ std::map<std::string, std::string> p3::client::command_shorthands {
{"pause", "hold"},
{"m", "mute"},
{"ma", "muteall"},
{"mr", "muteringing"},
{"a", "answer"},
{"b", "busy"},
{"ba", "busyall"},
......
......@@ -45,7 +45,7 @@ std::map<std::string, std::string> p3::server::default_config {
{"phone:busy_on_busy", "true"},
{"phone:busyall_exceptions", "none"},
{"phone:default_busyall", "false"},
{"phone:default_mute", "false"}
{"phone:default_mute_ringing", "false"}
};
......@@ -190,6 +190,8 @@ void p3::clientHandler::parse_command(const std::string& c) {
handle_mute();
} else if ("muteall" == c) {
handle_mute_all();
} else if ("muteringing" == c) {
handle_mute_ringing();
} else if ("busy" == c) {
handle_busy();
} else if ("busyall" == c) {
......@@ -264,10 +266,15 @@ void p3::clientHandler::handle_mute() {
}
void p3::clientHandler::handle_mute_all() {
phone.global_mute_toggle();
phone.mute_all_toggle();
connection.send(p3::protocol::OK, "(un)mute all OK");
}
void p3::clientHandler::handle_mute_ringing() {
phone.mute_ringing_toggle();
connection.send(p3::protocol::OK, "(un)mute ringing OK");
}
void p3::clientHandler::handle_busy() {
phone.busy(get_call_id("Call to reject (id)"));
connection.send(p3::protocol::OK, "busy OK");
......
......@@ -122,6 +122,7 @@ namespace p3 {
void handle_hold();
void handle_mute();
void handle_mute_all();
void handle_mute_ringing();
void handle_busy();
void handle_busy_all();
void handle_reload();
......
......@@ -31,7 +31,7 @@ p3::sipphone::sipphone(p3::config& c, p3::eventHook& e, p3::phonebook& b) :
ring_index(0)
{
always_busy = conf.get_bool("phone:default_busyall");
mute = conf.get_bool("phone:default_mute");
mute_ringing = conf.get_bool("phone:default_mute_ringing");
// Initiate pj
endpoint = new pj::Endpoint;
......@@ -165,32 +165,40 @@ void p3::sipphone::load_busyall_exceptions() {
}
void p3::sipphone::start_ringing() {
if (ringtone == nullptr) return;
if (ring_index == 0) {
try {
pj::AudioMedia& play_med = endpoint->audDevManager().getPlaybackDevMedia();
ringtone->startTransmit(play_med);
ringtone->adjustTxLevel(2);
} catch (pj::Error& err) {
throw p3::perror("sipphone:startRinging:", err.info());
}
if (ring_index == 0 && !mute_ringing) {
play_ringtone();
}
ring_index++;
}
void p3::sipphone::stop_ringing() {
if (ring_index == 1 && !mute_ringing) {
stop_ringtone();
}
ring_index--;
}
void p3::sipphone::play_ringtone() {
if (ringtone == nullptr) return;
try {
pj::AudioMedia& play_med = endpoint->audDevManager()
.getPlaybackDevMedia();
ringtone->startTransmit(play_med);
ringtone->adjustTxLevel(2);
} catch (pj::Error& err) {
throw p3::perror("sipphone:startRinging:", err.info());
}
}
if (ring_index == 1) {
try {
pj::AudioMedia& play_med = endpoint->audDevManager().getPlaybackDevMedia();
ringtone->stopTransmit(play_med);
} catch (pj::Error& err) {
throw p3::perror("sipphone:stopRinging:", err.info());
}
void p3::sipphone::stop_ringtone() {
if (ringtone == nullptr) return;
try {
pj::AudioMedia& play_med = endpoint->audDevManager()
.getPlaybackDevMedia();
ringtone->stopTransmit(play_med);
} catch (pj::Error& err) {
throw p3::perror("sipphone:stopRinging:", err.info());
}
ring_index--;
}
void p3::sipphone::renew_registration() {
......@@ -318,8 +326,6 @@ void p3::sipphone::hold_toggle(int id) {
void p3::sipphone::mute_toggle(int id) {
std::lock_guard<std::recursive_mutex> g(calls_mutex);
pj::CallOpParam o;
o.statusCode = PJSIP_SC_OK;
try {
get_call_by_id(id)->mute_toggle();
} catch (pj::Error &e) {
......@@ -327,20 +333,23 @@ void p3::sipphone::mute_toggle(int id) {
}
}
void p3::sipphone::global_mute_toggle() {
pj::AudDevManager& mgr = pj::Endpoint::instance().audDevManager();
try {
if (mute) {
mgr.getCaptureDevMedia().adjustTxLevel(2);
mute = false;
void p3::sipphone::mute_all_toggle() {
std::lock_guard<std::recursive_mutex> g(calls_mutex);
for (auto c : calls) {
mute_toggle(c.first);
}
}
void p3::sipphone::mute_ringing_toggle() {
mute_ringing = !mute_ringing;
if (ring_index > 0) {
if (mute_ringing) {
stop_ringtone();
} else {
mgr.getCaptureDevMedia().adjustTxLevel(0);
mute = true;
start_ringing();
}
eventhook.run_hook("muteall_toggle", std::to_string(mute));
} catch (pj::Error& e) {
throw p3::perror("sipphone:gmutetoggle", e.info());
}
eventhook.run_hook("muteringing_toggle", std::to_string(mute_ringing));
}
void p3::sipphone::conference() {
......@@ -468,7 +477,7 @@ std::map<std::string, std::string> p3::sipphone::get_status_dump() {
l["callRingingCount"] = std::to_string(get_call_count(p3::callState::INCOMING));
// Global toggles
l["allMute"] = std::to_string(mute);
l["muteRinging"] = std::to_string(mute_ringing);
l["allBusy"] = std::to_string(always_busy);
return l;
......
......@@ -57,7 +57,7 @@ namespace p3 {
pj::AudioMediaPlayer* ringtone;
pj::AudioMediaPlayer* hold_music;
bool mute;
bool mute_ringing;
bool always_busy;
std::list<std::string> busyall_exceptions;
......@@ -70,13 +70,19 @@ namespace p3 {
void start_ringing();
void stop_ringing();
// Use start_ringing/stop_ringing methods in call logic,
// else ringing will brake for multiple incoming calls at
// the same time.
void play_ringtone();
void stop_ringtone();
p3::call* register_new_call(int pjid = PJSUA_INVALID_ID);
void delete_call(int id);
p3::call* get_call_by_id(
int id,
callState f = callState::NONE,
bool update_active = true
bool update_allactive = true
);
void register_number(std::string nr, int id);
......@@ -104,7 +110,8 @@ namespace p3 {
void busyall_toggle();
void hold_toggle(int id = -1);
void mute_toggle(int id = -1);
void global_mute_toggle();
void mute_all_toggle();
void mute_ringing_toggle();
void conference();
void transfer(int id, int destId = -1);
void dial_dtmf(int id, const std::string& digits);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment