Skip to content

Commit

Permalink
fix #63 Mute Button - Mutes also N-1
Browse files Browse the repository at this point in the history
  • Loading branch information
sreimers committed Mar 18, 2019
1 parent b6a299b commit d87e1cc
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 67 deletions.
13 changes: 13 additions & 0 deletions src/modules/slrtaudio/slrtaudio.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ void webapp_ws_rtaudio_sync(void);
static int32_t *playmix;

static bool mono = false;
static bool mute = false;


void slrtaudio_mono_set(bool active)
Expand All @@ -71,6 +72,12 @@ void slrtaudio_mono_set(bool active)
}


void slrtaudio_mute_set(bool active)
{
mute = active;
}


static void sess_destruct(void *arg)
{
struct session *sess = arg;
Expand Down Expand Up @@ -206,6 +213,12 @@ int slrtaudio_callback(void *out, void *in, unsigned int nframes,
if (mono) {
downsample_stereo2mono(inBuffer, inBuffer, samples);
}

if (mute) {
for (uint32_t pos = 0; pos < samples; pos++) {
inBuffer[pos] = 0;
}
}

for (le = sessionl.head; le; le = le->next) {
sess = le->data;
Expand Down
1 change: 1 addition & 0 deletions src/modules/slrtaudio/slrtaudio.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ extern struct list sessionl;
void slrtaudio_record_init(void);
void slrtaudio_record_set(bool active);
void slrtaudio_mono_set(bool active);
void slrtaudio_mute_set(bool active);
const struct odict* slrtaudio_get_interfaces(void);
void slrtaudio_set_driver(int value);
void slrtaudio_set_input(int value);
Expand Down
9 changes: 9 additions & 0 deletions src/modules/webapp/option.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ void webapp_options_set(char *key, char *value)
slrtaudio_record_set(true);
}
}
if (!str_cmp(key, "mute")) {
if (!str_cmp(value, "false")) {
slrtaudio_mute_set(false);
}
else {
slrtaudio_mute_set(true);
}
}
if (!str_cmp(key, "onair")) {
static struct call *call = NULL;
if (!str_cmp(value, "false")) {
Expand Down Expand Up @@ -142,6 +150,7 @@ int webapp_options_init(void)
odict_entry_del(options, "onair");
odict_entry_del(options, "raisehand");
odict_entry_del(options, "afk");
odict_entry_del(options, "mute");

out:
mem_deref(mb);
Expand Down
1 change: 0 additions & 1 deletion src/modules/webapp/webapp.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ static void http_req_handler(struct http_conn *conn,
if (0 == pl_strcasecmp(&msg->path, "/ws_calls")) {
webapp_ws_handler(conn, WS_CALLS, msg, webapp_ws_calls);
ws_send_json(WS_CALLS, webapp_calls);
webapp_ws_call_mute_send();
return;
}
if (0 == pl_strcasecmp(&msg->path, "/ws_options")) {
Expand Down
2 changes: 1 addition & 1 deletion src/modules/webapp/webapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ void webapp_ws_baresip(const struct websock_hdr *hdr,
struct mbuf *mb, void *arg);
void webapp_ws_calls(const struct websock_hdr *hdr,
struct mbuf *mb, void *arg);
void webapp_ws_call_mute_send(void);
void webapp_ws_contacts(const struct websock_hdr *hdr,
struct mbuf *mb, void *arg);
void webapp_ws_chat(const struct websock_hdr *hdr,
Expand Down Expand Up @@ -142,3 +141,4 @@ int webapp_load_file(struct mbuf *mb, char *filename);
const struct odict* slrtaudio_get_interfaces(void);
void slrtaudio_record_set(bool active);
void slrtaudio_mono_set(bool active);
void slrtaudio_mute_set(bool active);
42 changes: 0 additions & 42 deletions src/modules/webapp/ws_calls.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,6 @@
#include "webapp.h"

#define SIP_CLOSED "{ \"callback\": \"CLOSED\"}"
#define CALLS_MUTED "{ \"callback\": \"MUTED\"}"
#define CALLS_UNMUTED "{ \"callback\": \"UNMUTED\"}"

static bool calls_muted = false;

void webapp_ws_call_mute_send() {
if (calls_muted) {
ws_send_all(WS_CALLS, CALLS_MUTED);
}
else {
ws_send_all(WS_CALLS, CALLS_UNMUTED);
}
}

static int mute_calls(bool muted)
{
struct list *calls = ua_calls(uag_current());
struct call *call = NULL;
struct le *le;
struct audio *audio;

for (le = list_head(calls); le; le = le->next) {
call = le->data;
audio = call_audio(call);
audio_mute(audio, muted);
}

calls_muted = muted;
webapp_ws_call_mute_send();

return 0;
}

static struct call* get_call(char *sid)
{
Expand Down Expand Up @@ -102,19 +70,9 @@ void webapp_ws_calls(const struct websock_hdr *hdr,
webapp_call_status = WS_CALL_OFF;
if (!active_calls()) {
ws_send_all(WS_CALLS, SIP_CLOSED);
calls_muted = false;
webapp_ws_call_mute_send();
}
ws_send_json(WS_CALLS, webapp_calls);
}
else if (!str_cmp(e->u.str, "buttonmute")) {
if (calls_muted) {
mute_calls(false);
}
else {
mute_calls(true);
}
}

out:
mem_deref(cmd);
Expand Down
4 changes: 2 additions & 2 deletions src/webui/mix-manifest.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"/dist/app.js": "/dist/app.js",
"/dist/app.css": "/dist/app.css",
"/dist/index.html": "/dist/index.html",
"/dist/fonts/Exo_2_500.eot": "/dist/fonts/Exo_2_500.eot",
"/dist/fonts/Exo_2_500.svg": "/dist/fonts/Exo_2_500.svg",
"/dist/fonts/Exo_2_500.ttf": "/dist/fonts/Exo_2_500.ttf",
"/dist/fonts/Exo_2_500.woff": "/dist/fonts/Exo_2_500.woff",
"/dist/fonts/Exo_2_500.woff2": "/dist/fonts/Exo_2_500.woff2"
"/dist/fonts/Exo_2_500.woff2": "/dist/fonts/Exo_2_500.woff2",
"/dist/index.html": "/dist/index.html"
}
2 changes: 1 addition & 1 deletion src/webui/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ <h2 class="float-left">
<button id="buttoncall" type="button" class="btn btn-primary btn-lg">
<i class="fa fa-phone" aria-hidden="true" style="transform: rotate(95deg);"></i> <b>Call</b>
</button>
<button id="buttonmute" type="button" class="btn btn-secondary btn-lg d-none">
<button id="btn-mute" type="button" class="btn btn-secondary btn-lg d-none">
<i class="fa fa-microphone-slash" aria-hidden="true"></i>
<span class="d-none d-lg-inline">Mute</span>
</button>
Expand Down
2 changes: 1 addition & 1 deletion src/webui/src/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ var marked = require('marked');
window.marked = marked;

window.ws_host = location.host;
//window.ws_host = "127.0.0.1:39963";
//window.ws_host = "127.0.0.1:42645";
23 changes: 4 additions & 19 deletions src/webui/src/websockets/ws_calls.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,6 @@ $(function () {
} else if (msg.callback == "CLOSED") {
bootbox.hideAll();
$.notify("Call closed: " + msg.message, "warn");
} else if (msg.callback == "MUTED") {
if ($( "#buttonmute" ).hasClass("btn-primary")) {
$( "#buttonmute" ).removeClass("btn-primary");
$( "#buttonmute" ).addClass("btn-danger");
}
} else if (msg.callback == "UNMUTED") {
if ($( "#buttonmute" ).hasClass("btn-danger")) {
$( "#buttonmute" ).removeClass("btn-danger");
$( "#buttonmute" ).addClass("btn-primary");
}
} else {
if (swvariant == "standalone") {
for (var key in msg) {
Expand Down Expand Up @@ -122,12 +112,12 @@ $(function () {
}

if (established_calls) {
if ($( "#buttonmute" ).hasClass("d-none")) {
$( "#buttonmute" ).removeClass("d-none");
if ($( "#btn-mute" ).hasClass("d-none")) {
$( "#btn-mute" ).removeClass("d-none");
}
} else {
if (!$( "#buttonmute" ).hasClass("d-none")) {
$( "#buttonmute" ).addClass("d-none");
if (!$( "#btn-mute" ).hasClass("d-none")) {
$( "#btn-mute" ).addClass("d-none");
}
}
}
Expand All @@ -137,10 +127,5 @@ $(function () {
}
};

$( "#buttonmute" ).on( "click", function() {
ws_calls.send('{"command": "buttonmute", "key": ""}');
});


RefreshEventListener();
});
30 changes: 30 additions & 0 deletions src/webui/src/websockets/ws_options.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ $(function () {
var onair = false;
var raisehand = false;
var afk = false;
var mute = false;

var hoptions = require("../templates/options.handlebars");

Expand Down Expand Up @@ -53,6 +54,7 @@ $(function () {
}
}


function RefreshOnair() {
if (onair) {
$("#btn-onair").removeClass("btn-secondary");
Expand Down Expand Up @@ -90,6 +92,16 @@ $(function () {

}

function RefreshMute() {
if (mute) {
$("#btn-mute").removeClass("btn-secondary");
$("#btn-mute").addClass("btn-danger");
} else {
$("#btn-mute").removeClass("btn-danger");
$("#btn-mute").addClass("btn-secondary");
}
}

ws_options.onmessage = function (message) {
var msg = JSON.parse(message.data);
if (msg.bypass) {
Expand Down Expand Up @@ -140,13 +152,22 @@ $(function () {
}
RefreshAFK();
}
if (msg.mute) {
if (msg.mute == "true") {
mute = true;
} else {
mute = false;
}
RefreshMute();
}

delete msg.bypass;
delete msg.mono;
delete msg.record;
delete msg.onair;
delete msg.raisehand;
delete msg.afk;
delete msg.mute;

$( "#options" ).html(hoptions(msg));

Expand Down Expand Up @@ -207,4 +228,13 @@ $(function () {

ws_options.send('{"key": "afk", "value": "'+afk+'"}');
});
$( "#btn-mute" ).on( "click", function() {
if (mute) {
mute = false;
} else {
mute = true;
}

ws_options.send('{"key": "mute", "value": "'+mute+'"}');
});
});

0 comments on commit d87e1cc

Please sign in to comment.