forked from Mirrors/freeswitch
bunch of tweaks to make ivr more fun
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@2351 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
4f17ab7714
commit
c92e1cb79a
@ -1217,6 +1217,7 @@ static switch_status_t exosip_create_call(eXosip_event_t * event)
|
||||
|
||||
snprintf(name, sizeof(name), "Exosip/%s-%04x", event->request->from->url->username, rand() & 0xffff);
|
||||
switch_channel_set_name(channel, name);
|
||||
switch_channel_set_variable(channel, "endpoint_disposition", "INVITE");
|
||||
|
||||
if (osip_message_header_get_byname (event->request, "SrtpRealm", 0, &tedious)) {
|
||||
tech_pvt->realm = switch_core_session_strdup(session, osip_header_get_value(tedious));
|
||||
@ -1503,31 +1504,31 @@ static void destroy_call_by_event(eXosip_event_t *event)
|
||||
|
||||
switch (event->type) {
|
||||
case EXOSIP_CALL_RELEASED:
|
||||
switch_channel_set_variable(channel, "exosip_disposition", "RELEASED");
|
||||
switch_channel_set_variable(channel, "endpoint_disposition", "RELEASED");
|
||||
cause = SWITCH_CAUSE_NORMAL_CLEARING;
|
||||
break;
|
||||
case EXOSIP_CALL_CLOSED:
|
||||
switch_channel_set_variable(channel, "exosip_disposition", "CLOSED");
|
||||
switch_channel_set_variable(channel, "endpoint_disposition", "CLOSED");
|
||||
cause = SWITCH_CAUSE_NORMAL_CLEARING;
|
||||
break;
|
||||
case EXOSIP_CALL_NOANSWER:
|
||||
switch_channel_set_variable(channel, "exosip_disposition", "NO ANSWER");
|
||||
switch_channel_set_variable(channel, "endpoint_disposition", "NO ANSWER");
|
||||
cause = SWITCH_CAUSE_NO_ANSWER;
|
||||
break;
|
||||
case EXOSIP_CALL_REQUESTFAILURE:
|
||||
switch_channel_set_variable(channel, "exosip_disposition", "REQUEST FAILURE");
|
||||
switch_channel_set_variable(channel, "endpoint_disposition", "REQUEST FAILURE");
|
||||
cause = SWITCH_CAUSE_REQUESTED_CHAN_UNAVAIL;
|
||||
break;
|
||||
case EXOSIP_CALL_SERVERFAILURE:
|
||||
switch_channel_set_variable(channel, "exosip_disposition", "SERVER FAILURE");
|
||||
switch_channel_set_variable(channel, "endpoint_disposition", "SERVER FAILURE");
|
||||
cause = SWITCH_CAUSE_CALL_REJECTED;
|
||||
break;
|
||||
case EXOSIP_CALL_GLOBALFAILURE:
|
||||
switch_channel_set_variable(channel, "exosip_disposition", "GLOBAL FAILURE");
|
||||
switch_channel_set_variable(channel, "endpoint_disposition", "GLOBAL FAILURE");
|
||||
cause = SWITCH_CAUSE_CALL_REJECTED;
|
||||
break;
|
||||
default:
|
||||
switch_channel_set_variable(channel, "exosip_disposition", "UNKNOWN");
|
||||
switch_channel_set_variable(channel, "endpoint_disposition", "UNKNOWN");
|
||||
cause = SWITCH_CAUSE_SWITCH_CONGESTION;
|
||||
break;
|
||||
}
|
||||
@ -1736,6 +1737,8 @@ static void handle_answer(eXosip_event_t * event)
|
||||
return;
|
||||
}
|
||||
|
||||
switch_channel_set_variable(channel, "endpoint_disposition", "ANSWER");
|
||||
|
||||
|
||||
conn = eXosip_get_audio_connection(remote_sdp);
|
||||
remote_med = eXosip_get_audio_media(remote_sdp);
|
||||
|
@ -803,6 +803,55 @@ static JSBool session_streamfile(JSContext *cx, JSObject *obj, uintN argc, jsval
|
||||
return (switch_channel_ready(channel)) ? JS_TRUE : JS_FALSE;
|
||||
}
|
||||
|
||||
static JSBool session_set_variable(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
{
|
||||
struct js_session *jss = JS_GetPrivate(cx, obj);
|
||||
switch_channel_t *channel;
|
||||
|
||||
channel = switch_core_session_get_channel(jss->session);
|
||||
assert(channel != NULL);
|
||||
|
||||
if (argc > 1) {
|
||||
char *var, *val;
|
||||
|
||||
var = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
|
||||
val = JS_GetStringBytes(JS_ValueToString(cx, argv[1]));
|
||||
switch_channel_set_variable(channel, var, val);
|
||||
*rval = BOOLEAN_TO_JSVAL( JS_TRUE );
|
||||
} else {
|
||||
*rval = BOOLEAN_TO_JSVAL( JS_FALSE );
|
||||
}
|
||||
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
static JSBool session_get_variable(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
{
|
||||
struct js_session *jss = JS_GetPrivate(cx, obj);
|
||||
switch_channel_t *channel;
|
||||
|
||||
channel = switch_core_session_get_channel(jss->session);
|
||||
assert(channel != NULL);
|
||||
|
||||
if (argc > 0) {
|
||||
char *var, *val;
|
||||
|
||||
var = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
|
||||
val = switch_channel_get_variable(channel, var);
|
||||
|
||||
if (val) {
|
||||
*rval = STRING_TO_JSVAL (JS_NewStringCopyZ(cx, val));
|
||||
} else {
|
||||
*rval = BOOLEAN_TO_JSVAL( JS_FALSE );
|
||||
}
|
||||
} else {
|
||||
*rval = BOOLEAN_TO_JSVAL( JS_FALSE );
|
||||
}
|
||||
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
|
||||
static JSBool session_speak(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
{
|
||||
struct js_session *jss = JS_GetPrivate(cx, obj);
|
||||
@ -1193,6 +1242,8 @@ static JSFunctionSpec session_methods[] = {
|
||||
{"flushEvents", session_flush_events, 1},
|
||||
{"flushDigits", session_flush_digits, 1},
|
||||
{"speak", session_speak, 1},
|
||||
{"setVariable", session_set_variable, 1},
|
||||
{"getVariable", session_get_variable, 1},
|
||||
{"getDigits", session_get_digits, 1},
|
||||
{"answer", session_answer, 0},
|
||||
{"ready", session_ready, 0},
|
||||
@ -1414,7 +1465,7 @@ static JSBool session_construct(JSContext *cx, JSObject *obj, uintN argc, jsval
|
||||
context,
|
||||
dest);
|
||||
|
||||
if (switch_ivr_originate(NULL, &peer_session, dest, to ? atoi(to) : 60, NULL, NULL, NULL, caller_profile) != SWITCH_STATUS_SUCCESS) {
|
||||
if (switch_ivr_originate(session, &peer_session, dest, to ? atoi(to) : 60, NULL, NULL, NULL, caller_profile) != SWITCH_STATUS_SUCCESS) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Cannot Create Outgoing Channel! [%s]\n", dest);
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
@ -1328,11 +1328,13 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
|
||||
status = SWITCH_STATUS_GENERR;
|
||||
goto done;
|
||||
}
|
||||
|
||||
|
||||
if (session) {
|
||||
caller_channel = switch_core_session_get_channel(session);
|
||||
assert(caller_channel != NULL);
|
||||
|
||||
switch_channel_set_variable(caller_channel, "originate_disposition", "failure");
|
||||
|
||||
if ((var = switch_channel_get_variable(caller_channel, "group_confirm_key"))) {
|
||||
key = switch_core_session_strdup(session, var);
|
||||
if ((var = switch_channel_get_variable(caller_channel, "group_confirm_file"))) {
|
||||
@ -1399,21 +1401,35 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
|
||||
goto done;
|
||||
}
|
||||
|
||||
caller_profiles[i] = switch_caller_profile_new(pool,
|
||||
NULL,
|
||||
NULL,
|
||||
cid_name_override,
|
||||
cid_num_override,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
__FILE__,
|
||||
NULL,
|
||||
chan_data);
|
||||
if (caller_profile_override) {
|
||||
caller_profiles[i] = switch_caller_profile_new(pool,
|
||||
caller_profile_override->username,
|
||||
caller_profile_override->dialplan,
|
||||
caller_profile_override->caller_id_name,
|
||||
caller_profile_override->caller_id_number,
|
||||
caller_profile_override->network_addr,
|
||||
caller_profile_override->ani,
|
||||
caller_profile_override->ani2,
|
||||
caller_profile_override->rdnis,
|
||||
caller_profile_override->source,
|
||||
caller_profile_override->context,
|
||||
chan_data);
|
||||
} else {
|
||||
caller_profiles[i] = switch_caller_profile_new(pool,
|
||||
NULL,
|
||||
NULL,
|
||||
cid_name_override,
|
||||
cid_num_override,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
__FILE__,
|
||||
NULL,
|
||||
chan_data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (switch_core_session_outgoing_channel(session, chan_type, caller_profiles[i], &peer_sessions[i], pool) != SWITCH_STATUS_SUCCESS) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot Create Outgoing Channel!\n");
|
||||
if (pool) {
|
||||
@ -1526,10 +1542,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
|
||||
continue;
|
||||
}
|
||||
if (i != idx) {
|
||||
if (caller_channel) {
|
||||
switch_channel_set_variable(caller_channel, "originate_disposition", "lost race");
|
||||
switch_channel_hangup(peer_channels[i], SWITCH_CAUSE_LOSE_RACE);
|
||||
}
|
||||
switch_channel_hangup(peer_channels[i], SWITCH_CAUSE_LOSE_RACE);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user