metaRTC5.0实现webrtc的TURN支持
概述
音視頻通信時為了節省服務器帶寬,通信效率最好的就是p2p,但是在現實的應用場景中,我們的客戶端都是在大局域網內部的,stun協議就是要解決如何穿透這些局域網實現p2p。但在有些網絡中不支持穿透就需要使用TURN或者SFU進行轉發。
metaRTC5.0新版實現對TURN支持。metaRTC5.0提供有metaRTC客戶端和瀏覽器TURN的demo。
源碼下載
GitHub - metartc/metaRTC: A cross-platform WebRTC SDKA cross-platform WebRTC SDK. Contribute to metartc/metaRTC development by creating an account on GitHub.https://github.com/metartc/metaRTCmetaRTC: metaRTC為純C版本的webrtc 可與谷歌webrtc類庫互通,支持Webrtc/SRT/RTMPhttps://gitee.com/metartc/metaRTC
瀏覽器TURN
如果瀏覽器使用turn,如ipc等客戶端則不需要配置
在metaipc5_html中js/srs.sdk.p2p.js文件中,用下面代碼替換280行代碼
const config = {bundlePolicy: 'balanced',// certificates?: RTCCertificate[];// iceCandidatePoolSize?: number;iceTransportPolicy: "relay",// allrtcpMuxPolicy : 'negotiate',iceServers: [{urls: "turn:192.168.1.102:3478",username: "metartc",credential: "metartc"}]};self.pc = new RTCPeerConnection(config);metaRTC Turn配置
配置文件yang_config.ini中
?iceCandidateType參數可以在配置文件中配置,也可以在程序中賦值。
typedef enum{YangIceHost,YangIceStun,YangIceTurn }YangIceCandidateType;配置參數后metaRTC會根據參數進行ice處理。
coturn配置
編輯配置文件/etc/turnserver.conf
# Uncomment if extra security is desired, # with nonce value having a limited lifetime. # The nonce value is unique for a session. # Set this option to limit the nonce lifetime. # Set it to 0 for unlimited lifetime. # It defaults to 600 secs (10 min) if no value is provided. After that delay, # the client will get 438 error and will have to re-authenticate itself.去掉#stale-nonce=600注釋 改為 stale-nonce = 0 #設置用戶名密碼 user=username2:password2 user=metartc:metartc #設置realm realm=metartc.cn #設置偵聽端口,默認為3478 listening-port=3478總結
以上是生活随笔為你收集整理的metaRTC5.0实现webrtc的TURN支持的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 斐讯k2路由虚拟服务器,斐讯K2P不死u
- 下一篇: 苹果cms内核H5网页漫画小说系统