2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 /* This file is based on:
18 * Copyright (c) 2014 LG Electronics.
19 * Created by Jeffrey Glenn on 07 Mar 2014
21 * Licensed under the Apache License, Version 2.0 (the "License");
22 * you may not use this file except in compliance with the License.
23 * You may obtain a copy of the License at
25 * http://www.apache.org/licenses/LICENSE-2.0
27 * Unless required by applicable law or agreed to in writing, software
28 * distributed under the License is distributed on an "AS IS" BASIS,
29 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
30 * See the License for the specific language governing permissions and
31 * limitations under the License.
34 package org.openhab.binding.lgwebos.internal.handler.core;
36 import org.openhab.binding.lgwebos.internal.handler.LGWebOSTVSocket;
39 * {@link LaunchSession} is a value object to describe a session with an application running on WebOSTV.
41 * Any time anything is launched onto a first screen device, there will be important session information that needs to
42 * be tracked. {@link LaunchSession} tracks this data, and must be retained to perform certain actions within the
45 * @author Jeffrey Glenn - Connect SDK initial contribution
46 * @author Sebastian Prehn - Adoption for openHAB
48 public class LaunchSession {
51 private String appName;
52 private String sessionId;
54 private transient LGWebOSTVSocket socket;
55 private transient LaunchSessionType sessionType;
58 * LaunchSession type is used to help DeviceService's know how to close a LaunchSession.
61 public enum LaunchSessionType {
62 /** Unknown LaunchSession type, may be unable to close this launch session */
64 /** LaunchSession represents a launched app */
66 /** LaunchSession represents an external input picker that was launched */
68 /** LaunchSession represents a media app */
70 /** LaunchSession represents a web app */
74 public LaunchSession() {
78 * Instantiates a LaunchSession object for a given app ID.
80 * @param appId System-specific, unique ID of the app
81 * @return the launch session
83 public static LaunchSession launchSessionForAppId(String appId) {
84 LaunchSession launchSession = new LaunchSession();
85 launchSession.appId = appId;
89 /** @return System-specific, unique ID of the app (ex. youtube.leanback.v4, 0000134, hulu) */
90 public String getAppId() {
95 * Sets the system-specific, unique ID of the app (ex. youtube.leanback.v4, 0000134, hulu)
97 * @param appId Id of the app
99 public void setAppId(String appId) {
103 /** @return User-friendly name of the app (ex. YouTube, Browser, Hulu) */
104 public String getAppName() {
109 * Sets the user-friendly name of the app (ex. YouTube, Browser, Hulu)
111 * @param appName Name of the app
113 public void setAppName(String appName) {
114 this.appName = appName;
117 /** @return Unique ID for the session (only provided by certain protocols) */
118 public String getSessionId() {
123 * Sets the session id (only provided by certain protocols)
125 * @param sessionId Id of the current session
127 public void setSessionId(String sessionId) {
128 this.sessionId = sessionId;
131 /** @return WebOSTVSocket responsible for launching the session. */
132 public LGWebOSTVSocket getService() {
137 * DeviceService responsible for launching the session.
139 * @param service Sets the DeviceService
141 public void setService(LGWebOSTVSocket service) {
142 this.socket = service;
146 * @return When closing a LaunchSession, the DeviceService relies on the sessionType to determine the method of
147 * closing the session.
149 public LaunchSessionType getSessionType() {
154 * Sets the LaunchSessionType of this LaunchSession.
156 * @param sessionType The type of LaunchSession
158 public void setSessionType(LaunchSessionType sessionType) {
159 this.sessionType = sessionType;
163 * Close the app/media associated with the session.
165 * @param listener the response listener
167 public void close(ResponseListener<CommandConfirmation> listener) {
168 socket.closeLaunchSession(this, listener);