Sender application can be more powerful with the following advanced feature like WOW,BLE,Multitsking,install etc..
Authentication should ONLY be passed with secure connection"(coming soon)
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") }
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]; } } }
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.
install()
Also, you have 2 times chance to call install().
: You call getinfo() then you received onError code '404' that means your TV webapp not exist.
: You call connect() then you received onError code '404' that means your TV webapp not exist.
//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()); } }); } }); }
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.
For '16 TV, WoL(Wake-on-LAN), turning on the TV on connection with LAN cable, is also supported.
SDK 2.4.0 makes your app enable WOW function automatically without NO source code change.
If your app have been connected once,
Basic UI scenario
New Feature will do the following:
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
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:
Apart from the new APIs, there are also Error codes added for different scenarios to help the developer identify the problem
ERROR_HOST_UNREACHABLE: This error can be received in the completion handler of connect function. It will be received, there can be various reasons:
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.
ERROR_CONNECT_FAILED: When connection failed due to reasons other than Host unreachable. This error will be received in OnConnect() of Channel Delegate protocol
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
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.
(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.
Check Smart View SDK UX guideline for implementing WoW API.
// 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
service!.getDeviceInfo(5, completionHandler: { (deviceInfo, error) -> Void in let device = deviceInfo!["device"] let wifi = device!["wifiMac"] })
Service.WakeOnWirelessLan(macAddr)
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 ..... ..... })
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.
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... }
serviceSearch.stopUsingBLE()
The default value for multitasking support is true. Your application should support multitasking
Your app will change the background state in the following circumstances
tizen.application.getCurrentApplication().hide()
Your App can select one of two operation.
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) } } }
It need to update mobile library to use TLS feature Android 2.3.7 higher iOS 2.3.8 higher JS 2.3.3 higher
SmartviewSDK can make secure connection between sender and receiver through wss & http
refer to latest CastVideo sample app.
1) setSecurityMode API
setSecurityMode(security:completionHandler:)
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() }) }