Skip to content

Commit

Permalink
FCE-815: Rename peers to remotePeers in usePeers (#166)
Browse files Browse the repository at this point in the history
## Description

- Deprecated `peers` in place of `remotePeers` in `usePeers` hook. 

## Motivation and Context

- This change unifies hook API between mobile and web clients. 

## Types of changes

- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to
      not work as expected)
  • Loading branch information
MiloszFilimowski authored Nov 5, 2024
1 parent e081ef8 commit 4c83b5c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { CallToolbar } from "./CallToolbar";
import { nonNullablePredicate } from "@/lib/utils";

export const RoomView = () => {
const { localPeer, peers } = usePeers();
const { localPeer, remotePeers } = usePeers();

const trackAmount = [localPeer, ...peers]
const trackAmount = [localPeer, ...remotePeers]
.filter(nonNullablePredicate)
.reduce((acc, curr) => {
if (curr.cameraTrack) acc++;
Expand Down Expand Up @@ -46,7 +46,7 @@ export const RoomView = () => {
</>
)}

{peers.map(
{remotePeers.map(
({
id,
cameraTrack,
Expand Down
4 changes: 2 additions & 2 deletions examples/react-client/minimal-react/src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const App = () => {
const connect = useConnect();
const disconnect = useDisconnect();
const status = useStatus();
const { peers } = usePeers();
const { remotePeers } = usePeers();
const screenShare = useScreenShare();
const client = useFishjamClient_DO_NOT_USE();

Expand Down Expand Up @@ -67,7 +67,7 @@ export const App = () => {
</div>

{/* Render the video remote tracks from other peers*/}
{peers.map(({ id, cameraTrack, screenShareVideoTrack }) => {
{remotePeers.map(({ id, cameraTrack, screenShareVideoTrack }) => {
const camera = cameraTrack?.stream;
const screenShare = screenShareVideoTrack?.stream;

Expand Down
29 changes: 26 additions & 3 deletions packages/react-client/src/hooks/usePeers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,43 @@ function endpointToPeerState(
};
}

/**
* Result type for the usePeers hook.
*/
export type UsePeersResult = {
/**
* The local peer with distinguished tracks (camera, microphone, screen share).
* Will be null if the local peer is not found.
*/
localPeer: PeerWithTracks | null;

/**
* Array of remote peers with distinguished tracks (camera, microphone, screen share).
*/
remotePeers: PeerWithTracks[];

/**
* @deprecated Use remotePeers instead
* Legacy array containing remote peers.
* This property will be removed in future versions.
*/
peers: PeerWithTracks[];
};

/**
*
* @category Connection
*/
export function usePeers() {
export function usePeers(): UsePeersResult {
const { clientState } = useFishjamContext();

const localPeer = clientState.localPeer
? getPeerWithDistinguishedTracks(endpointToPeerState(clientState.localPeer))
: null;

const peers = Object.values(clientState.peers).map((peer) =>
const remotePeers = Object.values(clientState.peers).map((peer) =>
getPeerWithDistinguishedTracks(endpointToPeerState(peer)),
);

return { localPeer, peers };
return { localPeer, remotePeers, peers: remotePeers };
}

0 comments on commit 4c83b5c

Please sign in to comment.