WebAppSession¶
com.connectsdk.service.sessions.WebAppSession
Overview When a web app is launched on a first screen device, there are¶
certain tasks that can be performed with that web app. WebAppSession serves as a second screen reference of the web app that was launched. It behaves similarly to LaunchSession, but is not nearly as static.
In Depth On top of maintaining session information (contained in the¶
launchSession property), WebAppSession provides access to a number of capabilities. - MediaPlayer - MediaControl - Bi-directional communication with web app
MediaPlayer and MediaControl are provided to allow for the most common first screen use cases a media player (audio, video, & images).
The Connect SDK JavaScript Bridge has been produced to provide normalized support for these capabilities across protocols (Chromecast, webOS, etc).
Properties¶
- LaunchSession launchSession
- LaunchSession object containing key session information. Much of this information is required for web app messaging & closing the web app.
Inner Classes¶
- LaunchListener <and-webappsession-launchlistener>
- StatusListener <and-statuslistener>
- WebAppPinStatusListener <and-webapppinstatuslistener>
- WebAppStatus <and-webappstatus>
Methods¶
WebAppSession (LaunchSession launchSession, DeviceService service)
Instantiates a WebAppSession object with all the information necessary to interact with a web app.
- Parameters:
- launchSession – LaunchSession containing info about the web app session
- service – DeviceService that was responsible for launching this web app
ServiceSubscription <MessageListener> subscribeWebAppStatus (MessageListener listener)
Subscribes to changes in the web app’s status.
- Parameters:
- listener – (optional) MessageListener to be called on app status change
void connect (ResponseListener <Object> connectionListener)
Establishes a communication channel with the web app.
- Parameters:
- connectionListener – (optional) ResponseListener to be called on success
void join (ResponseListener <Object> connectionListener)
Establishes a communication channel with a currently running web app.
- Parameters:
- connectionListener
void disconnectFromWebApp ()
Closes any open communication channel with the web app.
void pinWebApp (String webAppId, ResponseListener <Object> listener)
Pin the web app on the launcher.
- Parameters:
- webAppId
- listener – (optional) ResponseListener< Object > with methods to be called on success or failure
void unPinWebApp (String webAppId, ResponseListener <Object> listener)
UnPin the web app on the launcher.
- Parameters:
- webAppId – NSString webAppId to be unpinned.
- listener – (optional) ResponseListener< Object > with methods to be called on success or failure
void isWebAppPinned (String webAppId, WebAppPinStatusListener listener)
To check if the web app is pinned or not
- Parameters:
- webAppId
- listener – (optional) WebAppPinStatusListener with methods to be called on success or failure
ServiceSubscription <WebAppPinStatusListener> subscribeIsWebAppPinned (String webAppId, WebAppPinStatusListener listener)
Subscribe to check if the web app is pinned or not
- Parameters:
- webAppId
- listener – (optional) WebAppPinStatusListener with methods to be called on success or failure
void close (ResponseListener <Object> listener)
Closes the web app on the first screen device.
- Parameters:
- listener – (optional) ResponseListener to be called on success
void sendMessage (String message, ResponseListener <Object> listener)
Sends a simple string to the web app. The Connect SDK JavaScript Bridge will receive this message and hand it off as a string object.
- Parameters:
- message
- listener – (optional) ResponseListener to be called on success
void sendMessage (JSONObject message, ResponseListener <Object> listener)
Sends a JSON object to the web app. The Connect SDK JavaScript Bridge will receive this message and hand it off as a JavaScript object.
- Parameters:
- message
- listener – (optional) ResponseListener< Object > with methods to be called on success or failure
WebAppSessionListener getWebAppSessionListener ()
When messages are received from a web app, they are parsed into the appropriate object type (string vs JSON/NSDictionary) and routed to the WebAppSessionListener.
void setWebAppSessionListener (WebAppSessionListener listener)
When messages are received from a web app, they are parsed into the appropriate object type (string vs JSON/NSDictionary) and routed to the WebAppSessionListener.
- Parameters:
- listener – WebAppSessionListener to be called when messages are received from the web app
Inherited Methods¶
MediaControl getMediaControl ()
Get MediaControl implementation
Returns: MediaControl
CapabilityPriorityLevel getMediaControlCapabilityLevel ()
Get a capability priority for current implementation
Returns: CapabilityPriorityLevel
void play (ResponseListener <Object> listener)
Send play command.
- Related capabilities:
MediaControl.Play
- Parameters:
- listener – (optional) ResponseListener< Object > with methods to be called on success or failure
void pause (ResponseListener <Object> listener)
Send pause command.
- Related capabilities:
MediaControl.Pause
- Parameters:
- listener – (optional) ResponseListener< Object > with methods to be called on success or failure
void stop (ResponseListener <Object> listener)
Send play command.
- Related capabilities:
MediaControl.Stop
- Parameters:
- listener – (optional) ResponseListener< Object > with methods to be called on success or failure
void rewind (ResponseListener <Object> listener)
Send rewind command.
- Related capabilities:
MediaControl.Rewind
- Parameters:
- listener – (optional) ResponseListener< Object > with methods to be called on success or failure
void fastForward (ResponseListener <Object> listener)
Send play command.
- Related capabilities:
MediaControl.FastForward
- Parameters:
- listener – (optional) ResponseListener< Object > with methods to be called on success or failure
void previous (ResponseListener <Object> listener)
This method is deprecated. Use
PlaylistControl::previous(ResponseListener<Object> listener)
instead.
- Parameters:
- listener – (optional) ResponseListener< Object > with methods to be called on success or failure
void next (ResponseListener <Object> listener)
This method is deprecated. Use
PlaylistControl::next(ResponseListener<Object> listener)
instead.
- Parameters:
- listener – (optional) ResponseListener< Object > with methods to be called on success or failure
void seek (long position, ResponseListener <Object> listener)
Seeks to a new position within the current media item
- Related capabilities:
MediaControl.Seek
- Parameters:
- position – The new position, in milliseconds from the beginning of the stream
- listener – (optional) ResponseListener< Object > with methods to be called on success or failure
void getDuration (DurationListener listener)
Get the current media duration in milliseconds
- Parameters:
- listener – (optional) DurationListener with methods to be called on success or failure
void getPosition (PositionListener listener)
Get the current playback position in milliseconds
- Parameters:
- listener – (optional) PositionListener with methods to be called on success or failure
void getPlayState (PlayStateListener listener)
Get the current state of playback
- Parameters:
- listener – (optional) PlayStateListener with methods to be called on success or failure
ServiceSubscription <PlayStateListener> subscribePlayState (PlayStateListener listener)
Subscribe for playback state changes
- Parameters:
- listener – receives play state notifications
Returns: ServiceSubscription<PlayStateListener>
MediaPlayer getMediaPlayer ()
CapabilityPriorityLevel getMediaPlayerCapabilityLevel ()
void getMediaInfo (MediaInfoListener listener)
- Parameters:
- listener – (optional) MediaInfoListener with methods to be called on success or failure
ServiceSubscription <MediaInfoListener> subscribeMediaInfo (MediaInfoListener listener)
- Parameters:
- listener – (optional) MediaInfoListener with methods to be called on success or failure
void displayImage (MediaInfo mediaInfo, LaunchListener listener)
Display an image on the device. Not all devices support all of the parameters – supply as many as you have available.
- Related capabilities:
MediaPlayer.Display.Image
MediaPlayer.MediaData.Title
MediaPlayer.MediaData.Description
MediaPlayer.MediaData.Thumbnail
MediaPlayer.MediaData.MimeType
- Parameters:
- mediaInfo – Object of MediaInfo class which includes all the information about an image to display.
- listener – (optional) LaunchListener with methods to be called on success or failure
void playMedia (MediaInfo mediaInfo, boolean shouldLoop, LaunchListener listener)
Play an audio or video file on the device. Not all devices support all of the parameters – supply as many as you have available.
- Related capabilities:
MediaPlayer.Play.Video
MediaPlayer.Play.Audio
MediaPlayer.MediaData.Title
MediaPlayer.MediaData.Description
MediaPlayer.MediaData.Thumbnail
MediaPlayer.MediaData.MimeType
- Parameters:
- mediaInfo – Object of MediaInfo class which includes all the information about an image to display.
- shouldLoop – Whether to automatically loop playback
- listener – (optional) LaunchListener with methods to be called on success or failure
void closeMedia (LaunchSession launchSession, ResponseListener <Object> listener)
Close a running media session. Because media is handled differently on different platforms, it is required to keep track of LaunchSession and MediaControl objects to control that media session in the future. LaunchSession will be required to close the media and mediaControl will be required to control the media.
- Related capabilities:
MediaPlayer.Close
- Parameters:
- launchSession – LaunchSession object for use in closing media instance
- listener – (optional) ResponseListener< Object > with methods to be called on success or failure
PlaylistControl getPlaylistControl ()
CapabilityPriorityLevel getPlaylistControlCapabilityLevel ()
void jumpToTrack (long index, ResponseListener <Object> listener)
Jump the playlist to the designated track.
Play a track specified by index in the playlist
- Related capabilities:
PlaylistControl.JumpToTrack
- Parameters:
- index – index in the playlist, it starts from zero like index of array
- listener – optional response listener
void setPlayMode (PlayMode playMode, ResponseListener <Object> listener)
Set order of playing tracks
- Parameters:
- playMode
- listener – optional response listener