我正在编写一个Electron应用程序,在这个应用程序中,我需要与一些Node.js API进行交互 - 读取文件,获取目录条目,监听事件.
当然,我可以用编写JavaScript的方式编写ClojureScript,但是我想知道ClojureScripts对回调式API,流,EventEmitter采用什么,以及如何以不使用的方式编写有关node.js API的包装器.在ClojureScript中看起来很陌生.
再具体一点:
fs.readdir)有没有办法在已建立对等连接时创建数据通道?
这是我正在做的事情:
peerConnection.onstatechange = function(event){
var state = peerConnection.readyState;
console.log('state changed to : '+state);
if(state==='stable'){
console.log('connection is stable');
var dataChannel = peerConnection.createDataChannel('test',{reliable: false});
dataChannel.onopen = function(){
console.log('data channel opened');
dataChannel.send('hello data channel');
};
peerConnection.ondatachannel = function(event){
console.log('ondatachannel event fire ',event);
};
}
};
Run Code Online (Sandbox Code Playgroud)
它给了我以下输出:
state changed to : have-local-offer
state changed to : stable
connection is stable
Run Code Online (Sandbox Code Playgroud)
如何确保连接真正建立?我在这里发现stable状态等于active状态.
onopen 事件由于某种原因不会触发,所以我仍然不确定是否建立了连接.
如果您需要更多代码,请告诉我.
编辑:我添加了onnegotiationneeded事件处理程序,现在peerConnection.ondatachannel正在触发,但通道处于connecting状态