Add TURN indicator to PeerUI and add method to RTCPeer to get the connection type of the webrtc connection. If connection type is relay show TURN indicator

This commit is contained in:
schlagmichdoch 2024-02-20 18:04:53 +01:00
parent 5a56251ee3
commit 880e8bd195
5 changed files with 90 additions and 8 deletions

View file

@ -1029,6 +1029,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';
}
@ -1158,13 +1185,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();