Message.cs 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #if !BESTHTTP_DISABLE_SIGNALR_CORE
  2. using System;
  3. namespace BestHTTP.SignalRCore.Messages
  4. {
  5. public enum MessageTypes : int
  6. {
  7. /// <summary>
  8. /// This is a made up message type, for easier handshake handling.
  9. /// </summary>
  10. Handshake = 0,
  11. /// <summary>
  12. /// https://github.com/dotnet/aspnetcore/blob/master/src/SignalR/docs/specs/HubProtocol.md#invocation-message-encoding
  13. /// </summary>
  14. Invocation = 1,
  15. /// <summary>
  16. /// https://github.com/dotnet/aspnetcore/blob/master/src/SignalR/docs/specs/HubProtocol.md#streamitem-message-encoding
  17. /// </summary>
  18. StreamItem = 2,
  19. /// <summary>
  20. /// https://github.com/dotnet/aspnetcore/blob/master/src/SignalR/docs/specs/HubProtocol.md#completion-message-encoding
  21. /// </summary>
  22. Completion = 3,
  23. /// <summary>
  24. /// https://github.com/dotnet/aspnetcore/blob/master/src/SignalR/docs/specs/HubProtocol.md#streaminvocation-message-encoding
  25. /// </summary>
  26. StreamInvocation = 4,
  27. /// <summary>
  28. /// https://github.com/dotnet/aspnetcore/blob/master/src/SignalR/docs/specs/HubProtocol.md#cancelinvocation-message-encoding
  29. /// </summary>
  30. CancelInvocation = 5,
  31. /// <summary>
  32. /// https://github.com/dotnet/aspnetcore/blob/master/src/SignalR/docs/specs/HubProtocol.md#ping-message-encoding
  33. /// </summary>
  34. Ping = 6,
  35. /// <summary>
  36. /// https://github.com/dotnet/aspnetcore/blob/master/src/SignalR/docs/specs/HubProtocol.md#close-message-encoding
  37. /// </summary>
  38. Close = 7
  39. }
  40. [PlatformSupport.IL2CPP.Preserve]
  41. public struct Message
  42. {
  43. [PlatformSupport.IL2CPP.Preserve] public MessageTypes type;
  44. [PlatformSupport.IL2CPP.Preserve] public string invocationId;
  45. [PlatformSupport.IL2CPP.Preserve] public bool nonblocking;
  46. [PlatformSupport.IL2CPP.Preserve] public string target;
  47. [PlatformSupport.IL2CPP.Preserve] public object[] arguments;
  48. [PlatformSupport.IL2CPP.Preserve] public string[] streamIds;
  49. [PlatformSupport.IL2CPP.Preserve] public object item;
  50. [PlatformSupport.IL2CPP.Preserve] public object result;
  51. [PlatformSupport.IL2CPP.Preserve] public string error;
  52. [PlatformSupport.IL2CPP.Preserve] public bool allowReconnect;
  53. public override string ToString()
  54. {
  55. switch (this.type)
  56. {
  57. case MessageTypes.Invocation:
  58. return string.Format("[Invocation Id: {0}, Target: '{1}', Argument count: {2}, Stream Ids: {3}]", this.invocationId, this.target, this.arguments != null ? this.arguments.Length : 0, this.streamIds != null ? this.streamIds.Length : 0);
  59. case MessageTypes.StreamItem:
  60. return string.Format("[StreamItem Id: {0}, Item: {1}]", this.invocationId, this.item.ToString());
  61. case MessageTypes.Completion:
  62. return string.Format("[Completion Id: {0}, Result: {1}, Error: '{2}']", this.invocationId, this.result, this.error);
  63. case MessageTypes.StreamInvocation:
  64. return string.Format("[StreamInvocation Id: {0}, Target: '{1}', Argument count: {2}]", this.invocationId, this.target, this.arguments != null ? this.arguments.Length : 0);
  65. case MessageTypes.CancelInvocation:
  66. return string.Format("[CancelInvocation Id: {0}]", this.invocationId);
  67. case MessageTypes.Ping:
  68. return "[Ping]";
  69. case MessageTypes.Close:
  70. return string.IsNullOrEmpty(this.error) ?
  71. string.Format("[Close allowReconnect: {0}]", this.allowReconnect) :
  72. string.Format("[Close Error: '{0}', allowReconnect: {1}]", this.error, this.allowReconnect);
  73. default:
  74. return "Unknown message! Type: " + this.type;
  75. }
  76. }
  77. }
  78. }
  79. #endif