private void AppStoreCommandExecute(object obj)
        {
            if (appStoreSession != null)
            {
                appStoreSession.Close(null);
                appStoreSession = null;
            }
            var listener = new ResponseListener
                (
                loadEventArg =>
                {
                    var session = LoadEventArgs.GetValue<LaunchSession>(loadEventArg);
                    appStoreSession = session;
                },
                serviceCommandError =>
                {

                }
                );

            String appId = null;

            if (selectedDevice.GetServiceByName("Netcast TV") != null)
                appId = "125071";
            else if (selectedDevice.GetServiceByName("webOS TV") != null)
                appId = "redbox";
            else if (selectedDevice.GetServiceByName("Roku") != null)
                appId = "13535";

            launcher.LaunchAppStore(appId, listener);
        }
        public WebOsWebAppSession(LaunchSession launchSession, DeviceService service)
            : base(launchSession, service)
        {
            uid = 0;
            mActiveCommands = new ConcurrentDictionary<String, ServiceCommand>();
            Connected = false;

            Service = (WebOstvService) service;
            mSocketListener = new WebOstvServiceSocketClientListener(this);
        }
        public static LaunchSession LaunchSessionFromJsonObject(JsonObject json)
        {
            var launchSession = new LaunchSession();
            try
            {
                launchSession.FromJsonObject(json);
            }
            // ReSharper disable once EmptyGeneralCatchClause
            catch (Exception)
            {

            }

            return launchSession;
        }
        private void InputCommandExecute(object obj)
        {
            var listener = new ResponseListener
                (
                loadEventArg =>
                {
                    var launchPickerSession = LoadEventArgs.GetValue<LaunchSession>(loadEventArg);
                    inputPickerSession = launchPickerSession;
                },
                serviceCommandError =>
                {

                }
                );
            externalInputControl.LaunchInputPicker(listener);
        }
        private void MyDialAppCommandExecute(object obj)
        {
            if (runningAppSession != null)
            {
                myAppSession.Close(null);
                myAppSession = null;
            }

            var listener = new ResponseListener
                (
                loadEventArg =>
                {
                    var session = LoadEventArgs.GetValue<LaunchSession>(loadEventArg);
                    myAppSession = session;
                },
                serviceCommandError =>
                {

                }
                );

            launcher.LaunchApp("Levak", listener);
        }
        public void LaunchInputPicker(ResponseListener pListener)
        {
            const string appName = "Input List";
            var encodedStr = HttpMessage.Encode(appName);

            var responseListener = new ResponseListener
            (
                loadEventArg =>
                {

                    var responseLaunchListener = new ResponseListener
                    (
                        loadEventArg2 =>
                        {
                            if (inputPickerSession == null)
                            {
                                inputPickerSession = (LaunchSession)loadEventArg2;
                            }

                            Util.PostSuccess(pListener, loadEventArg2);
                        },
                        serviceCommandError => Util.PostError(pListener, serviceCommandError)
                    );
                    LaunchApplication(appName, ((AppInfo)loadEventArg).Id, null, responseLaunchListener);
                },
                serviceCommandError => Util.PostError(pListener, serviceCommandError)
            );

            GetApplication(encodedStr, responseListener);
        }
        public void CloseMedia(LaunchSession launchSession, ResponseListener listener)
        {
            if (dlnaService == null)
            {
                Util.PostError(listener, new ServiceCommandError(0, null));
                return;
            }

            dlnaService.CloseMedia(launchSession, listener);
        }
        public void CloseApp(LaunchSession launchSession, ResponseListener listener)
        {
            var requestUrl = GetUdapRequestUrl(UdapPathApptoappCommand);

            var ps = new Dictionary<string, string> { { "name", "AppTerminate" }, { "auid", launchSession.AppId } };
            if (launchSession.AppName != null)
                ps.Add("appname", HttpMessage.Encode(launchSession.AppName));

            var httpMessage = GetUdapMessageBody(UdapApiCommand, ps);

            var command = new ServiceCommand(launchSession.Service,
                requestUrl, httpMessage, listener);
            command.Send();
        }
 public MediaLaunchObject(LaunchSession launchSession, IMediaControl mediaControl, IPlayListControl playlistControl)
 {
     LaunchSession = launchSession;
     MediaControl = mediaControl;
     PlaylistControl = playlistControl;
 }
        public ServiceCommand GetAppState(bool subscription, LaunchSession launchSession, ResponseListener listener)
        {
            var payload = new JsonObject();

            try
            {
                payload.Add("id", JsonValue.CreateStringValue(launchSession.AppId));
                payload.Add("sessionId", JsonValue.CreateStringValue(launchSession.SessionId));
            }
            catch
            {
            }

            var responseListener = new ResponseListener
            (
                loadEventArg =>
                {
                    var jsonObj = (JsonObject)(((LoadEventArgs)loadEventArg).Load.GetPayload());

                    try
                    {
                        Util.PostSuccess(listener,
                            new AppState(jsonObj.GetNamedBoolean("running"), jsonObj.GetNamedBoolean("visible")));
                    }
                    catch
                    {
                        Util.PostError(listener, new ServiceCommandError(0, "Malformed JSONObject"));
                    }
                },
                serviceCommandError => Util.PostError(listener, serviceCommandError)
            );

            var request = subscription
                ? new UrlServiceSubscription(this, AppStatus, payload, true, responseListener)
                : new ServiceCommand(this, AppStatus, payload, responseListener);

            request.Send();

            return request;
        }
        private WebOsWebAppSession WebAppSessionForLaunchSession(LaunchSession launchSession)
        {
            if (WebAppSessions == null)
                WebAppSessions = new Dictionary<String, WebOsWebAppSession>();

            if (launchSession.Service == null)
                launchSession.Service = this;

            WebOsWebAppSession webAppSession = WebAppSessions.ContainsKey(launchSession.AppId) ? WebAppSessions[launchSession.AppId] : null;

            if (webAppSession == null)
            {
                webAppSession = new WebOsWebAppSession(launchSession, this);
                WebAppSessions.Add(launchSession.AppId, webAppSession);
            }

            return webAppSession;
        }
        public static LaunchSession LaunchSessionForAppId(string appId)
        {
            var launchSession = new LaunchSession { AppId = appId };

            return launchSession;
        }
        private void GoogleCommandExecute(object obj)
        {
            if (runningAppSession != null)
            {
                runningAppSession.Close(null);
                runningAppSession = null;
            }
            var listener = new ResponseListener
                (
                loadEventArg =>
                {
                    var session = LoadEventArgs.GetValue<LaunchSession>(loadEventArg);
                    SetRunningAppInfo(session);
                },
                serviceCommandError =>
                {

                }
                );

            launcher.LaunchBrowser("http://connectsdk.com/", listener);
        }
        private void YouTubeCommandExecute(object obj)
        {
            if (runningAppSession != null)
            {
                runningAppSession.Close(null);
                runningAppSession = null;
            }

            var listener = new ResponseListener
                (
                loadEventArg =>
                {
                    var session = LoadEventArgs.GetValue<LaunchSession>(loadEventArg);
                    SetRunningAppInfo(session);
                },
                serviceCommandError =>
                {

                }
                );

            launcher.LaunchYouTube("eRsGyueVLvQ", listener);
        }
 private void SetRunningAppInfo(LaunchSession session)
 {
     runningAppSession = session;
 }
 public IServiceSubscription SubscribeAppState(LaunchSession launchSession, ResponseListener listener)
 {
     return (UrlServiceSubscription)GetAppState(true, launchSession, listener);
 }
        public void CloseWebApp(LaunchSession launchSession, ResponseListener listener)
        {
            if (launchSession == null || launchSession.AppId == null || launchSession.AppId.Length == 0)
            {
                Util.PostError(listener, new ServiceCommandError(0, null));
                return;
            }

            var webAppSession = WebAppSessions.ContainsKey(launchSession.AppId) ? WebAppSessions[launchSession.AppId] : null;

            if (webAppSession != null && webAppSession.IsConnected())
            {
                var serviceCommand = new JsonObject();
                var closeCommand = new JsonObject();

                try
                {
                    serviceCommand.Add("type", JsonValue.CreateStringValue("close"));

                    closeCommand.Add("contentType", JsonValue.CreateStringValue("connectsdk.serviceCommand"));
                    closeCommand.Add("serviceCommand", serviceCommand);
                }
                catch (Exception ex)
                {
                    throw ex;
                }

                var responseListener = new ResponseListener
                (
                    loadEventArg =>
                    {
                        webAppSession.DisconnectFromWebApp();

                        if (listener != null)
                            listener.OnSuccess(loadEventArg);
                    },
                    serviceCommandError =>
                    {
                        webAppSession.DisconnectFromWebApp();

                        if (listener != null)
                            listener.OnError(serviceCommandError);
                    }
                );

                webAppSession.SendMessage(closeCommand, responseListener);
            }
            else
            {
                //if (webAppSession != null)
                //    webAppSession.DisconnectFromWebApp();

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

                try
                {
                    if (launchSession.AppId != null)
                        payload.Add("webAppId", JsonValue.CreateStringValue(launchSession.AppId));
                    if (launchSession.SessionId != null)
                        payload.Add("sessionId", JsonValue.CreateStringValue(launchSession.SessionId));
                }
                catch (Exception e)
                {
                    throw e;
                }

                var request = new ServiceCommand(this, uri, payload, listener);
                request.Send();
            }
        }
        public void JoinWebApp(LaunchSession webAppLaunchSession, ResponseListener listener)
        {
            var webAppSession = WebAppSessionForLaunchSession(webAppLaunchSession);

            var responseListener = new ResponseListener
            (
                loadEventArg =>
                {
                    Util.PostSuccess(listener, webAppSession);
                },
                serviceCommandError =>
                {
                    Util.PostError(listener, serviceCommandError);
                });
            webAppSession.Join(responseListener);
        }
 public void GetAppState(LaunchSession launchSession, ResponseListener listener)
 {
     GetAppState(false, launchSession, listener);
 }
        public void LaunchAppWithInfo(AppInfo appInfo, object ps, ResponseListener listener)
        {
            const string uri = "ssap://system.launcher/launch";
            var payload = new JsonObject();

            var appId = appInfo.Id;
            string contentId = null;

            if (ps != null)
            {
                if (((JsonObject) ps).ContainsKey("contentId"))
                {
                    try
                    {
                        contentId = ((JsonObject)ps).GetNamedString("contentId");
                    }
                    // ReSharper disable once EmptyGeneralCatchClause
                    catch
                    {

                    }
                }
            }

            try
            {
                payload.Add("id", JsonValue.CreateStringValue(appId));

                if (contentId != null)
                    payload.Add("contentId", JsonValue.CreateStringValue(contentId));

                if (ps != null)
                    payload.Add("params", (JsonObject)ps);
            }
            // ReSharper disable once EmptyGeneralCatchClause
            catch
            {

            }

            var responseListener = new ResponseListener
                (
                loadEventArg =>
                {
                    var obj = (JsonObject)(((LoadEventArgs)loadEventArg).Load.GetPayload());
                    var launchSession = new LaunchSession
                    {
                        Service = this,
                        AppId = appId,
                        SessionId = obj.GetNamedString("sessionId"),
                        SessionType = LaunchSessionType.App
                    };

                    Util.PostSuccess(listener, launchSession);
                },
                serviceCommandError => Util.PostError(listener, serviceCommandError)
                );
            var request = new ServiceCommand(this, uri, payload, responseListener);
            request.Send();
        }
 public MediaLaunchObject(LaunchSession launchSession, IMediaControl mediaControl)
 {
     LaunchSession = launchSession;
     MediaControl = mediaControl;
 }
        public void LaunchBrowser(string url, ResponseListener listener)
        {
            const string uri = "ssap://system.launcher/open";
            var payload = new JsonObject();

            var responseListener = new ResponseListener
                (
                loadEventArg =>
                {
                    var obj = LoadEventArgs.GetValue<JsonObject>(loadEventArg);
                    var launchSession = new LaunchSession
                    {
                        Service = this,
                        AppId = obj.GetNamedString("id"),
                        SessionId = obj.GetNamedString("sessionId"),
                        SessionType = LaunchSessionType.App,
                        RawData = obj
                    };

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

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

            var request = new ServiceCommand(this, uri, payload, responseListener);
            request.Send();
        }
 public IServiceSubscription SubscribeAppState(LaunchSession launchSession, ResponseListener listener)
 {
     Util.PostError(listener, ServiceCommandError.NotSupported());
     return null;
 }
        public void CloseApp(LaunchSession launchSession, ResponseListener listener)
        {
            const string uri = "ssap://system.launcher/close";

            var appId = launchSession.AppId;
            var sessionId = launchSession.SessionId;
            var payload = new JsonObject();

            try
            {
                payload.Add("id", JsonValue.CreateStringValue(appId));
                if (sessionId != null)
                    payload.Add("sessionId", JsonValue.CreateStringValue(sessionId));
            }
            catch
            {
            }

            var request = new ServiceCommand(this, uri, payload, listener);
            request.Send();
        }
 public void CloseInputPicker(LaunchSession launchSession, ResponseListener pListener)
 {
     if (inputPickerSession != null)
     {
         inputPickerSession.Close(pListener);
     }
 }
 public void CloseInputPicker(LaunchSession launchSession, ResponseListener listener)
 {
     CloseApp(launchSession, listener);
 }
        public void GetAppState(LaunchSession launchSession, ResponseListener listener)
        {
            var requestUrl = string.Format("{0}{1}", GetUdapRequestUrl(UdapPathApptoappData),
                string.Format("/{0}/status", launchSession.AppId));

            var responseListener = new ResponseListener
            (
                loadEventArg =>
                {
                    var response = (string)loadEventArg;
                    AppState appState;
                    if (response.Equals("NONE"))
                        appState = new AppState(false, false);
                    else if (response.Equals("LOAD"))
                        appState = new AppState(false, true);
                    else if (response.Equals("RUN_NF"))
                        appState = new AppState(true, false);
                    else if (response.Equals("TERM"))
                        appState = new AppState(false, true);
                    else
                        appState = new AppState(false, false);

                    Util.PostSuccess(listener, appState);

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

            var command = new ServiceCommand(this, requestUrl, null, responseListener) { HttpMethod = ServiceCommand.TypeGet };
            command.Send();
        }
        public void CloseMedia(LaunchSession launchSession, ResponseListener listener)
        {
            var payload = new JsonObject();

            try
            {
                if (!string.IsNullOrEmpty(launchSession.AppId))
                    payload.Add("id", JsonValue.CreateStringValue(launchSession.AppId));

                if (!string.IsNullOrEmpty(launchSession.SessionId))
                    payload.Add("sessionId", JsonValue.CreateStringValue(launchSession.SessionId));
            }
            catch
            {

            }

            var request = new ServiceCommand(launchSession.Service, CloseMediaUri, payload, listener);
            request.Send();
        }
        public NetcastTvService(ServiceDescription serviceDescription, ServiceConfig serviceConfig)
            : base(serviceDescription, serviceConfig)
        {
            dlnaService = new DlnaService(serviceDescription, serviceConfig);

            if (serviceDescription != null && serviceDescription.Port != 8080)
                serviceDescription.Port = 8080;

            applications = new List<AppInfo>();
            subscriptions = new List<IServiceSubscription>();

            keyboardstring = new StringBuilder();

            httpClient = new HttpClient();
            inputPickerSession = null;
        }
Exemplo n.º 30
0
        public void DisplayMedia(string url, string mimeType, string title, string description, string iconSrc,
             ResponseListener listener)
        {
            const string instanceId = "0";
            var mediaElements = mimeType.Split('/');
            var mediaType = mediaElements[0];
            var mediaFormat = mediaElements[1];

            if (string.IsNullOrEmpty(mediaType) || string.IsNullOrEmpty(mediaFormat))
            {
                Util.PostError(listener,
                    new ServiceCommandError(0, null));
                return;
            }

            mediaFormat = "mp3".Equals(mediaFormat) ? "mpeg" : mediaFormat;
            var mMimeType = String.Format("{0}/{1}", mediaType, mediaFormat);

            var responseListener = new ResponseListener
            (
                loadEventArg =>
                {
                    const string playMethod = "Play";

                    var playParameters = new Dictionary<String, String> { { "Speed", "1" } };

                    var playPayload = GetMethodBody(AV_TRANSPORT_URN, "0", playMethod, playParameters);

                    var playResponseListener = new ResponseListener
                    (
                        loadEventArg2 =>
                        {
                            var launchSession = new LaunchSession { Service = this, SessionType = LaunchSessionType.Media };

                            Util.PostSuccess(listener, new MediaLaunchObject(launchSession, this, this));
                        },
                        serviceCommandError2 => Util.PostError(listener, serviceCommandError2));

                    var playRequest = new ServiceCommand(this, playMethod, playPayload, playResponseListener);
                    playRequest.Send();
                },
                serviceCommandError =>
                {
                    throw new Exception(serviceCommandError.ToString());
                }
            );

            const string setTransportMethod = "SetAVTransportURI";
            var metadata = GetMetadata(url, mMimeType, title, description, iconSrc);

            var setTransportParams = new Dictionary<String, String> { { "CurrentURI", url }, { "CurrentURIMetaData", metadata } };

            var setTransportPayload = GetMethodBody(AV_TRANSPORT_URN, instanceId, setTransportMethod, setTransportParams);

            var setTransportRequest = new ServiceCommand(this, setTransportMethod, setTransportPayload, responseListener);
            setTransportRequest.Send();
        }