using InABox.Client.WebSocket;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;

namespace InABox.Clients
{
    public static class SocketClientCache
    {
        private static Dictionary<string, WebSocketClient> Clients = new Dictionary<string, WebSocketClient>();

        public static void StartWebSocket(string url, int port, Guid session)
        {
            var host = url.Split(new[] { "://" }, StringSplitOptions.RemoveEmptyEntries).LastOrDefault();

            Uri uri = new Uri($"http://{host}");
            var key = $"{uri.Host}:{uri.Port}${session}";
            if (!Clients.ContainsKey(key))
                Clients[key] = new WebSocketClient(uri.Host, port, session);
        }
    }
}