There are several problems that need to be addressed in your kamailio.cfg but let me try to focus only on mediaprxoy-ng related ones.
First instead of engaging mediaproxy in failure route, engage it main route or branch route. Why wait for failure when we know call will fail anyway if you try to call webrtc to sip or vice versa.
Secondly you need to keep track of connection type of both caller and callee and set appropriate mediaproxy-ng flags according to call direction, e.g. call from webrtc to sip, or sip to webrtc or webrtc to webrtc or sip to sip, each type of call needs different set of flags for both rtpproxy_offer and rtpproxy_answer.
How you do this, is pretty simple, to detect if caller is webrtc endpoint you can use,
if ($avp(mline) =~ "SAVPF") {
# caller is a webrtc endpoint
};
To check if callee is a webrtc endpoint, you can use,
if ($(ru{uri.param,transport}) =~ "ws") {
# callee is a webrtc endpoint
};
For testing purpose, i recommend you only use mediaproxy-ng for bridging webrtc to sip or vice versa calls, i.e. if both endpoints are using same transport (e.g. sip to sip or webrtc to webrtc calls) then don't use mediaproxy-ng at all and allow endpoints to establish media directly (that would work out the box at least for webrtc to webrtc calls).
Finally use correct flags for each type of call (i recommend doing it in branch route), for example,
For WebRTC to SIP call use flags (case-sensitive),
$avp(rtpproxy_offer_flags) = "froc-sp";
$avp(rtpproxy_answer_flags) = "froc+SP";
rtpproxy_offer($avp(rtpproxy_offer_flags));
For SIP to WebRTC call use flags (case-sensitive),
$avp(rtpproxy_offer_flags) = "froc+SP";
$avp(rtpproxy_answer_flags) = "froc-sp";
rtpproxy_offer($avp(rtpproxy_offer_flags));
Then in reply route,
rtpproxy_answer($avp(rtpproxy_answer_flags));
Remember, currently mediaproxy-ng does NOT support SRTP/DTLS, which is required by firefox, so as result your webrtc endpoint MUST be running on Chrome.
Hope this helps.
Thank you.