From 5ddcb3d67e0fa29fa402777202997e66b6d86642 Mon Sep 17 00:00:00 2001 From: Lorenzo Miniero Date: Tue, 25 Aug 2015 17:53:20 +0200 Subject: [PATCH] Better management of issue #312, new missed_call event in SIP plugin, and fixed missing registration_failed event handler in SIP demo --- html/siptest.js | 10 ++++++++++ plugins/janus_sip.c | 22 +++++++++++++++------- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/html/siptest.js b/html/siptest.js index d28742ae56..c94586c7d9 100644 --- a/html/siptest.js +++ b/html/siptest.js @@ -162,6 +162,16 @@ $(document).ready(function() { var result = msg["result"]; if(result !== null && result !== undefined && result["event"] !== undefined && result["event"] !== null) { var event = result["event"]; + if(event === 'registration_failed') { + console.log("Registration failed: " + result["code"] + " " + result["reason"]); + $('#server').removeAttr('disabled'); + $('#username').removeAttr('disabled'); + $('#password').removeAttr('disabled'); + $('#register').removeAttr('disabled').click(registerUsername); + $('#registerset').removeAttr('disabled'); + bootbox.alert(result["code"] + " " + result["reason"]); + return; + } if(event === 'registered') { console.log("Successfully registered as " + result["username"] + "!"); $('#you').removeClass('hide').show().text("Registered as '" + result["username"] + "'"); diff --git a/plugins/janus_sip.c b/plugins/janus_sip.c index fcc9e2c413..88e5349f79 100644 --- a/plugins/janus_sip.c +++ b/plugins/janus_sip.c @@ -1413,15 +1413,11 @@ void janus_sip_sofia_callback(nua_event_t event, int status, char const *phrase, tagi_t const *ti = tl_find(tags, nutag_callstate); enum nua_callstate callstate = ti ? ti->t_value : -1; /* There are several call states, but we only care about the terminated state - * in order to send the 'hangup' event. + * in order to send the 'hangup' event (assuming this is the right session, of course). * http://sofia-sip.sourceforge.net/refdocs/nua/nua__tag_8h.html#a516dc237722dc8ca4f4aa3524b2b444b */ - if(status == 486 && session->status != janus_sip_call_status_inviting) { - /* FIXME If it's a "busy" state, don't forward it if we're already in a call - * https://github.com/meetecho/janus-gateway/issues/312 */ - break; - } - if(callstate == nua_callstate_terminated) { + if(callstate == nua_callstate_terminated && + (session->stack->s_nh_i == nh || session->stack->s_nh_i == NULL)) { session->status = janus_sip_call_status_idle; json_t *call = json_object(); json_object_set_new(call, "sip", json_string("event")); @@ -1473,6 +1469,18 @@ void janus_sip_sofia_callback(nua_event_t event, int status, char const *phrase, /* Busy */ JANUS_LOG(LOG_VERB, "\tAlready in a call (busy, status=%s)\n", janus_sip_call_status_string(session->status)); nua_respond(nh, 486, sip_status_phrase(486), TAG_END()); + /* Notify the web app about the missed missed */ + json_t *missed = json_object(); + json_object_set_new(missed, "sip", json_string("event")); + json_t *result = json_object(); + json_object_set_new(result, "event", json_string("missed_call")); + json_object_set_new(result, "caller", json_string(url_as_string(session->stack->s_home, sip->sip_from->a_url))); + json_object_set_new(missed, "result", result); + char *missed_text = json_dumps(missed, JSON_INDENT(3) | JSON_PRESERVE_ORDER); + json_decref(missed); + JANUS_LOG(LOG_VERB, "Pushing event to peer: %s\n", missed_text); + int ret = gateway->push_event(session->handle, &janus_sip_plugin, session->transaction, missed_text, NULL, NULL); + JANUS_LOG(LOG_VERB, " >> %d (%s)\n", ret, janus_get_api_error(ret)); break; } session->callee = g_strdup(url_as_string(session->stack->s_home, sip->sip_from->a_url));