mirror of
https://github.com/schlagmichdoch/PairDrop.git
synced 2025-06-16 03:05:19 -04:00
Merge 880e8bd195
into 50539ed485
This commit is contained in:
commit
70f4ea06c9
5 changed files with 111 additions and 14 deletions
|
@ -1147,6 +1147,33 @@ class RTCPeer extends Peer {
|
|||
);
|
||||
}
|
||||
|
||||
async _connectionType() {
|
||||
if (!this._conn) return "";
|
||||
|
||||
const stats = await this._conn.getStats(null);
|
||||
|
||||
let id;
|
||||
stats.forEach((report) => {
|
||||
if (report.type === "candidate-pair" && report.state === "succeeded") {
|
||||
id = report.localCandidateId;
|
||||
}
|
||||
});
|
||||
|
||||
if (!id) return "";
|
||||
|
||||
let connectionType;
|
||||
stats.forEach((report) => {
|
||||
if (report.id === id) {
|
||||
connectionType = report.candidateType;
|
||||
}
|
||||
});
|
||||
return connectionType;
|
||||
}
|
||||
|
||||
async _isTurn() {
|
||||
return await this._connectionType() === "relay";
|
||||
}
|
||||
|
||||
_messageChannelOpen() {
|
||||
return this._messageChannel && this._messageChannel.readyState === 'open';
|
||||
}
|
||||
|
@ -1276,13 +1303,13 @@ class RTCPeer extends Peer {
|
|||
return channel;
|
||||
}
|
||||
|
||||
_onChannelOpened(e) {
|
||||
async _onChannelOpened(e) {
|
||||
Logger.debug(`RTC: Channel ${e.target.label} opened with`, this._peerId);
|
||||
|
||||
// wait until all channels are open
|
||||
if (!this._stable()) return;
|
||||
|
||||
Events.fire('peer-connected', {peerId: this._peerId, connectionHash: this.getConnectionHash()});
|
||||
Events.fire('peer-connected', {peerId: this._peerId, connectionHash: this.getConnectionHash(), connectionType: await this._connectionType()});
|
||||
super._onPeerConnected();
|
||||
|
||||
this._sendPendingOutboundMessaged();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue