public IServiceSubscription SubscribeTextInputStatus(ResponseListener listener)
        {
            keyboardstring = new StringBuilder();

            var request = new UrlServiceSubscription(this, "KeyboardVisible", null, null);
            request.AddListener(listener);

            AddSubscription(request);

            return request;
        }
 public override void Unsubscribe(UrlServiceSubscription subscription)
 {
     subscriptions.Remove(subscription);
 }
        public IServiceSubscription Subscribe3DEnabled(ResponseListener listener)
        {
            Get3DEnabled(listener);

            var request = new UrlServiceSubscription(this, Target_3DMode, null, null) { HttpMethod = ServiceCommand.TypeGet };
            request.AddListener(listener);

            AddSubscription(request);

            return request;
        }
        public IServiceSubscription SubscribeCurrentChannel(ResponseListener listener)
        {
            GetCurrentChannel(listener); // This is for the initial Current TV Channel Info.

            var request = new UrlServiceSubscription(this, "ChannelChanged", null, null)
            {
                HttpMethod = ServiceCommand.TypeGet
            };
            request.AddListener(listener);
            AddSubscription(request);

            return request;
        }
        public void UnPinWebApp(string webAppId, ResponseListener listener)
        {
            if (string.IsNullOrEmpty(webAppId))
            {
                if (listener != null)
                {
                    listener.OnError(new ServiceCommandError(-1, "You must provide a valid web app id"));
                }
                return;
            }

            const string uri = "ssap://webapp/removePinnedWebApp";
            var payload = new JsonObject();

            try
            {
                payload.Add("webAppId", JsonValue.CreateStringValue(webAppId));
            }
            // ReSharper disable once EmptyGeneralCatchClause
            catch (Exception)
            {

            }

            var responseListener = new ResponseListener
            (
                loadEventArg =>
                {
                    var loadEventArgs = loadEventArg as LoadEventArgs;
                    if (loadEventArgs == null) return;
                    var jsonObj = (JsonObject)(loadEventArgs.Load.GetPayload());
                    if (jsonObj.ContainsKey("pairingType"))
                    {
                        NotifyPairingRequired();
                    }
                    else
                    {
                        listener.OnSuccess(loadEventArg);
                    }
                },
                serviceCommandError => Util.PostError(listener, serviceCommandError)
            );

            ServiceCommand request = new UrlServiceSubscription(this, uri, payload, true, responseListener);
            request.Send();
        }
 public override void Unsubscribe(UrlServiceSubscription subscription)
 {
     if (socket != null)
         socket.Unsubscribe(subscription);
 }
        public override void DisconnectFromWebApp()
        {
            Connected = false;
            MConnectionListener = null;

            if (AppToAppSubscription != null)
            {
                AppToAppSubscription.RemoveListeners();
                AppToAppSubscription.Unsubscribe();
                AppToAppSubscription = null;
            }

            if (Socket == null) return;

            Socket.Listener = null;
            Socket.Disconnect();
            Socket = null;
        }
        public void Unsubscribe(UrlServiceSubscription subscription)
        {
            var requestId = subscription.RequestId;

            if (Requests[requestId] == null) return;
            var headers = new JsonObject();

            try
            {
                headers.Add("type", JsonValue.CreateStringValue("unsubscribe"));
                headers.Add("id", JsonValue.CreateStringValue(requestId.ToString()));
            }
            // ReSharper disable once RedundantCatchClause
            catch
            {
                throw;
            }

            SendMessage(headers, null);
            Requests.Remove(requestId);
        }
        // ReSharper disable once UnusedParameter.Local
        private void AddSubscription(UrlServiceSubscription subscription)
        {
            if (!httpServer.IsRunning)
            {
                httpServer.Start();
                SubscribeServices();
            }

            httpServer.Subscriptions.Add(subscription);
        }
        public override void Unsubscribe(UrlServiceSubscription subscription)
        {
            httpServer.Subscriptions.Remove(subscription);

            if (httpServer.Subscriptions.Count == 0)
            {
                UnsubscribeServices();
            }
        }
 public IServiceSubscription SubscribePlayState(ResponseListener listener)
 {
     var request = new UrlServiceSubscription(this, PLAY_STATE, null, null);
     request.AddListener(listener);
     AddSubscription(request);
     return request;
 }
 public IServiceSubscription SubscribeMediaInfo(ResponseListener listener)
 {
     var request = new UrlServiceSubscription(this, "info", null, null);
     request.AddListener(listener);
     AddSubscription(request);
     return request;
 }
        public UrlServiceSubscription Connect(ResponseListener listener)
        {
            var responseListener = new ResponseListener
            (
                loadEventArg =>
                {
                    var jsonObj = LoadEventArgs.GetValue<JsonObject>(loadEventArg);

                    var keyboard = parseRawKeyboardData(jsonObj);

                    Util.PostSuccess(listener, keyboard);
                },
                serviceCommandError => Util.PostError(listener, serviceCommandError)
            );

            var subscription = new UrlServiceSubscription(service, KeyboardInputUrl, null, true,
                responseListener);
            subscription.Send();

            return subscription;
        }