mirror of
https://github.com/vector-im/element-call.git
synced 2024-11-15 00:04:59 +08:00
Check for existing track before creating one. (#1459)
Signed-off-by: Timo K <toger5@hotmail.de>
This commit is contained in:
parent
cd5c0c9b55
commit
b979fc85bb
@ -17,8 +17,10 @@ limitations under the License.
|
||||
import {
|
||||
AudioCaptureOptions,
|
||||
ConnectionState,
|
||||
LocalTrackPublication,
|
||||
Room,
|
||||
RoomEvent,
|
||||
Track,
|
||||
} from "livekit-client";
|
||||
import { useCallback, useEffect, useRef, useState } from "react";
|
||||
import { logger } from "matrix-js-sdk/src/logger";
|
||||
@ -54,6 +56,13 @@ async function doConnect(
|
||||
audioOptions: AudioCaptureOptions
|
||||
): Promise<void> {
|
||||
await livekitRoom!.connect(sfuConfig!.url, sfuConfig!.jwt);
|
||||
const hasMicrophoneTrack = Array.from(
|
||||
livekitRoom?.localParticipant.audioTracks.values()
|
||||
).some((track: LocalTrackPublication) => {
|
||||
return track.source == Track.Source.Microphone;
|
||||
});
|
||||
// We create a track in case there isn't any.
|
||||
if (!hasMicrophoneTrack) {
|
||||
const audioTracks = await livekitRoom!.localParticipant.createTracks({
|
||||
audio: audioOptions,
|
||||
});
|
||||
@ -65,6 +74,7 @@ async function doConnect(
|
||||
|
||||
await livekitRoom?.localParticipant.publishTrack(audioTracks[0]);
|
||||
}
|
||||
}
|
||||
|
||||
export function useECConnectionState(
|
||||
initialAudioOptions: AudioCaptureOptions,
|
||||
|
Loading…
Reference in New Issue
Block a user