ExecuteSignalingEvents.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. using System;
  2. using UnityEngine.EventSystems;
  3. namespace Unity.RenderStreaming
  4. {
  5. static class ExecuteSignalingEvents
  6. {
  7. public static T ValidateEventData<T>(BaseEventData data) where T : class
  8. {
  9. if ((data as T) == null)
  10. throw new ArgumentException(
  11. $"Invalid type: {data.GetType()} passed to event expecting {typeof(T)}");
  12. return data as T;
  13. }
  14. private static readonly ExecuteEvents.EventFunction<ICreatedConnectionHandler>
  15. s_CreatedConnectionHandler = Execute;
  16. private static readonly ExecuteEvents.EventFunction<IDeletedConnectionHandler>
  17. s_DeletedConnectionHandler = Execute;
  18. private static readonly ExecuteEvents.EventFunction<IConnectHandler>
  19. s_ConnectHandler = Execute;
  20. private static readonly ExecuteEvents.EventFunction<IDisconnectHandler>
  21. s_DisconnectHandler = Execute;
  22. private static readonly ExecuteEvents.EventFunction<IOfferHandler>
  23. s_OfferHandler = Execute;
  24. private static readonly ExecuteEvents.EventFunction<IAnswerHandler>
  25. s_AnswerHandler = Execute;
  26. private static readonly ExecuteEvents.EventFunction<IAddChannelHandler>
  27. s_AddChannelHandler = Execute;
  28. private static readonly ExecuteEvents.EventFunction<IAddReceiverHandler>
  29. s_AddReceiverHandler = Execute;
  30. private static void Execute(ICreatedConnectionHandler handler, BaseEventData eventData)
  31. {
  32. handler.OnCreatedConnection(ValidateEventData<SignalingEventData>(eventData));
  33. }
  34. private static void Execute(IDeletedConnectionHandler handler, BaseEventData eventData)
  35. {
  36. handler.OnDeletedConnection(ValidateEventData<SignalingEventData>(eventData));
  37. }
  38. private static void Execute(IConnectHandler handler, BaseEventData eventData)
  39. {
  40. handler.OnConnect(ValidateEventData<SignalingEventData>(eventData));
  41. }
  42. private static void Execute(IDisconnectHandler handler, BaseEventData eventData)
  43. {
  44. handler.OnDisconnect(ValidateEventData<SignalingEventData>(eventData));
  45. }
  46. private static void Execute(IOfferHandler handler, BaseEventData eventData)
  47. {
  48. handler.OnOffer(ValidateEventData<SignalingEventData>(eventData));
  49. }
  50. private static void Execute(IAnswerHandler handler, BaseEventData eventData)
  51. {
  52. handler.OnAnswer(ValidateEventData<SignalingEventData>(eventData));
  53. }
  54. private static void Execute(IAddChannelHandler handler, BaseEventData eventData)
  55. {
  56. handler.OnAddChannel(ValidateEventData<SignalingEventData>(eventData));
  57. }
  58. private static void Execute(IAddReceiverHandler handler, BaseEventData eventData)
  59. {
  60. handler.OnAddReceiver(ValidateEventData<SignalingEventData>(eventData));
  61. }
  62. public static ExecuteEvents.EventFunction<ICreatedConnectionHandler> createdConnectionHandler
  63. {
  64. get { return s_CreatedConnectionHandler; }
  65. }
  66. public static ExecuteEvents.EventFunction<IDeletedConnectionHandler> deletedConnectionHandler
  67. {
  68. get { return s_DeletedConnectionHandler; }
  69. }
  70. public static ExecuteEvents.EventFunction<IConnectHandler> connectHandler
  71. {
  72. get { return s_ConnectHandler; }
  73. }
  74. public static ExecuteEvents.EventFunction<IDisconnectHandler> disconnectHandler
  75. {
  76. get { return s_DisconnectHandler; }
  77. }
  78. public static ExecuteEvents.EventFunction<IOfferHandler> offerHandler
  79. {
  80. get { return s_OfferHandler; }
  81. }
  82. public static ExecuteEvents.EventFunction<IAnswerHandler> answerHandler
  83. {
  84. get { return s_AnswerHandler; }
  85. }
  86. public static ExecuteEvents.EventFunction<IAddChannelHandler> addChannelHandler
  87. {
  88. get { return s_AddChannelHandler; }
  89. }
  90. public static ExecuteEvents.EventFunction<IAddReceiverHandler> addReceiverHandler
  91. {
  92. get { return s_AddReceiverHandler; }
  93. }
  94. }
  95. }