Make webrtc go through websocket

My asterisk server is in a restricted network that blocks UDP packets.

I am trying to run asterisk for webrtc clients according to the docs.
The client connects and can dial/receive calls however there is no sound, and it disconnects after 30seconds of no rtp stream timeout.

I enabled rtp debug on the asterisk server and noticed that asterisk is trying to send rtp directly to the webrtc client while I have already set direct_media=no in pjsip endpoint config file.

Is it possible to make webrtc to go through websocket and avoid making direct udp connections here?

There is not. You would need to do this outside of Asterisk, potentially using a TURN server with your WebRTC client.

I think you man RTP through the websocket, but RTP is UDP. If you really cannot have UDP, I think you would have to tunnel it though a TCP VPN.

Direct media refers to cases where the RTP bypasses the PABX, so doesn’t mean what I think you think it means.

In most cases, if you have the server on a network, where you’re supposed to run a server, you will be able to get the restrictions lifted for your server.

It sounds like you’re trying to circumvent a policy from either your ISP or company network depeartment. This is generally a cat and mouse game, and trying to work against the network admins, instead of WITH them, will never give you reliable service.

But you COULD setting up an RTP proxy externally on the public internet, then make the WebRTC client use that, and request audio from asterisk being sent to the same proxy server.

It would also require you to setup something to handle the session registration on the RTP Proxy server.

But the best solution would be to host the server on another, unrestricted, network, or work with the network admin, and get the traffic allowed.

Oof, I misread the initial post. Yeah - Asterisk needs open ports. My mind was in WebRTC client land, because that’s where the problem is generally. Running Asterisk in such an environment is rare / a bad idea.

I have enabled TURN for my webrtc client and it works fine now on the client side. The webrtc client can now connect to a test asterisk server that I have installed on the same VPS as coturn.

My original asterisk box,however, is behind NAT at home and it does not have a public IP. It uses mobile network to connect to my VPS and I forward the required ports from the public IP address of my VPS to this asterisk box.

This setup works fine with TCP however I have noticed UDP connections are unstable and frequently get blocked in the mobile networks that asterisk/clients use to connect to the VPS.

Shall I also set the asterisk to use a turn server in this case similar to the guide? Is it also helpful to use a stun server?

You could run a VPN between your home network and your VPS.

TCP has a static connection running, that keeps the NAT entry alive with the mobile provider.

For UDP you do not have an open connection running, instead when the NAT device see outbound UDP traffic, it set a timeout for the NAT entry, this timeout is usually reset whenever new traffic is seen on the connection, if no traffic is seen for a while, the NAT entry is removed, after which inbound traffic will be rejected.

Running a VoIP server in such an environment will be a maintenance headache. You would have a MUCH easier time, running Asterisk on the VPS instead of using the mobile connection for it.

If you MUST have an Asterisk server locally, you can setup another on the VPS that acts as a gateway from the outside world. Your local Asterisk server would register to the server running on the VPS, as a client, with a tuned keepalive setup, or frequent registrations, you can keep the connection alive, you can also setup the SIP connection using TCP.

Whenever you need an RTP stream, should “just work” as the NAT entry will be created on your initial RTP packet, allowing inbound traffic as well.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.