[Service] Expose app id related APIs to public and add getCallerAppId 03/239803/6
authorYoungsoo Choi <kenshin.choi@samsung.com>
Thu, 30 Jul 2020 02:35:16 +0000 (19:35 -0700)
committerYoungsoo Choi <kenshin.choi@samsung.com>
Wed, 19 Aug 2020 23:44:41 +0000 (16:44 -0700)
This exposes getServiceId and getPackageId APIs to puglic profile.

Also, this newly adds getCallerAppId for the use of service apps.
For instance, it can be used when a service app wants to make
a messageport connection with a caller web app.

If there's no caller app, it returns ''.

Change-Id: Icfe221cb23acfb3587b38bd75fdce28ea5d2a23e
Signed-off-by: Youngsoo Choi <kenshin.choi@samsung.com>
wrt_app/common/service_manager.ts

index a4222ab..330e441 100644 (file)
@@ -47,12 +47,17 @@ export function startService(id: string, filename?: string) {
       module: new Module,
       require: require,
       tizen: global.tizen,
+      webapis: wrt.tv ? global.webapis : global.webapis = {},
     };
     sandbox[id].module.exports.onStop = () => {
       callFunctionInContext('module.exports.onExit', id);
     };
-    let service_id = id.split(':')[0];
-    sandbox[id].webapis = wrt.tv ? global.webapis : {};
+    let ids = id.split(':');
+    let caller_app_id = ids[1] ?? '';
+    sandbox[id].webapis.getCallerAppId = () => {
+      return caller_app_id;
+    }
+    let service_id = ids[0];
     sandbox[id].webapis.getServiceId = () => {
       return service_id;
     }
@@ -60,7 +65,7 @@ export function startService(id: string, filename?: string) {
       let app_info = global.tizen.application.getAppInfo(service_id);
       if (app_info)
         return app_info.packageId;
-      return '';
+      return ids[0].split('.')[0];
     }
 
     if (service_type !== 'UI') {