Exemple #1
0
        public async Task InitializeAsync()
        {
            var callStatus = await _callChannel.GetCallStatusAsync();

            if (callStatus != null)
            {
                await CallStatusUpdate(callStatus);
            }

            if (CallState != CallState.Idle)
            {
                FrameFormat localFrameFormat = await _callChannel.GetFrameFormatAsync(true);

                if (localFrameFormat != null)
                {
                    OnFrameFormatUpdate(localFrameFormat);
                }

                FrameFormat remoteFrameFormat = await _callChannel.GetFrameFormatAsync(false);

                if (remoteFrameFormat != null)
                {
                    OnFrameFormatUpdate(remoteFrameFormat);
                }
            }

            // Get stored relay messages
            OnRelayMessagesUpdated();

            _cameras = await _settingsChannel.GetVideoCaptureDevicesAsync();
        }
        private async void LoadSettings()
        {
            await _callChannel.InitializeRtcAsync();

            SignalingServerPort = int.Parse(SignalingSettings.SignalingServerPort);
            SignalingServerHost = SignalingSettings.SignalingServerHost;
            Domain             = RegistrationSettings.Domain;
            AppInsightsEnabled = SignalingSettings.AppInsightsEnabled;
            RegisteredUserName = RegistrationSettings.Name;

            if (_localSettings.Values[nameof(NtpServerIp)] != null)
            {
                NtpServerIp = (string)_localSettings.Values[nameof(NtpServerIp)];
            }

            Cameras        = new ObservableCollection <MediaDevice>((await _mediaSettings.GetVideoCaptureDevicesAsync()).Devices);
            SelectedCamera = Cameras.FirstOrDefault(c => c.IsPreferred) ?? Cameras.FirstOrDefault();

            Microphones = await GetAudioCaptureDevicesAsync();

            SelectedMicrophone = Microphones.FirstOrDefault(c => c.IsPreferred);
            if (SelectedMicrophone == null)
            {
                SelectedMicrophone = Microphones.First();
                await _mediaSettings.SetAudioDeviceAsync(SelectedMicrophone.Id == DefaultAudioDeviceId
                                                         ?null
                                                         : SelectedMicrophone);
            }

            AudioPlayoutDevices = await GetAudioPlayoutDevicesAsync();

            SelectedAudioPlayoutDevice = AudioPlayoutDevices.FirstOrDefault(c => c.IsPreferred);
            if (SelectedAudioPlayoutDevice == null)
            {
                SelectedAudioPlayoutDevice = AudioPlayoutDevices.First();
                await _mediaSettings.SetAudioPlayoutDeviceAsync(SelectedAudioPlayoutDevice.Id == DefaultAudioDeviceId
                                                                ?null
                                                                : SelectedAudioPlayoutDevice);
            }

            AudioCodecs = new ObservableCollection <CodecInfo>();
            var audioCodecList = await _mediaSettings.GetAudioCodecsAsync();

            foreach (var audioCodec in audioCodecList.Codecs)
            {
                if (!_incompatibleAudioCodecs.Contains(audioCodec.Name + audioCodec.ClockRate))
                {
                    AudioCodecs.Add(audioCodec);
                }
            }
            SelectedAudioCodec = null;
            if (_localSettings.Values[nameof(SelectedAudioCodec)] != null)
            {
                var audioCodecId = (int)_localSettings.Values[nameof(SelectedAudioCodec)];
                var audioCodec   = AudioCodecs.SingleOrDefault(a => a.Id.Equals(audioCodecId));
                if (audioCodec != null)
                {
                    SelectedAudioCodec = audioCodec;
                }
            }
            if (SelectedAudioCodec == null && AudioCodecs.Count > 0)
            {
                SelectedAudioCodec = AudioCodecs.First();
            }
            await _mediaSettings.SetAudioCodecAsync(SelectedAudioCodec);

            var videoCodecList = (await _mediaSettings.GetVideoCodecsAsync()).Codecs.OrderBy(codec =>
            {
                switch (codec.Name)
                {
                case "VP8":
                    return(1);

                case "VP9":
                    return(2);

                case "H264":
                    return(3);

                default:
                    return(99);
                }
            });

            VideoCodecs        = new ObservableCollection <CodecInfo>(videoCodecList);
            SelectedVideoCodec = null;
            if (_localSettings.Values[nameof(SelectedVideoCodec)] != null)
            {
                var videoCodecId = (int)_localSettings.Values[nameof(SelectedVideoCodec)];
                var videoCodec   = VideoCodecs.SingleOrDefault(v => v.Id.Equals(videoCodecId));
                if (videoCodec != null)
                {
                    SelectedVideoCodec = videoCodec;
                }
            }
            if (SelectedVideoCodec == null && VideoCodecs.Count > 0)
            {
                SelectedVideoCodec = VideoCodecs.First();
            }
            await _mediaSettings.SetVideoCodecAsync(SelectedVideoCodec);

            IceServers = new ObservableCollection <IceServerViewModel>(
                IceServerSettings.IceServers.Select(ices => new IceServerViewModel(ices)));

            if (_localSettings.Values[nameof(StatsServerPort)] != null)
            {
                StatsServerPort = (int)_localSettings.Values[nameof(StatsServerPort)];
            }
            else
            {
                StatsServerPort = 47005;
            }

            if (_localSettings.Values[nameof(StatsServerHost)] != null)
            {
                StatsServerHost = (string)_localSettings.Values[nameof(StatsServerHost)];
            }
            else
            {
                StatsServerHost = "localhost";
            }
        }