fix dtmf code
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@7125 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
1fbb21e8fd
commit
df749a420f
|
@ -134,13 +134,19 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_collect_digits_callback(switch_core_s
|
|||
\param maxdigits max number of digits to read
|
||||
\param terminators digits to end the collection
|
||||
\param terminator actual digit that caused the collection to end (if any)
|
||||
\param timeout timeout in ms
|
||||
\param first_timeout timeout in ms
|
||||
\param digit_timeout digit timeout in ms
|
||||
\param abs_timeout abs timeout in ms
|
||||
\return SWITCH_STATUS_SUCCESS to keep the collection moving.
|
||||
*/
|
||||
SWITCH_DECLARE(switch_status_t) switch_ivr_collect_digits_count(switch_core_session_t *session,
|
||||
char *buf,
|
||||
switch_size_t buflen,
|
||||
switch_size_t maxdigits, const char *terminators, char *terminator, uint32_t timeout);
|
||||
switch_size_t maxdigits,
|
||||
const char *terminators, char *terminator,
|
||||
uint32_t first_timeout,
|
||||
uint32_t digit_timeout,
|
||||
uint32_t abs_timeout);
|
||||
|
||||
/*!
|
||||
\brief Engage background Speech detection on a session
|
||||
|
|
|
@ -4125,7 +4125,7 @@ SWITCH_STANDARD_APP(conference_function)
|
|||
status = switch_ivr_collect_digits_count(session,
|
||||
buf,
|
||||
sizeof(pin_buf) - strlen(pin_buf),
|
||||
strlen(conference->pin) - strlen(pin_buf), "#", &term, 10000);
|
||||
strlen(conference->pin) - strlen(pin_buf), "#", &term, 10000, 0, 0);
|
||||
}
|
||||
|
||||
pin_valid = (status == SWITCH_STATUS_SUCCESS && strcmp(pin_buf, conference->pin) == 0);
|
||||
|
|
|
@ -367,7 +367,7 @@ SWITCH_STANDARD_APP(rss_function)
|
|||
switch_size_t blen = sizeof(cmd) - strlen(cmd);
|
||||
|
||||
cp = cmd + blen;
|
||||
switch_ivr_collect_digits_count(session, cp, blen, blen, "#", &term, 5000);
|
||||
switch_ivr_collect_digits_count(session, cp, blen, blen, "#", &term, 5000, 0, 0);
|
||||
}
|
||||
|
||||
x = atoi(cmd) - 1;
|
||||
|
|
|
@ -826,7 +826,7 @@ static switch_status_t vm_macro_get(switch_core_session_t *session,
|
|||
maxlen = buflen -1;
|
||||
}
|
||||
if (bslen < maxlen) {
|
||||
status = switch_ivr_collect_digits_count(session, buf + bslen, buflen, maxlen - bslen, term_chars, terminator_key, timeout);
|
||||
status = switch_ivr_collect_digits_count(session, buf + bslen, buflen, maxlen - bslen, term_chars, terminator_key, timeout, 0, 0);
|
||||
}
|
||||
|
||||
return status;
|
||||
|
|
|
@ -1928,7 +1928,7 @@ static JSBool session_get_digits(JSContext * cx, JSObject * obj, uintN argc, jsv
|
|||
struct js_session *jss = JS_GetPrivate(cx, obj);
|
||||
char *terminators = NULL;
|
||||
char buf[513] = { 0 };
|
||||
int32 digits = 0, timeout = 5000;
|
||||
int32 digits = 0, timeout = 5000, digit_timeout = 0, abs_timeout = 0;
|
||||
switch_channel_t *channel;
|
||||
|
||||
METHOD_SANITY_CHECK();
|
||||
|
@ -1950,12 +1950,21 @@ static JSBool session_get_digits(JSContext * cx, JSObject * obj, uintN argc, jsv
|
|||
if (argc > 1) {
|
||||
terminators = JS_GetStringBytes(JS_ValueToString(cx, argv[1]));
|
||||
}
|
||||
|
||||
if (argc > 2) {
|
||||
JS_ValueToInt32(cx, argv[2], &timeout);
|
||||
}
|
||||
|
||||
if (argc > 3) {
|
||||
JS_ValueToInt32(cx, argv[3], &digit_timeout);
|
||||
}
|
||||
|
||||
switch_ivr_collect_digits_count(jss->session, buf, sizeof(buf), digits, terminators, &term, timeout);
|
||||
if (argc > 4) {
|
||||
JS_ValueToInt32(cx, argv[4], &abs_timeout);
|
||||
}
|
||||
|
||||
|
||||
switch_ivr_collect_digits_count(jss->session, buf, sizeof(buf), digits, terminators, &term, timeout, digit_timeout, abs_timeout);
|
||||
*rval = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, buf));
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
|
|
@ -216,7 +216,7 @@ int CoreSession::getDigits(char *dtmf_buf,
|
|||
maxdigits,
|
||||
terminators,
|
||||
terminator,
|
||||
(uint32_t) timeout);
|
||||
(uint32_t) timeout, 0, 0);
|
||||
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "getDigits dtmf_buf: %s\n", dtmf_buf);
|
||||
end_allow_threads();
|
||||
|
|
|
@ -599,13 +599,18 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_collect_digits_callback(switch_core_s
|
|||
SWITCH_DECLARE(switch_status_t) switch_ivr_collect_digits_count(switch_core_session_t *session,
|
||||
char *buf,
|
||||
switch_size_t buflen,
|
||||
switch_size_t maxdigits, const char *terminators, char *terminator, uint32_t timeout)
|
||||
switch_size_t maxdigits,
|
||||
const char *terminators, char *terminator,
|
||||
uint32_t first_timeout,
|
||||
uint32_t digit_timeout,
|
||||
uint32_t abs_timeout)
|
||||
{
|
||||
switch_size_t i = 0, x = strlen(buf);
|
||||
switch_channel_t *channel;
|
||||
switch_status_t status = SWITCH_STATUS_FALSE;
|
||||
switch_time_t started = 0;
|
||||
uint32_t elapsed;
|
||||
switch_time_t started = 0, digit_started = 0;
|
||||
uint32_t abs_elapsed = 0, digit_elapsed = 0;
|
||||
uint32_t eff_timeout = 0;
|
||||
|
||||
channel = switch_core_session_get_channel(session);
|
||||
switch_assert(channel != NULL);
|
||||
|
@ -622,16 +627,31 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_collect_digits_count(switch_core_sess
|
|||
}
|
||||
}
|
||||
|
||||
if (timeout) {
|
||||
started = switch_time_now();
|
||||
if (abs_timeout) {
|
||||
started = switch_timestamp_now();
|
||||
}
|
||||
|
||||
if (digit_timeout && first_timeout) {
|
||||
eff_timeout = first_timeout;
|
||||
} else if (digit_timeout && !first_timeout) {
|
||||
first_timeout = eff_timeout = digit_timeout;
|
||||
} else if (first_timeout) {
|
||||
digit_timeout = eff_timeout = first_timeout;
|
||||
}
|
||||
|
||||
|
||||
if (eff_timeout) {
|
||||
digit_started = switch_timestamp_now();
|
||||
}
|
||||
|
||||
|
||||
|
||||
while (switch_channel_ready(channel)) {
|
||||
switch_frame_t *read_frame;
|
||||
|
||||
if (timeout) {
|
||||
elapsed = (uint32_t) ((switch_time_now() - started) / 1000);
|
||||
if (elapsed >= timeout) {
|
||||
if (abs_timeout) {
|
||||
abs_elapsed = (uint32_t) ((switch_timestamp_now() - started) / 1000);
|
||||
if (abs_elapsed >= abs_timeout) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -640,10 +660,23 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_collect_digits_count(switch_core_sess
|
|||
switch_ivr_parse_all_events(session);
|
||||
}
|
||||
|
||||
|
||||
if (eff_timeout) {
|
||||
digit_elapsed = (uint32_t) ((switch_timestamp_now() - digit_started) / 1000);
|
||||
if (digit_elapsed >= eff_timeout) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (switch_channel_has_dtmf(channel)) {
|
||||
switch_dtmf_t dtmf = {0};
|
||||
switch_size_t y;
|
||||
|
||||
if (eff_timeout) {
|
||||
eff_timeout = digit_timeout;
|
||||
digit_started = switch_timestamp_now();
|
||||
}
|
||||
|
||||
for (y = 0; y < maxdigits; y++) {
|
||||
if (switch_channel_dequeue_dtmf(channel, &dtmf) != SWITCH_STATUS_SUCCESS) {
|
||||
break;
|
||||
|
|
|
@ -274,7 +274,7 @@ static switch_status_t play_or_say(switch_core_session_t *session, switch_ivr_me
|
|||
menu->ptr += strlen(menu->buf);
|
||||
if (strlen(menu->buf) < need) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "waiting for %u digits\n", (uint32_t)need);
|
||||
status = switch_ivr_collect_digits_count(session, menu->ptr, menu->inlen - strlen(menu->buf), need, "#", &terminator, menu->timeout);
|
||||
status = switch_ivr_collect_digits_count(session, menu->ptr, menu->inlen - strlen(menu->buf), need, "#", &terminator, menu->timeout, 0, 0);
|
||||
}
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "digits '%s'\n", menu->buf);
|
||||
}
|
||||
|
|
|
@ -129,7 +129,7 @@ static void *SWITCH_THREAD_FUNC collect_thread_run(switch_thread_t * thread, voi
|
|||
args.buflen = sizeof(buf);
|
||||
switch_ivr_play_file(collect->session, NULL, collect->file, &args);
|
||||
} else {
|
||||
switch_ivr_collect_digits_count(collect->session, buf, sizeof(buf), 1, SWITCH_BLANK_STRING, &term, 0);
|
||||
switch_ivr_collect_digits_count(collect->session, buf, sizeof(buf), 1, SWITCH_BLANK_STRING, &term, 0, 0, 0);
|
||||
}
|
||||
|
||||
for (p = buf; *p; p++) {
|
||||
|
|
|
@ -1179,7 +1179,7 @@ SWITCH_DECLARE(switch_status_t) switch_play_and_get_digits(switch_core_session_t
|
|||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Calling more digits try %d\n", max_tries);
|
||||
|
||||
//Try to grab some more digits for the timeout period
|
||||
status = switch_ivr_collect_digits_count(session, digit_buffer, digit_buffer_length, max_digits, valid_terminators, &terminator, timeout);
|
||||
status = switch_ivr_collect_digits_count(session, digit_buffer, digit_buffer_length, max_digits, valid_terminators, &terminator, timeout, 0, 0);
|
||||
|
||||
//Make sure we made it out alive
|
||||
if (status != SWITCH_STATUS_SUCCESS) {
|
||||
|
|
Loading…
Reference in New Issue