export const { wrt }: NativeWRTjs.WRTBinding = process.wrtBinding('wrt');
Object.setPrototypeOf(Object.getPrototypeOf(wrt), EventEmitter.prototype);
-console.log = console.info = console.error = console.warn = function(format: any, ...param: any[]) {
+console.log = console.info = console.error = console.warn = (format: any, ...param: any[]) => {
wrt.log(util.format(format, ...param));
};
+
+console.debug = (format: any, ...param: any[]) => {
+ wrt.log(`[debug] ${util.format(format, ...param)}`);
+};
+
console.logd = console.logv = console.loge = console.log;
function write(chunk: Uint8Array | string, encoding?: any, callback?: (err?: Error) => void): boolean {
var extensions: NativeXWalkExtension[] = binding.getExtensions();
for (var i = 0; i < extensions.length; i++) {
extensions[i].loaded = false;
- console.log("Load extension : " + extensions[i].name);
+ console.debug("Load extension : " + extensions[i].name);
extensions_[extensions[i].name] = extensions[i];
}
for (var name in extensions_) {
}
static runtimeMessageHandler(type: string, data?: string, callback?: (message: string) => void): void {
- console.log('This is prototype of runtimeMessageHandler');
+ console.debug('This is prototype of runtimeMessageHandler');
}
/**
var api = (ext.use_trampoline) ? api_ : global;
var extension_api = ext.jsapi;
if (global.serviceType === 'GLOBAL' && ext.name === 'xwalk') {
- console.log(`Delete freeze exports.utils for override method`);
+ console.debug(`Delete freeze exports.utils for override method`);
extension_api = extension_api.replace('Object.freeze(exports.utils);', '');
extension_api = extension_api.replace('Object.freeze(Utils.prototype);', '');
}
this.exposeApi(ext);
}
} catch (err) {
- console.log('Error loading extension "' + ext.name + '": ' + err.message);
+ console.debug('Error loading extension "' + ext.name + '": ' + err.message);
}
}
this.load(ext);
return api_[parent_name][base_name];
} catch (e) {
- console.log(e.stack);
+ console.debug(e.stack);
}
}.bind(this);
}.call(this, parent_name, base_name),
import * as XWalkExtension from '../../common/wrt_xwalk_extension';
function getManifestFile(manifestUrl: string) {
- console.log('manifestUrl : '+manifestUrl);
+ console.debug('manifestUrl : '+manifestUrl);
return new Promise((resolve, reject) => {
const req = https.request(manifestUrl, (res) => {
res.setEncoding('utf8');
resolve(JSON.parse(responseBody));
});
}).on('error', (err) => {
- console.log(`error : ${err}`);
+ console.debug(`error : ${err}`);
reject(err);
});
req.end();
}
async function downloadIcon(iconSrc: string, iconFile: string) {
- console.log('iconSrc : ' + iconSrc);
+ console.debug('iconSrc : ' + iconSrc);
return new Promise((resolve, reject) => {
const req = https.request(iconSrc, (res) => {
const Stream = require('stream').Transform;
resolve('done');
});
}).on('error', (err) => {
- console.log(`error : ${err}`);
+ console.debug(`error : ${err}`);
reject(err);
});
req.end();
function getAppName(appName: string) {
appName = appName.replace(/ /g, '');
- console.log('appName : ' + appName);
+ console.debug('appName : ' + appName);
return appName;
}
fs.rmdirSync(workingDir, { recursive: true });
fs.mkdir(workingDir, { recursive: true }, (err) => {
if (err)
- console.log(`mkdir error : ${err}`)
+ console.debug(`mkdir error : ${err}`)
});
}
function makePkgId(startUrl: string) {
let id = Buffer.from(startUrl).toString('base64');
id = id.replace(/=/gi, '');
- console.log(`id : ${id}`);
+ console.debug(`id : ${id}`);
return id.substr(-10);
}
function installWgt(appName: string) {
let wgtPath = `${baseWorkingDir}/${appName}/${appName}.wgt`;
let installinfo = "{\"app_id\":\"" + appName + "\",\"pkg_path\":\"" + wgtPath + "\"}";
- console.log(`installWgt info: ${installinfo}`);
+ console.debug(`installWgt info: ${installinfo}`);
(wrt.tv as any).notifyInstall(installinfo);
process.exit();
}
let wgtPath = `${downloadVirtualDir}/${appName}/${appName}.wgt`;
let onArchive = (archive: any) => {
function progressCallback(opId: string, val: number, name: any) {
- console.log('opId: ' + opId + ' with progress val: ' + (val * 100).toFixed(0) + '%');
+ console.debug('opId: ' + opId + ' with progress val: ' + (val * 100).toFixed(0) + '%');
}
function successCallback() {
- console.log(`File added : ${refCount}`);
+ console.debug(`File added : ${refCount}`);
refCount--;
if (!refCount) {
installWgt(appName);
}
}
- console.log(`convertedConfigXml : ${convertedConfigXml}`);
- console.log(`manifestFile : ${manifestFile}`);
- console.log(`iconFile : ${iconFile}`);
+ console.debug(`convertedConfigXml : ${convertedConfigXml}`);
+ console.debug(`manifestFile : ${manifestFile}`);
+ console.debug(`iconFile : ${iconFile}`);
let defaultArchiveFileEntryOption = { destination:'', stripSourceDirectory: true};
archive.add(convertedConfigXml, successCallback, null, progressCallback, defaultArchiveFileEntryOption);
archive.add(manifestFile, successCallback, null, progressCallback, defaultArchiveFileEntryOption);
}
makeWgt(appName);
} catch (e) {
- console.log(`Exception: ${e}`);
+ console.debug(`Exception: ${e}`);
cleanUpAndQuit(appName);
}
}
export function run(manifestUrl: string) {
- console.log(`Appmanifest parser starts for ${manifestUrl}`);
+ console.debug(`Appmanifest parser starts for ${manifestUrl}`);
setInterval(() => { }, 500);
wrt.tv?.delayShutdown();
XWalkExtension.initialize();
function compileWasmForCaching(files: string[]) {
try {
files.forEach(async filePath => {
- console.log(`Requesting WASM compilation for building a cache, file_path:(${filePath})`);
+ console.debug(`Requesting WASM compilation for building a cache, file_path:(${filePath})`);
let source = fs.readFileSync(filePath);
let file = new Uint8Array(source);
await WebAssembly.compile(file);
}
export function run(appId: string) {
- console.log(`wasm_builder.js starts, app_id:(${appId})`);
+ console.debug(`wasm_builder.js starts, app_id:(${appId})`);
let tv = wrt.tv as NativeWRTjs.TVExtension;
tv.setWasmFlags();
tv.setDiskCache(appId);
let files = tv.getWasmFiles(appId);
- console.log(files);
+ console.debug(files);
tv.delayShutdown();
compileWasmForCaching(files);
process.exit();
// tizen.application.getCurrentApplication()
this.funcCurrentApplication = global.tizen.application.getCurrentApplication;
global.tizen.application.getCurrentApplication = () => {
- console.log(`Routing - getCurrentApplication() : ${this.getServiceId()}`);
+ console.debug(`Routing - getCurrentApplication() : ${this.getServiceId()}`);
if (this.currentApplication)
return this.currentApplication;
this.currentApplication = {};
// tizen.application.getCurrentApplication().getRequestedAppControl()
this.funcRequestedAppcontrol = this.currentApplication.getRequestedAppControl;
this.currentApplication.getRequestedAppControl = () => {
- console.log(`Routing - getRequestedAppControl() : ${this.getServiceId()}`);
+ console.debug(`Routing - getRequestedAppControl() : ${this.getServiceId()}`);
return this.funcRequestedAppcontrol();
}
return this.currentApplication;
let app_id = args[0];
if (this.hasNoneOrNull(args))
app_id = this.getServiceId();
- console.log(`Routing - getAppInfo(${app_id})`);
+ console.debug(`Routing - getAppInfo(${app_id})`);
return this.funcGetAppInfo(app_id);
}
// tizen.application.getAppCerts()
let app_id = args[0];
if (this.hasNoneOrNull(args))
app_id = this.getServiceId();
- console.log(`Routing - getAppCerts() ` + app_id);
+ console.debug(`Routing - getAppCerts() ` + app_id);
return this.funcGetAppcerts(app_id);
}
// tizen.application.getAppContext()
this.funcGetContext = global.tizen.application.getAppContext;
global.tizen.application.getAppContext = (...args: any[]) => {
- console.log(`Routing - getAppContext()`);
+ console.debug(`Routing - getAppContext()`);
if (this.hasNoneOrNull(args)) {
const context = {"id": this.funcGetContext().id, "appId": this.getServiceId()};
Object.defineProperties(context, {
let app_id = args[0];
if (this.hasNoneOrNull(args))
app_id = this.getServiceId();
- console.log(`Routing - getAppSharedURI()`);
+ console.debug(`Routing - getAppSharedURI()`);
return this.funcGetSharedUri(app_id);
}
// tizen.application.getAppMetaData()
let app_id = args[0];
if (this.hasNoneOrNull(args))
app_id = this.getServiceId();
- console.log(`Routing - getAppMetaData()`);
+ console.debug(`Routing - getAppMetaData()`);
return this.funcGetMetadata(app_id);
}
}
let package_id = args[0];
if (this.hasNoneOrNull(args))
package_id = this.getPackageId();
- console.log(`Routing - getPackageInfo() : ${package_id}`);
+ console.debug(`Routing - getPackageInfo() : ${package_id}`);
return this.funcGetPackageInfo(package_id);
}
}
global.tizen.filesystem.setVirtualPath(name, realPath, 'INTERVAL', 'MOUNTED');
});
} catch (e) {
- console.log(`refineFilesystemApis has an error ${e}`);
+ console.debug(`refineFilesystemApis has an error ${e}`);
}
}
"http://tizen.org/appcontrol/operation/default", null, null, null,
data_payload, null);
global.tizen.application.launchAppControl(appControl, this.serviceId,
- () => console.log(`'${this.serviceId}::${name}' is requsted`));
+ () => console.debug(`'${this.serviceId}::${name}' is requsted`));
}
global.tizen.messageport.requestLocalMessagePort = (portName: string) => {
import * as ServiceManager from './service_manager';
wrt.on('start-service', (event: any, internal_id: string) => {
- console.log(`start service app : ${internal_id}`);
+ console.debug(`start service app : ${internal_id}`);
ServiceManager.startService(internal_id, '');
});
wrt.on('stop-service', (event: any, internal_id: string) => {
- console.log(`stop service app : ${internal_id}`);
+ console.debug(`stop service app : ${internal_id}`);
ServiceManager.stopService(internal_id);
});
wrt.on('builtin-service', (event: any, internal_id: string, service_name: string) => {
- console.log(`id: ${internal_id}, service_name: ${service_name}`);
+ console.debug(`id: ${internal_id}, service_name: ${service_name}`);
ServiceManager.handleBuiltinService(internal_id, service_name);
});
});
process.on('exit', (code) => {
- console.log('Exit with code : ' + code);
+ console.debug('Exit with code : ' + code);
});
workers[id].on('exit', (code: number) => {
delete workers[id];
let runningServices = Object.keys(workers).length;
- console.log(`exit code(${code}), remain services(${runningServices})`);
+ console.debug(`exit code(${code}), remain services(${runningServices})`);
});
}
function terminateWorker(id: string, delay: number) {
if (!workers[id]) {
- console.log(`This worker is already terminated. ${id}`);
+ console.debug(`This worker is already terminated. ${id}`);
return;
}
- console.log(`${id} will shutdown after ${delay}ms`);
+ console.debug(`${id} will shutdown after ${delay}ms`);
workers[id].postMessage({ type: 'stop', delay });
}
export function startService(id: string, filename: string) {
- console.log(`startService - ${id}`);
+ console.debug(`startService - ${id}`);
if (global['serviceType'] === 'STANDALONE') {
let ids = id.split(':');
let serviceId = ids[0];
}
export function stopService(id: string) {
- console.log(`stopService - ${id}`);
+ console.debug(`stopService - ${id}`);
terminateWorker(id, 500);
}
}
let need_stop = (serviceName.substr(0, 5) === 'stop_');
if (need_stop) {
- console.log(`${serviceName} will be terminated.`);
+ console.debug(`${serviceName} will be terminated.`);
workers[serviceId].terminate();
} else {
- console.log(`Builtin service is ${serviceName}`);
+ console.debug(`Builtin service is ${serviceName}`);
let startService = `${__dirname}/../service/builtins/${serviceName}.js`;
createWorker(serviceId, startService, '');
}
function printAppControlData(id: string) {
let reqAppControl = global.tizen.application.getCurrentApplication().getRequestedAppControl();
if (reqAppControl) {
- console.log(`id: ${id}, appControlData operation: ${reqAppControl.appControl.operation}`);
+ console.debug(`id: ${id}, appControlData operation: ${reqAppControl.appControl.operation}`);
let appControlData = reqAppControl.appControl.data;
for (let dataIndex in appControlData) {
for (let valueIndex in appControlData[dataIndex].value)
- console.log(`data[${dataIndex}][${valueIndex}]: ${appControlData[dataIndex].value[valueIndex]}`);
+ console.debug(`data[${dataIndex}][${valueIndex}]: ${appControlData[dataIndex].value[valueIndex]}`);
}
}
}
function registerExtensionResolver(id: string) {
if (wrt.tv) {
let extensionResolver = (module: any, file_path: string) => {
- console.log(`resolved path: ${file_path}`);
+ console.debug(`resolved path: ${file_path}`);
let content = (wrt.tv as NativeWRTjs.TVExtension).decryptFile(id, file_path);
if (content) {
// Remove BOM
if (!periodLauncherAlive) {
periodLauncherAlive = 20;
if (!wrt.checkLauncherAlive(id)) {
- console.log(`${id} launcher was killed.`)
+ console.debug(`${id} launcher was killed.`)
requestStopService(id);
checkLauncherAlive = () => {};
}
XWalkExtension.initialize();
XWalkExtension.setRuntimeMessageHandler((type, data) => {
if (type === 'tizen://exit') {
- console.log(`${id} will be closed by ${type}`);
+ console.debug(`${id} will be closed by ${type}`);
requestStopService(id);
}
});
- console.log(`serviceType : ${global['serviceType']}`)
+ console.debug(`serviceType : ${global['serviceType']}`)
new DeviceAPIRouter(id, isGlobalService());
// this is workaround solution to make webapis singleton worker
if (isServiceApplication()) {
registerExtensionResolver(id);
filename = wrt.getStartServiceFile(id);
- console.log(`start global service file: ${filename}`);
+ console.debug(`start global service file: ${filename}`);
}
try {
wrt.finishStartingService(id);
}
} catch (e) {
- console.log(`exception on start: ${e}`);
+ console.debug(`exception on start: ${e}`);
requestStopService(id);
}
}
app.onExit();
}
} catch (e) {
- console.log(`exception on stop: ${e}`);
+ console.debug(`exception on stop: ${e}`);
}
}
if (!parentPort)
return;
parentPort.on('message', (message) => {
- console.log(`Received message type : ${message.type}`);
+ console.debug(`Received message type : ${message.type}`);
if (message.type === 'wake') {
app?.onRequest();
} else if (message.type === 'stop') {
+++ /dev/null
-interface TimerAPI {
- clearInterval(id: NodeJS.Timeout): void;
- clearTimeout(id: NodeJS.Timeout): void;
- setInterval(callback: (...args: any[]) => void, ms: number): NodeJS.Timeout;
- setTimeout(callback: (...args: any[]) => void, ms: number): NodeJS.Timeout;
- setServiceInterval(callback: (...args: any[]) => void, after:number, repeat:number): void;
-}
-
-export class TimerManager {
- interval_handlers: NodeJS.Timeout[] = [];
- timeout_handlers: NodeJS.Timeout[] = [];
- timer_api: TimerAPI;
- constructor() {
- this.timer_api = {
- clearInterval: (handler) => {
- const index = this.interval_handlers.indexOf(handler);
- clearInterval(this.interval_handlers.splice(index, 1)[0]);
- },
- clearTimeout: (handler) => {
- const index = this.timeout_handlers.indexOf(handler);
- clearTimeout(this.timeout_handlers.splice(index, 1)[0]);
- },
- setInterval: (func, delay) => {
- let id = setInterval(func, delay);
- this.interval_handlers.push(id);
- return id;
- },
- setTimeout: (func, delay) => {
- let id = setTimeout(func, delay);
- this.timeout_handlers.push(id);
- return id;
- },
- setServiceInterval: (func, after = 1000, repeat = 0) => {
- if (typeof func !== "function") {
- console.log("Use function as the first parameter.");
- return;
- }
- let count = 1;
- let handler = this.timer_api.setInterval(() => {
- func();
- count++;
- if (count > repeat && repeat !== 0) {
- this.timer_api.clearInterval(handler);
- }
- }, after);
- }
- }
- }
- getTimerAPI() {
- return this.timer_api;
- }
- releaseRemainingTimers() {
- console.log('Remaining interval(s) : ' + this.interval_handlers.length);
- for (let id of this.interval_handlers)
- clearInterval(id);
- this.interval_handlers = [];
- console.log('Remaining timer(s) : ' + this.timeout_handlers.length);
- for (let id of this.timeout_handlers)
- clearTimeout(id);
- this.timeout_handlers = [];
- }
-}