EventNames.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #if !BESTHTTP_DISABLE_SOCKETIO
  2. using System;
  3. namespace BestHTTP.SocketIO.Events
  4. {
  5. /// <summary>
  6. /// Helper class to provide functions to an easy Enum->string conversation of the transport and SocketIO evenet types.
  7. /// </summary>
  8. public static class EventNames
  9. {
  10. public const string Connect = "connect";
  11. public const string Disconnect = "disconnect";
  12. public const string Event = "event";
  13. public const string Ack = "ack";
  14. public const string Error = "error";
  15. public const string BinaryEvent = "binaryevent";
  16. public const string BinaryAck = "binaryack";
  17. private static string[] SocketIONames = new string[] { "unknown", "connect", "disconnect", "event", "ack", "error", "binaryevent", "binaryack" };
  18. private static string[] TransportNames = new string[] { "unknown", "open", "close", "ping", "pong", "message", "upgrade", "noop" };
  19. private static string[] BlacklistedEvents = new string[] { "connect", "connect_error", "connect_timeout", "disconnect", "error", "reconnect",
  20. "reconnect_attempt", "reconnect_failed", "reconnect_error", "reconnecting" };
  21. public static string GetNameFor(SocketIOEventTypes type)
  22. {
  23. return SocketIONames[(int)type + 1];
  24. }
  25. public static string GetNameFor(TransportEventTypes transEvent)
  26. {
  27. return TransportNames[(int)transEvent + 1];
  28. }
  29. /// <summary>
  30. /// Checks an event name whether it's blacklisted or not.
  31. /// </summary>
  32. public static bool IsBlacklisted(string eventName)
  33. {
  34. for (int i = 0; i < BlacklistedEvents.Length; ++i)
  35. if (string.Compare(BlacklistedEvents[i], eventName, StringComparison.OrdinalIgnoreCase) == 0)
  36. return true;
  37. return false;
  38. }
  39. }
  40. }
  41. #endif