返回

webrtc RTCPeerConnection前端使用记录

发布时间:2023-02-08 10:51:55 276
# 前端# 后端# 数据# 信息

参考资料

​​https://developer.mozilla.org/zh-CN/docs/Web/API/RTCPeerConnection​​​​https://developer.mozilla.org/zh-CN/docs/Web/API/RTCPeerConnection#createdatachannel
https://developer.mozilla.org/zh-CN/docs/Web/API/RTCPeerConnection/createDataChannel
https://www.jianshu.com/p/4cce381994e2​​

问题

前后端进行非视频音频信息交互

createDataChannel
RTCDataChannel createDataChannel (DOMString label, optional RTCDataChannelInit dataChannelDict);

通过 peerconnection 建立一条数据信道,用于发送非视频音频信息。

例子

var pc = new PeerConnection();
var channel = pc.createDataChannel("Mydata");
channel.onopen = function(event) {
channel.send('sending a message');
}
channel.onmessage = function(event) { console.log(event.data); }

思考

前端使用的变量pc.createDataChannel失败,原因是交互的方式采用了websocket,并不是已有的链接

    this.sdp = '';
this.candidate = '';
let trace = this.trace;
try { if (this.pc) this.pc.close(); if (this.ws) this.ws.close(); } catch (e) {}
this.pc = null;
this.ws = new WebSocket(location.protocol.replace('http', 'ws') + '//' + location.host + '/?serv=' + this.serv + '&args=' + this.args);
特别声明:以上内容(图片及文字)均为互联网收集或者用户上传发布,本站仅提供信息存储服务!如有侵权或有涉及法律问题请联系我们。
举报
评论区(0)
按点赞数排序
用户头像
精选文章
thumb 中国研究员首次曝光美国国安局顶级后门—“方程式组织”
thumb 俄乌线上战争,网络攻击弥漫着数字硝烟
thumb 从网络安全角度了解俄罗斯入侵乌克兰的相关事件时间线
下一篇
软件测试 2023-02-08 10:12:55