参考资料
https://developer.mozilla.org/zh-CN/docs/Web/API/RTCPeerConnectionhttps://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 = '';标签:Web,前端,pc,ws,createDataChannel,RTCPeerConnection,webrtc,channel From: https://blog.51cto.com/fengyuzaitu/6036046
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);