4
4
AudioPresets ,
5
5
createLocalScreenTracks ,
6
6
Room ,
7
- LocalVideoTrack
7
+ LocalVideoTrack ,
8
+ LocalAudioTrack
8
9
} from 'livekit-client'
9
10
import type {
10
11
RemoteTrack ,
@@ -85,7 +86,7 @@ type CameraProcessor = {
85
86
const room = ref < Room > ( )
86
87
const audioContext = ref < AudioContext > ( )
87
88
const isRnnoiseSupported = computed ( ( ) => ! ! audioContext . value )
88
- const speakerIdentity = ref < string [ ] > ( [ ] )
89
+ const speakerIdentitys = ref < { identity : string ; name ?: string } [ ] > ( [ ] )
89
90
const tracksMap : Ref < Map < string , TrackInfo > > = ref ( new Map ( ) )
90
91
const cameraProcessorMap : Ref < Map < string , CameraProcessor > > = ref ( new Map ( ) )
91
92
const screenShareTrackSidMap = ref < Map < string , string > > ( new Map ( ) )
@@ -141,7 +142,7 @@ function handleLocalTrackPublished(
141
142
142
143
function handleActiveSpeakerChange ( speakers : Participant [ ] ) {
143
144
// show UI indicators when participant is speaking
144
- speakerIdentity . value = speakers . map ( s => s . identity )
145
+ speakerIdentitys . value = speakers
145
146
}
146
147
147
148
function handleDisconnect ( ) {
@@ -264,8 +265,7 @@ async function leaveRoom() {
264
265
const addMicTrack = async ( ) => {
265
266
let stream : MediaStream | undefined
266
267
267
- const noiseSuppression = useRtcSettings ( ) . noiseSuppression
268
- . value as NoiseSuppressionType
268
+ const { noiseSuppression, audioInputDeviceId } = useRtcSettings ( )
269
269
try {
270
270
if ( ! room . value ?. localParticipant ?. permissions ?. canPublish ) {
271
271
throw new Error ( '権限がありません' )
@@ -275,12 +275,21 @@ const addMicTrack = async () => {
275
275
audioContext . value = new AudioContext ( )
276
276
}
277
277
278
- stream = await navigator . mediaDevices . getUserMedia ( { audio : true } )
278
+ stream = await navigator . mediaDevices . getUserMedia ( {
279
+ audio : {
280
+ deviceId : {
281
+ ideal : audioInputDeviceId . value
282
+ } ,
283
+ autoGainControl : true ,
284
+ noiseSuppression : true ,
285
+ echoCancellation : true
286
+ }
287
+ } )
279
288
const source = audioContext . value . createMediaStreamSource ( stream )
280
289
281
290
let lastNode : AudioNode = source
282
291
283
- if ( noiseSuppression === 'rnnoise' ) {
292
+ if ( noiseSuppression . value === 'rnnoise' ) {
284
293
const [ rnnoiseBinary ] = await Promise . all ( [
285
294
loadRnnoiseWasmBinary ( ) ,
286
295
audioContext . value ?. audioWorklet . addModule ( rnnoiseWorkletPath )
@@ -291,7 +300,7 @@ const addMicTrack = async () => {
291
300
} )
292
301
source . connect ( rnnoiseNode )
293
302
lastNode = rnnoiseNode
294
- } else if ( noiseSuppression === 'speex' ) {
303
+ } else if ( noiseSuppression . value === 'speex' ) {
295
304
const [ speexBinary ] = await Promise . all ( [
296
305
loadSpeexWasmBinary ( ) ,
297
306
audioContext . value ?. audioWorklet . addModule ( speexWorkletPath )
@@ -313,9 +322,11 @@ const addMicTrack = async () => {
313
322
}
314
323
315
324
audioTrackId . value = audioTrack . id
325
+ const livekitAudioTrack = new LocalAudioTrack ( audioTrack , undefined , false )
326
+ livekitAudioTrack . source = Track . Source . Microphone
316
327
317
328
// Publish the processed stream
318
- await room . value . localParticipant . publishTrack ( audioTrack , {
329
+ await room . value . localParticipant . publishTrack ( livekitAudioTrack , {
319
330
audioPreset : AudioPresets . speech ,
320
331
forceStereo : true ,
321
332
red : false ,
@@ -334,7 +345,6 @@ const addMicTrack = async () => {
334
345
addErrorToast ( 'マイクの共有に失敗しました' )
335
346
}
336
347
}
337
-
338
348
const removeMicTrack = async ( ) => {
339
349
try {
340
350
if ( ! room . value ) {
@@ -633,6 +643,7 @@ export const useLiveKitSDK = () => {
633
643
tracksMap,
634
644
screenShareTrackSidMap,
635
645
screenShareTracks,
646
+ speakerIdentitys,
636
647
isMicOn,
637
648
qallMitt
638
649
}
0 commit comments