using System; using System.Collections; using System.Collections.Generic; using System.Linq; using Unity.WebRTC; using Unity.WebRTC.Samples; using UnityEngine; using UnityEngine.UI; using Button = UnityEngine.UI.Button; class TrickleIceSample : MonoBehaviour { #pragma warning disable 0649 [SerializeField] private Button addServerButton; [SerializeField] private Button removeServerButton; [SerializeField] private Button resetToDefaultButton; [SerializeField] private Button gatherCandidatesButton; [SerializeField] private InputField urlInputField; [SerializeField] private InputField usernameInputField; [SerializeField] private InputField passwordInputField; [SerializeField] private GameObject optionElement; [SerializeField] private Transform optionParent; [SerializeField] private GameObject candidateElement; [SerializeField] private Transform candidateParent; [SerializeField] private ToggleGroup iceTransportOption; [SerializeField] private Slider candidatePoolSizeSlider; [SerializeField] private Text candidatePoolSizeText; #pragma warning restore 0649 private RTCPeerConnection _pc1; private RTCRtpTransceiver _transceiver; private float beginTime = 0f; private Dictionary iceServers = new Dictionary(); private GameObject selectedOption = null; private void Awake() { addServerButton.onClick.AddListener(OnAddServer); removeServerButton.onClick.AddListener(OnRemoveServer); resetToDefaultButton.onClick.AddListener(OnResetToDefault); gatherCandidatesButton.onClick.AddListener(OnGatherCandidate); candidatePoolSizeSlider.onValueChanged.AddListener(OnChangedCandidatePoolSize); } private void Start() { OnResetToDefault(); } void OnAddServer() { string url = urlInputField.text; string username = usernameInputField.text; string password = passwordInputField.text; string scheme = url.Split(':')[0]; if (scheme != "stun" && scheme != "turn" && scheme != "turns") { Debug.LogError( $"URI scheme `{scheme}` is not valid parameter. \n" + $"ex. `stun:192.168.11.1`, `turn:192.168.11.2:3478?transport=udp`"); return; } AddServer(url, username, password); } void AddServer(string url, string username = null, string password = null) { // Store the ICE server as a stringified JSON object in option.value. GameObject option = Instantiate(optionElement, optionParent); Text optionText = option.GetComponentInChildren(); Button optionButton = option.GetComponentInChildren