Enhanced Features

Sender application can be more powerful with the following advanced feature like WOW,BLE,Multitsking,install etc..


Related Info


StartArgs

Authentication should ONLY be passed with secure connection"(coming soon)

  • StartArg can be 'login user info','deeplink','AuthToken' etc..
  • Above Mobile Library Android 2.0.18 and iOS 2.2.2
  • Mobile App(Android)
    • MUST write "id" startArgs map's key.
    • simple string ("id","aaa");
    • json ,("id",data{"id":"XX","pw":"1234","pairing_code":"XX@1234"}
let dic:Dictionary  = ["userID":"idTest", "userPW":"1234"]

do{
    let data = try NSJSONSerialization.dataWithJSONObject(dic, options: .PrettyPrinted)
    let final : [String : AnyObject] = ["id" : String.init(data: data, encoding: NSUTF8StringEncoding)!]
    application = service.createApplication(appId, channelURI: channelId, args: final)
} catch {
    print("error")
}

TV Web App

To received "Start Args", MUST write "PAYLOAD" to get Data

msf.local(function(err, service){
var reqAppControl = tizen.application.getCurrentApplication().getRequestedAppControl();
log("reqAppControl =" + reqAppControl + ", appControl = "+reqAppControl.appControl);
if (reqAppControl && reqAppControl.appControl) {
  var data = reqAppControl.appControl.data;

  for (var i = 0; i < data.length; i++) {
   log("WRT param #" + i + " key : " + data[i].key);
      for (var j = 0; j < data[i].value.length; j++) {
          console.log("WRT param #" + i + " #" + j + " value : " + data[i].value[j]);
      }
      if (data[i].key == "PAYLOAD") {
       log("payload =" + data[i].value[0]);
       var payload = data[i].value[0];
      }
  }
}

Install API

Mobile app can make TV to show of webapp installation page when TV webapp is not exist. install() API is possible to make this scenario.

Also, you have 2 times chance to call install().

1. getinfo()

: You call getinfo() then you received onError code '404' that means your TV webapp not exist.

2. connect()

: You call connect() then you received onError code '404' that means your TV webapp not exist.

3. code flow

//1. Create Appication
mApplication = mService.createApplication(mApplicationId, mChannelId);

//2. Get AppicationInfo if you need
mApplication.getInfo(new Result<ApplicationInfo>() {

    @Override
    public void onSuccess(ApplicationInfo applicationInfo) {
        Log.d(TAG, "getInfo " + applicationInfo.toString());
    }


    @Override
    public void onError(com.samsung.multiscreen.Error error) {
        if (error.getCode() == 404) {
            //Install the application on the TV. 
            //Note: This will only bring up the installation page on the TV. 
            //The user will still have to acknowledge by selecting "install" using the TV remote.

            application.install(new Result<Boolean>() {
                @Override
                public void onSuccess(Boolean result) {
                    Log.d(LOGTAG, "Application.install onSuccess() " + result.toString());
                }
            });  
        }
    });
});

//3. Launch installed app
mApplication.connect(new Result<Client>() {
    @Override
    public void onSuccess(Client client) {
        Log.d(TAG, "application.connect onSuccess " + client.toString());
    }

    @Override
    public void onError(com.samsung.multiscreen.Error error) {
        if (error.getCode() == 404) {
            //Install the application on the TV. 
            //Note: This will only bring up the installation page on the TV. 
            //The user will still have to acknowledge by selecting "install" using the TV remote.
            application.install(new Result<Boolean>() {
                @Override
                public void onSuccess(Boolean result) {
                    Log.d(LOGTAG, "Application.install onSuccess() " + result.toString());
                }
            });     
        }
    });
} 

WoW (Wake on Wireless LAN)

This section explains how a Samsung Tizen TV can use Wake on Wireless LAN (WoWLAN) to power on a previously discovered TV.

This enables the mobile device to subsequently start and interact with applications on the Samsung Tizen TV.

Latest SmartViewSDK include Enhaned WOW feature

SDK 2.4.0 makes your app enable WOW function automatically without NO source code change.

  1. If your app have been connected once,

    • SDK manage the TV device list for WOW feature
    • SDK handles below Basic UI scenario
  2. Basic UI scenario

    • Turn the TV off (put to standby).
    • Appears marked as “TV_NAME(standby)” within 7 seconds.
    • Select the TV.
    • The TV power on
    • The TV WebApp(or DMP) should start loading on the TV.
    • The video should start playing on the TV.

New Feature will do the following:

  1. Show standby devices: Devices which were successfully connected in the past but now are switched-OFF will be visible to the Application developer after 7 seconds when he/she starts discovery

  2. Integrated Connect API: Calling connect on the standby devices will try to wake the TV if switched off. Then it will try for 1 minute to get updated service from the switched-ON TV. If able to get the service then will connect with the TV.

In order to use this feature the following new APIs are available for Developer’s ease:

  1. WOW on/off:
    • Search.start() : By default will show standby devices.
    • Search.start(false) : will disable this feature and the Application developer will no longer be shown standby devices
  2. Service.remove()
    will remove the stored standby service from the Data base
  3. Search.clearStandbyDevices()
    will clear all the saved devices from the Data base

Apart from the new APIs, there are also Error codes added for different scenarios to help the developer identify the problem

  1. ERROR_HOST_UNREACHABLE: This error can be received in the completion handler of connect function. It will be received, there can be various reasons:

    1. TV power OFF
    2. TV Switched ON but discovery not done in 1 minute
  2. ERROR_ALREADY_CONNECTED: This error comes when User tries to connect to already connected device. Error can be received in the completion handler of connect function.

  3. ERROR_CONNECT_FAILED: When connection failed due to reasons other than Host unreachable. This error will be received in OnConnect() of Channel Delegate protocol

  4. ERROR_WEBSOCKET_DISCONNECTED: After connection to TV is successful but due to some reason, the websocket disconnects. This error will be received in OnError() of Channel Delegate protocol

Implement manually lower version of SDK 2.4.0

1. Simple implementation guide

The Mobile device must get TV's MAC info when connected successfully.

The Mobile device must store certain values(MAC), so that the Mobile device can use Wake-up to power on the TV next time.

2. Pre-condition

(MUST) Mobile App should have connected successfully at least once so that TV can register mobile MAC.

When TV is turned off, the TV status should be displayed as “{TV Name} (standby)” on the mobile device.

3. Basic UI scenario

  1. Turn the TV off (put to standby).
  2. Within 60 seconds TV disappears from the list and within 30 seconds reappears marked as "(standby)".
  3. Select the TV.
  4. The TV should start loading.
  5. The TV WebApp(or DMP) should start loading on the TV.
  6. The video should start playing on the TV.

4. API Usage

// Send a packet for WakeOnWirelessLan. func WakeOnWirelessLan(macAddr:String)         
where: macAddr - MAC address of TV

// Send a packet via WakeOnWirelessLan and create and connect to particular application
func WakeOnWirelessAndConnect(macAddr:String, uri:String, timeOut:NSTimeInterval, completionHandler: (service:Service? , error: NSError? ) -> Void) -> Void

where:
macAddr - MAC address of TV
uri     - URI of service
completionHandler - callback to invoke with the result of connect request

// get the service of wake up TV
func WakeUpAndConnect(uri:String, completionHandler: (service:Service?, error:NSError?) -> Void)      

where:
uri - URI of service
completionHandler - callback to invoke with the result of connect request           

1) How to get MAC address:

service!.getDeviceInfo(5, completionHandler: {  (deviceInfo, error) -> Void in        

    let device = deviceInfo!["device"]
    let wifi = device!["wifiMac"]
})

2) Wake up TV :

Service.WakeOnWirelessLan(macAddr) 

3) Wake up TV and connect :

This API turns on the selected TV and Smart View SDK confirm to be ready.

Then, you can turn on the TV and launch your application.

Default timeout for connection is used Service.DEFAULT_WOW_TIMEOUT_VALUE:NSTimeInterval = 6

Service.WakeOnWirelessAndConnect(macAddr, uri, completionHandler: {(service, error) -> Void in

    if(service != nil) {
        let url = NSURL(string: "http://dev-multiscreen-examples.s3-website-us-west-1.amazonaws.com/examples/helloworld/tv/")
        let app = service?.createApplication(url!, channelURI: "com.samsung.multiscreen.msf20", args: nil)
        app?.delegate = self
        app?.connect()

    }         
})

//Connect using custom timeout
//let timeout:NSTimeInterval = 12
Service.WakeOnWirelessAndConnect(macAddr, uri, timeout, completionHandler: {(service, error) -> Void in
    .....    
    .....           
})

BLE Discovery (Bluetooth Low Energy)

Smart View framework supports discovery of Samsung devices via Bluetooth Low Energy in the surrounding area.

BLE discovery allows user to see the list of available TVs that user can connect with. BLE discovery does not support retrieving the Service objects using Bluetooth currently.

The following example demonstrates how to launch BLE discovery and get the discovered devices.

Launch the search for BLE devices:

let serviceSearch = Service.search()
init () {
    // The delegate is implemented as a weak reference
    serviceSearch.startUsingBLE()
}

// MARK: - ServiceSearchDelegate -
func onFoundOnlyBLE(NameOfTV: String)
{
    print("Found BLE device: \(NameOfTV)")
    // Update your UI...
}

Stop BLE Discovery:

serviceSearch.stopUsingBLE()

Support Multitasking

The default value for multitasking support is true. Your application should support multitasking

Your app will change the background state in the following circumstances

  • Launching other application over currently running application.
  • Calling tizen.application.getCurrentApplication().hide() method.
  • Turning off TV during application running in Samsung Instant On mode.
  • Clicking "Smart Hub" button and going to the Apps page.

Your App can select one of two operation.

  • Keep connection
  • Close connection

Keep connection

Webapp and mobile app keep the connection.

and mobile app can change the state TV app(background to foreground)

Example Javascript API Usage(Web App)

// Support MultiTasking
// Case 2) Keep Connection.
// 1. Keep connect status.
// 2. Notify to Mobile
document.addEventListener("visibilitychange", function() {

log("App become be hide "+document.hidden);
   if(document.hidden){
     console.log("App become be hide");
     channel.publish('visibilitychange', 'hide');
    }
} );

Example mobile API Usage

// MARK: - ChannelDelegate -
func onMessage(_ message: Message)
{
    print("Message Received")
    switch message.event {
    case "visibilitychange" :
        if let data = message.data as? String {
            if data == "hide" {
                TVwebAppHide = true
            } else {
                TVwebAppHide = false
            }
        }
        break
    default:
        break
    }
}

//And then check TvAppHide
func publish(event: String, message: AnyObject?) {
    if (self.remote != nil) {
        if (TVwebAppHide) {
            application?.start({ (result, error) in
                if (error == nil) {
                    self.TVwebAppHide = false
                    self.msApplication?.publish(event: event, message: message)
                } else {
                    print("application start error \(error)")
                }
            })
        } else {
            self.msApplication?.publish(event: event, message: message)
        }
    }
}

TLS (make secure connection)

SmartviewSDK can make secure connection between sender and receiver through wss & http

refer to latest CastVideo sample app.

1) setSecurityMode API

setSecurityMode(security:completionHandler:)

  • Set security mode status to for web socket connection or rest API
  • Parameters:
    • securityMode - security mode status to set
    • result - result to return whether security mode was set or not

2) Sample Code

var app: Application?
var appURL_SSL:String = "http://www.samsungdforum.com/smartview/helloworldssl/tv/"
var services = [Service]()

func connect(_ service: Service)
{
    app = service.createApplication(NSURL(string: self.appURL_SSL)!, channelURI: self.channelId, args: nil)
    app?.setSecurityMode(security: true, completionHandler:
    {(isSupport, error) ? Void in
      self.app!.delegate = self
      self.app!.connect()
   }) 
}