From 6f0e9a8166b86205c77bb5c22b2dd8ea4df21642 Mon Sep 17 00:00:00 2001 From: Aron kim Date: Wed, 9 Sep 2020 22:16:15 -0700 Subject: [PATCH] [D2D] Modify to not launch d2d app repeatedly. When the remote client launching the d2d app in device home, change to connect only the websocket if the d2d app status is visible. Change-Id: Iab323ee86cc3a979521daf6c3a6b7485904233a6 Signed-off-by: Aron kim --- d2d_app/service/app_proxy.js | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/d2d_app/service/app_proxy.js b/d2d_app/service/app_proxy.js index 7255840..3db4507 100644 --- a/d2d_app/service/app_proxy.js +++ b/d2d_app/service/app_proxy.js @@ -2,6 +2,7 @@ var express = require('express'); const AppRouter = require('./app_router'); var appRouters = []; var path = null; +var currentD2DAppId = null; module.exports = function(app, port) { var appProxy = express.Router(); @@ -27,16 +28,34 @@ module.exports = function(app, port) { }); } - var appControl = new tizen.ApplicationControl( - "http://tizen.org/appcontrol/operation/default", null, null, null, - [new tizen.ApplicationControlData( - "http://tizen.org/appcontrol/data/launch_port", [port] - )] - ); + function onRunningAppsContext(contexts) { + var isRunning = false; + for (var i = 0; i < contexts.length; i++) { + if (appId === contexts[i].appId) { + isRunning = true; + break; + } + } + + if (isRunning && currentD2DAppId === appId) { + res.send({port:port}); + } else { + var appControl = new tizen.ApplicationControl( + "http://tizen.org/appcontrol/operation/default", null, null, null, + [new tizen.ApplicationControlData( + "http://tizen.org/appcontrol/data/launch_port", [port] + )] + ); + + tizen.application.launchAppControl(appControl, appId, function() { + res.send({port:port}); + }); + + currentD2DAppId = appId; + } + } - tizen.application.launchAppControl(appControl, appId, function() { - res.send({port:port}); - }); + tizen.application.getAppsContext(onRunningAppsContext); }); appProxy.get('/', (req, res) => { -- 2.7.4