Sender application can be more powerful with the following advanced feature like WOW,BLE,Multitsking,install etc..
Android API Guide
SmartViewSDKCastVideo
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)
//String Type Map<String,Object> startArgs1 = new HashMap<String, Object>(); Object payload = "aaa"; startArgs1.put(Message.PROPERTY_MESSAGE_ID,payload); mApplication = mService.createApplication(mApplicationId, mChannelId,startArgs1);
//JSON Object Type JSONObject test2 = new JSONObject(); try { test2.put("userID","XX"); test2.put("userPW","1234"); test2.put("pairCode","XX@1234"); } catch (JSONException e) { e.printtackTrace(); } Map<String,Object> startArgs2 = new HashMap<String, Object>(); Object payload = test2.toString(); startArgs2.put(Message.PROPERTY_MESSAGE_ID,payload); mApplication = mService.createApplication(mApplicationId, mChannelId,startArgs2);
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 Smart 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 WOW APIs
SmartView SDK now supports WOW (enabled as default) for 2016 and above Samsung SmartTVs. It enables user to connect to a TV currently in standby mode. Upon making a connect() call to a standby TV, it tries to turn ON the TV and to establish a connection with the same.
Errors
Following error codes have been added, to identify problems w.r.t. WOW feature.
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
Check Smart View SDK UX guideline for implementing WoW API.
4. API Usage
1) How to get MAC address:
Service service.getDeviceInfo(new Result<Device>() { @Override public void onSuccess(Device device) { if (device != null) String wifiMac = device.getWifiMac(); SharedPreferences.Editor editor = getSharedPreferences("WoWMacs", 0).edit(); editor.putString(name, wifiMac); editor.commit(); } @Override public void onError(com.samsung.multiscreen.Error error) { } });
2) Wake up TV :
String mac = getSharedPreferences("WoWMacs", 0).getString(service.getName(), 0); Service.WakeOnWirelessLan(mac);
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.
//For connection is used default timeout: Service.DEFAULT_WOW_TIMEOUT_VALUE = 60000 String mac = getSharedPreferences("WoWMacs", 0).getString(service.getName(), 0); String uri = getSharedPreferences("WoWIps", 0).getString(mac, 0); Service.WakeOnWirelessAndConnect(mac, uri, new Result<Service>() { @Override public void onSuccess(Service service) { if (service != null) { Application application = service.createApplication("YOUR_APP_ID","YOUR_CHANNEL_ID"); application.connect(new Result<Client>() { @Override public void onSuccess(Client client) { if (client != null) { Log.d("log", "onSuccess: " + client.toString()); } } @Override public void onError(com.samsung.multiscreen.Error error) { Log.d("log", "onError: " + error.getMessage()); } }); } } @Override public void onError(com.samsung.multiscreen.Error error) { Log.d("log", "onError: " + error.getMessage()); } }); //Connect using custom timeout: int timeout = 120000; Service.WakeOnWirelessAndConnect(mac, uri, timeout, new Result<Service>()){ .... }
4) Make WoW TV list: This is a sample code showing how to manage the TV list.
// create Wow TV list ListView wowList = (ListView)findViewById(R.id.wowListView); standByListAdapter = new StandByModeTVListAdapter(this, R.layout.listview_item); wowList.setAdapter(standByListAdapter); // create available TV list ListView tvList = (ListView)findViewById(R.id.tvListView); tvListAdapter = new TVListAdapter(this, R.layout.listview_item); tvList.setAdapter(tvListAdapter); // stored names and mac addresses of connected before TVs SharedPreferences WoWMacs = getSharedPreferences("WoWMacs", 0); // stored names and uri of connected before TVs SharedPreferences WoWIps = getSharedPreferences("WoWIps", 0); // stored mac addresses and network's ids of connected before TVs to show available TVs only SharedPreferences WoWIds = getSharedPreferences("WoWIds", 0); if (WoWMacs!=null && WoWIps!=null && WoWIds!=null) { // get all stored TV's macs Map<String, String> macsList = (Map<String, String>) WoWMacs.getAll(); // get all stored TV's names Set<String> names = macsList.keySet(); for (String name : names) { // get TV mac according to name String mac = WoWMacs.getString(name, null); // get TV uri according to mac String uri = WoWIps.getString(mac, null); // get network id according to mac int wifiId = WoWIds.getInt(mac, 0); // check whether TV is on or off // check whether TV is in network or not if (mac != null && null != uri && !tvListAdapter.contains(uri) && wifiId == wifiManager.getConnectionInfo().getNetworkId() ) { // check regarding duplicates if (!ListWoW.contains(name + " (standby) : " + mac)) { ListWoW.add(name + " (standby) : " + mac); standByListAdapter.add(name + " (standby) : " + mac); standByListAdapter.notifyDataSetChanged(); } } } }
You can discover a compatible Samsung smart TV using Bluetooth Low Energy network by the Search class or BLESearchProvider class.
To start BLE discovery we need to Search object to discover TV's using startUsingBle() API of Smart View SDK.
startUsingBle()
Search search = com.samsung.multiscreen.Service.search(this); search.startUsingBle();
To get the discovered devices we need to register search object with setOnBleFoundListener listener. If BLE discovers any device, it notify through onFound() method of OnBleFoundListener.
onFound()
OnBleFoundListener
search.setOnBleFoundListener(new Search.OnBleFoundListener() { @Override public void onFoundOnlyBLE(String tvname) { bleTVList.add(tvname); Log.i(TAG,"TV found isActivityRunning(getApplicationContext()"+isActivityRunning(getApplicationContext()))); showNotification(tvname); onTimerTick(tvname); } });
To stop BLE discovery, call stopUsingBLE() API of Smart View SDK.
stopUsingBLE()
search.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 Android API Usage
//1. get "visibilitychange" message //2. manage TV Web App status. mApplication.addOnMessageListener("visibilitychange", new Application.OnMessageListener() { @Override public void onMessage(Message message) { Log.d(TAG, "addOnMessageListener visibilitychange : " + message.toString()+"date = "+message.getData()); if("hide".equals(message.getData())){ TVwebAppHide = true; Log.d(TAG, "addOnMessageListener TVwebAppHide : " + TVwebAppHide); } } }); //And then check TvAppHide //WebApp private void publish(final String event, final Object data){ if(mApplication != null) { if (TVwebAppHide) { //try to start(tv web app move background to foreground) mApplication.start(new Result<Boolean>() { @Override public void onSuccess(Boolean aBoolean) { TVwebAppHide = false; mApplication.publish(event, data); Log.d(TAG, "application.connect onSuccess " + aBoolean.toString()); } @Override public void onError(Error error) { Log.d(TAG, "application.connect onError " + error.toString()); } }); }else{ mApplication.publish(event,data); } } }
WebApp and Mobile app just close the connection when TV web app is in the background.
// 1. Disconnect when webapp become background status(hide) // 2. and mobile app(android) fire callback onDisconnect() and handle mobile app status. document.addEventListener("visibilitychange", function() { if(document.hidden){ console.log("App become be hide"); var app = tizen.application.getCurrentApplication(); if(app) app.exit(); } } );
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
public void setSecurityMode(boolean securityMode, Result <boolean> result)
<boolean>
2) Sample Code
mRemoteApp.setSecurityMode(true, new Result<Boolean>() { @Override public void onSuccess(Boolean aBoolean) { if (attributes != null) { mRemoteApp.connect(attributes, mConnectResult); } else { mRemoteApp.connect(mConnectResult); } mTimeoutTimer = new Timer(); mTimeoutTimer.schedule(new TimeoutTask(), timeout); } @Override public void onError(Error error) { FCError libError = new FCError(203, "Connecting error. Can't create TLS channel."); for (OnFCErrorListener listener : mFCErrorListeners) { listener.OnError(libError); } } });