mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-07-15 19:40:06 +00:00
add presence for conference and dial an eavesdrop
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@8091 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
cd7b1e1224
commit
f96422026a
@ -582,8 +582,8 @@ static switch_status_t conference_add_member(conference_obj_t * conference, conf
|
||||
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "event_count", "%d", EC++);
|
||||
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "unique-id", "%s", conference->name);
|
||||
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "channel-state", "%s", "CS_RING");
|
||||
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "answer-state", "%s", "confirmed");
|
||||
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "call-direction", "%s", "inbound");
|
||||
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "answer-state", "%s", conference->count == 1 ? "early" : "confirmed");
|
||||
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "call-direction", "%s", conference->count == 1 ? "outbound" : "inbound");
|
||||
switch_event_fire(&event);
|
||||
}
|
||||
|
||||
@ -724,8 +724,8 @@ static switch_status_t conference_del_member(conference_obj_t * conference, conf
|
||||
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "event_count", "%d", EC++);
|
||||
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "unique-id", "%s", conference->name);
|
||||
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "channel-state", "%s", "CS_RING");
|
||||
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "answer-state", "%s", "confirmed");
|
||||
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "call-direction", "%s", "inbound");
|
||||
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "answer-state", "%s", conference->count == 1 ? "early" : "confirmed");
|
||||
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "call-direction", "%s", conference->count == 1 ? "outbound" : "inbound");
|
||||
switch_event_fire(&event);
|
||||
}
|
||||
|
||||
@ -5125,8 +5125,8 @@ static void pres_event_handler(switch_event_t *event)
|
||||
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "event_count", "%d", EC++);
|
||||
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "unique-id", "%s", conf_name);
|
||||
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "channel-state", "%s", "CS_RING");
|
||||
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "answer-state", "%s", "confirmed");
|
||||
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "call-direction", "%s", "inbound");
|
||||
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "answer-state", "%s", conference->count == 1 ? "early" : "confirmed");
|
||||
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "call-direction", "%s", conference->count == 1 ? "outbound" : "inbound");
|
||||
switch_event_fire(&event);
|
||||
}
|
||||
} else if (switch_event_create(&event, SWITCH_EVENT_PRESENCE_IN) == SWITCH_STATUS_SUCCESS) {
|
||||
|
@ -121,15 +121,91 @@ SWITCH_STANDARD_APP(intercept_function)
|
||||
switch_ivr_intercept_session(session, data);
|
||||
}
|
||||
|
||||
#define MAX_SPY 3000
|
||||
struct e_data {
|
||||
char *uuid_list[MAX_SPY];
|
||||
int total;
|
||||
};
|
||||
|
||||
static int e_callback(void *pArg, int argc, char **argv, char **columnNames)
|
||||
{
|
||||
char *uuid = argv[0];
|
||||
struct e_data *e_data = (struct e_data *) pArg;
|
||||
|
||||
if (uuid && e_data) {
|
||||
e_data->uuid_list[e_data->total++] = strdup(uuid);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
#define eavesdrop_SYNTAX "<uuid>"
|
||||
SWITCH_STANDARD_APP(eavesdrop_function)
|
||||
{
|
||||
if (switch_strlen_zero(data)) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Usage: %s\n", eavesdrop_SYNTAX);
|
||||
} else {
|
||||
if (!strcasecmp((char *)data, "all")) {
|
||||
switch_core_db_t *db = switch_core_db_handle();
|
||||
char *errmsg = NULL;
|
||||
struct e_data e_data = {{ 0 }};
|
||||
char *sql = switch_mprintf("select uuid from channels where uuid != '%q'", switch_core_session_get_uuid(session));
|
||||
switch_channel_t *channel = switch_core_session_get_channel(session);
|
||||
const char *file = NULL;
|
||||
int x = 0;
|
||||
char buf[2] = "";
|
||||
switch_size_t buflen = sizeof(buf);
|
||||
char terminator;
|
||||
|
||||
while(switch_channel_ready(channel)) {
|
||||
for(x = 0; x < MAX_SPY; x++) {
|
||||
switch_safe_free(e_data.uuid_list[x]);
|
||||
}
|
||||
e_data.total = 0;
|
||||
switch_core_db_exec(db, sql, e_callback, &e_data, &errmsg);
|
||||
if (errmsg) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Error: %s\n", errmsg);
|
||||
switch_core_db_free(errmsg);
|
||||
if ((file = switch_channel_get_variable(channel, "eavesdrop_indicate_failed"))) {
|
||||
switch_ivr_play_file(session, NULL, file, NULL);
|
||||
}
|
||||
switch_ivr_collect_digits_count(session, buf, buflen, 1, "*", &terminator, 5000, 0, 0);
|
||||
continue;
|
||||
}
|
||||
if (e_data.total) {
|
||||
for (x = 0; x < e_data.total && switch_channel_ready(channel); x++) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Spy: %s\n", e_data.uuid_list[x]);
|
||||
if ((file = switch_channel_get_variable(channel, "eavesdrop_indicate_new"))) {
|
||||
switch_ivr_play_file(session, NULL, file, NULL);
|
||||
}
|
||||
if (switch_ivr_eavesdrop_session(session, e_data.uuid_list[x], ED_DTMF) != SWITCH_STATUS_SUCCESS) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Spy: %s Failed\n", e_data.uuid_list[x]);
|
||||
if ((file = switch_channel_get_variable(channel, "eavesdrop_indicate_failed"))) {
|
||||
switch_ivr_play_file(session, NULL, file, NULL);
|
||||
}
|
||||
switch_ivr_collect_digits_count(session, buf, buflen, 1, "*", &terminator, 5000, 0, 0);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ((file = switch_channel_get_variable(channel, "eavesdrop_indicate_idle"))) {
|
||||
switch_ivr_play_file(session, NULL, file, NULL);
|
||||
}
|
||||
switch_ivr_collect_digits_count(session, buf, buflen, 1, "*", &terminator, 2000, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
for(x = 0; x < MAX_SPY; x++) {
|
||||
switch_safe_free(e_data.uuid_list[x]);
|
||||
}
|
||||
|
||||
switch_core_db_close(db);
|
||||
|
||||
} else {
|
||||
switch_ivr_eavesdrop_session(session, data, ED_DTMF);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#define eavesdrop_SYNTAX "<uuid>"
|
||||
|
@ -83,8 +83,6 @@ static switch_status_t on_dtmf(switch_core_session_t *session, void *input, swit
|
||||
}
|
||||
|
||||
switch_ivr_soft_hold(session, "0", moh_a, moh_b);
|
||||
|
||||
|
||||
return SWITCH_STATUS_IGNORE;
|
||||
}
|
||||
}
|
||||
|
@ -497,17 +497,23 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_eavesdrop_session(switch_core_session
|
||||
switch_codec_t *read_codec = switch_core_session_get_read_codec(session);
|
||||
|
||||
if ((tsession = switch_core_session_locate(uuid))) {
|
||||
struct eavesdrop_pvt *ep;
|
||||
struct eavesdrop_pvt *ep = NULL;
|
||||
switch_media_bug_t *bug = NULL;
|
||||
switch_channel_t *tchannel = switch_core_session_get_channel(tsession);
|
||||
switch_frame_t *read_frame, write_frame = { 0 };
|
||||
switch_codec_t codec = {0};
|
||||
int16_t buf[SWITCH_RECOMMENDED_BUFFER_SIZE/2];
|
||||
switch_codec_t *tread_codec = switch_core_session_get_read_codec(tsession);
|
||||
uint32_t tlen = tread_codec->implementation->bytes_per_frame;
|
||||
uint32_t tlen;
|
||||
|
||||
if (!switch_channel_media_ready(channel)) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
ep = switch_core_session_alloc(session, sizeof(*ep));
|
||||
|
||||
tlen = tread_codec->implementation->bytes_per_frame;
|
||||
|
||||
switch_channel_pre_answer(channel);
|
||||
|
||||
if (switch_core_codec_init(&codec,
|
||||
@ -520,7 +526,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_eavesdrop_session(switch_core_session
|
||||
NULL, switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot init codec\n");
|
||||
switch_core_session_rwunlock(tsession);
|
||||
return status;
|
||||
goto end;
|
||||
}
|
||||
|
||||
switch_core_session_set_read_codec(session, &codec);
|
||||
@ -599,6 +605,8 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_eavesdrop_session(switch_core_session
|
||||
switch_clear_flag(ep, ED_MUX_READ);
|
||||
switch_clear_flag(ep, ED_MUX_WRITE);
|
||||
break;
|
||||
case '*':
|
||||
goto end;
|
||||
default:
|
||||
z = 0;
|
||||
break;
|
||||
@ -657,6 +665,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_eavesdrop_session(switch_core_session
|
||||
switch_core_media_bug_remove(tsession, &bug);
|
||||
}
|
||||
|
||||
if (ep) {
|
||||
if (ep->buffer) {
|
||||
switch_buffer_destroy(&ep->buffer);
|
||||
}
|
||||
@ -668,6 +677,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_eavesdrop_session(switch_core_session
|
||||
if (ep->w_buffer) {
|
||||
switch_buffer_destroy(&ep->w_buffer);
|
||||
}
|
||||
}
|
||||
|
||||
switch_core_session_rwunlock(tsession);
|
||||
status = SWITCH_STATUS_SUCCESS;
|
||||
|
Loading…
x
Reference in New Issue
Block a user