最初我部署在虚拟机里,发现两个浏览器端进入同一个房间,可以看到对方这个端,但是视频画面是默认图标,分辨率显示0x0。效果如下图:
不断排查,也怀疑过是不是虚拟机隔离或者防火墙的原因。在物理机Windows上部署了mediasoup-demo,还是一样,排除虚拟机隔离或者防火墙的原因。
(参考了:Windows搭建Nodejs【全网最详细】https://blog.csdn.net/weixin_43409994/article/details/124472220windows mediasoup-demo 公网部署 解决部署后无法看到对方的视频https://www.cnblogs.com/jiayouba/p/15232423.html)
最后发现,config.js里webRtcTransportOptions的ip,绝对不要填0.0.0.0和127.0.0.1。在mediasoup的文档里面原来是有写的,有很多文章说0.0.0.0可以用,但是最新版(到2022年2月9日)可能已经不行了。
搜索WebRtcTransportOptions查看表格下方蓝色边框的注释说明https://mediasoup.org/documentation/v3/mediasoup/api/#WorkerSettings而且127.0.0.1也不行,必须是一个真实网卡的IP地址,才能正常绑定。server起来之后,客户端或者网页如果跟server在一台机器,可以用127.0.0.1访问服务。
给出一个正确的config.js的示例
/**
* IMPORTANT (PLEASE READ THIS):
*
* This is not the "configuration file" of mediasoup. This is the configuration
* file of the mediasoup-demo app. mediasoup itself is a server-side library, it
* does not read any "configuration file". Instead it exposes an API. This demo
* application just reads settings from this file (once copied to config.js) and
* calls the mediasoup API with those settings when appropriate.
*/
const os = require('os');
module.exports =
{
// Listening hostname (just for `gulp live` task).
domain : process.env.DOMAIN || 'localhost',
// Signaling settings (protoo WebSocket server and HTTP API server).
https :
{
listenIp : '0.0.0.0',
// NOTE: Don't change listenPort (client app assumes 4443).
listenPort : process.env.PROTOO_LISTEN_PORT || 4443,
// NOTE: Set your own valid certificate files.
tls :
{
cert : process.env.HTTPS_CERT_FULLCHAIN || `${__dirname}/certs/fullchain.pem`,
key : process.env.HTTPS_CERT_PRIVKEY || `${__dirname}/certs/privkey.pem`
}
},
// mediasoup settings.
mediasoup :
{
// Number of mediasoup workers to launch. Object.keys(os.cpus()).length
numWorkers : 1,
// mediasoup WorkerSettings.
// See https://mediasoup.org/documentation/v3/mediasoup/api/#WorkerSettings
workerSettings :
{
logLevel : 'warn',
logTags :
[
'info',
'ice',
'dtls',
'rtp',
'srtp',
'rtcp',
'rtx',
'bwe',
'score',
'simulcast',
'svc',
'sctp'
],
rtcMinPort : process.env.MEDIASOUP_MIN_PORT || 40000,
rtcMaxPort : process.env.MEDIASOUP_MAX_PORT || 49999
},
// mediasoup Router options.
// See https://mediasoup.org/documentation/v3/mediasoup/api/#RouterOptions
routerOptions :
{
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/VP9',
clockRate : 90000,
parameters :
{
'profile-id' : 2,
'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
}
}
]
},
// mediasoup WebRtcTransport options for WebRTC endpoints (mediasoup-client,
// libmediasoupclient).
// See https://mediasoup.org/documentation/v3/mediasoup/api/#WebRtcTransportOptions
webRtcTransportOptions :
{
listenIps :
[
{
// '192.168.0.106'是内网IP,不能填0.0.0.0,在本机测试部署的时候也不能填127.0.0.1
ip : process.env.MEDIASOUP_LISTEN_IP || '192.168.0.106',
// 公网IP,目前没用到,看到有下面两种写法,可以自己尝试
// 1)announcedIp : '10.23.34.56'
// 2)announcedIp : process.env.MEDIASOUP_ANNOUNCED_IP || '10.23.34.56'
announcedIp : process.env.MEDIASOUP_ANNOUNCED_IP
}
],
initialAvailableOutgoingBitrate : 1000000,
minimumAvailableOutgoingBitrate : 600000,
maxSctpMessageSize : 262144,
// Additional options that are not part of WebRtcTransportOptions.
maxIncomingBitrate : 1500000
},
// mediasoup PlainTransport options for legacy RTP endpoints (FFmpeg,
// GStreamer).
// See https://mediasoup.org/documentation/v3/mediasoup/api/#PlainTransportOptions
plainTransportOptions :
{
listenIp :
{
// '192.168.0.106'是内网IP,不能填0.0.0.0,在本机测试部署的时候也不能填127.0.0.1
ip : process.env.MEDIASOUP_LISTEN_IP || '192.168.0.106',
announcedIp : process.env.MEDIASOUP_ANNOUNCED_IP
},
maxSctpMessageSize : 262144
}
}
};
|