/// <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() + "." + Enjin.AppID.ToString() + "." + identityID); channel.BindAll((eventName, eventData) => { string dataString = JsonHelper.Serialize(eventData); RequestEvent transactionData = JsonUtility.FromJson <RequestEvent>(dataString); if (Enjin.IsDebugLogActive) { Debug.Log("<color=aqua>[PUSHER]</color> Event: " + transactionData.event_type); } if (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(); } }); }
public void TriggerEvent(string eventName, RequestEvent request) { Action <RequestEvent> thisAction = null; if (instance._requestEventDictionary.TryGetValue(eventName, out thisAction)) { thisAction.Invoke(request); } }
/// <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 (Enjin.IsDebugLogActive) { Debug.Log("<color=aqua>[PUSHER]</color> Event: " + trackData.event_type); } if (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 (Enjin.EventListeners.ContainsKey(eventName)) { for (int i = 0; i < Enjin.EventListeners[eventName].Count; i++) { 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 (Enjin.RequestCallbacks.ContainsKey(requestId)) { System.Action <RequestEvent> callback = Enjin.RequestCallbacks[requestId]; callback(trackData); Enjin.RequestCallbacks.Remove(requestId); } } }