123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- #if !BESTHTTP_DISABLE_SOCKETIO
- using System;
- using System.Text;
- using PlatformSupport.Collections.ObjectModel;
- #if !NETFX_CORE
- using PlatformSupport.Collections.Specialized;
- #else
- using System.Collections.Specialized;
- #endif
- namespace BestHTTP.SocketIO
- {
- public sealed class SocketOptions
- {
- #region Properties
-
-
-
- public Transports.TransportTypes ConnectWith { get; set; }
-
-
-
- public bool Reconnection { get; set; }
-
-
-
- public int ReconnectionAttempts { get; set; }
-
-
-
-
- public TimeSpan ReconnectionDelay { get; set; }
-
-
-
-
- public TimeSpan ReconnectionDelayMax { get; set; }
-
-
-
- public float RandomizationFactor { get { return randomizationFactor; } set { randomizationFactor = Math.Min(1.0f, Math.Max(0.0f, value)); } }
- private float randomizationFactor;
-
-
-
- public TimeSpan Timeout { get; set; }
-
-
-
- public bool AutoConnect { get; set; }
-
-
-
-
- public ObservableDictionary<string, string> AdditionalQueryParams
- {
- get { return additionalQueryParams; }
- set
- {
-
- if (additionalQueryParams != null)
- additionalQueryParams.CollectionChanged -= AdditionalQueryParams_CollectionChanged;
- additionalQueryParams = value;
-
- BuiltQueryParams = null;
-
- if (value != null)
- value.CollectionChanged += AdditionalQueryParams_CollectionChanged;
- }
- }
- private ObservableDictionary<string, string> additionalQueryParams;
-
-
-
- public bool QueryParamsOnlyForHandshake { get; set; }
- #endregion
-
-
-
- private string BuiltQueryParams;
-
-
-
- public SocketOptions()
- {
- ConnectWith = Transports.TransportTypes.Polling;
- Reconnection = true;
- ReconnectionAttempts = int.MaxValue;
- ReconnectionDelay = TimeSpan.FromMilliseconds(1000);
- ReconnectionDelayMax = TimeSpan.FromMilliseconds(5000);
- RandomizationFactor = 0.5f;
- Timeout = TimeSpan.FromMilliseconds(20000);
- AutoConnect = true;
- QueryParamsOnlyForHandshake = true;
- }
- #region Helper Functions
-
-
-
- internal string BuildQueryParams()
- {
- if (AdditionalQueryParams == null || AdditionalQueryParams.Count == 0)
- return string.Empty;
- if (!string.IsNullOrEmpty(BuiltQueryParams))
- return BuiltQueryParams;
- StringBuilder sb = new StringBuilder(AdditionalQueryParams.Count * 4);
- foreach(var kvp in AdditionalQueryParams)
- {
- sb.Append("&");
- sb.Append(kvp.Key);
- if (!string.IsNullOrEmpty(kvp.Value))
- {
- sb.Append("=");
- sb.Append(kvp.Value);
- }
- }
- return BuiltQueryParams = sb.ToString();
- }
-
-
-
- private void AdditionalQueryParams_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
- {
- BuiltQueryParams = null;
- }
- #endregion
- }
- }
- #endif
|