mirror of
https://github.com/signalwire/freeswitch.git
synced 2026-11-10 11:50:53 +00:00
Add state change i/o hook to the core and change some spidermonkey behaviour.
The most important thing to check is you now must create a new session with a blank constructor:
s = new Session();
then call s.originate() with all the former args that were documented to be for the constructor
this will will return true or false to indicate if the call worked.
See below this sample code demonstrates all of the changes:
////////////////////////////////////////////////////////////////////////////////
function on_hangup(hup_session)
{
console_log("debug", "HANGUP!!!! name: " + hup_session.name + " cause: " + hup_session.cause + "\n");
//exit here would end the script so you could cleanup and just be done
//exit();
}
//set the on_hangup function to be called when this session is hungup
session.setHangupHook(on_hangup);
//allocate a new b_session
var b_session = new Session();
//make a call with b_session. If this fails, all we will be able to access is the b_session.cause attr
if (b_session.originate(session, "sofia/mydomain.com/888@conference.freeswitch.org")) {
//Inform the scripting engine to automaticly hang this session up when the script ends
b_session.setAutoHangup(true);
//set the on_hangup function to be called when this session is hungup
b_session.setHangupHook(on_hangup);
//bridge session with b_session
bridge(session, b_session);
} else {
console_log("debug", "Originate Failed.. cause: " + b_session.cause + "\n");
}
////////////////////////////////////////////////////////////////////////////////
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@4773 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
1 parent
f628a159af
commit
d9de1807ee
6 files changed
+369
-96
No files matched your search
+60
-17
@@ -185,7 +185,6 @@ static void switch_core_standard_on_hold(switch_core_session_t *session);
|
||||
/* The main runtime obj we keep this hidden for ourselves */
|
||||
static struct switch_core_runtime runtime;
|
||||
|
||||
|
||||
static void db_pick_path(char *dbname, char *buf, switch_size_t size)
|
||||
{
|
||||
|
||||
@@ -1835,20 +1834,22 @@ SWITCH_DECLARE(switch_call_cause_t) switch_core_session_outgoing_channel(switch_
|
||||
SWITCH_DECLARE(switch_status_t) switch_core_session_answer_channel(switch_core_session_t *session)
|
||||
{
|
||||
switch_io_event_hook_answer_channel_t *ptr;
|
||||
switch_status_t status = SWITCH_STATUS_FALSE;
|
||||
switch_status_t status = SWITCH_STATUS_SUCCESS;
|
||||
|
||||
assert(session != NULL);
|
||||
|
||||
if (session->endpoint_interface->io_routines->answer_channel) {
|
||||
if ((status = session->endpoint_interface->io_routines->answer_channel(session)) == SWITCH_STATUS_SUCCESS) {
|
||||
for (ptr = session->event_hooks.answer_channel; ptr; ptr = ptr->next) {
|
||||
if ((status = ptr->answer_channel(session)) != SWITCH_STATUS_SUCCESS) {
|
||||
break;
|
||||
}
|
||||
status = session->endpoint_interface->io_routines->answer_channel(session);
|
||||
}
|
||||
|
||||
if (status == SWITCH_STATUS_SUCCESS) {
|
||||
for (ptr = session->event_hooks.answer_channel; ptr; ptr = ptr->next) {
|
||||
if ((status = ptr->answer_channel(session)) != SWITCH_STATUS_SUCCESS) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
status = SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
return status;
|
||||
}
|
||||
@@ -1856,19 +1857,23 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_answer_channel(switch_core_s
|
||||
SWITCH_DECLARE(switch_status_t) switch_core_session_receive_message(switch_core_session_t *session, switch_core_session_message_t *message)
|
||||
{
|
||||
switch_io_event_hook_receive_message_t *ptr;
|
||||
switch_status_t status = SWITCH_STATUS_FALSE;
|
||||
switch_status_t status = SWITCH_STATUS_SUCCESS;
|
||||
|
||||
assert(session != NULL);
|
||||
|
||||
if (session->endpoint_interface->io_routines->receive_message) {
|
||||
if ((status =
|
||||
session->endpoint_interface->io_routines->receive_message(session, message)) == SWITCH_STATUS_SUCCESS) {
|
||||
for (ptr = session->event_hooks.receive_message; ptr; ptr = ptr->next) {
|
||||
if ((status = ptr->receive_message(session, message)) != SWITCH_STATUS_SUCCESS) {
|
||||
break;
|
||||
}
|
||||
status = session->endpoint_interface->io_routines->receive_message(session, message);
|
||||
|
||||
}
|
||||
|
||||
if (status == SWITCH_STATUS_SUCCESS) {
|
||||
for (ptr = session->event_hooks.receive_message; ptr; ptr = ptr->next) {
|
||||
if ((status = ptr->receive_message(session, message)) != SWITCH_STATUS_SUCCESS) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch_core_session_kill_channel(session, SWITCH_SIG_BREAK);
|
||||
return status;
|
||||
}
|
||||
@@ -2874,6 +2879,31 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_add_event_hook_answer_channe
|
||||
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_core_session_add_event_hook_state_change(switch_core_session_t *session,
|
||||
switch_answer_channel_hook_t state_change)
|
||||
|
||||
|
||||
{
|
||||
switch_io_event_hook_state_change_t *hook, *ptr;
|
||||
|
||||
assert(state_change != NULL);
|
||||
if ((hook = switch_core_session_alloc(session, sizeof(*hook))) != 0) {
|
||||
hook->state_change = state_change;
|
||||
if (!session->event_hooks.state_change) {
|
||||
session->event_hooks.state_change = hook;
|
||||
} else {
|
||||
for (ptr = session->event_hooks.state_change; ptr && ptr->next; ptr = ptr->next);
|
||||
ptr->next = hook;
|
||||
|
||||
}
|
||||
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
return SWITCH_STATUS_MEMERR;
|
||||
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_core_session_add_event_hook_read_frame(switch_core_session_t *session,
|
||||
switch_read_frame_hook_t read_frame)
|
||||
{
|
||||
@@ -3216,13 +3246,26 @@ static void switch_core_standard_on_hibernate(switch_core_session_t *session)
|
||||
|
||||
SWITCH_DECLARE(void) switch_core_session_signal_state_change(switch_core_session_t *session)
|
||||
{
|
||||
switch_status_t status = SWITCH_STATUS_SUCCESS;
|
||||
switch_io_event_hook_state_change_t *ptr;
|
||||
|
||||
/* If trylock fails the signal is already awake so we needn't bother */
|
||||
if (switch_mutex_trylock(session->mutex) == SWITCH_STATUS_SUCCESS) {
|
||||
switch_thread_cond_signal(session->cond);
|
||||
switch_mutex_unlock(session->mutex);
|
||||
}
|
||||
|
||||
|
||||
if (session->endpoint_interface->io_routines->state_change) {
|
||||
status = session->endpoint_interface->io_routines->state_change(session);
|
||||
}
|
||||
|
||||
if (status == SWITCH_STATUS_SUCCESS) {
|
||||
for (ptr = session->event_hooks.state_change; ptr; ptr = ptr->next) {
|
||||
if ((status = ptr->state_change(session)) != SWITCH_STATUS_SUCCESS) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(unsigned int) switch_core_session_running(switch_core_session_t *session)
|
||||
|
||||
Reference in new issue
Block a user