-
Notifications
You must be signed in to change notification settings - Fork 270
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show connection information for each user
- Loading branch information
Showing
15 changed files
with
140 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { useState } from 'react' | ||
import type { User } from '~/types/Messages' | ||
import { cn } from '~/utils/style' | ||
import { Icon } from './Icon/Icon' | ||
import { Tooltip } from './Tooltip' | ||
|
||
export function ConnectionInformation(props: { user: User }) { | ||
const { inboundPacketLoss, outboundPacketLoss } = | ||
props.user.connectionInformation | ||
const [open, setOpen] = useState(false) | ||
|
||
const inbound = (inboundPacketLoss * 100).toFixed(2) | ||
const outbound = (outboundPacketLoss * 100).toFixed(2) | ||
|
||
const connectionGood = inboundPacketLoss <= 0.01 && outboundPacketLoss <= 0.01 | ||
const connectionUnstable = | ||
(inboundPacketLoss > 0.01 && inboundPacketLoss <= 0.03) || | ||
(outboundPacketLoss > 0.01 && outboundPacketLoss <= 0.03) | ||
const connectionBad = inboundPacketLoss > 0.03 || outboundPacketLoss > 0.03 | ||
|
||
return ( | ||
<Tooltip | ||
open={open} | ||
onOpenChange={setOpen} | ||
content={ | ||
<div className="text-gray-700 dark:text-gray-400"> | ||
<div>Packet Loss</div> | ||
<div className="flex gap-4"> | ||
<div className="flex items-center gap-1"> | ||
<div className="sr-only">Outbound</div> | ||
<Icon | ||
className="text-gray-400 dark:text-gray-300" | ||
type="ArrowUpOnSquareIcon" | ||
/> | ||
<span>{outbound}%</span> | ||
</div> | ||
<div className="flex items-center gap-1"> | ||
<div className="sr-only">Inbound</div> | ||
<Icon | ||
className="text-gray-400 dark:text-gray-300" | ||
type="ArrowDownOnSquareIcon" | ||
/> | ||
<span>{inbound}%</span> | ||
</div> | ||
</div> | ||
</div> | ||
} | ||
> | ||
<button className="flex items-center" onClick={() => setOpen(!open)}> | ||
<Icon | ||
className={cn( | ||
connectionGood && 'text-green-400', | ||
connectionUnstable && 'text-yellow-400', | ||
connectionBad && 'text-red-400' | ||
)} | ||
type={connectionBad ? 'SignalSlashIcon' : 'SignalIcon'} | ||
/> | ||
</button> | ||
</Tooltip> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { useMemo } from 'react' | ||
import { getPacketLossStats$ } from '~/utils/rxjs/getPacketLossStats$' | ||
import type { RxjsPeer } from '~/utils/rxjs/RxjsPeer.client' | ||
import { useSubscribedState } from './rxjsHooks' | ||
|
||
export function useConnectionStats(peer: RxjsPeer) { | ||
const stats$ = useMemo( | ||
() => getPacketLossStats$(peer.peerConnection$), | ||
[peer.peerConnection$] | ||
) | ||
const stats = useSubscribedState(stats$, { | ||
inboundPacketLossPercentage: 0, | ||
outboundPacketLossPercentage: 0, | ||
}) | ||
|
||
return stats | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters