我们原来基于Janus的webrtc系统基本上可用了,系统目前最高到5万人同时在线,不过确实发现Janus的一些不足,对于我这种喜欢c++的人来说,看Janus的代码实在是比较痛苦,于是处于研究目的,研究下Medooze,Mediasoup等,比较下来Medooze服务端不支持windows平台(因我一些原因我需要在windows 下搭建),Mediasoup的框架和代码风格看的最让人舒爽,易懂好维护,性能好,下面记录的是Mediasoup学习过程中碰到的一些坑。
其实主要因为对node不熟导致的坑,记一下,也许对同样的新学者有用,
错误一:npm install 错误
Error: Unknown platform: win32
at Object. (E:\code\mediasoup-demo\server\node_modules\clang-tools-prebuilt\install.js:24:33)
at Module._compile (internal/modules/cjs/loader.js:1158:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
at Module.load (internal/modules/cjs/loader.js:1002:32)
at Function.Module._load (internal/modules/cjs/loader.js:901:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
at internal/main/run_main_module.js:18:47
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules\clang-tools-prebuilt):
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] postinstall: `node install.js`
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: Exit status 1
这个google海外找也没找到解决方法,最后用 npm install --ignore-scripts 通过, 不知道有没有影响
错误二: npm start 错误提示:'DEBUG' 不是内部或外部命令,也不是可运行的程序
解决办法,改为如下方式启动:
set DEBUG=${DEBUG:='*mediasoup* *INFO* *WARN* *ERROR*'} INTERACTIVE=${INTERACTIVE:='true'}
node server.js
错误三:启动WEB APP错误:error Expected linebreaks to be 'LF' but found 'CRLF' linebreak-style
解决:修改.eslintrc.js 文件 'linebreak-style': [ 2, 'windows' ],
错误四:mediasoup throwing MediaSoupTypeError: invalid IP 'localhost'
解决:服务器端config.js配置问题,注意我只是本机测试
const os = require('os');
module.exports =
{
// Listening hostname (just for `gulp live` task).
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.
numWorkers : Object.keys(os.cpus()).length,
// 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 :
[
{
ip : '192.168.2.100',
announcedIp : null
}
],
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 :
{
ip : '192.168.2.100',
announcedIp : null
},
maxSctpMessageSize : 262144
}
}
};
其他对新学者可能有用的信息:
1. mediasoup使用ortc接口,用的不是目前webrtc那套sdp交换机制,虽然ortc说是webrtc的下一代接口,好几年前google就号称要支持ortc,但是目前也查不到chrome支持ortc的记录,倒是微软的edge曾经支持过ortc接口,所以用mediasoup的话,无论是web还是win,ios,android都要用mediasoup封装的客户端库