This commit is contained in:
schlagmichdoch 2024-08-31 14:25:24 +02:00 committed by GitHub
commit 70f4ea06c9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 111 additions and 14 deletions

View file

@ -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();