搭建SRS推流服务器[webRTC]

https://github.com/ossrs/srs 

 

目前SRS对WebRTC的支持进度如下:

  • SRS4.0.14,支持了RTMP推流,WebRTC播放。
  • SRS4.0.76,支持了WebRTC推流,WebRTC播放。
  • 开发中,WebRTC推流,RTMP播放。

相关Wiki(会在开发完成后完善):


 https://www.jianshu.com/p/acb4f2af44b5

下载代码:

wget https://github.com/ossrs/srs/archive/v4.0.76.tar.gz

 tar -zxvf srs-4.0.76.tar.gz

cd  /usr/local/srs-4.0.76/trunk

 ./configure --with-hls --with-ssl --with-http-server --with-http-callback --with-http-api --with-ingest --with-stream-caster && make

./objs -c conf/rtc.conf

推流地址:

 

rtmp://192.168.12.187:1935/live/1

 

拉流地址:

rtmp://10.130.24.200/live/1

下面是一个使用WebRTC将视频流推送到SRS流媒体服务器的示例代码。请注意,此示例仅涵盖WebRTCSRS之间的连接,不包括WebRTC的SDP交换和媒体协商。 ```javascript // 创建WebRTC连接 const peerConnection = new RTCPeerConnection(); // 添加本地媒体流 navigator.mediaDevices.getUserMedia({ video: true, audio: true }) .then((stream) => { stream.getTracks().forEach((track) => { peerConnection.addTrack(track, stream); }); }); // 创建SRS推流对象 const srsPublish = new SrsPublish('rtmp://127.0.0.1:1935/live/app/stream'); // 监听WebRTC连接的ICE候选事件 peerConnection.addEventListener('icecandidate', (event) => { if (event.candidate) { // 将ICE候选发送到SRS服务器 srsPublish.sendIceCandidate(event.candidate); } }); // 监听SRS连接成功事件 srsPublish.addEventListener('connected', () => { // 创建SDP offer并将其设置为本地描述 peerConnection.createOffer() .then((offer) => { return peerConnection.setLocalDescription(offer); }) .then(() => { // 将SDP offer发送到SRS服务器 srsPublish.sendSdpOffer(peerConnection.localDescription); }); }); // 监听SRS收到远程SDP answer事件 srsPublish.addEventListener('remoteSdpAnswer', (answer) => { // 将远程SDP answer设置为远程描述 peerConnection.setRemoteDescription(answer); }); // 监听SRS收到ICE候选事件 srsPublish.addEventListener('remoteIceCandidate', (candidate) => { // 添加远程ICE候选到WebRTC连接 peerConnection.addIceCandidate(candidate); }); // 开始推流 srsPublish.start(); ``` 在上面的示例代码中,`SrsPublish`类是一个自定义类,用于向SRS服务器推送视频流。它包含以下方法: - `start()`:开始推流。 - `sendSdpOffer(offer)`:向SRS服务器发送SDP offer。 - `sendIceCandidate(candidate)`:向SRS服务器发送ICE候选。 - `addEventListener(eventType, listener)`:添加事件监听器。 - `removeEventListener(eventType, listener)`:删除事件监听器。 你需要根据自己的需求实现这个类,以确保它能够正确地将视频流推送到SRS服务器
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值