Resolved Listen for Link via GraphQL

Hey!

Is there a recommended way to simulate the functionality of the Unity SDK's Enjin.ListenForLink function using GraphQL?

To be clear, I'm trying to be considerate of the Enjin Platform and do not want to spam it up with repeated requests just to see when the "ethereum_address" is null.

If this is the way it's intended to be done (and there's not some fancy subscription, long polling, or WebSocket to do it), what's a desirable interval to use to be considerate of the platform while still being fast enough to satisfy the performance expectations of users? Once every 10 seconds? Etc.

Thanks!

By the way, I'm loving the Enjin Platform thus far (y)!
 

Simon

Enjineer
Staff member
Hi! You can use the identity pusher channel to listen for identity_linked events, as well as various other user, identity and app events (y)

You can get the Pusher key with this query:

Code:
query platform{
  EnjinPlatform{
    name,
    notifications
  }
}
Then subscribe to this channel, replacing the data in { } with your app_id and the user's identity_id:

enjin.server.kovan.5.identity.{identityId}

e.g. enjin.server.kovan.5.identity.2
 
Last edited:
I'm grateful for the quick response as always!

For some reason, when I connect to the channel (which is public given the naming convention) the only event I see is the subscription event even when I link a wallet to the identity.

JavaScript:
/* This is a placeholder, the actual platform values are retrieved from the query you provided. */
const platform = {
   key: "4a923...",
   options: { cluster: "mt1", encrypted: true }
};

let pusher = new Pusher(platform.key, platform.options);

const channel = pusher.subscribe(channelKey);
// channelKey = enjin.server.kovan.5.{appID}.identity.{identityID}

channel.bind_global((event, data) => {
    console.log(event, data);
    // pusher:subscription_succeeded {}
});
Is there something I'm missing? Thanks!
 
Last edited:
I just read through the source code of the Enjin Unity SDK to see if there were any clues as to what I was doing wrong.

Judging by the source:

C#:
        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();
                }
            });
        }
It seems there is another channel key format used by the Unity SDK:

JavaScript:
`enjin.server.${PLATFORM_NETWORK}.${PLATFORM_ID}.${APP_ID}.${IDENTITY_ID}`
However, I tried to connect to this channel as well and received no events upon linking of my wallet to an Enjin Identity of my application.

I'm still not sure what I'm doing wrong, but I do really appreciate the help (y) !
 

Simon

Enjineer
Staff member
Apologies, it looks like the channel name is slightly different, please can you try:

enjin.server.kovan.5.identity.{identityId}
 

stealthOne

Member
Enjin.ListenForLink not working for me (enjin.server.kovan.5.xxxx.xxxx), no events received upon linking! any idea?
 
Top