From 618392299b831f09b683f2e98c0d93b5b6ef342e Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 10 Aug 2012 20:12:20 -0500 Subject: [PATCH] add javascript chatplan app --- .../mod_spidermonkey/mod_spidermonkey.c | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c b/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c index 83e723e061..7ba7975e98 100644 --- a/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c +++ b/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c @@ -3628,7 +3628,7 @@ static int env_init(JSContext * cx, JSObject * javascript_object) return 1; } -static void js_parse_and_execute(switch_core_session_t *session, const char *input_code, struct request_obj *ro) +static void js_parse_and_execute(switch_core_session_t *session, const char *input_code, struct request_obj *ro, switch_event_t *message) { JSObject *javascript_global_object = NULL; char buf[1024], *arg, *argv[512]; @@ -3657,6 +3657,12 @@ static void js_parse_and_execute(switch_core_session_t *session, const char *inp if (!(session && new_js_session(cx, javascript_global_object, session, &jss, "session", flags))) { switch_snprintf(buf, sizeof(buf), "~var session = false;"); eval_some_js(buf, cx, javascript_global_object, &rval); + + if (message) { + new_js_event(message, "message", cx, javascript_global_object); + } + + } if (ro) { new_request(cx, javascript_global_object, ro); @@ -3704,7 +3710,16 @@ static void js_parse_and_execute(switch_core_session_t *session, const char *inp SWITCH_STANDARD_APP(js_dp_function) { - js_parse_and_execute(session, data, NULL); + js_parse_and_execute(session, data, NULL, NULL); +} + +SWITCH_STANDARD_CHAT_APP(js_chat_function) +{ + + js_parse_and_execute(NULL, data, NULL, message); + + return SWITCH_STATUS_SUCCESS; + } struct js_task { @@ -3717,7 +3732,7 @@ static void *SWITCH_THREAD_FUNC js_thread_run(switch_thread_t *thread, void *obj struct js_task *task = (struct js_task *) obj; switch_memory_pool_t *pool; - js_parse_and_execute(NULL, task->code, NULL); + js_parse_and_execute(NULL, task->code, NULL, NULL); if ((pool = task->pool)) { switch_core_destroy_memory_pool(&pool); @@ -3775,7 +3790,7 @@ SWITCH_STANDARD_API(jsapi_function) ro.session = session; ro.stream = stream; - js_parse_and_execute(session, (char *) cmd, &ro); + js_parse_and_execute(session, (char *) cmd, &ro, NULL); return SWITCH_STATUS_SUCCESS; } @@ -3795,6 +3810,8 @@ SWITCH_STANDARD_API(launch_async) SWITCH_MODULE_LOAD_FUNCTION(mod_spidermonkey_load) { switch_application_interface_t *app_interface; + switch_chat_application_interface_t *chat_app_interface; + //switch_status_t status; //if ((status = init_js()) != SWITCH_STATUS_SUCCESS) { @@ -3812,6 +3829,8 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_spidermonkey_load) SWITCH_ADD_APP(app_interface, "javascript", "Launch JS ivr", "Run a javascript ivr on a channel", js_dp_function, "