Esempio n. 1
0
        void Start()
        {
            WebRTC.Initialize(WebRTCSettings.EncoderType, WebRTCSettings.LimitTextureSize);
            StartCoroutine(WebRTC.Update());
            StartCoroutine(LoopStatsCoroutine());

            toggleEnableMicrophone.isOn = false;
            toggleEnableMicrophone.onValueChanged.AddListener(OnEnableMicrophone);
            dropdownAudioClips.interactable = true;
            dropdownAudioClips.options      =
                audioclipList.Select(clip => new Dropdown.OptionData(clip.name)).ToList();
            dropdownMicrophoneDevices.interactable = false;
            dropdownMicrophoneDevices.options      =
                Microphone.devices.Select(name => new Dropdown.OptionData(name)).ToList();
            dropdownMicrophoneDevices.onValueChanged.AddListener(OnDeviceChanged);
            var audioConf = AudioSettings.GetConfiguration();

            dropdownSpeakerMode.options =
                Enum.GetNames(typeof(AudioSpeakerMode)).Select(mode => new Dropdown.OptionData(mode)).ToList();
            dropdownSpeakerMode.value = (int)audioConf.speakerMode;
            dropdownSpeakerMode.onValueChanged.AddListener(OnSpeakerModeChanged);

            dropdownDSPBufferSize.options =
                dspBufferSizeOptions.Select(clip => new Dropdown.OptionData(clip.Key)).ToList();
            dropdownDSPBufferSize.onValueChanged.AddListener(OnDSPBufferSizeChanged);

            // best latency is default
            OnDSPBufferSizeChanged(dropdownDSPBufferSize.value);

            dropdownAudioCodecs.AddOptions(new List <string> {
                "Default"
            });
            var codecs = RTCRtpSender.GetCapabilities(TrackKind.Audio).codecs;

            var excludeCodecTypes = new[] { "audio/CN", "audio/telephone-event" };

            foreach (var codec in codecs)
            {
                if (excludeCodecTypes.Count(type => codec.mimeType.Contains(type)) > 0)
                {
                    continue;
                }
                availableCodecs.Add(codec);
            }
            dropdownAudioCodecs.AddOptions(availableCodecs.Select(codec =>
                                                                  new Dropdown.OptionData(CodecToOptionName(codec))).ToList());

            dropdownBandwidth.options = bandwidthOptions
                                        .Select(pair => new Dropdown.OptionData {
                text = pair.Key
            })
                                        .ToList();
            dropdownBandwidth.onValueChanged.AddListener(OnBandwidthChanged);
            dropdownBandwidth.interactable = false;

            // Update UI
            OnDeviceChanged(dropdownMicrophoneDevices.value);

            buttonStart.onClick.AddListener(OnStart);
            buttonCall.onClick.AddListener(OnCall);
            buttonPause.onClick.AddListener(OnPause);
            buttonResume.onClick.AddListener(OnResume);
            buttonHangup.onClick.AddListener(OnHangUp);
        }