-
Notifications
You must be signed in to change notification settings - Fork 465
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
openvidu-testapp: refactor TrackComponent
- Loading branch information
1 parent
4354561
commit 0ce0e2a
Showing
7 changed files
with
98 additions
and
120 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
openvidu-testapp/src/app/components/audio-track/audio-track.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 6 additions & 44 deletions
50
openvidu-testapp/src/app/components/audio-track/audio-track.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,22 @@ | ||
import { Component, ElementRef, Input, ViewChild } from '@angular/core'; | ||
import { LocalTrack, AudioTrack, AudioCaptureOptions } from 'livekit-client'; | ||
import { Component } from '@angular/core'; | ||
import { LocalTrack } from 'livekit-client'; | ||
import { TrackComponent } from '../track/track.component'; | ||
|
||
@Component({ | ||
selector: 'app-audio-track', | ||
templateUrl: './audio-track.component.html', | ||
styleUrls: ['./audio-track.component.css'] | ||
styleUrls: ['./audio-track.component.css'], | ||
}) | ||
export class AudioTrackComponent extends TrackComponent { | ||
|
||
@ViewChild('audioElement') elementRef: ElementRef; | ||
elementRefId: string = ''; | ||
|
||
muteAudioIcon: string = 'mic'; | ||
|
||
private _audioTrack: AudioTrack | undefined; | ||
|
||
private audioCaptureOptions: AudioCaptureOptions; | ||
|
||
@Input() set audioTrack(audioTrack: AudioTrack | undefined) { | ||
this._audioTrack = audioTrack; | ||
this.track = this._audioTrack; | ||
|
||
this.setupTrackEventListeners(); | ||
|
||
let id = ''; | ||
id = `${this.getTrackOrigin()}--audio--${this._audioTrack?.source}--${this._audioTrack?.sid}`; | ||
if (this._audioTrack?.sid !== this._audioTrack?.mediaStreamID) { | ||
id += `--${this._audioTrack?.mediaStreamID}`; | ||
} | ||
id = id.replace(/[^0-9a-z-A-Z_-]+/g, ''); | ||
this.elementRefId = id; | ||
|
||
if (this.elementRef && !this.localParticipant) { | ||
this._audioTrack?.attach(this.elementRef.nativeElement); | ||
} | ||
} | ||
|
||
ngAfterViewInit() { | ||
if (!this.localParticipant) { | ||
this._audioTrack?.attach(this.elementRef.nativeElement); | ||
} | ||
} | ||
|
||
ngOnDestroy() { | ||
this._audioTrack?.detach(this.elementRef.nativeElement); | ||
} | ||
|
||
async muteUnmuteAudio() { | ||
if (this._audioTrack?.isMuted) { | ||
if (this._track?.isMuted) { | ||
this.muteAudioIcon = 'mic'; | ||
await (this._audioTrack as LocalTrack).unmute(); | ||
await (this._track as LocalTrack).unmute(); | ||
} else { | ||
this.muteAudioIcon = 'mic_off'; | ||
await (this._audioTrack as LocalTrack).mute(); | ||
await (this._track as LocalTrack).mute(); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
openvidu-testapp/src/app/components/video-track/video-track.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.