/// <summary> /// Subscribe the specified callback. /// </summary> /// <param name="realtimeHandler">Delegate used to forward realtime messages.</param> public async Task <bool> Subscribe(KinveyDataStoreDelegate <T> realtimeHandler) { bool success = false; // TODO request subscribe access with KCS var subscribeRequest = new SubscribeRequest <T>(client, collectionName, client.DeviceID); var result = await subscribeRequest.ExecuteAsync(); if (realtimeHandler != null) { RealtimeDelegate = realtimeHandler; var routerDelegate = new KinveyRealtimeDelegate { OnError = (error) => RealtimeDelegate.OnError(error), OnNext = (message) => { var messageObj = Newtonsoft.Json.JsonConvert.DeserializeObject <T>(message); RealtimeDelegate.OnNext(messageObj); }, OnStatus = (status) => RealtimeDelegate.OnStatus(status) }; RealtimeRouter.Instance.SubscribeCollection(CollectionName, routerDelegate); success = true; } return(success); }
void AddChannel(string channel, KinveyRealtimeDelegate callback) { if (mapChannelToCallback.ContainsKey(channel)) { mapChannelToCallback[channel] = callback; } else { mapChannelToCallback.Add(channel, callback); } }
internal void SubscribeCollection(string collectionName, KinveyRealtimeDelegate callback) { string appKey = (KinveyClient.RequestInitializer as KinveyClientRequestInitializer).AppKey; string channel = appKey + Constants.CHAR_PERIOD + Constants.STR_REALTIME_COLLECTION_CHANNEL_PREPEND + collectionName; AddChannel(channel, callback); // In the case of collection subscription, in addition to creating a // channel for the collection, another channel should be created for // this collection and the active user, since certain ACL rules may // not allow collection-wide subscription, but may allow this user // access to the update (see MLIBZ-2223 for more information). string activeUserChannel = BuildCollectionUserChannel(collectionName, Client.SharedClient.ActiveUser.Id); AddChannel(activeUserChannel, callback); }
internal void SubscribeStream(string channelName, KinveyRealtimeDelegate callback) { AddChannel(channelName, callback); }