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