|
1 | 1 | import { useState, useEffect, useMemo } from 'react'; |
2 | 2 | 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'; |
4 | 9 | import AudioSession, { |
5 | 10 | getDefaultAppleAudioConfigurationForMode, |
6 | 11 | type AppleAudioConfiguration, |
@@ -50,27 +55,35 @@ export function useIOSAudioManagement( |
50 | 55 | return () => {}; |
51 | 56 | } |
52 | 57 |
|
53 | | - let onLocalPublished = () => { |
54 | | - setLocalTrackCount(localTrackCount + 1); |
| 58 | + let onLocalPublished = (publication: LocalTrackPublication) => { |
| 59 | + if (publication.kind === 'audio') { |
| 60 | + setLocalTrackCount(localTrackCount + 1); |
| 61 | + } |
55 | 62 | }; |
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)); |
61 | 71 | } |
62 | | - setLocalTrackCount(Math.max(localTrackCount - 1, 0)); |
63 | 72 | }; |
64 | | - let onRemotePublished = () => { |
65 | | - setRemoteTrackCount(remoteTrackCount + 1); |
| 73 | + let onRemotePublished = (publication: RemoteTrackPublication) => { |
| 74 | + if (publication.kind === 'audio') { |
| 75 | + setRemoteTrackCount(remoteTrackCount + 1); |
| 76 | + } |
66 | 77 | }; |
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)); |
72 | 86 | } |
73 | | - setRemoteTrackCount(Math.max(remoteTrackCount - 1, 0)); |
74 | 87 | }; |
75 | 88 |
|
76 | 89 | room |
@@ -124,6 +137,5 @@ function getRemoteAudioTrackCount(room: Room): number { |
124 | 137 | room.remoteParticipants.forEach((participant) => { |
125 | 138 | audioTracks += participant.audioTrackPublications.size; |
126 | 139 | }); |
127 | | - |
128 | 140 | return audioTracks; |
129 | 141 | } |
0 commit comments