示例#1
0
        internal static async Task <TurnClient> CreateTurnClient(
            IEnumerable <IceServer> iceServers)
        {
            foreach (IceServer server in iceServers)
            {
                foreach (Uri url in server.Urls)
                {
                    if (url.Scheme != "turn")
                    {
                        throw new ArgumentException($"{url} is not a valid TURN url.");
                    }

                    int port = url.IsDefaultPort
                        ? TurnClient.TurnDefaultPort
                        : url.Port;
                    var turnClient = new TurnClient(
                        url.Host,
                        server.Username,
                        server.Credential,
                        port);

                    if (await turnClient.IsConnectable())
                    {
                        Log.Debug("TURN client created: {Host}:{Port}", url.Host, url.Port);
                        return(turnClient);
                    }
                }
            }

            throw new IceServerException("Could not find a suitable ICE server.");
        }
示例#2
0
        internal static async Task <TurnClient> CreateTurnClient(
            IEnumerable <IceServer> iceServers)
        {
            foreach (IceServer server in iceServers)
            {
                foreach (Uri url in server.Urls)
                {
                    if (url.Scheme != "turn")
                    {
                        throw new ArgumentException($"{url} isn't valid TURN url.");
                    }

                    int port = url.IsDefaultPort
                        ? TurnClient.TurnDefaultPort
                        : url.Port;
                    var turnClient = new TurnClient(
                        url.Host,
                        server.Username,
                        server.Credential,
                        port);

                    var isConnectable = await turnClient.IsConnectable();

                    if (!isConnectable)
                    {
                        continue;
                    }

                    Log.Debug($"TURN client is created: {url.Host}:{url.Port}");
                    return(turnClient);
                }
            }

            throw new IceServerException("Can't find suitable server.");
        }
示例#3
0
        internal static async Task <TurnClient> CreateTurnClient(
            IEnumerable <IceServer> iceServers)
        {
            foreach (IceServer server in iceServers)
            {
                foreach (Uri url in server.Urls)
                {
                    if (url.Scheme != "turn")
                    {
                        throw new ArgumentException($"{url} isn't valid TURN url.");
                    }

                    try
                    {
                        int port = url.IsDefaultPort
                            ? TurnClient.TurnDefaultPort
                            : url.Port;
                        var turnClient = new TurnClient(
                            url.Host,
                            server.Username,
                            server.Credential,
                            port);

                        // Check connectability
                        await turnClient.GetMappedAddressAsync();

                        return(turnClient);
                    }
                    catch (ArgumentException)
                    {
                        continue;
                    }
                    catch (SocketException)
                    {
                        continue;
                    }
                }
            }

            throw new IceServerException("Can't find suitable server.");
        }