using System; using Vinno.IUS.Common.Log; using Vinno.vCloud.Common.FIS; namespace Vinno.vCloud.FIS.Windows { class DeviceDetector : IDeviceDetector { private string _currentMicId; private string _currentSpeakerId; /// /// Raised when mic volume is change. /// public event EventHandler MicVolumeUpdated; /// /// Raised when speaking volume is change. /// public event EventHandler SpeakerVolumeUpdated; public DeviceDetector() { TrtcDetector.Instance.MicVolumeUpdated += OnMicVolumeUpdated; TrtcDetector.Instance.SpeakerVolumeUpdated += OnSpeakerVolumeUpdated; } public void StartMicTest(string micId, string speakerId) { if (string.IsNullOrEmpty(_currentMicId)) { _currentMicId = micId; TrtcDetector.Instance.StartMicTest(micId, speakerId); } else { Logger.WriteLineError($"Start mic {micId} test error because another mic {_currentMicId} already testing"); } } /// /// Stop mic test. /// public void StopMicTest() { TrtcDetector.Instance.StopMicTest(); _currentMicId = null; } /// /// Set mic device volume /// /// The mic device id. /// The volume of the mic. public void SetMicDeviceVolume(string micId, uint volume) { TrtcDetector.Instance.SetMicDeviceVolume(micId, volume); } /// /// Start speaker test. /// /// The speaker id. /// The audio file path. public void StartSpeakerTest(string speakerId, string audioFilePath) { if (string.IsNullOrEmpty(_currentSpeakerId)) { _currentSpeakerId = speakerId; TrtcDetector.Instance.StartSpeakerTest(speakerId, audioFilePath); } else { Logger.WriteLineError($"Start speaker {speakerId} test error because another speaker {_currentMicId} already testing"); } } /// /// Stop speaker test. /// public void StopSpeakerTest() { TrtcDetector.Instance.StopSpeakerTest(); _currentSpeakerId = null; } /// /// Set speaker volume. /// /// The speaker device id. /// The volume of the speaker. public void SetSpeakerVolume(string speakerId, uint volume) { TrtcDetector.Instance.SetSpeakerVolume(speakerId, volume); } /// /// Set speakder mute. /// /// The speaker id. /// True: mute, False: not mute. /// public void SetSpeakerMute(string speakerId, bool isMute) { TrtcDetector.Instance.SetSpeakerMute(speakerId, isMute); } /// /// Set speakder mute. /// /// The mic id. /// True: mute, False: not mute. /// public void SetMicMute(string micId, bool isMute) { TrtcDetector.Instance.SetMicMute(micId, isMute); } /// /// Dispose. /// public void Dispose() { TrtcDetector.Instance.MicVolumeUpdated -= OnMicVolumeUpdated; TrtcDetector.Instance.SpeakerVolumeUpdated -= OnSpeakerVolumeUpdated; } private void OnSpeakerVolumeUpdated(object sender, uint e) { SpeakerVolumeUpdated?.Invoke(this, e); } private void OnMicVolumeUpdated(object sender, uint e) { MicVolumeUpdated.Invoke(this, e); } } }