]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
add destroy method to js
authorAnthony Minessale <anthony.minessale@gmail.com>
Tue, 14 Apr 2009 16:45:35 +0000 (16:45 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Tue, 14 Apr 2009 16:45:35 +0000 (16:45 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@13016 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/mod/languages/mod_spidermonkey/mod_spidermonkey.c

index 65634cb44c151ef06a60e7cb3414b057019ef19a..b5a19b8ff219d0b9d2b49300b832d379d438dc25 100644 (file)
@@ -2216,6 +2216,40 @@ static JSBool session_wait_for_answer(JSContext * cx, JSObject * obj, uintN argc
        return ret;
 }
 
+static JSBool session_detach(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
+{
+       struct js_session *jss = JS_GetPrivate(cx, obj);
+       jsval ret = JS_TRUE;
+       switch_call_cause_t cause = 0;
+       switch_channel_t *channel;
+       switch_core_session_t *session;
+       METHOD_SANITY_CHECK();
+
+       if ((session = jss->session)) {
+               jss->session = NULL;
+
+               if (argc > 1) {
+                       if (JSVAL_IS_INT(argv[0])) {
+                               int32 i = 0;
+                               JS_ValueToInt32(cx, argv[0], &i);
+                               cause = i;
+                       }
+               }
+               
+               if (cause) {
+                       channel = switch_core_session_get_channel(session);
+                       switch_channel_hangup(channel, cause);
+               }
+
+               switch_core_session_rwunlock(session);
+               *rval = JS_TRUE;
+       } else {
+               *rval = JS_FALSE;
+       }
+
+       return ret;
+}
+
 static JSBool session_execute(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
 {
        JSBool retval = JS_FALSE;
@@ -2617,6 +2651,7 @@ static JSFunctionSpec session_methods[] = {
        {"sendEvent", session_send_event, 0},
        {"hangup", session_hangup, 0},
        {"execute", session_execute, 0},
+       {"destroy", session_detach, 0},
        {"sleep", session_sleep, 1},
        {0}
 };