SocketIOOptions.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using SocketIOClient.Transport;
  2. using System;
  3. using System.Collections.Generic;
  4. namespace SocketIOClient
  5. {
  6. public sealed class SocketIOOptions
  7. {
  8. public SocketIOOptions()
  9. {
  10. RandomizationFactor = 0.5;
  11. ReconnectionDelay = 1000;
  12. ReconnectionDelayMax = 5000;
  13. ReconnectionAttempts = int.MaxValue;
  14. Path = "/socket.io";
  15. ConnectionTimeout = TimeSpan.FromSeconds(20);
  16. Reconnection = true;
  17. Transport = TransportProtocol.Polling;
  18. EIO = 4;
  19. AutoUpgrade = true;
  20. }
  21. public string Path { get; set; }
  22. public TimeSpan ConnectionTimeout { get; set; }
  23. public IEnumerable<KeyValuePair<string, string>> Query { get; set; }
  24. /// <summary>
  25. /// Whether to allow reconnection if accidentally disconnected
  26. /// </summary>
  27. public bool Reconnection { get; set; }
  28. public double ReconnectionDelay { get; set; }
  29. public int ReconnectionDelayMax { get; set; }
  30. public int ReconnectionAttempts { get; set; }
  31. double _randomizationFactor;
  32. public double RandomizationFactor
  33. {
  34. get => _randomizationFactor;
  35. set
  36. {
  37. if (value >= 0 && value <= 1)
  38. {
  39. _randomizationFactor = value;
  40. }
  41. else
  42. {
  43. throw new ArgumentException($"{nameof(RandomizationFactor)} should be greater than or equal to 0.0, and less than 1.0.");
  44. }
  45. }
  46. }
  47. public Dictionary<string, string> ExtraHeaders { get; set; }
  48. public TransportProtocol Transport { get; set; }
  49. public int EIO { get; set; }
  50. public bool AutoUpgrade { get; set; }
  51. public object Auth { get; set; }
  52. }
  53. }