开发app时,uniapp不支持推流RTCPeerConnection 中的WHIP协议推流。app难道没有h5强大?
// H5平台WebRTC实现
async startH5Push() {
const stream = await navigator.mediaDevices.getUserMedia({
video: { facingMode: 'environment' },
audio: true
});
const videoElement = document.getElementById('localVideo');
videoElement.srcObject = stream;
this.h5StreamActive = true;
// 创建PeerConnection
this.h5PeerConnection = new RTCPeerConnection({
iceServers: [{ urls: 'stun:stun.l.google.com:19302' }]
});
// 添加媒体轨道
stream.getTracks().forEach(track => {
this.h5PeerConnection.addTrack(track, stream);
});
// WHIP协议交互
const offer = await this.h5PeerConnection.createOffer();
await this.h5PeerConnection.setLocalDescription(offer);
const response = await fetch('https://www.8888.cn/push', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ sdp: offer.sdp })
});
if (!response.ok) throw new Error('SDP交换失败');
const answer = await response.json();
await this.h5PeerConnection.setRemoteDescription(answer);
},
uniapp推流各平台技术方案对比:
功能 H5方案 小程序方案 App方案
视频采集 WebRTC API live-pusher组件 ZEGO SDK // App端需安装ZEGO SDK:npm install zego-express-engine-webrtc , 然后登录 ZEGO 官网(https://www.zego.im/) 注册账号,根据自身实际业务需求选择场景,获取 AppID 与 AppSign,用于初始化 SDK。,感觉不太靠谱这个方案
推流协议 WHIP over HTTP RTMP 私有协议
分辨率控制 通过constraints设置 mode属性控制 SDK参数配置
延迟 200-800ms 1-3s 200-500ms
安装包体积 无增加 增加约200KB 增加约5MB
推荐场景 低延迟监控 直播带货 视频会议
以上代码码只是h5上有效。
0 个回复