Merge remote-tracking branch 'origin/main' into bobbyd-status-bar
This commit is contained in:
@@ -78,7 +78,7 @@ export class PeerManager {
|
||||
return { first, second }
|
||||
}
|
||||
|
||||
getPeername(peerID:string) {
|
||||
getPeername(peerID: string) {
|
||||
let { first: adjective, second: snake } = this.funkyName(peerID, this.adjectives, this.snakes);
|
||||
let peername = `${adjective}_${snake}`
|
||||
return peername;
|
||||
@@ -293,7 +293,7 @@ export class PeerManager {
|
||||
let numActive = 0;
|
||||
|
||||
for (let [id, peer] of this.peers) {
|
||||
if (id === this.bootstrapPeerID ||
|
||||
if (/*id === this.bootstrapPeerID ||*/
|
||||
peer.rtcPeer?.connectionState === "new" ||
|
||||
peer.rtcPeer?.connectionState === "connecting"
|
||||
) {
|
||||
@@ -321,7 +321,7 @@ export class PeerManager {
|
||||
|
||||
let output = `Current status:` + "\n" + `[${logID(this.peerID)}]${this.getPeername(this.peerID)}[local]` + "\n";
|
||||
for (let [peerID, peer] of this.peers) {
|
||||
output += `[${logID(peerID)}]${peer.rtcPeer?.connectionState}:${this.getPeername(peerID)}${(peerID === this.bootstrapPeerID) ? "[Bootstrap]":""}` + "\n";
|
||||
output += `[${logID(peerID)}]${peer.rtcPeer?.connectionState}:${this.getPeername(peerID)}${(peerID === this.bootstrapPeerID) ? "[Bootstrap]" : ""}` + "\n";
|
||||
}
|
||||
|
||||
output += `numActivePeers: ${numActive}` + "\n";
|
||||
@@ -396,11 +396,11 @@ export class PeerManager {
|
||||
}
|
||||
}
|
||||
|
||||
onPeerDisconnected(remotePeerID: PeerID) {
|
||||
let deleted = this.peers.delete(remotePeerID);
|
||||
onPeerDisconnected(peerID: PeerID) {
|
||||
let deleted = this.peers.delete(peerID);
|
||||
|
||||
if (!deleted) {
|
||||
throw new Error(`Can't find peer that disconnected ${remotePeerID}`);
|
||||
throw new Error(`Can't find peer that disconnected ${peerID}`);
|
||||
}
|
||||
|
||||
// TODO: What do we do if we lose connection to the bootstrap peer?
|
||||
@@ -409,12 +409,14 @@ export class PeerManager {
|
||||
// We should disconnect from the websocket once we connect to our intial peers.
|
||||
|
||||
// If we have no peer connections, try to connect. If connection fails, start a timer to reconnect.
|
||||
if (remotePeerID === this.bootstrapPeerID) {
|
||||
if (peerID === this.bootstrapPeerID) {
|
||||
this.bootstrapPeerID = null;
|
||||
this.bootstrapPeerConnection = null;
|
||||
}
|
||||
|
||||
this.dispatchEvent(PeerEventTypes.PEER_DISCONNECTED, { peerID: remotePeerID });
|
||||
this.peerStateSuperlog && console.log.apply(null, log(`PeerManager: disconnected from peer ${peerID}`));
|
||||
|
||||
this.dispatchEvent(PeerEventTypes.PEER_DISCONNECTED, { peerID: peerID });
|
||||
|
||||
}
|
||||
|
||||
@@ -499,7 +501,7 @@ class PeerConnection {
|
||||
private ignoreOffer: boolean = false;
|
||||
private isSettingRemoteAnswerPending: boolean = false;
|
||||
private polite = true;
|
||||
private webRTCSuperlog = false;
|
||||
private webRTCSuperlog = true;
|
||||
private dataChannelSuperlog = false;
|
||||
private chunkSize = (16 * 1024) - 100;
|
||||
messageSuperlog: boolean = false;
|
||||
@@ -518,7 +520,7 @@ class PeerConnection {
|
||||
static config = {
|
||||
iceServers: [
|
||||
{ urls: "stun:ddln.app" },
|
||||
{ urls: "turn:ddln.app", username: "a", credential: "b" },
|
||||
// { urls: "turn:ddln.app", username: "a", credential: "b" },
|
||||
{ urls: "stun:stun.l.google.com" }, // keeping this for now as my STUN server is not returning ipv6
|
||||
{ urls: "stun:stun1.l.google.com" },
|
||||
{ urls: "stun:stun2.l.google.com" },
|
||||
@@ -649,9 +651,23 @@ class PeerConnection {
|
||||
// this.rtcPeer.onicecandidate = ({ candidate }) => this.signaler.send(JSON.stringify({ candidate }));
|
||||
// this.rtcPeer.onicecandidate = ({ candidate }) => console.log.apply(null, log(candidate);
|
||||
|
||||
this.rtcPeer.onicegatheringstatechange = (event) => {
|
||||
this.webRTCSuperlog && console.log.apply(null, log("onicegatheringstatechange:", this.rtcPeer?.iceGatheringState));
|
||||
|
||||
}
|
||||
|
||||
this.rtcPeer.oniceconnectionstatechange = (event:Event) => {
|
||||
this.webRTCSuperlog && console.log.apply(null, log("oniceconnectionstatechange:", this.rtcPeer?.iceConnectionState));
|
||||
|
||||
}
|
||||
|
||||
|
||||
this.rtcPeer.onicecandidateerror = (event: RTCPeerConnectionIceErrorEvent) => {
|
||||
this.webRTCSuperlog && console.log.apply(null, log(`onicecandidateerror: ${event.errorCode} ${event.errorText} ${event.address} ${event.url}`));
|
||||
}
|
||||
|
||||
this.rtcPeer.onicecandidate = ({ candidate }) => {
|
||||
this.webRTCSuperlog && console.log.apply(null, log(candidate));
|
||||
this.webRTCSuperlog && console.log.apply(null, log(`onicecandidate`, candidate));
|
||||
this.sendPeerMessage(this.remotePeerID, { type: "rtc_candidate", candidate: candidate });
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user