Skip to content
This repository has been archived by the owner on Mar 1, 2024. It is now read-only.

Add TCP+Relay detection event #485

Merged
merged 22 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
8b5bbd8
Change the label for the remote candidate
david-macpherson Feb 13, 2024
daff998
Added the following missing properties id,timestamp,type,lastPacketRe…
david-macpherson Feb 13, 2024
5542d91
Added relayProtocol and transport ID to the candidate Stat
david-macpherson Feb 13, 2024
1be9ed5
Added relayProtocol and transport ID to the candidate Stat
david-macpherson Feb 13, 2024
03ee5b6
Set the parsed candidate pair stat to the nominated and selected pair
david-macpherson Feb 13, 2024
7d97eb1
Implemeneted a stream waring event
david-macpherson Feb 14, 2024
f05ce78
Implemented the emitting of the stream warning event when if the loca…
david-macpherson Feb 14, 2024
5b9f8b0
Fixed up styling
david-macpherson Feb 14, 2024
1b8e9c3
Refactored the candidate pair to an array, Implemneted a helper funct…
david-macpherson Feb 15, 2024
86fbdb2
Refactored to use Array.find
david-macpherson Feb 15, 2024
0e89638
Replaced the stream warning event with WebRtcTCPRelayDetectedEvent
david-macpherson Feb 15, 2024
bdf41af
Implemeneted the WebRtcTCPRelayDetectedEvent to dispatch if the web r…
david-macpherson Feb 15, 2024
55d02d6
Refactored the stats panel to use the getActiveCandidatePair
david-macpherson Feb 15, 2024
fb6bf16
Refactored the webrtc tcp detect check to act on an event instead of …
david-macpherson Feb 15, 2024
533d88a
Refactored the getting of the active candidate pair to be stored as a…
david-macpherson Feb 15, 2024
9d26239
Updated the candidate pair to the candidate pairs array
david-macpherson Feb 15, 2024
7eab39d
Added a warning if the stream is relayed over tcp
david-macpherson Feb 15, 2024
51babfd
Moved the logic for emitting the webrtc tcp relay detect event to it'…
david-macpherson Feb 15, 2024
d00bf75
Refactored the binding of the stats recieved event to the setup web r…
david-macpherson Feb 16, 2024
8567df6
Removed un needed new lines
david-macpherson Feb 16, 2024
15ed4ad
Added a check if the get active candidate is null to return a new can…
david-macpherson Feb 16, 2024
ad24cc9
Reverted the refactor the binding of the stats recieved event function
david-macpherson Feb 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions Frontend/library/src/PeerConnectionController/AggregatedStats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,10 @@ export class AggregatedStats {
* @param stat - the stats coming in from ice candidates
*/
handleCandidatePair(stat: CandidatePairStats) {
this.candidatePair.bytesReceived = stat.bytesReceived;
this.candidatePair.bytesSent = stat.bytesSent;
this.candidatePair.localCandidateId = stat.localCandidateId;
this.candidatePair.remoteCandidateId = stat.remoteCandidateId;
this.candidatePair.nominated = stat.nominated;
this.candidatePair.readable = stat.readable;
this.candidatePair.selected = stat.selected;
this.candidatePair.writable = stat.writable;
this.candidatePair.state = stat.state;
this.candidatePair.currentRoundTripTime = stat.currentRoundTripTime;
// If the candidate pair has received bytes then set as the candidate pair
if (stat.bytesReceived > 0){
lukehb marked this conversation as resolved.
Show resolved Hide resolved
this.candidatePair = stat;
}
}

/**
Expand Down Expand Up @@ -162,6 +156,8 @@ export class AggregatedStats {
localCandidate.protocol = stat.protocol;
localCandidate.candidateType = stat.candidateType;
localCandidate.id = stat.id;
localCandidate.relayProtocol = stat.relayProtocol;
localCandidate.transportId = stat.transportId;
this.localCandidates.push(localCandidate);
}

Expand All @@ -171,12 +167,14 @@ export class AggregatedStats {
*/
handleRemoteCandidate(stat: CandidateStat) {
const RemoteCandidate = new CandidateStat();
RemoteCandidate.label = 'local-candidate';
RemoteCandidate.label = 'remote-candidate';
RemoteCandidate.address = stat.address;
RemoteCandidate.port = stat.port;
RemoteCandidate.protocol = stat.protocol;
RemoteCandidate.id = stat.id;
RemoteCandidate.candidateType = stat.candidateType;
RemoteCandidate.relayProtocol = stat.relayProtocol;
RemoteCandidate.transportId = stat.transportId
this.remoteCandidates.push(RemoteCandidate);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,19 @@
export class CandidatePairStats {
bytesReceived: number;
bytesSent: number;
currentRoundTripTime: number;
id: string;
lastPacketReceivedTimestamp: number;
lastPacketSentTimestamp: number;
localCandidateId: string;
remoteCandidateId: string;
nominated: boolean;
priority: number;
readable: boolean;
writable: boolean;
remoteCandidateId: string;
selected: boolean;
state: string;
currentRoundTripTime: number;
timestamp: number;
transportId: string;
type: string;
writable: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
* ICE Candidate Stat collected from the RTC Stats Report
*/
export class CandidateStat {
label: string;
id: string;
address: string;
candidateType: string;
id: string;
label: string;
port: number;
protocol: 'tcp' | 'udp';
relayProtocol: 'tcp' | 'udp' | 'tls';
transportId: string;
}
25 changes: 25 additions & 0 deletions Frontend/library/src/PixelStreaming/PixelStreaming.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
StreamPreConnectEvent,
StreamReconnectEvent,
StreamPreDisconnectEvent,
StreamWarningEvent,
lukehb marked this conversation as resolved.
Show resolved Hide resolved
VideoEncoderAvgQPEvent,
VideoInitializedEvent,
WebRtcAutoConnectEvent,
Expand Down Expand Up @@ -533,6 +534,30 @@ export class PixelStreaming {
this._eventEmitter.dispatchEvent(
new StatsReceivedEvent({ aggregatedStats: videoStats })
);

lukehb marked this conversation as resolved.
Show resolved Hide resolved
// Get the local candidate from the candidate pair
let localSelectedCandidate = videoStats.localCandidates.find((candid) => {
return candid.id == videoStats.candidatePair.localCandidateId
})

// Check if the local candidate is relaying over TCP
if (localSelectedCandidate.candidateType == 'relay' && localSelectedCandidate.relayProtocol == 'tcp'){

// Send a warning to the logger informing the user the stream will be severely degraded
Logger.Warning(
lukehb marked this conversation as resolved.
Show resolved Hide resolved
Logger.GetStackTrace(),
`Stream quality severely degraded, local connection is relayed over TCP due to the local network environment.`
);

// Emit a stream warning event
this._eventEmitter.dispatchEvent(
new StreamWarningEvent({
lukehb marked this conversation as resolved.
Show resolved Hide resolved
candidateType: localSelectedCandidate.candidateType,
protocol: localSelectedCandidate.protocol,
relayProtocol: localSelectedCandidate.relayProtocol,
})
);
}
}

/**
Expand Down
18 changes: 18 additions & 0 deletions Frontend/library/src/Util/EventEmitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,23 @@ export class PlayerCountEvent extends Event {
}
}

/**
* An event that is emitted when the stream quality is degraded due to local network environment.
*/
export class StreamWarningEvent extends Event {
lukehb marked this conversation as resolved.
Show resolved Hide resolved
readonly type: 'streamWarning';
readonly data: {
/** stream warning event */
protocol: 'tcp' | 'udp'
relayProtocol: 'tcp' | 'udp' | 'tls'
candidateType: string
};
constructor(data: StreamWarningEvent['data']) {
super('streamWarning');
this.data = data;
}
}

export type PixelStreamingEvent =
| AfkWarningActivateEvent
| AfkWarningUpdateEvent
Expand All @@ -557,6 +574,7 @@ export type PixelStreamingEvent =
| StreamPreConnectEvent
| StreamReconnectEvent
| StreamPreDisconnectEvent
| StreamWarningEvent
| PlayStreamErrorEvent
| PlayStreamEvent
| PlayStreamRejectedEvent
Expand Down
Loading