static const char js_class_name[] = "Session";
-#define METHOD_SANITY_CHECK() if (!this->_session) { \
+#define METHOD_SANITY_CHECK() if (!this->_session) {\
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "No session is active, you must have an active session before calling this method"));\
return;\
} else CheckHangupHook(this, NULL)
}\
} while (foo == 1)
+#define LOCK_ISOLATE_ON_CALLBACK_MACRO() \
+ FSSession *obj = cb_state->session_state;\
+ Isolate *isolate = obj->GetOwner()->GetIsolate();\
+ Locker lock(isolate);\
+ Isolate::Scope isolate_scope(isolate);\
+ HandleScope handle_scope(isolate);\
+ Local<Context> context = Local<Context>::New(isolate, cb_state->context);\
+ Context::Scope context_scope(context);
+
static int foo = 0;
string FSSession::GetJSClassName()
ret.Reset();
session_obj_a.Reset();
session_obj_b.Reset();
+ context.Reset();
}
#define MAX_STACK_DEPTH 2
switch_status_t FSSession::StreamInputCallback(switch_core_session_t *session, void *input, switch_input_type_t itype, void *buf, unsigned int buflen)
{
FSInputCallbackState *cb_state = (FSInputCallbackState *)buf;
- FSSession *obj = cb_state->session_state;
- HandleScope handle_scope(obj->GetOwner()->GetIsolate());
+ LOCK_ISOLATE_ON_CALLBACK_MACRO();
+
switch_status_t status;
switch_file_handle_t *fh = (switch_file_handle_t *)cb_state->extra;
switch_status_t FSSession::RecordInputCallback(switch_core_session_t *session, void *input, switch_input_type_t itype, void *buf, unsigned int buflen)
{
FSInputCallbackState *cb_state = (FSInputCallbackState *)buf;
- FSSession *obj = cb_state->session_state;
- HandleScope handle_scope(obj->GetOwner()->GetIsolate());
+ LOCK_ISOLATE_ON_CALLBACK_MACRO();
+
switch_status_t status;
switch_file_handle_t *fh = (switch_file_handle_t *)cb_state->extra;
switch_status_t FSSession::CollectInputCallback(switch_core_session_t *session, void *input, switch_input_type_t itype, void *buf, unsigned int buflen)
{
FSInputCallbackState *cb_state = (FSInputCallbackState *)buf;
- FSSession *obj = cb_state->session_state;
- HandleScope handle_scope(obj->GetOwner()->GetIsolate());
+ LOCK_ISOLATE_ON_CALLBACK_MACRO();
+
const char *ret;
switch_status_t status;
if (!func.IsEmpty()) {
cb_state.session_state = this;
+ cb_state.context.Reset(info.GetIsolate(), info.GetIsolate()->GetCurrentContext());
cb_state.function.Reset(info.GetIsolate(), func);
if (info.Length() > 2 && !info[2].IsEmpty()) {
cb_state.arg.Reset(info.GetIsolate(), info[2]);
args.buf = bp;
args.buflen = len;
- switch_ivr_record_file(this->_session, &fh, file_name.c_str(), &args, limit);
+ JS_EXECUTE_LONG_RUNNING_C_CALL_WITH_UNLOCKER(switch_ivr_record_file(this->_session, &fh, file_name.c_str(), &args, limit));
info.GetReturnValue().Set(cb_state.ret);
CheckHangupHook(this, &ret);
}
cb_state.session_state = this;
+ cb_state.context.Reset(info.GetIsolate(), info.GetIsolate()->GetCurrentContext());
dtmf_func = CollectInputCallback;
bp = &cb_state;
len = sizeof(cb_state);
args.buf = bp;
args.buflen = len;
- switch_ivr_collect_digits_callback(this->_session, &args, digit_timeout, abs_timeout);
+ JS_EXECUTE_LONG_RUNNING_C_CALL_WITH_UNLOCKER(switch_ivr_collect_digits_callback(this->_session, &args, digit_timeout, abs_timeout));
info.GetReturnValue().Set(cb_state.ret);
CheckHangupHook(this, &ret);
}
cb_state.session_state = this;
+ cb_state.context.Reset(info.GetIsolate(), info.GetIsolate()->GetCurrentContext());
dtmf_func = CollectInputCallback;
bp = &cb_state;
len = sizeof(cb_state);
args.buf = bp;
args.buflen = len;
- switch_ivr_phrase_macro(this->_session, phrase_name.c_str(), phrase_data.c_str(), phrase_lang.c_str(), &args);
+ JS_EXECUTE_LONG_RUNNING_C_CALL_WITH_UNLOCKER(switch_ivr_phrase_macro(this->_session, phrase_name.c_str(), phrase_data.c_str(), phrase_lang.c_str(), &args));
info.GetReturnValue().Set(cb_state.ret);
CheckHangupHook(this, &ret);
}
cb_state.session_state = this;
+ cb_state.context.Reset(info.GetIsolate(), info.GetIsolate()->GetCurrentContext());
dtmf_func = StreamInputCallback;
bp = &cb_state;
len = sizeof(cb_state);
args.input_callback = dtmf_func;
args.buf = bp;
args.buflen = len;
- switch_ivr_play_file(this->_session, &fh, file_name.c_str(), &args);
+ JS_EXECUTE_LONG_RUNNING_C_CALL_WITH_UNLOCKER(switch_ivr_play_file(this->_session, &fh, file_name.c_str(), &args));
info.GetReturnValue().Set(cb_state.ret);
switch_snprintf(posbuf, sizeof(posbuf), "%u", fh.offset_pos);
}
cb_state.session_state = this;
+ cb_state.context.Reset(info.GetIsolate(), info.GetIsolate()->GetCurrentContext());
dtmf_func = CollectInputCallback;
bp = &cb_state;
len = sizeof(cb_state);
args.input_callback = dtmf_func;
args.buf = bp;
args.buflen = len;
- switch_ivr_sleep(this->_session, ms, (switch_bool_t)sync, &args);
+ JS_EXECUTE_LONG_RUNNING_C_CALL_WITH_UNLOCKER(switch_ivr_sleep(this->_session, ms, (switch_bool_t)sync, &args));
info.GetReturnValue().Set(cb_state.ret);
CheckHangupHook(this, &ret);
}
cb_state.session_state = this;
+ cb_state.context.Reset(info.GetIsolate(), info.GetIsolate()->GetCurrentContext());
dtmf_func = CollectInputCallback;
bp = &cb_state;
len = sizeof(cb_state);
switch_core_speech_flush_tts(&this->_speech->sh);
if (switch_core_codec_ready(&this->_speech->codec)) {
this->_speech->speaking = 1;
- switch_ivr_speak_text_handle(this->_session, &this->_speech->sh, &this->_speech->codec, NULL, (char *)text, &args);
+ JS_EXECUTE_LONG_RUNNING_C_CALL_WITH_UNLOCKER(switch_ivr_speak_text_handle(this->_session, &this->_speech->sh, &this->_speech->codec, NULL, (char *)text, &args));
this->_speech->speaking = 0;
}
cb_state.session_obj_a.Reset(info.GetIsolate(), info.Holder());
cb_state.session_obj_b.Reset(info.GetIsolate(), obj_b);
cb_state.session_state = this;
+ cb_state.context.Reset(info.GetIsolate(), info.GetIsolate()->GetCurrentContext());
dtmf_func = CollectInputCallback;
bp = &cb_state;
}
}
- switch_ivr_multi_threaded_bridge(_session, jss_b->_session, dtmf_func, bp, bp);
+ JS_EXECUTE_LONG_RUNNING_C_CALL_WITH_UNLOCKER(switch_ivr_multi_threaded_bridge(_session, jss_b->_session, dtmf_func, bp, bp));
info.GetReturnValue().Set(true);
}