Skip to content

Commit

Permalink
fix: fix useIOSAudioManagement audio tracking calculation (#178)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidliu authored Oct 9, 2024
1 parent a35b7ba commit 173a165
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 20 deletions.
4 changes: 2 additions & 2 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1201,7 +1201,7 @@ PODS:
- ReactCommon/turbomodule/core
- Yoga
- SocketRocket (0.7.0)
- WebRTC-SDK (125.6422.04)
- WebRTC-SDK (125.6422.05)
- Yoga (0.0.0)

DEPENDENCIES:
Expand Down Expand Up @@ -1461,7 +1461,7 @@ SPEC CHECKSUMS:
RNCAsyncStorage: 0c357f3156fcb16c8589ede67cc036330b6698ca
RNScreens: b32a9ff15bea7fcdbe5dff6477bc503f792b1208
SocketRocket: abac6f5de4d4d62d24e11868d7a2f427e0ef940d
WebRTC-SDK: c3d69a87e7185fad3568f6f3cff7c9ac5890acf3
WebRTC-SDK: 1990a1a595bd0b59c17485ce13ff17f575732c12
Yoga: ae3c32c514802d30f687a04a6a35b348506d411f

PODFILE CHECKSUM: 6fcbd8445e8602c6a7ab17fb1523c62772c821da
Expand Down
48 changes: 30 additions & 18 deletions src/audio/AudioManager.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { useState, useEffect, useMemo } from 'react';
import { Platform } from 'react-native';
import { RoomEvent, Room } from 'livekit-client';
import {
RoomEvent,
Room,
type LocalTrackPublication,
type RemoteTrackPublication,
} from 'livekit-client';
import AudioSession, {
getDefaultAppleAudioConfigurationForMode,
type AppleAudioConfiguration,
Expand Down Expand Up @@ -50,27 +55,35 @@ export function useIOSAudioManagement(
return () => {};
}

let onLocalPublished = () => {
setLocalTrackCount(localTrackCount + 1);
let onLocalPublished = (publication: LocalTrackPublication) => {
if (publication.kind === 'audio') {
setLocalTrackCount(localTrackCount + 1);
}
};
let onLocalUnpublished = () => {
if (localTrackCount - 1 < 0) {
log.warn(
'mismatched local audio track count! attempted to reduce track count below zero.'
);
let onLocalUnpublished = (publication: LocalTrackPublication) => {
if (publication.kind === 'audio') {
if (localTrackCount - 1 < 0) {
log.warn(
'mismatched local audio track count! attempted to reduce track count below zero.'
);
}
setLocalTrackCount(Math.max(localTrackCount - 1, 0));
}
setLocalTrackCount(Math.max(localTrackCount - 1, 0));
};
let onRemotePublished = () => {
setRemoteTrackCount(remoteTrackCount + 1);
let onRemotePublished = (publication: RemoteTrackPublication) => {
if (publication.kind === 'audio') {
setRemoteTrackCount(remoteTrackCount + 1);
}
};
let onRemoteUnpublished = () => {
if (remoteTrackCount - 1 < 0) {
log.warn(
'mismatched remote audio track count! attempted to reduce track count below zero.'
);
let onRemoteUnpublished = (publication: RemoteTrackPublication) => {
if (publication.kind === 'audio') {
if (remoteTrackCount - 1 < 0) {
log.warn(
'mismatched remote audio track count! attempted to reduce track count below zero.'
);
}
setRemoteTrackCount(Math.max(remoteTrackCount - 1, 0));
}
setRemoteTrackCount(Math.max(remoteTrackCount - 1, 0));
};

room
Expand Down Expand Up @@ -124,6 +137,5 @@ function getRemoteAudioTrackCount(room: Room): number {
room.remoteParticipants.forEach((participant) => {
audioTracks += participant.audioTrackPublications.size;
});

return audioTracks;
}

0 comments on commit 173a165

Please sign in to comment.