@ccos/ccsdk-lite 1.0.26 → 1.0.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/bundle.js CHANGED
@@ -60,6 +60,8 @@ var bus = new Bus();
60
60
  var hasInitialized = false;
61
61
  var actionList = []; // 这里保存, 未注册命令处理函数之前,APP发过来的命令
62
62
  var apiCode = '';
63
+ var nativeObject = null;
64
+ var nativeType = '';
63
65
  function defaultAppCmd(cmd, payload) {
64
66
  console.log('default appCmd ' + cmd);
65
67
  actionList.push({ cmd: cmd, payload: payload }); // 有可能APP发过来的命令比较早,而页面的一些初始化还没有做完,这时把命令先存起来,放到 actionList 中
@@ -84,6 +86,10 @@ function unsetAppCommandCallback() {
84
86
  appCmdProcessor = defaultAppCmd;
85
87
  actionList = [];
86
88
  }
89
+ function setNativeObject(obj, _type) {
90
+ nativeObject = obj;
91
+ nativeType = _type;
92
+ }
87
93
  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
88
94
  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
89
95
  var persistentCallbackMap = new Map(); // 持久化 callback-id 与回调函数对应的列表 (回调函数可以多个,组成一个Set)
@@ -128,6 +134,18 @@ function nativeCall(funcName, callbackId, params) {
128
134
  apkNativeCallJs(resData);
129
135
  });
130
136
  }
137
+ else if (nativeObject) {
138
+ if (nativeType == 'cocos') {
139
+ // 运行于 android 的 cocos 平台
140
+ var object2 = {
141
+ func: funcName,
142
+ id: callbackId,
143
+ params: params || {},
144
+ apiCode: apiCode,
145
+ };
146
+ nativeObject.reflection.callStaticMethod('com/coocaa/cocos_game/UniNativeAPI', 'callToHostApp', "(Ljava/lang/String;)V", JSON.stringify(object2));
147
+ }
148
+ }
131
149
  }
132
150
  function nativeRequest(funcName, params, persistent, persistentIdName, persistentCallback) {
133
151
  if (!persistent) {
@@ -1294,10 +1312,17 @@ function apkNativeCallJs(str) {
1294
1312
  function isRunInAppBrowser() {
1295
1313
  return window['_liteNativeApi'] ? true : false;
1296
1314
  }
1297
- function init() {
1315
+ function init(nativeObject, nativeType) {
1316
+ if (nativeObject === void 0) { nativeObject = null; }
1317
+ if (nativeType === void 0) { nativeType = ''; }
1298
1318
  if (window['_liteNativeApi']) {
1299
1319
  window['appNativeCall'] = apkNativeCallJs;
1300
1320
  }
1321
+ else if (window['CoocaaJsApiBridge']) ;
1322
+ else if (nativeObject) {
1323
+ setNativeObject(nativeObject, nativeType);
1324
+ window['appNativeCall'] = apkNativeCallJs;
1325
+ }
1301
1326
  initSDK();
1302
1327
  }
1303
1328
  init();
@@ -1,6 +1,7 @@
1
1
  export declare function onCommandFromApp(cmd: string, payload: string): void;
2
2
  export declare function setAppCommandCallback(cb: Function): void;
3
3
  export declare function unsetAppCommandCallback(): void;
4
+ export declare function setNativeObject(obj: any, _type: string): void;
4
5
  export declare function callNative(funcName: string, params: any): Promise<any>;
5
6
  export declare function callWithPersistentCallBack(funcName: string, params: any, persistentIdName: string, callback: Function): Promise<any>;
6
7
  export declare function deletePersistentCallBack(persistentIdName: string, callback: Function): boolean;
package/lib/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export { setAppCommandCallback, unsetAppCommandCallback } from './core';
2
2
  export declare function apkNativeCallJs(str: string | object): void;
3
3
  export declare function isRunInAppBrowser(): boolean;
4
- export declare function init(): void;
4
+ export declare function init(nativeObject?: any, nativeType?: string): void;
5
5
  declare const _default: {
6
6
  init: typeof init;
7
7
  network: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ccos/ccsdk-lite",
3
- "version": "1.0.26",
3
+ "version": "1.0.27",
4
4
  "description": "a jssdk for coocaa tv-system",
5
5
  "type": "module",
6
6
  "main": "lib/bundle.js",