using System; using UnityEngine.EventSystems; namespace Unity.RenderStreaming { static class ExecuteSignalingEvents { public static T ValidateEventData(BaseEventData data) where T : class { if ((data as T) == null) throw new ArgumentException( $"Invalid type: {data.GetType()} passed to event expecting {typeof(T)}"); return data as T; } private static readonly ExecuteEvents.EventFunction s_CreatedConnectionHandler = Execute; private static readonly ExecuteEvents.EventFunction s_DeletedConnectionHandler = Execute; private static readonly ExecuteEvents.EventFunction s_ConnectHandler = Execute; private static readonly ExecuteEvents.EventFunction s_DisconnectHandler = Execute; private static readonly ExecuteEvents.EventFunction s_OfferHandler = Execute; private static readonly ExecuteEvents.EventFunction s_AnswerHandler = Execute; private static readonly ExecuteEvents.EventFunction s_AddChannelHandler = Execute; private static readonly ExecuteEvents.EventFunction s_AddReceiverHandler = Execute; private static void Execute(ICreatedConnectionHandler handler, BaseEventData eventData) { handler.OnCreatedConnection(ValidateEventData(eventData)); } private static void Execute(IDeletedConnectionHandler handler, BaseEventData eventData) { handler.OnDeletedConnection(ValidateEventData(eventData)); } private static void Execute(IConnectHandler handler, BaseEventData eventData) { handler.OnConnect(ValidateEventData(eventData)); } private static void Execute(IDisconnectHandler handler, BaseEventData eventData) { handler.OnDisconnect(ValidateEventData(eventData)); } private static void Execute(IOfferHandler handler, BaseEventData eventData) { handler.OnOffer(ValidateEventData(eventData)); } private static void Execute(IAnswerHandler handler, BaseEventData eventData) { handler.OnAnswer(ValidateEventData(eventData)); } private static void Execute(IAddChannelHandler handler, BaseEventData eventData) { handler.OnAddChannel(ValidateEventData(eventData)); } private static void Execute(IAddReceiverHandler handler, BaseEventData eventData) { handler.OnAddReceiver(ValidateEventData(eventData)); } public static ExecuteEvents.EventFunction createdConnectionHandler { get { return s_CreatedConnectionHandler; } } public static ExecuteEvents.EventFunction deletedConnectionHandler { get { return s_DeletedConnectionHandler; } } public static ExecuteEvents.EventFunction connectHandler { get { return s_ConnectHandler; } } public static ExecuteEvents.EventFunction disconnectHandler { get { return s_DisconnectHandler; } } public static ExecuteEvents.EventFunction offerHandler { get { return s_OfferHandler; } } public static ExecuteEvents.EventFunction answerHandler { get { return s_AnswerHandler; } } public static ExecuteEvents.EventFunction addChannelHandler { get { return s_AddChannelHandler; } } public static ExecuteEvents.EventFunction addReceiverHandler { get { return s_AddReceiverHandler; } } } }