zalo-js-bridge
Advanced tools
Comparing version 1.10.19 to 1.10.20
# Base Library Update Logs | ||
## 1.10.20 (2021-05-04) | ||
### Bug Fixes | ||
* call multi same action 75859bc | ||
## 1.10.19 (2021-04-28) | ||
@@ -4,0 +11,0 @@ |
@@ -17,7 +17,11 @@ "use strict"; | ||
} | ||
onJSCall(data) { | ||
native_bridge_1.default.onJSCall(data); | ||
onJSCall(key) { | ||
return function (data) { | ||
native_bridge_1.default.onJSCall(key, data); | ||
}; | ||
} | ||
onMultiJSCall(data) { | ||
native_bridge_1.default.onMultiJSCall(data); | ||
onMultiJSCall(key) { | ||
return function (data) { | ||
native_bridge_1.default.onMultiJSCall(key, data); | ||
}; | ||
} | ||
@@ -24,0 +28,0 @@ login(callback) { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getZaloVersion = exports.checkPlatform = exports.getUserAgent = exports.getToken = exports.isFunction = exports.serialize = exports.isZaloBrowser = exports.parseJSON = exports.isString = exports.isEmpty = exports.isObject = exports.writeCookie = void 0; | ||
exports.generateUniqueString = exports.getZaloVersion = exports.checkPlatform = exports.getUserAgent = exports.getToken = exports.isFunction = exports.serialize = exports.isZaloBrowser = exports.parseJSON = exports.isString = exports.isEmpty = exports.isObject = exports.writeCookie = void 0; | ||
const Cookies = require("js-cookie"); | ||
@@ -33,3 +33,3 @@ const readCookie = (name) => { | ||
expires: expiresTime, | ||
secure: secure | ||
secure: secure, | ||
}); | ||
@@ -110,3 +110,5 @@ } | ||
if (exports.isObject(JSON) && JSON.parse && exports.isString(str)) { | ||
return JSON.parse(str); | ||
return JSON.parse(str, (key, value) => { | ||
return value; | ||
}); | ||
} | ||
@@ -178,1 +180,25 @@ else if (typeof str === "object") { | ||
exports.getZaloVersion = () => readCookie("zversion"); | ||
const REGEXP_SPECIAL_UNICODE = new RegExp("[\\u0300-\\u036f]", "g"); | ||
const REGEXP_ACCENT_D = new RegExp("[đ|Đ]", "g"); | ||
const REGEXP_SPACES = new RegExp("\\s", "g"); | ||
/** | ||
* Generate a unique string from a input string by: | ||
* 1. Remove accents from input string | ||
* 2. Remove all spaces | ||
* 3. Lower case | ||
* 4. Concat with a random string | ||
* @param {string} str | ||
* @returns unique string | ||
*/ | ||
exports.generateUniqueString = (str = "") => { | ||
const RANDOM_STRING_LENGTH = 4; | ||
const formattedStr = str | ||
.normalize("NFD") | ||
.replace(REGEXP_SPECIAL_UNICODE, "") | ||
.replace(REGEXP_ACCENT_D, "d") | ||
.replace(REGEXP_SPACES, "") | ||
.toLowerCase(); | ||
return `${formattedStr}_${Math.random() | ||
.toString(36) | ||
.substr(2, RANDOM_STRING_LENGTH)}`; | ||
}; |
@@ -58,3 +58,3 @@ "use strict"; | ||
} | ||
onJSCall(data) { | ||
onJSCall(key, data) { | ||
try { | ||
@@ -64,6 +64,6 @@ this._debug("onJSCall", "data from native callback", data); | ||
this._debug("onJSCall", "data is parsed", parsedData); | ||
if (this._jsCallFuncCallbacks[parsedData.action]) { | ||
const callback = this._jsCallFuncCallbacks[parsedData.action] | ||
if (this._jsCallFuncCallbacks[key]) { | ||
const callback = this._jsCallFuncCallbacks[key] | ||
.callback; | ||
const timeout = this._jsCallFuncCallbacks[parsedData.action] | ||
const timeout = this._jsCallFuncCallbacks[key] | ||
.timeout; | ||
@@ -78,4 +78,4 @@ if (!!callback) { | ||
!!timeout && clearTimeout(timeout); | ||
this._jsCallFuncCallbacks[parsedData.action] = null; | ||
delete this._jsCallFuncCallbacks[parsedData.action]; | ||
this._jsCallFuncCallbacks[key] = null; | ||
delete this._jsCallFuncCallbacks[key]; | ||
} | ||
@@ -92,3 +92,3 @@ } | ||
} | ||
onMultiJSCall(data) { | ||
onMultiJSCall(key, data) { | ||
try { | ||
@@ -98,6 +98,6 @@ this._debug("onMultiJSCall", "data from native callback", data); | ||
this._debug("onMultiJSCall", "data is parsed", parsedData); | ||
if (this._jsCallFuncCallbacks[parsedData.action]) { | ||
const callback = this._jsCallFuncCallbacks[parsedData.action] | ||
if (this._jsCallFuncCallbacks[key]) { | ||
const callback = this._jsCallFuncCallbacks[key] | ||
.callback; | ||
const timeout = this._jsCallFuncCallbacks[parsedData.action] | ||
const timeout = this._jsCallFuncCallbacks[key] | ||
.timeout; | ||
@@ -154,4 +154,5 @@ if (!!callback) { | ||
try { | ||
const key = common_1.generateUniqueString(action); | ||
if (!this._device.isMobile || common_1.isEmpty(action)) { | ||
this.onJSCall({ | ||
this.onJSCall(key, { | ||
error_code: -13, | ||
@@ -184,6 +185,6 @@ error_message: "params invalid!", | ||
}; | ||
this._jsCallFuncCallbacks[action] = { | ||
this._jsCallFuncCallbacks[key] = { | ||
timeout: config_1.ActionHaveCallBack.includes(action) && | ||
setTimeout(() => { | ||
this.onJSCall(timeoutCallback); | ||
this.onJSCall(key, timeoutCallback); | ||
}, 8000), | ||
@@ -201,10 +202,10 @@ callback: callback, | ||
if (this._device.isIOS) { | ||
return ZaloJavaScriptInterface.jsCall(this._jsAccessTk, action, this._accessTk, options, window.ZJSBridge.onMultiJSCall); | ||
return ZaloJavaScriptInterface.jsCall(this._jsAccessTk, action, this._accessTk, options, window.ZJSBridge.onMultiJSCall(key)); | ||
} | ||
return ZaloJavaScriptInterface.jsCall(this._jsAccessTk, action, this._accessTk, options, "ZJSBridge.onMultiJSCall"); | ||
return ZaloJavaScriptInterface.jsCall(this._jsAccessTk, action, this._accessTk, options, `ZJSBridge.onMultiJSCall('${key}')`); | ||
} | ||
if (this._device.isIOS) { | ||
return ZaloJavaScriptInterface.jsCall(this._jsAccessTk, action, this._accessTk, options, window.ZJSBridge.onJSCall); | ||
return ZaloJavaScriptInterface.jsCall(this._jsAccessTk, action, this._accessTk, options, window.ZJSBridge.onJSCall(key)); | ||
} | ||
return ZaloJavaScriptInterface.jsCall(this._jsAccessTk, action, this._accessTk, options, "ZJSBridge.onJSCall"); | ||
return ZaloJavaScriptInterface.jsCall(this._jsAccessTk, action, this._accessTk, options, `ZJSBridge.onJSCall('${key}')`); | ||
} | ||
@@ -230,3 +231,3 @@ catch (error) { | ||
}; | ||
this.onJSCall(errorCallback); | ||
this.onJSCall(key, errorCallback); | ||
return false; | ||
@@ -233,0 +234,0 @@ } |
{ | ||
"name": "zalo-js-bridge", | ||
"description": "A Javascript Framework for WebApp", | ||
"version": "1.10.19", | ||
"version": "1.10.20", | ||
"main": "lib/index.js", | ||
@@ -6,0 +6,0 @@ "files": [ |
88266
2212