Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

消息偶发性的失败,尤其是在初始化时,webview运行比较大的工作量的时候。 #170

Open
tanmeifang opened this issue Mar 22, 2019 · 1 comment

Comments

@tanmeifang
Copy link

tanmeifang commented Mar 22, 2019

//提供给native使用, 这个函数调用的setTimeout ,里面的function有时候不执行。导致通信失败

function _dispatchMessageFromNative(messageJSON) {
    setTimeout(function() {
        var message = JSON.parse(messageJSON);
        var responseCallback;
        //java call finished, now need to call js callback function
        if (message.responseId) {
            responseCallback = responseCallbacks[message.responseId];
            if (!responseCallback) {
                return;
            }
            responseCallback(message.responseData);
            delete responseCallbacks[message.responseId];
        } else {
            //直接发送
            if (message.callbackId) {
                var callbackResponseId = message.callbackId;
                responseCallback = function(responseData) {
                    _doSend({
                        responseId: callbackResponseId,
                        responseData: responseData
                    });
                };
            }

            var handler = vipAccountBridge._messageHandler;
            if (message.handlerName) {
                handler = messageHandlers[message.handlerName];
            }
           
            try {
                handler(message.data, responseCallback);
            } catch (exception) {
                if (typeof console != 'undefined') {
                    console.log("vipAccountBridge: WARNING: javascript handler threw.", message, exception);
                }
            }
        }
    });
}
@Anshiii
Copy link
Contributor

Anshiii commented May 24, 2019

关于这个问题,我试着找到了原因并提供了一个解决方法,当然我的解决方法不一定是最好的,但是可以解决目前的问题,同时也欢迎讨论,寻求更佳的解决方案。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants