mirror of
https://github.com/amark/gun.git
synced 2025-06-05 21:56:51 +00:00
fix webrtc
This commit is contained in:
parent
eb313d6f65
commit
9a6495dc21
@ -221,7 +221,7 @@
|
||||
});
|
||||
function send(raw){
|
||||
if(!raw){ return }
|
||||
if(raw.indexOf('webrtc') >= 0){
|
||||
if(raw.indexOf('rtc') >= 0){
|
||||
if(!this._send){ return }
|
||||
return this._send(raw);
|
||||
}
|
||||
|
@ -31,16 +31,13 @@
|
||||
opt.rtc.dataChannel = opt.rtc.dataChannel || {ordered: false, maxRetransmits: 2};
|
||||
opt.rtc.sdp = opt.rtc.sdp || {mandatory: {OfferToReceiveAudio: false, OfferToReceiveVideo: false}};
|
||||
opt.announce = function(to){
|
||||
//setTimeout(function() {
|
||||
console.log('[WEBRTC] announce ', opt.pid, to);
|
||||
root.on('out', {rtc: {id: opt.pid, to:to}});
|
||||
// }, 1);
|
||||
}; // announce ourself
|
||||
root.on('out', {rtc: {id: opt.pid, to:to}}); // announce ourself
|
||||
};
|
||||
var mesh = opt.mesh = opt.mesh || Gun.Mesh(root);
|
||||
// root.on('create', function(at){
|
||||
// this.to.next(at);
|
||||
// setTimeout(function(){ root.on('out', {rtc: {id: opt.pid}}) },1); // announce ourself
|
||||
// });
|
||||
root.on('create', function(at){
|
||||
this.to.next(at);
|
||||
setTimeout(opt.announce, 1);
|
||||
});
|
||||
root.on('in', function(msg){
|
||||
if(msg.rtc){ open(msg) }
|
||||
this.to.next(msg);
|
||||
@ -51,30 +48,26 @@
|
||||
if(!rtc || !rtc.id){ return }
|
||||
delete opt.announce[rtc.id]; /// remove after connect
|
||||
if(tmp = rtc.answer){
|
||||
if(!(peer = opt.peers[rtc.id]) || peer.remoteSet){ return }
|
||||
if(!(peer = opt.peers[rtc.id] || open[rtc.id]) || peer.remoteSet){ return }
|
||||
return peer.setRemoteDescription(peer.remoteSet = new opt.RTCSessionDescription(tmp));
|
||||
}
|
||||
if(tmp = rtc.candidate){
|
||||
peer = opt.peers[rtc.id] || open({rtc: {id: rtc.id}});
|
||||
peer = opt.peers[rtc.id] || open[rtc.id] || open({rtc: {id: rtc.id}});
|
||||
return peer.addIceCandidate(new opt.RTCIceCandidate(tmp));
|
||||
}
|
||||
if(opt.peers[rtc.id]){ return }
|
||||
//if(opt.peers[rtc.id]){ return }
|
||||
if(open[rtc.id]){ return }
|
||||
(peer = new opt.RTCPeerConnection(opt.rtc)).id = rtc.id;
|
||||
var wire = peer.wire = peer.createDataChannel('dc', opt.rtc.dataChannel);
|
||||
mesh.hi(peer);
|
||||
open[rtc.id] = peer;
|
||||
wire.onclose = function(){
|
||||
delete open[rtc.id];
|
||||
mesh.bye(peer);
|
||||
peer.wire = null;
|
||||
//reconnect(peer);
|
||||
};
|
||||
wire.onerror = function(error){
|
||||
//reconnect(peer); // placement?
|
||||
if(!error){ return }
|
||||
if(error.code === 'ECONNREFUSED'){
|
||||
//reconnect(peer, as);
|
||||
}
|
||||
};
|
||||
wire.onerror = function(err){};
|
||||
wire.onopen = function(e){
|
||||
//delete open[rtc.id];
|
||||
mesh.hi(peer);
|
||||
}
|
||||
wire.onmessage = function(msg){
|
||||
|
Loading…
x
Reference in New Issue
Block a user