搭建webrtc视频服务rtcmulticonnection-server完整教程
1.ubuntu/centos服务器皆可
服务器版本选择较新稳定版本即可。ubuntu推荐16版本,centos推荐8.0版本。
2.该服务器要求有证书,无证书则nginx开个80的demo网站,使用certrbo生成证书
参考链接
https://www.bbsmax.com/A/6pdDb0wXJw/
3.可使用git安装或下载导入安装或wget等多种方式安装视频服务
git clone https://github.com/muaz-khan/RTCMultiConnection-Server.git ./
or 使用wget:
git clone https://github.com/muaz-khan/RTCMultiConnection-Server.git ./
or 使用npm:
npm install rtcmulticonnection-server
4.前提要先安装node,node/npm版本必须>8.0.
npm install
5.本地连接的客户端代码中,sokect.io > 3.0(因为socket.io 不支持3.0以上版本向2.X版本通信)
6.本服务默认开启https
7.上完整流程
1.创建和定位到服务目录,如kiven
mkdir /kiven && cd /kiven
2.安装程序可使用多种方式之一实现:使用git:
git clone https://github.com/muaz-khan/RTCMultiConnection-Server.git ./
npm install
3.定位到程序解压目录下的rtcmulticonnection-server下
cd rtcmulticonnection-server
npm install
4.我们需要对config.json server.js进行编辑
cd /kiven/node_modules/rtcmulticonnection-server
vi config.json
config.json内容:
{
"socketURL": "/",
"dirPath": "",
"homePage": "/demos/index.html",
"socketMessageEvent": "RTCMultiConnection-Message",
"socketCustomEvent": "RTCMultiConnection-Custom-Message",
"port": "443",
"enableLogs": "false",
"autoRebootServerOnFailure": "false",
"isUseHTTPs": "true",
"sslKey": "/etc/letsencrypt/live/v.rgeyes.com/privkey.pem",
"sslCert": "/etc/letsencrypt/live/v.rgeyes.com/fullchain.pem",
"sslCabundle": "",
"enableAdmin": "false",
"adminUserName": "kiven",
"adminPassword": "@WSX3edc"
}
说明:
port:视频服务的端口
autoRebootServerOnFailure:服务失败自动重启
isUseHTTPs:是否使用https证书
sslKey:cerbot生成的privkey.pem
sslCert:cerbot生成的fullchain.pem
5.修改 server.js,使其支持跨域
ioServer(httpApp, {
cors: {
origin: ['http://localhost:8080','https:/xxxxxx:4433','http://localhost:8081'],
credentials: true
}
}).on('connection', function(socket) {
RTCMultiConnectionServer.addSocket(socket, config);
// ----------------------
// below code is optional
const params = socket.handshake.query;
if (!params.socketCustomEvent) {
params.socketCustomEvent = 'custom-message';
}
socket.on(params.socketCustomEvent, function(message) {
socket.broadcast.emit(params.socketCustomEvent, message);
});
});
6.启动服务
cd
nohup node server.js &