add uuid fsapi function, last_file_position variable, and volume controls to js callback volume:+1 etc

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@5498 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale
2007-07-05 17:03:14 +00:00
parent c02f435a30
commit 7feef76fb2
5 changed files with 78 additions and 9 deletions
@@ -311,6 +311,19 @@ SWITCH_STANDARD_API(tone_detect_session_function)
return SWITCH_STATUS_SUCCESS;
}
SWITCH_STANDARD_API(uuid_function)
{
switch_uuid_t uuid;
char uuid_str[SWITCH_UUID_FORMATTED_LENGTH + 1];
switch_uuid_get(&uuid);
switch_uuid_format(uuid_str, &uuid);
stream->write_function(stream, "%s", uuid_str);
return SWITCH_STATUS_SUCCESS;
}
#define SCHED_TRANSFER_SYNTAX "[+]<time> <uuid> <extension> [<dialplan>] [<context>]"
SWITCH_STANDARD_API(sched_transfer_function)
{
@@ -1282,7 +1295,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_commands_load)
SWITCH_ADD_API(commands_api_interface, "break", "Break", break_function, BREAK_SYNTAX);
SWITCH_ADD_API(commands_api_interface, "show", "Show", show_function, SHOW_SYNTAX);
SWITCH_ADD_API(commands_api_interface, "status", "status", status_function, "");
SWITCH_ADD_API(commands_api_interface, "uuid_bridge", "uuid_bridge", uuid_bridge_function, UUID_SYNTAX);
SWITCH_ADD_API(commands_api_interface, "uuid_bridge", "uuid_bridge", uuid_bridge_function, "");
SWITCH_ADD_API(commands_api_interface, "session_displace", "session displace", session_displace_function, "<uuid> [start|stop] <path> [<limit>] [mux]");
SWITCH_ADD_API(commands_api_interface, "session_record", "session record", session_record_function, SESS_REC_SYNTAX);
SWITCH_ADD_API(commands_api_interface, "broadcast", "broadcast", uuid_broadcast_function, BROADCAST_SYNTAX);
@@ -1294,6 +1307,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_commands_load)
SWITCH_ADD_API(commands_api_interface, "sched_hangup", "Schedule a running call to hangup", sched_hangup_function, SCHED_HANGUP_SYNTAX);
SWITCH_ADD_API(commands_api_interface, "sched_broadcast", "Schedule a broadcast event to a running call", sched_broadcast_function, SCHED_BROADCAST_SYNTAX);
SWITCH_ADD_API(commands_api_interface, "sched_transfer", "Schedule a broadcast event to a running call", sched_transfer_function, SCHED_TRANSFER_SYNTAX);
SWITCH_ADD_API(commands_api_interface, "create_uuid", "Create a uuid", uuid_function, UUID_SYNTAX);
SWITCH_ADD_API(commands_api_interface, "sched_api", "Schedule an api command", sched_api_function, "[+]<time> <group_name> <command_string>");
SWITCH_ADD_API(commands_api_interface, "sched_del", "Delete a Scheduled task", sched_del_function, "<task_id>|<group_id>");
SWITCH_ADD_API(commands_api_interface, "xml_wrap", "Wrap another api command in xml", xml_wrap_api_function, "<command> <args>");
@@ -929,6 +929,29 @@ static switch_status_t js_stream_input_callback(switch_core_session_t *session,
return SWITCH_STATUS_SUCCESS;
}
return SWITCH_STATUS_FALSE;
} else if (!strncasecmp(ret, "volume", 6)) {
char *p;
if ((p = strchr(ret, ':'))) {
p++;
if (*p == '+' || *p == '-') {
int step;
if (!(step = atoi(p))) {
step = 1;
}
fh->vol += step;
} else {
int vol = atoi(p);
fh->vol = vol;
}
return SWITCH_STATUS_SUCCESS;
}
if (fh->vol) {
switch_normalize_volume(fh->vol);
}
return SWITCH_STATUS_FALSE;
} else if (!strcasecmp(ret, "pause")) {
if (switch_test_flag(fh, SWITCH_FILE_PAUSE)) {
@@ -1361,8 +1384,8 @@ static JSBool session_streamfile(JSContext * cx, JSObject * obj, uintN argc, jsv
switch_file_handle_t fh = { 0 };
JSFunction *function;
switch_input_args_t args = { 0 };
char *prebuf;
char *prebuf, posbuf[35] = "";
METHOD_SANITY_CHECK();
channel = switch_core_session_get_channel(jss->session);
@@ -1420,6 +1443,9 @@ static JSBool session_streamfile(JSContext * cx, JSObject * obj, uintN argc, jsv
JS_ResumeRequest(cx, cb_state.saveDepth);
*rval = cb_state.ret;
snprintf(posbuf, sizeof(posbuf), "%u", fh.offset_pos);
switch_channel_set_variable(channel, "last_file_position", posbuf);
return JS_TRUE;
}
@@ -1768,15 +1794,19 @@ static JSBool session_execute(JSContext * cx, JSObject * obj, uintN argc, jsval
CHANNEL_SANITY_CHECK();
if (argc > 1) {
if (argc > 0) {
const switch_application_interface_t *application_interface;
char *app_name = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
char *app_arg = JS_GetStringBytes(JS_ValueToString(cx, argv[1]));
char *app_arg = NULL;
struct js_session *jss = JS_GetPrivate(cx, obj);
jsrefcount saveDepth;
METHOD_SANITY_CHECK();
if (argc > 1) {
app_arg = JS_GetStringBytes(JS_ValueToString(cx, argv[1]));
}
if ((application_interface = switch_loadable_module_get_application_interface(app_name))) {
if (application_interface->application_function) {
saveDepth = JS_SuspendRequest(cx);