Skip to content

Commit

Permalink
use JS SDK's isLocal check (#1050)
Browse files Browse the repository at this point in the history
Co-authored-by: lukasIO <[email protected]>
  • Loading branch information
davidzhao and lukasIO authored Dec 14, 2024
1 parent 207ce97 commit ebe78fb
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
6 changes: 6 additions & 0 deletions .changeset/wise-ghosts-talk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@livekit/components-core": patch
"@livekit/components-react": patch
---

use JS SDK's isLocal check
7 changes: 3 additions & 4 deletions packages/core/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import type { Participant, TrackPublication } from 'livekit-client';
import { LocalParticipant, RemoteParticipant } from 'livekit-client';

import type { PinState } from './types';
import type { TrackReference } from './track-reference';
import { isEqualTrackRef } from './track-reference';
import type { PinState } from './types';

export function isLocal(p: Participant) {
return p instanceof LocalParticipant;
return p.isLocal;
}

export function isRemote(p: Participant) {
return p instanceof RemoteParticipant;
return !p.isLocal;
}

export const attachIfSubscribed = (
Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/components/RoomAudioRenderer.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getTrackReferenceId, isLocal } from '@livekit/components-core';
import { getTrackReferenceId } from '@livekit/components-core';
import { Track } from 'livekit-client';
import * as React from 'react';
import { useTracks } from '../hooks';
Expand Down Expand Up @@ -36,7 +36,7 @@ export function RoomAudioRenderer({ volume, muted }: RoomAudioRendererProps) {
updateOnlyOn: [],
onlySubscribed: true,
},
).filter((ref) => !isLocal(ref.participant) && ref.publication.kind === Track.Kind.Audio);
).filter((ref) => !ref.participant.isLocal && ref.publication.kind === Track.Kind.Audio);

return (
<div style={{ display: 'none' }}>
Expand Down
10 changes: 7 additions & 3 deletions packages/react/src/hooks/useMediaTrackBySourceOrName.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import type { TrackIdentifier } from '@livekit/components-core';
import { isTrackReference } from '@livekit/components-core';
import { setupMediaTrack, log, isLocal, getTrackByIdentifier } from '@livekit/components-core';
import {
getTrackByIdentifier,
isTrackReference,
log,
setupMediaTrack,
} from '@livekit/components-core';
import * as React from 'react';
import { mergeProps } from '../utils';

Expand Down Expand Up @@ -52,7 +56,7 @@ export function useMediaTrackBySourceOrName(
}
if (
options.element?.current &&
!(isLocal(observerOptions.participant) && track?.kind === 'audio')
!(observerOptions.participant.isLocal && track?.kind === 'audio')
) {
track.attach(options.element.current);
}
Expand Down

0 comments on commit ebe78fb

Please sign in to comment.