Ejemplo n.º 1
0
        public PureWebSocket(string url, IPureWebSocketOptions options)
        {
            _options = (PureWebSocketOptions)options;
            Url      = url;

            Log("Creating new instance.");

            Task.Run(() =>
            {
                Monitor();
            });
        }
Ejemplo n.º 2
0
        public PureWebSocket(string url, IPureWebSocketOptions options)
        {
            _options = (PureWebSocketOptions)options;
            Url      = url;

            _autoReconnect = _options.MyReconnectStrategy != null &&
                             !_options.MyReconnectStrategy.AreAttemptsComplete() &&
                             _options.MyReconnectStrategy.GetReconnectInterval() > 0 &&
                             _options.MyReconnectStrategy.GetReconnectInterval() != int.MaxValue;

            _logger = new Logger(_options);

            _logger.Log("Creating new instance.");

            InitializeClient();

            StartMonitor();
        }
Ejemplo n.º 3
0
        public PureWebSocket(string url, IPureWebSocketOptions options)
        {
            InstanceName = $"I{DateTime.UtcNow.Ticks.ToString()}";
            _options     = (PureWebSocketOptions)options;
            Url          = url;

            _autoReconnect = _options.MyReconnectStrategy != null &&
                             !_options.MyReconnectStrategy.AreAttemptsComplete() &&
                             _options.MyReconnectStrategy.GetReconnectInterval() > 0 &&
                             _options.MyReconnectStrategy.GetReconnectInterval() != int.MaxValue;

            _logger = new Logger(_options);

            _logger.Log($"Creating new instance name {InstanceName}.");

            InitializeClient();

            StartMonitor();
        }
Ejemplo n.º 4
0
        internal static PureWebSocket Reconnect(string host, string connectionToken, string[] hubs, string messageId, string groupsToken, IPureWebSocketOptions socketOptions)
        {
            // Transport: ws
            // example which should be url encoded before sending
            // reconnect?transport=webSockets&clientProtocol=1.4&connectionToken=Aa-aQA&connectionData=[{"Name":"hubConnection"}]&messageId=d-3104A0A8-H,0|L,0|M,2|K,0&groupsToken=AQ
            var sb = new StringBuilder();

            sb.Append(host).Append("/connect?transport=webSockets&clientProtocol=").Append(WebUtility.UrlEncode("1.4")).Append("&connectionToken=").Append(WebUtility.UrlEncode(connectionToken)).Append("&connectionData=").Append(WebUtility.UrlEncode("["));
            if (hubs.Length > 0)
            {
                for (var i = 0; i < hubs.Length; i++)
                {
                    sb.Append("{{\"name\":\"").Append(hubs[i]).Append("\"}}");
                    if (i < hubs.Length - 1)
                    {
                        sb.Append(",");
                    }
                }
            }

            sb.Append(WebUtility.UrlEncode("]")).Append("&messageId=").Append(WebUtility.UrlEncode(messageId)).Append("&groupsToken=").Append(WebUtility.UrlEncode(groupsToken));

            return(new PureWebSocket(sb.ToString(), socketOptions));
        }
Ejemplo n.º 5
0
        internal static PureWebSocket Connect(string host, string connectionToken, string[] hubs, IPureWebSocketOptions socketOptions)
        {
            // Transport: ws
            // example which should be url encoded before sending
            // connect?transport=webSockets&clientProtocol=1.4&connectionToken=dst4yfTh7tLAxZZtTPhpQh53uon9RDA+Aag56A6XP5xEL4/FADijbZjvoLWtplY+S570UXZwhatkSLQPOBF5RLBRZGoAK4O865XNAoF2ZbOMs03fKcbdirFh8sNSfFqV&connectionData=[{"name":"chathub"},{"name":"notificationhub"}]
            var sb = new StringBuilder();

            sb.Append(host).Append("/connect?transport=webSockets&clientProtocol=").Append(WebUtility.UrlEncode("1.4")).Append("&connectionToken=").Append(WebUtility.UrlEncode(connectionToken)).Append("&connectionData=").Append(WebUtility.UrlEncode("["));
            if (hubs.Length > 0)
            {
                for (var i = 0; i < hubs.Length; i++)
                {
                    sb.Append(WebUtility.UrlEncode($"{{\"name\":\"{hubs[i]}\"}}"));
                    if (i < hubs.Length - 1)
                    {
                        sb.Append(WebUtility.UrlEncode(","));
                    }
                }
            }

            sb.Append(WebUtility.UrlEncode("]"));

            return(new PureWebSocket(sb.ToString(), socketOptions));
        }