UNPKG

link-node

Version:

link pc,ios,android by node.

48 lines 1.37 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const enum_1 = require("./enum"); const _global = (window || global); class AppChannel { constructor() { this.handleMessage = null; this.device = enum_1.Device.auto; this.callBack = (v) => { if (this.handleMessage) { this.handleMessage(v); } }; console.log("[INFO][ch.app.constructor]"); } init(device = enum_1.Device.auto) { console.log("[INFO][ch.app.init]"); if (this.device != device) { this.device = device; } _global.setLinkCallBack(this.callBack); } send(jsonrpc = {}) { let data; if (typeof jsonrpc === "object") { data = JSON.stringify(jsonrpc); } else { data = jsonrpc; } if (_global.linkCallMobileNative) { _global.linkCallMobileNative(data, this.device); } } close() { console.log("[INFO][ch.app.close]"); if (_global.setLinkCallBack) { _global.setLinkCallBack(null); } this.handleMessage = null; } setHandle(handle) { console.log("[INFO][ch.app.setHandle]"); this.handleMessage = handle; } } exports.default = AppChannel; //# sourceMappingURL=app_channel.js.map