[Service][TV] Introduce ServiceMessage 87/272287/4 accepted/tizen/unified/20220318.020441 submit/tizen/20220316.160023
authorDongHyun Song <dh81.song@samsung.com>
Mon, 14 Mar 2022 06:11:20 +0000 (15:11 +0900)
committerDongHyun Song <dh81.song@samsung.com>
Wed, 16 Mar 2022 07:59:57 +0000 (16:59 +0900)
This introduces service message notification for DeviceHome
The case doesn't use Samsung IME, the UI app can utilize ServiceMessage
to catch propagating message from DeviceHome.
notifyServiceMessage() will give a message only to foreground application.

Change-Id: If36cb754382fc2c0f6d186c212a40c28ccf3eb9b
Signed-off-by: DongHyun Song <dh81.song@samsung.com>
wrt_app/common/service_message.ts [new file with mode: 0644]
wrt_app/service/device_api_router.ts

diff --git a/wrt_app/common/service_message.ts b/wrt_app/common/service_message.ts
new file mode 100644 (file)
index 0000000..4080701
--- /dev/null
@@ -0,0 +1,20 @@
+import { wrt } from '../browser/wrt';
+
+let foregroundAppMessagePort: any = null;
+let lastForegroundApp: string = '';
+
+export function notifyServiceMessage(type: string, message: string) {
+  let foregroundApp = wrt.tv?.getForegroundApp();
+  if (!foregroundApp || foregroundApp == 'none')
+    return;
+
+  try {
+    if (!foregroundAppMessagePort || lastForegroundApp != foregroundApp) {
+      foregroundAppMessagePort =
+        global.tizen.messageport.requestRemoteMessagePort(foregroundApp, 'wrt.message.port');
+      lastForegroundApp = foregroundApp;
+    }
+    if (foregroundAppMessagePort)
+      foregroundAppMessagePort.sendMessage([{key: type, value: ['', message]}]);
+  } catch { }
+}
index afbd161..eed2979 100644 (file)
@@ -1,4 +1,5 @@
 import { wrt } from '../browser/wrt';
+import * as ServiceMessage from '../common/service_message';
 
 export class DeviceAPIRouter {
   currentApplication: any;
@@ -101,6 +102,7 @@ export class DeviceAPIRouter {
         }
         global.webapis.mde.updateRemoteInput = (inputString: string) => {
           mde.updateRemoteInput(inputString);
+          ServiceMessage.notifyServiceMessage('remote-input', inputString);
         }
         global.webapis.mde.selectRemoteInput = () => {
           mde.selectRemoteInput();