FS-7285 allow eavesdrop to bridge only one leg

Add channel variables eavesdrop_bridge_aleg and eavesdrop_bridge_bleg,
and if one is set to true on the eavesdrop channel, bridge that leg from
the target.  If neither is specified, bridge both.
This commit is contained in:
Dave Olszewski 2015-02-09 18:03:56 -08:00
parent 69a7b5fd11
commit 2890afc918
3 changed files with 27 additions and 3 deletions

View File

@ -331,7 +331,9 @@ typedef enum {
ED_MUX_READ = (1 << 0),
ED_MUX_WRITE = (1 << 1),
ED_DTMF = (1 << 2),
ED_COPY_DISPLAY = (1 << 3)
ED_COPY_DISPLAY = (1 << 3),
ED_BRIDGE_READ = (1 << 4),
ED_BRIDGE_WRITE = (1 << 5)
} switch_eavesdrop_flag_enum_t;
typedef uint32_t switch_eavesdrop_flag_t;

View File

@ -818,11 +818,21 @@ SWITCH_STANDARD_APP(eavesdrop_function)
switch_channel_t *channel = switch_core_session_get_channel(session);
const char *require_group = switch_channel_get_variable(channel, "eavesdrop_require_group");
const char *enable_dtmf = switch_channel_get_variable(channel, "eavesdrop_enable_dtmf");
const char *bridge_aleg = switch_channel_get_variable(channel, "eavesdrop_bridge_aleg");
const char *bridge_bleg = switch_channel_get_variable(channel, "eavesdrop_bridge_bleg");
if (enable_dtmf) {
flags = switch_true(enable_dtmf) ? ED_DTMF : ED_NONE;
}
/* Defaults to both, if neither is set */
if (switch_true(bridge_aleg)) {
flags |= ED_BRIDGE_READ;
}
if (switch_true(bridge_bleg)) {
flags |= ED_BRIDGE_WRITE;
}
if (!strcasecmp((char *) data, "all")) {
switch_cache_db_handle_t *db = NULL;
char *errmsg = NULL;

View File

@ -1758,6 +1758,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_eavesdrop_session(switch_core_session
char cid_buf[1024] = "";
switch_caller_profile_t *cp = NULL;
uint32_t sanity = 600;
switch_media_bug_flag_t read_flags = 0, write_flags = 0;
if (!switch_channel_media_up(channel)) {
goto end;
@ -1847,6 +1848,11 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_eavesdrop_session(switch_core_session
write_frame.buflen = sizeof(buf);
write_frame.rate = codec.implementation->actual_samples_per_second;
/* Make sure that at least one leg is bridged, default to both */
if (! (flags & (ED_BRIDGE_READ | ED_BRIDGE_WRITE))) {
flags |= ED_BRIDGE_READ | ED_BRIDGE_WRITE;
}
ep->eavesdropper = session;
ep->flags = flags;
switch_mutex_init(&ep->mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(tsession));
@ -1862,10 +1868,16 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_eavesdrop_session(switch_core_session
switch_buffer_add_mutex(ep->r_buffer, ep->r_mutex);
if (flags & ED_BRIDGE_READ) {
read_flags = SMBF_READ_STREAM | SMBF_READ_REPLACE;
}
if (flags & ED_BRIDGE_WRITE) {
write_flags = SMBF_WRITE_STREAM | SMBF_WRITE_REPLACE;
}
if (switch_core_media_bug_add(tsession, "eavesdrop", uuid,
eavesdrop_callback, ep, 0,
SMBF_READ_STREAM | SMBF_WRITE_STREAM | SMBF_READ_REPLACE | SMBF_WRITE_REPLACE |
SMBF_READ_PING | SMBF_THREAD_LOCK | SMBF_NO_PAUSE,
read_flags | write_flags | SMBF_READ_PING | SMBF_THREAD_LOCK | SMBF_NO_PAUSE,
&bug) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Cannot attach bug\n");
goto end;