OpenSIPS / opensips

OpenSIPS is a GPL implementation of a multi-functionality SIP Server that targets to deliver a high-level technical solution (performance, security and quality) to be used in professional SIP server platforms.
https://opensips.org
Other
1.28k stars 581 forks source link

Is it possible to t_relay to a websocket address #2946

Open truong-hua opened 2 years ago

truong-hua commented 2 years ago

I would like to leverage the media server of an existed SIP server while using OpenSIP as proxy in front of that SIP server. The problem is that seems like the SIP server detects websocket client by the inbound protocol so I expect that if OpenSIP can relay to the SIP server through ws or wss protocol, it will save our cost to deploy another rtpengine.

The SIP server already has their own Websocket gateway but the url has a path which is not able to pass to t_relay (Ex: wss://host:port/sipws). So is it possible to ask t_relay to relay the SIP message to wss:host:port/path.

truong-hua commented 2 years ago

Additionally, some websocket gateway may restrict access by some HTTP headers like Origin, so it would be great if we can also input HTTP headers to t_relay in case of destination is using websocket protocol.

razvancrainea commented 2 years ago

Yes, OpenSIPS can act as a WS/WSS client, but unfortunately tuning the path and other HTTP headers is currently not available in OpenSIPS. I will switch this ticket to a feature request and try to define some mechanisms to specify the information you asked for.

truong-hua commented 2 years ago

thank @razvancrainea OpenSIPS will more robust to act as a proxy with this feature.

truong-hua commented 1 year ago

@razvancrainea how about passing it to parameter of SIP uri like: wss:host:port;path=<path>;headers=<url_encoded_headers>. Regarding headers, it is not mandatory for my problem.

razvancrainea commented 1 year ago

I would try to avoid defining our own format of SIP URI - the standard way seems to be wss:host:port/path, but indeed, there is no place for headers here. But since it is not mandatory yet, we can leave that for later.

truong-hua commented 1 year ago

Yes @razvancrainea , with customizable path (not sure if HTTP GET parameters are available), people can use another reverse proxy nginx on the middle to have more complex relay logic.

truong-hua commented 1 year ago

Hi @razvancrainea, I have just checked the document and seem like SIP has supported headers inside the uri

uri-parameters    =  *( ";" uri-parameter)
uri-parameter     =  transport-param / user-param / method-param
                     / ttl-param / maddr-param / lr-param / other-param
transport-param   =  "transport="
                     ( "udp" / "tcp" / "sctp" / "tls"
                     / other-transport)
other-transport   =  token
user-param        =  "user=" ( "phone" / "ip" / other-user)
other-user        =  token
method-param      =  "method=" Method
ttl-param         =  "ttl=" ttl
maddr-param       =  "maddr=" host
lr-param          =  "lr"
other-param       =  pname [ "=" pvalue ]
pname             =  1*paramchar
pvalue            =  1*paramchar
paramchar         =  param-unreserved / unreserved / escaped
param-unreserved  =  "[" / "]" / "/" / ":" / "&" / "+" / "$"

headers         =  "?" header *( "&" header )
header          =  hname "=" hvalue
hname           =  1*( hnv-unreserved / unreserved / escaped )
hvalue          =  *( hnv-unreserved / unreserved / escaped )
hnv-unreserved  =  "[" / "]" / "/" / "?" / ":" / "+" / "$"

FYI, a attended REFER request usually use it by issuing a request to, for example: sip:09799xxxxx@171.x.x.x?Replaces=B2B.188.1910090.1677161952%3Bto-tag%3D3c2816ae47f9c3ce2228132fa9885159-daba%3Bfrom-tag%3Dmnar3e7koj