英文:
Pion custom SFU server not working inside docker
问题
我按照这个示例进行了操作:https://github.com/pion/example-webrtc-applications/tree/master/sfu-ws
- 在本地环境中运行正常。
- 我进行了 Linux 构建,并将其放在服务器上,也正常工作。
- 我将其放入了一个 Docker 容器中,但是无法正常工作。
在 Docker 中,我打开了端口范围:
- 50000-50200:50000-50200/udp
以下是 Docker 配置文件的内容:
version: '3'
services:
app:
image: xxxx
container_name: web_preprod
ports:
- 127.0.0.1:8080:8080
- 127.0.0.1:6060:6060
- 50000-50200:50000-50200/udp
restart: on-failure
networks:
- xxxx
nginx:
image: nginx:latest
restart: always
container_name: nginx_preprod
command: "/bin/sh -c 'while :; do sleep 6h & wait $${!}; nginx -s reload; done & nginx -g \"daemon off;\"'"
ports:
- "80:80"
- "443:443"
- "6061:6061"
- "6062:6062"
networks:
- xxxx
volumes:
- /tmp:/tmp
- ./nginx.conf:/etc/nginx/nginx.conf
- ./data/certbot/conf:/etc/letsencrypt
- ./data/certbot/www:/var/www/certbot
depends_on:
- app
networks:
xxxx:
driver: bridge
端口 6061
用于测试,不安全。
在我的服务器上,我设置了相同的端口:
se := webrtc.SettingEngine{}
se.SetEphemeralUDPPortRange(50000, 50200)
WebRTCApi = webrtc.NewAPI(webrtc.WithMediaEngine(getPublisherMediaEngine()), webrtc.WithSettingEngine(se))
但是我无法在服务器或客户端上收到 onTrack
事件。
我注意到,在服务器上我收到了 PeerConnectionStateFailed
的状态。
我在客户端使用了 Google 的 STUN 服务器,并且使用了一个免费的 TURN 服务器:
var config = {
iceServers: [{
urls: "stun:stun1.l.google.com:19302"
},
{
urls: 'turn:numb.viagenie.ca:3478',
credential: 'xxxx',
username: 'xxxx@gmail.com'
}]
};
pc = new RTCPeerConnection(config);
如果你有任何想法,我将非常感激。
英文:
I followed this example: https://github.com/pion/example-webrtc-applications/tree/master/sfu-ws
-
on local is working
-
I made a linux build, I put it on a server, is working
-
I put it inside a docker container, it's not working anymore.
On docker I opened the port range:
-
50000-50200:50000-50200/udp
version: '3' services: app: image: xxxx container_name: web_preprod ports: - 127.0.0.1:8080:8080 - 127.0.0.1:6060:6060 - 50000-50200:50000-50200/udp restart: on-failure networks: - xxxx nginx: image: nginx:latest restart: always container_name: nginx_preprod command: "/bin/sh -c 'while :; do sleep 6h & wait $${!}; nginx -s reload; done & nginx -g \"daemon off;\"'" ports: - "80:80" - "443:443" - "6061:6061" - "6062:6062" networks: - xxxx volumes: - /tmp:/tmp - ./nginx.conf:/etc/nginx/nginx.conf - ./data/certbot/conf:/etc/letsencrypt - ./data/certbot/www:/var/www/certbot depends_on: - app networks: xxxx: driver: bridge
port 6061
is not secure, used for testing.
On my server I put the same ports to be used:
se := webrtc.SettingEngine{}
se.SetEphemeralUDPPortRange(50000, 50200)
WebRTCApi = webrtc.NewAPI(webrtc.WithMediaEngine(getPublisherMediaEngine()), webrtc.WithSettingEngine(se))
But I don't get onTrack
neither on the server or client.
What I saw, on server I receive
PeerConnectionStateFailed
I use google stun, and a free turn server on client
var config = {
iceServers: [{
urls: ["stun:stun1.l.google.com:19302"]
},
{
urls: 'turn:numb.viagenie.ca:3478',
credential: 'xxxx',
username: 'xxxx@gmail.com'
}
]
};
pc = new RTCPeerConnection(config)
If you have any ideas I will apreciate.
答案1
得分: 4
问题在于Pion(或任何WebRTC实现)只知道它正在侦听的IP地址。它无法知道所有映射/转发到它的地址。人们也称之为“公共IP”或“NAT映射”。因此,当Pion发出候选者时,它们可能看起来像10.10.0.*
,远程对等方将无法与其联系。
你应该使用SettingEngine并设置SetNat1To1IPs。如果你知道主机的公共IP,它将使用公共IP重写候选者。
ICE是一个棘手的过程。要在概念上理解它,WebRTC for the Curious#Networking可能会有所帮助。我会确保尽快回答任何关于SO的后续问题!
英文:
The issue is that Pion (or any WebRTC implementation) is only aware of IP address it is listening on. It can't be aware of all the address that map/forward to it. People will also call this the Public IP
or NAT Mapping
. So when Pion emits it candidates they will probably look like 10.10.0.*
and the remote peer will be unable to contact that.
What you should do is use the SettingEngine and set SetNat1To1IPs. If you know the public IP of the host it will rewrite the candidates with the public IP.
ICE is a tricky process. To understand it conceptually WebRTC for the Curious#Networking may be helpful. Will make sure to answer any follow up questions on SO quickly!
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论