Hello Antony. This my customised cfg sample. After this you should call t_relay() func:
One thing - you should handle ACK messages for WS at loose_route. thomething like this:
if (is_request()) {
if (!has_totag()) {
if(t_is_branch_route()) {
add_rr_param(";nat=yes");
}
xlog("L_INFO","first {$rm}");
}
xlog("L_INFO","It Is request {$rm}");
if ($ru =~ "transport=ws"){
$var(received)=0;
#$var(to_uri)=$(ru{s.select,0,@});
sql_pvquery("ca","select received from location where contact like '$(ru{s.select,0,@})%'","$var(received)");
xlog("L_INFO","RECIEVED for {$rm} = {$var(received)}");
$du=$var(received);
}
}
It is very important because ACK message sends to UDP endpoint by default, so you should change $du for this packet, or your call will bend after few seconds (if WS socket picked up) with message "transaction does not exists". Because ACK messages will be send to UDP endpoint or nowere because contact field at location for WS endpoint have thomething like "dsfs353fwrf@ivalid.sddfsdg:transport=ws". Offcourse this will not be resolve. You need data from received field with right destination address.
there is main cfg
sql_query("ca", "select contact from location where username='$tU'", "ra");
xlog("rows: $dbr(ra=>rows) cols: $dbr(ra=>cols)\n");
if($dbr(ra=>rows)>0){
$var(i)=0;
while($var(i)<$dbr(ra=>rows)){
xlog("L_INFO","SQL query return contact {$dbr(ra=>[$var(i),0])} for {$tU} at step {$var(i)}\n");
if ($dbr(ra=>[$var(i),0])=~"transport=ws"){
xlog("L_INFO", "This is a Websocket call to endpoint");
sql_pvquery("ca", "select received from location where contact='$dbr(ra=>[$var(i),0])'","$var(recieved)");
$du=$var(recieved);
xlog("L_INFO","SQL query return recieved {$var(recieved)} for {$tU}. Destination is {$du}\n");
append_branch("sip:$tU@$(du{s.select,1,:})");
}
else
{
xlog("L_INFO", "This is a classic UDP call to endpoint");
$du="sip:"+$(dbr(ra=>[$var(i),0]){s.select,1,@});
$var(UDP_contact)="sip:"+$(dbr(ra=>[$var(i),0]){s.select,1,@});
append_branch("sip:$tU@$(du{s.select,1,:})");
xlog("L_INFO","Classic Destination URI is {$dbr(ra=>[$var(i),0])} for {$tU}}. Destination is {$du}\n");
}
$var(i) = $var(i) + 1;
}
}
t_on_branch("1");
return;
}
}
}
branch_route[1]{
if($du=~"transport=ws"){
xlog("L_INFO","Websocket Branch is {$du} for {$tU}\n");
rtpproxy_manage("froc+SP");
t_on_reply("REPLY_FROM_WS");
}
else{
xlog("L_INFO","UDP Branch is {$du)} for {$tU}\n");
rtpproxy_manage("co-sp");
t_on_reply("MANAGE_CLASSIC_REPLY");
}
}