Skip to content

Commit c90fdf2

Browse files
committed
fix: fix useIOSAudioManagement audio tracking calculation
1 parent d142538 commit c90fdf2

File tree

2 files changed

+32
-20
lines changed

2 files changed

+32
-20
lines changed

example/ios/Podfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,7 +1201,7 @@ PODS:
12011201
- ReactCommon/turbomodule/core
12021202
- Yoga
12031203
- SocketRocket (0.7.0)
1204-
- WebRTC-SDK (125.6422.04)
1204+
- WebRTC-SDK (125.6422.05)
12051205
- Yoga (0.0.0)
12061206

12071207
DEPENDENCIES:
@@ -1461,7 +1461,7 @@ SPEC CHECKSUMS:
14611461
RNCAsyncStorage: 0c357f3156fcb16c8589ede67cc036330b6698ca
14621462
RNScreens: b32a9ff15bea7fcdbe5dff6477bc503f792b1208
14631463
SocketRocket: abac6f5de4d4d62d24e11868d7a2f427e0ef940d
1464-
WebRTC-SDK: c3d69a87e7185fad3568f6f3cff7c9ac5890acf3
1464+
WebRTC-SDK: 1990a1a595bd0b59c17485ce13ff17f575732c12
14651465
Yoga: ae3c32c514802d30f687a04a6a35b348506d411f
14661466

14671467
PODFILE CHECKSUM: 6fcbd8445e8602c6a7ab17fb1523c62772c821da

src/audio/AudioManager.ts

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import { useState, useEffect, useMemo } from 'react';
22
import { Platform } from 'react-native';
3-
import { RoomEvent, Room } from 'livekit-client';
3+
import {
4+
RoomEvent,
5+
Room,
6+
type LocalTrackPublication,
7+
type RemoteTrackPublication,
8+
} from 'livekit-client';
49
import AudioSession, {
510
getDefaultAppleAudioConfigurationForMode,
611
type AppleAudioConfiguration,
@@ -50,27 +55,35 @@ export function useIOSAudioManagement(
5055
return () => {};
5156
}
5257

53-
let onLocalPublished = () => {
54-
setLocalTrackCount(localTrackCount + 1);
58+
let onLocalPublished = (publication: LocalTrackPublication) => {
59+
if (publication.kind === 'audio') {
60+
setLocalTrackCount(localTrackCount + 1);
61+
}
5562
};
56-
let onLocalUnpublished = () => {
57-
if (localTrackCount - 1 < 0) {
58-
log.warn(
59-
'mismatched local audio track count! attempted to reduce track count below zero.'
60-
);
63+
let onLocalUnpublished = (publication: LocalTrackPublication) => {
64+
if (publication.kind === 'audio') {
65+
if (localTrackCount - 1 < 0) {
66+
log.warn(
67+
'mismatched local audio track count! attempted to reduce track count below zero.'
68+
);
69+
}
70+
setLocalTrackCount(Math.max(localTrackCount - 1, 0));
6171
}
62-
setLocalTrackCount(Math.max(localTrackCount - 1, 0));
6372
};
64-
let onRemotePublished = () => {
65-
setRemoteTrackCount(remoteTrackCount + 1);
73+
let onRemotePublished = (publication: RemoteTrackPublication) => {
74+
if (publication.kind === 'audio') {
75+
setRemoteTrackCount(remoteTrackCount + 1);
76+
}
6677
};
67-
let onRemoteUnpublished = () => {
68-
if (remoteTrackCount - 1 < 0) {
69-
log.warn(
70-
'mismatched remote audio track count! attempted to reduce track count below zero.'
71-
);
78+
let onRemoteUnpublished = (publication: RemoteTrackPublication) => {
79+
if (publication.kind === 'audio') {
80+
if (remoteTrackCount - 1 < 0) {
81+
log.warn(
82+
'mismatched remote audio track count! attempted to reduce track count below zero.'
83+
);
84+
}
85+
setRemoteTrackCount(Math.max(remoteTrackCount - 1, 0));
7286
}
73-
setRemoteTrackCount(Math.max(remoteTrackCount - 1, 0));
7487
};
7588

7689
room
@@ -124,6 +137,5 @@ function getRemoteAudioTrackCount(room: Room): number {
124137
room.remoteParticipants.forEach((participant) => {
125138
audioTracks += participant.audioTrackPublications.size;
126139
});
127-
128140
return audioTracks;
129141
}

0 commit comments

Comments
 (0)