/// <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); }
/// <summary> /// Unsubscribe this instance. /// </summary> public async Task Unsubscribe() { RealtimeRouter.Instance.UnsubscribeCollection(CollectionName); RealtimeDelegate = null; }