sandbox[id].module.exports.onStop = () => {
callFunctionInContext('module.exports.onExit', sandbox[id]);
};
- if (wrt.tv) {
- sandbox[id].webapis = global.webapis;
- sandbox[id].webapis.getServiceId = () => {
- let service_id = id.split(':')[0];
- return service_id;
- }
- sandbox[id].webapis.getPackageId = () => {
- let service_id = id.split(':')[0];
- let app_info = global.tizen.application.getAppInfo(service_id);
- if (app_info)
- return app_info.packageId;
- return '';
- }
+ let service_id = id.split(':')[0];
+ sandbox[id].webapis = wrt.tv ? global.webapis : {};
+ sandbox[id].webapis.getServiceId = () => {
+ return service_id;
+ }
+ sandbox[id].webapis.getPackageId = () => {
+ let app_info = global.tizen.application.getAppInfo(service_id);
+ if (app_info)
+ return app_info.packageId;
+ return '';
}
if (service_type !== 'UI') {
}
code = `const app = require('${filename}')`;
if (service_type === 'DAEMON') {
- internal_handler[id].deivce_api_router = new DeviceAPIRouter(id, sandbox);
+ internal_handler[id].deivce_api_router = new DeviceAPIRouter();
}
vm.runInNewContext(code, sandbox[id], options);
}
import { wrt } from '../browser/wrt';
export class DeviceAPIRouter {
- service_id?: string;
- package_id?: string;
- current_application?: any;
+ currentApplication: any;
+ funcCurrentApplication: any;
+ funcRequestedAppcontrol: any;
+ funcGetAppinfo: any;
+ funcGetAppcerts: any;
+ funcGetSharedUri: any;
+ funcGetMetadata: any;
- constructor(id: string, sandbox: any) {
- let tizen = global.tizen;
- this.service_id = id.split(':')[0];
- let app_info = tizen.application.getAppInfo(this.service_id);
- if (app_info)
- this.package_id = app_info.packageId;
- console.log(`DeviceAPIRouter created for ${this.service_id} ${this.package_id}`);
- // TODO
+ constructor() {
+ this.RefineApplicationApis();
+ }
+
+ GetServiceId() {
+ return global.webapis.getServiceId();
+ }
+
+ RefineApplicationApis() {
+ // tizen.application.getCurrentApplication()
+ this.funcCurrentApplication = global.tizen.application.getCurrentApplication;
+ global.tizen.application.getCurrentApplication = () => {
+ console.log(`getCurrentApplication() : ${this.GetServiceId()}`);
+ if (this.currentApplication)
+ return this.currentApplication;
+ this.currentApplication = this.funcCurrentApplication();
+ // tizen.application.getCurrentApplication().getRequestedAppControl()
+ this.funcRequestedAppcontrol = this.currentApplication.getRequestedAppControl;
+ this.currentApplication.getRequestedAppControl = () => {
+ console.log(`getRequestedAppControl() : ${this.GetServiceId()}`);
+ if (wrt.tv)
+ wrt.tv.setCurrentApplication(this.GetServiceId());
+ return this.funcRequestedAppcontrol();
+ }
+ return this.currentApplication;
+ }
+ // tizen.application.getAppInfo()
+ this.funcGetAppinfo = global.tizen.application.getAppInfo;
+ global.tizen.application.getAppInfo = (app_id?: string) => {
+ console.log(`getAppInfo()`);
+ if (!app_id)
+ app_id = this.GetServiceId();
+ return this.funcGetAppinfo(app_id);
+ }
+ // tizen.application.getAppCerts()
+ this.funcGetAppcerts = global.tizen.application.getAppCerts;
+ global.tizen.application.getAppCerts = (app_id?: string) => {
+ console.log(`getAppCerts()`);
+ if (!app_id)
+ app_id = this.GetServiceId();
+ return this.funcGetAppcerts(app_id);
+ }
+ // tizen.application.getAppSharedURI()
+ this.funcGetSharedUri = global.tizen.application.getAppSharedURI;
+ global.tizen.application.getAppSharedURI = (app_id?: string) => {
+ console.log(`getAppSharedURI()`);
+ if (!app_id)
+ app_id = this.GetServiceId();
+ return this.funcGetSharedUri(app_id);
+ }
+ // tizen.application.getAppMetaData()
+ this.funcGetMetadata = global.tizen.application.getAppMetaData;
+ global.tizen.application.getAppMetaData = (app_id?: string) => {
+ console.log(`getAppMetaData()`);
+ if (!app_id)
+ app_id = this.GetServiceId();
+ return this.funcGetMetadata(app_id);
+ }
}
}
\ No newline at end of file