javascript - 我是否为 mediasoup 打开了错误的端口?
问题描述
它在本地主机上的 Chrome 下运行良好。(Firefox 存在问题,希望使用 HTTPS 远程运行会使问题消失。但这与这个问题无关。)
我使用 AWS 控制台打开了 readme.MD 上指定的端口(入站 TCP 到端口 3000,入站 UDP 到端口 40000-49999,允许所有传出流量。)
然后将 config.json 改编为:
module.exports = {
// http server ip, port, and peer timeout constant
//
httpIp: "0.0.0.0",
httpPort: 3000,
httpPeerStale: 15000,
// ssl certs. we'll start as http instead of https if we don't have
// these
sslCrt: "local.crt",
sslKey: "local.key",
mediasoup: {
worker: {
rtcMinPort: 40000,
rtcMaxPort: 49999,
logLevel: "debug",
logTags: [
"info",
"ice",
"dtls",
"rtp",
"srtp",
"rtcp",
// 'rtx',
// 'bwe',
// 'score',
// 'simulcast',
// 'svc'
],
},
router: {
mediaCodecs: [
{
kind: "audio",
mimeType: "audio/opus",
clockRate: 48000,
channels: 2,
},
{
kind: "video",
mimeType: "video/VP8",
clockRate: 90000,
parameters: {
// 'x-google-start-bitrate': 1000
},
},
{
kind: "video",
mimeType: "video/h264",
clockRate: 90000,
parameters: {
"packetization-mode": 1,
"profile-level-id": "4d0032",
"level-asymmetry-allowed": 1,
// 'x-google-start-bitrate' : 1000
},
},
{
kind: "video",
mimeType: "video/h264",
clockRate: 90000,
parameters: {
"packetization-mode": 1,
"profile-level-id": "42e01f",
"level-asymmetry-allowed": 1,
// 'x-google-start-bitrate' : 1000
},
},
],
},
// rtp listenIps are the most important thing, below. you'll need
// to set these appropriately for your network for the demo to
// run anywhere but on localhost
webRtcTransport: {
listenIps: [
{ ip: "172.3.-.-", announcedIp: "18.255.8.87" },
// { ip: "192.168.42.68", announcedIp: null },
// { ip: '10.10.23.101', announcedIp: null },
],
initialAvailableOutgoingBitrate: 800000,
},
},
};
(一段时间后,Chrome 的控制台显示mediasoup-client:Transport connection state changed to disconnected +17s
)
在我看来,好像我需要打开一两个额外的端口,但我不确定是哪一个。
我将非常感谢一些帮助。先感谢您... :)
解决方案
这是怎么回事?
listenIps: [
{ ip: "172.3.-.-", announcedIp: "18.255.8.87" },
尝试将您的 EC2 的公共 IP 放入ip
,并设置announcedIp
为 null。
或者,做我在这里所做的,因为我厌倦了摆弄 config.js 设置。
function getListenIps () {
const listenIps = []
if (typeof window === 'undefined') {
const os = require('os')
const networkInterfaces = os.networkInterfaces()
const ips = []
if (networkInterfaces) {
for (const [key, addresses] of Object.entries(networkInterfaces)) {
addresses.forEach(address => {
if (address.family === 'IPv4') {
listenIps.push({ ip: address.address, announcedIp: null })
}
/* ignore link-local and other special ipv6 addresses.
* https://www.iana.org/assignments/ipv6-address-space/ipv6-address-space.xhtml
*/
else if (address.family === 'IPv6'
&& address.address[0] !== 'f') {
listenIps.push({ ip: address.address, announcedIp: null })
}
})
}
}
}
if (listenIps.length === 0) {
listenIps.push({ ip: '127.0.0.1', announcedIp: null })
}
return listenIps
}
并且,请注意,WebRTC 可以在 mediasoup Web 服务器端口以外的端口上使用 TLS 连接。
推荐阅读
- json - 如何向来自 CloudWatch 代理的日志添加自定义项
- spring-boot - Spring Boot 不支持 hikari keepaliveTime 配置
- mysql - Laravel 自定义 belongsTo 动态绑定
- python - 如何根据我收到的错误消息更新数据库?
- javascript - 使用 Fetch 从后端 API 收集信息?
- python - 如何在 python 中为 RNN 设置初始拓扑?
- php - 产品在 php 数组中出现两次
- angular - 后端翻译在 SSR Spartacus 中不起作用
- node.js - 尝试用 Jest 模拟 SecretsManager 后“配置中缺少区域”
- google-apps-script - 在 Google App Script 中获取键/值对的值