diff --git a/src/include/switch_core_media.h b/src/include/switch_core_media.h index f8ab87a5d9..d6a35fae79 100644 --- a/src/include/switch_core_media.h +++ b/src/include/switch_core_media.h @@ -247,6 +247,7 @@ SWITCH_DECLARE(void) switch_core_media_check_outgoing_proxy(switch_core_session_ SWITCH_DECLARE(switch_status_t) switch_core_media_codec_chosen(switch_core_session_t *session, switch_media_type_t media); SWITCH_DECLARE (void) switch_core_media_recover_session(switch_core_session_t *session); SWITCH_DECLARE(switch_status_t) switch_core_media_add_ice_acl(switch_core_session_t *session, switch_media_type_t type, const char *acl_name); +SWITCH_DECLARE(void) switch_core_session_set_ice(switch_core_session_t *session); SWITCH_DECLARE(void) switch_core_media_init(void); SWITCH_DECLARE(void) switch_core_media_deinit(void); diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.c b/src/mod/endpoints/mod_sofia/mod_sofia.c index 8fb4b5d194..867e9ed272 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.c +++ b/src/mod/endpoints/mod_sofia/mod_sofia.c @@ -4142,6 +4142,13 @@ static switch_call_cause_t sofia_outgoing_channel(switch_core_session_t *session switch_channel_set_variable(nchannel, "rtp_secure_media", hval); } + if (!zstr(tech_pvt->dest) && switch_stristr("transport=ws", tech_pvt->dest)) { + switch_channel_set_variable(nchannel, "rtp_secure_media", SWITCH_RTP_CRYPTO_KEY_80); + switch_channel_set_variable(nchannel, "media_webrtc", "true"); + switch_core_session_set_ice(nsession); + } + + sofia_glue_attach_private(nsession, profile, tech_pvt, dest); if (tech_pvt->local_url) { diff --git a/src/mod/endpoints/mod_sofia/sofia_reg.c b/src/mod/endpoints/mod_sofia/sofia_reg.c index e7b1ae7560..f711d0eafa 100644 --- a/src/mod/endpoints/mod_sofia/sofia_reg.c +++ b/src/mod/endpoints/mod_sofia/sofia_reg.c @@ -1109,7 +1109,7 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand const char *agent = "unknown"; const char *pres_on_reg = NULL; int send_pres = 0; - int is_tls = 0, is_tcp = 0; + int is_tls = 0, is_tcp = 0, is_ws = 0; char expbuf[35] = ""; time_t reg_time = switch_epoch_time_now(NULL); @@ -1184,7 +1184,12 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand is_nat++; } - if (sip->sip_contact->m_url->url_type == url_sips) { + if (switch_stristr("transport=ws", sip->sip_contact->m_url->url_params)) { + is_nat++; + is_ws += 1; + } + + if (sip->sip_contact->m_url->url_type == url_sips && !switch_stristr("transport=ws", sip->sip_contact->m_url->url_params)) { proto = "sips"; is_tls += 2; is_nat++; @@ -1202,6 +1207,8 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand reg_desc = "Registered(TLS-NAT)"; } else if (is_tcp) { reg_desc = "Registered(TCP-NAT)"; + } else if (is_ws) { + reg_desc = "Registered(WS-NAT)"; } else { reg_desc = "Registered(UDP-NAT)"; } diff --git a/src/switch_core_media.c b/src/switch_core_media.c index 00ccd1dece..ea6eff193e 100644 --- a/src/switch_core_media.c +++ b/src/switch_core_media.c @@ -1828,7 +1828,8 @@ static void check_ice(switch_media_handle_t *smh, switch_media_type_t type, sdp_ } else if (!strcasecmp(attr->a_name, "candidate")) { if (!engine->cand_acl_count) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(smh->session), SWITCH_LOG_WARNING, "NO candidate ACL defined, skipping candidate check.\n"); + engine->cand_acl[engine->cand_acl_count++] = "wan.auto"; + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(smh->session), SWITCH_LOG_WARNING, "NO candidate ACL defined, Defaulting to wan.auto\n"); goto end; } @@ -1937,6 +1938,22 @@ static void check_ice(switch_media_handle_t *smh, switch_media_type_t type, sdp_ } +SWITCH_DECLARE(void) switch_core_session_set_ice(switch_core_session_t *session) +{ + switch_media_handle_t *smh; + + switch_assert(session); + + if (!(smh = session->media_handle)) { + return; + } + + switch_channel_set_flag(session->channel, CF_WEBRTC); + switch_channel_set_flag(session->channel, CF_ICE); + smh->mparams->rtcp_audio_interval_msec = "5000"; + smh->mparams->rtcp_video_interval_msec = "5000"; +} + //? SWITCH_DECLARE(uint8_t) switch_core_media_negotiate_sdp(switch_core_session_t *session, const char *r_sdp, uint8_t *proceed) { @@ -2129,10 +2146,7 @@ SWITCH_DECLARE(uint8_t) switch_core_media_negotiate_sdp(switch_core_session_t *s if (m->m_proto == sdp_proto_extended_srtp) { got_webrtc++; - switch_channel_set_flag(session->channel, CF_WEBRTC); - switch_channel_set_flag(session->channel, CF_ICE); - smh->mparams->rtcp_audio_interval_msec = "5000"; - smh->mparams->rtcp_video_interval_msec = "5000"; + switch_core_session_set_ice(session); } if (m->m_proto == sdp_proto_srtp || m->m_proto == sdp_proto_extended_srtp) { @@ -2397,7 +2411,7 @@ SWITCH_DECLARE(uint8_t) switch_core_media_negotiate_sdp(switch_core_session_t *s } if (zstr(map->rm_fmtp)) { - if (!strcasecmp(map->rm_encoding, "ilbc")) { + if (!strcasecmp(map->rm_encoding, "ilbc") || !strcasecmp(map->rm_encoding, "isac")) { codec_ms = 30; map_bit_rate = 13330; } @@ -2430,7 +2444,8 @@ SWITCH_DECLARE(uint8_t) switch_core_media_negotiate_sdp(switch_core_session_t *s match = strcasecmp(rm_encoding, imp->iananame) ? 0 : 1; } - if (match && bit_rate && map_bit_rate && map_bit_rate != bit_rate && strcasecmp(map->rm_encoding, "ilbc")) { + if (match && bit_rate && map_bit_rate && map_bit_rate != bit_rate && strcasecmp(map->rm_encoding, "ilbc") && + strcasecmp(map->rm_encoding, "isac")) { /* if a bit rate is specified and doesn't match, this is not a codec match, except for ILBC */ match = 0; } @@ -4175,7 +4190,7 @@ static void generate_m(switch_core_session_t *session, char *buf, size_t buflen, const switch_codec_implementation_t *imp = smh->codecs[i]; int this_ptime = (imp->microseconds_per_packet / 1000); - if (!strcasecmp(imp->iananame, "ilbc")) { + if (!strcasecmp(imp->iananame, "ilbc") || !strcasecmp(imp->iananame, "isac") ) { this_ptime = 20; } @@ -4230,7 +4245,7 @@ static void generate_m(switch_core_session_t *session, char *buf, size_t buflen, continue; } - if (!strcasecmp(imp->iananame, "ilbc")) { + if (!strcasecmp(imp->iananame, "ilbc") || !strcasecmp(imp->iananame, "isac")) { this_ptime = 20; } @@ -4841,10 +4856,11 @@ SWITCH_DECLARE(void) switch_core_media_gen_local_sdp(switch_core_session_t *sess } mult = switch_channel_get_variable(session->channel, "sdp_m_per_ptime"); + - if (mult && switch_false(mult)) { + if (switch_channel_test_flag(session->channel, CF_WEBRTC) || (mult && switch_false(mult))) { char *bp = buf; - int both = 1; + int both = switch_channel_test_flag(session->channel, CF_WEBRTC) ? 0 : 1; if ((!zstr(local_audio_crypto_key) && switch_channel_test_flag(session->channel, CF_SECURE))) { generate_m(session, buf, SDPBUFLEN, port, family, ip, 0, append_audio, sr, use_cng, cng_type, map, verbose_sdp, 1); @@ -4872,7 +4888,7 @@ SWITCH_DECLARE(void) switch_core_media_gen_local_sdp(switch_core_session_t *sess this_ptime = imp->microseconds_per_packet / 1000; - if (!strcasecmp(imp->iananame, "ilbc")) { + if (!strcasecmp(imp->iananame, "ilbc") && !strcasecmp(imp->iananame, "isac")) { this_ptime = 20; } @@ -6319,7 +6335,7 @@ static void add_audio_codec(sdp_rtpmap_t *map, int ptime, char *buf, switch_size } if (zstr(map->rm_fmtp)) { - if (!strcasecmp(map->rm_encoding, "ilbc")) { + if (!strcasecmp(map->rm_encoding, "ilbc") || !strcasecmp(map->rm_encoding, "isac")) { ptime = codec_ms = 30; map_bit_rate = 13330; }