[Service] Routing API - tizen.application
[platform/framework/web/wrtjs.git] / wrt_app / service / device_api_router.ts
1 import { wrt } from '../browser/wrt';
2
3 export class DeviceAPIRouter {
4   currentApplication: any;
5   funcCurrentApplication: any;
6   funcRequestedAppcontrol: any;
7   funcGetAppinfo: any;
8   funcGetAppcerts: any;
9   funcGetSharedUri: any;
10   funcGetMetadata: any;
11
12   constructor() {
13     this.RefineApplicationApis();
14   }
15
16   GetServiceId() {
17     return global.webapis.getServiceId();
18   }
19
20   RefineApplicationApis() {
21     // tizen.application.getCurrentApplication()
22     this.funcCurrentApplication = global.tizen.application.getCurrentApplication;
23     global.tizen.application.getCurrentApplication = () => {
24       console.log(`getCurrentApplication() : ${this.GetServiceId()}`);
25       if (this.currentApplication)
26         return this.currentApplication;
27       this.currentApplication = this.funcCurrentApplication();
28       // tizen.application.getCurrentApplication().getRequestedAppControl()
29       this.funcRequestedAppcontrol = this.currentApplication.getRequestedAppControl;
30       this.currentApplication.getRequestedAppControl = () => {
31         console.log(`getRequestedAppControl() : ${this.GetServiceId()}`);
32         if (wrt.tv)
33           wrt.tv.setCurrentApplication(this.GetServiceId());
34         return this.funcRequestedAppcontrol();
35       }
36       return this.currentApplication;
37     }
38     // tizen.application.getAppInfo()
39     this.funcGetAppinfo = global.tizen.application.getAppInfo;
40     global.tizen.application.getAppInfo = (app_id?: string) => {
41       console.log(`getAppInfo()`);
42       if (!app_id)
43         app_id = this.GetServiceId();
44       return this.funcGetAppinfo(app_id);
45     }
46     // tizen.application.getAppCerts()
47     this.funcGetAppcerts = global.tizen.application.getAppCerts;
48     global.tizen.application.getAppCerts = (app_id?: string) => {
49       console.log(`getAppCerts()`);
50       if (!app_id)
51         app_id = this.GetServiceId();
52       return this.funcGetAppcerts(app_id);
53     }
54     // tizen.application.getAppSharedURI()
55     this.funcGetSharedUri = global.tizen.application.getAppSharedURI;
56     global.tizen.application.getAppSharedURI = (app_id?: string) => {
57       console.log(`getAppSharedURI()`);
58       if (!app_id)
59         app_id = this.GetServiceId();
60       return this.funcGetSharedUri(app_id);
61     }
62     // tizen.application.getAppMetaData()
63     this.funcGetMetadata = global.tizen.application.getAppMetaData;
64     global.tizen.application.getAppMetaData = (app_id?: string) => {
65       console.log(`getAppMetaData()`);
66       if (!app_id)
67         app_id = this.GetServiceId();
68       return this.funcGetMetadata(app_id);
69     }
70   }
71 }