コード例 #1
0
        /// <summary>
        /// Bind a listener to fire when an event indicating that the given Identity ID has linked a wallet is received from pusher
        /// </summary>
        /// <param name="identityID">The integer ID of the Identity to listen for a linked wallet on</param>
        /// <param name="listener">The listening action to fire with the responding event data</param>
        internal void ListenForLink(int identityID, System.Action <RequestEvent> listener)
        {
            Channel channel = _client.Subscribe("enjin.server." + _platformInfo.network + "." +
                                                _platformInfo.id.ToString() + "." +
                                                global::Enjin.SDK.Core.Enjin.AppID.ToString() + "." +
                                                identityID);

            channel.BindAll((eventName, eventData) =>
            {
                string dataString            = JsonHelper.Serialize(eventData);
                RequestEvent transactionData = JsonUtility.FromJson <RequestEvent>(dataString);
                if (global::Enjin.SDK.Core.Enjin.IsDebugLogActive)
                {
                    Debug.Log("<color=aqua>[PUSHER]</color> Event: " + transactionData.event_type);
                }

                if (global::Enjin.SDK.Core.Enjin.IsDebugLogActive)
                {
                    Debug.Log("<color=aqua>[PUSHER]</color> Event " + eventName + " recieved. Data: " + dataString);
                }

                // If we see that this client has updated their event, fire our awaiting callback.
                if (transactionData.event_type.Equals("identity_updated"))
                {
                    listener(transactionData);
                    channel.Unsubscribe();
                }
            });
        }
コード例 #2
0
        public void TriggerEvent(string eventName, RequestEvent request)
        {
            Action <RequestEvent> thisAction = null;

            if (instance._requestEventDictionary.TryGetValue(eventName, out thisAction))
            {
                thisAction.Invoke(request);
            }
        }
コード例 #3
0
        /// <summary>
        /// Pusher event channel. Can be subscribed to for handling pusher events
        /// </summary>
        /// <param name="eventName">Event type</param>
        /// <param name="eventData">Data associated to event</param>
        private void ChannelEvent(string eventName, object eventData)
        {
            TRData = JsonHelper.Serialize(eventData);
            RequestEvent trackData = JsonUtility.FromJson <RequestEvent>(TRData);

            if (global::Enjin.SDK.Core.Enjin.IsDebugLogActive)
            {
                Debug.Log("<color=aqua>[PUSHER]</color> Event: " + trackData.event_type);
            }

            if (global::Enjin.SDK.Core.Enjin.IsDebugLogActive)
            {
                Debug.Log("<color=aqua>[PUSHER]</color> Event " + eventName + " recieved. Data: " + TRData);
            }

            // Temp fix for action duplication issue. Will replace with event manager integration
            // Execute any event handlers which are listening to this specific event.
            if (global::Enjin.SDK.Core.Enjin.EventListeners.ContainsKey(eventName))
            {
                for (int i = 0; i < global::Enjin.SDK.Core.Enjin.EventListeners[eventName].Count; i++)
                {
                    global::Enjin.SDK.Core.Enjin.EventListeners[eventName][i](trackData);
                }
            }

            // Notify any callback functions listening for this request that we've broadcasted.

            /*
             * if (trackData.event_type.Equals("tx_broadcast"))
             * {
             *  int requestId = trackData.data.id;
             *  if (Enjin.RequestCallbacks.ContainsKey(requestId))
             *  {
             *      System.Action<RequestEvent> callback = Enjin.RequestCallbacks[requestId];
             *      callback(trackData);
             *  }
             * }
             */

            // Execute any callback function which is listening for this request.
            if (trackData.event_type.Equals("tx_executed"))
            {
                int requestId = trackData.data.transaction_id;
                if (global::Enjin.SDK.Core.Enjin.RequestCallbacks.ContainsKey(requestId))
                {
                    System.Action <RequestEvent> callback = global::Enjin.SDK.Core.Enjin.RequestCallbacks[requestId];
                    callback(trackData);
                    global::Enjin.SDK.Core.Enjin.RequestCallbacks.Remove(requestId);
                }
            }
        }