using System; using System.Collections.Generic; using System.Linq; using Unity.WebRTC; using UnityEngine; namespace Unity.RenderStreaming { /// /// The attribute is used for commandline argument of "-signalingType". /// public sealed class SignalingTypeAttribute : Attribute { /// /// /// public string typename => m_typename; private string m_typename; /// /// /// /// public SignalingTypeAttribute(string name) { m_typename = name; } } internal sealed class SignalingSettingsAttribute : PropertyAttribute { } /// /// /// public enum IceCredentialType { /// /// /// Password = 0, /// /// /// OAuth = 1 } /// /// /// [Serializable] public class IceServer { /// /// /// public IReadOnlyCollection urls => m_urls; /// /// /// public string username => m_username; /// /// /// public IceCredentialType credentialType => m_credentialType; /// /// /// public string credential => m_credential; [SerializeField] private string[] m_urls; [SerializeField] private string m_username; [SerializeField] private IceCredentialType m_credentialType; [SerializeField] private string m_credential; /// /// /// /// public static implicit operator RTCIceServer(IceServer server) { var iceServer = new RTCIceServer { urls = server.urls.ToArray(), username = server.username, credential = server.credential, credentialType = (RTCIceCredentialType)server.credentialType }; return iceServer; } /// /// /// /// public IceServer Clone() { return new IceServer(this.urls.ToArray(), this.username, this.credentialType, this.credential); } public IceServer Clone(string[] urls = null, string username = null, IceCredentialType? credentialType = null, string credential = null) { var server = new IceServer(this.urls.ToArray(), this.username, this.credentialType, this.credential); if (urls != null) server.m_urls = urls; if (username != null) server.m_username = username; if (credentialType != null) server.m_credentialType = credentialType.Value; if (credential != null) server.m_credential = credential; return server; } /// /// /// /// /// /// /// public IceServer(string[] urls = null, string username = null, IceCredentialType credentialType = IceCredentialType.Password, string credential = null) { m_urls = urls?.ToArray(); m_username = username; m_credential = credential; m_credentialType = credentialType; } internal IceServer(RTCIceServer server) { m_urls = server.urls.ToArray(); m_username = server.username; m_credential = server.credential; m_credentialType = (IceCredentialType)server.credentialType; } } /// /// /// public abstract class SignalingSettings { /// /// /// public abstract IReadOnlyCollection iceServers { get; } /// /// /// public abstract Type signalingClass { get; } /// /// /// /// /// public abstract bool ParseArguments(string[] arguments); } internal static class RuntimeTypeCache where T : class { private static Type[] s_types; public static Type[] GetTypesDerivedFrom() { if (s_types != null) return s_types; s_types = AppDomain.CurrentDomain.GetAssemblies() .SelectMany(domainAssembly => domainAssembly.GetTypes()) .Where(type => typeof(T).IsAssignableFrom(type) && !type.IsAbstract).ToArray(); return s_types; } } }