[Freeswitch-svn] [commit] r7918 - in freeswitch/trunk/src/mod: applications/mod_dptools languages/mod_spidermonkey

Freeswitch SVN anthm at freeswitch.org
Tue Mar 18 14:48:32 EDT 2008


Author: anthm
Date: Tue Mar 18 14:48:32 2008
New Revision: 7918

Modified:
   freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c
   freeswitch/trunk/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c

Log:
make some sleep and javascript ok with no-media

Modified: freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c	(original)
+++ freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c	Tue Mar 18 14:48:32 2008
@@ -1760,7 +1760,7 @@
 	SWITCH_ADD_API(api_interface, "presence", "presence", presence_api_function, "<user> <rpid> <message>");
 	SWITCH_ADD_APP(app_interface, "privacy", "Set privacy on calls", "Set caller privacy on calls.", privacy_function, "off|on|name|full|number", SAF_SUPPORT_NOMEDIA);
 	SWITCH_ADD_APP(app_interface, "transfer", "Transfer a channel", TRANSFER_LONG_DESC, transfer_function, "<exten> [<dialplan> <context>]", SAF_SUPPORT_NOMEDIA);
-	SWITCH_ADD_APP(app_interface, "sleep", "Pause a channel", SLEEP_LONG_DESC, sleep_function, "<pausemilliseconds>", SAF_NONE);
+	SWITCH_ADD_APP(app_interface, "sleep", "Pause a channel", SLEEP_LONG_DESC, sleep_function, "<pausemilliseconds>", SAF_SUPPORT_NOMEDIA);
 	SWITCH_ADD_APP(app_interface, "delay_echo", "echo audio at a specified delay", "Delay n ms", delay_function, "<delay ms>", SAF_NONE);
 	SWITCH_ADD_APP(app_interface, "strftime", NULL, NULL, strftime_function, NULL, SAF_SUPPORT_NOMEDIA);
 	SWITCH_ADD_APP(app_interface, "phrase", "Say a Phrase", "Say a Phrase", phrase_function, "<macro_name>,<data>", SAF_NONE);

Modified: freeswitch/trunk/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c
==============================================================================
--- freeswitch/trunk/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c	(original)
+++ freeswitch/trunk/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c	Tue Mar 18 14:48:32 2008
@@ -72,6 +72,14 @@
 		}																\
 	} while (foo == 1)
 
+#define CHANNEL_MEDIA_SANITY_CHECK() do {								\
+		if (!switch_channel_media_ready(channel)) {						\
+			eval_some_js("~throw new Error(\"Session is not in media mode!\");", cx, obj, rval); \
+			*rval = BOOLEAN_TO_JSVAL(JS_FALSE);							\
+			return JS_FALSE;											\
+		}																\
+	} while (foo == 1)
+
 static void session_destroy(JSContext * cx, JSObject * obj);
 static JSBool session_construct(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval);
 static JSBool session_originate(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval);
@@ -1092,7 +1100,7 @@
 	jsval nval , *rval = &nval; 
 	JSContext *cx = cb_state->cx;
 	JSObject *obj = cb_state->obj;
-
+	
 	METHOD_SANITY_CHECK();
 
 	jss->stack_depth++;
@@ -1317,7 +1325,11 @@
 static JSBool session_flush_digits(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
 {
 	struct js_session *jss = JS_GetPrivate(cx, obj);
+	switch_channel_t *channel;
+
 	METHOD_SANITY_CHECK();
+	channel = switch_core_session_get_channel(jss->session);
+	CHANNEL_MEDIA_SANITY_CHECK();
 
 	switch_channel_flush_dtmf(switch_core_session_get_channel(jss->session));
 
@@ -1362,6 +1374,8 @@
 	channel = switch_core_session_get_channel(jss->session);
 	CHANNEL_SANITY_CHECK();
 
+	CHANNEL_MEDIA_SANITY_CHECK();
+
 	if (argc > 0) {
 		file_name = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
 		if (switch_strlen_zero(file_name)) {
@@ -1429,6 +1443,7 @@
 	METHOD_SANITY_CHECK();
 	channel = switch_core_session_get_channel(jss->session);
 	CHANNEL_SANITY_CHECK();
+	CHANNEL_MEDIA_SANITY_CHECK();
 
 	if (argc > 0) {
 		if ((function = JS_ValueToFunction(cx, argv[0]))) {
@@ -1485,6 +1500,7 @@
 	METHOD_SANITY_CHECK();
 	channel = switch_core_session_get_channel(jss->session);
 	CHANNEL_SANITY_CHECK();
+	CHANNEL_MEDIA_SANITY_CHECK();
 
 	if (argc > 0) {
 		phrase_name = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
@@ -1612,6 +1628,7 @@
 	METHOD_SANITY_CHECK();
 	channel = switch_core_session_get_channel(jss->session);
 	CHANNEL_SANITY_CHECK();
+	CHANNEL_MEDIA_SANITY_CHECK();
 
 	if (argc > 0) {
 		file_name = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
@@ -1781,9 +1798,11 @@
 
 	METHOD_SANITY_CHECK();
 
+
 	*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
 	channel = switch_core_session_get_channel(jss->session);
 	CHANNEL_SANITY_CHECK();
+	CHANNEL_MEDIA_SANITY_CHECK();
 
 	if (argc < 3) {
 		return JS_FALSE;
@@ -1986,6 +2005,7 @@
 	METHOD_SANITY_CHECK();
 
 	channel = switch_core_session_get_channel(jss->session);
+	CHANNEL_MEDIA_SANITY_CHECK();
 
 	started = switch_timestamp_now();
 
@@ -3483,7 +3503,7 @@
 	*module_interface = switch_loadable_module_create_module_interface(pool, modname);
 	SWITCH_ADD_API(api_interface, "jsrun", "run a script", launch_async, "jsrun <script> [additional_vars [...]]");
 	SWITCH_ADD_API(api_interface, "jsapi", "execute an api call", jsapi_function, "jsapi <script> [additional_vars [...]]");
-	SWITCH_ADD_APP(app_interface, "javascript", "Launch JS ivr", "Run a javascript ivr on a channel", js_dp_function, "<script> [additional_vars [...]]", SAF_NONE);
+	SWITCH_ADD_APP(app_interface, "javascript", "Launch JS ivr", "Run a javascript ivr on a channel", js_dp_function, "<script> [additional_vars [...]]", SAF_SUPPORT_NOMEDIA);
 
 	curl_global_init(CURL_GLOBAL_ALL);
 



More information about the Freeswitch-svn mailing list