Пример #1
0
        private void DoSendMessage(Model.WebViewMessages.Message message)
        {
            if (!_webViewLoaded || (message.Action != "init" && !_webViewReaderInit))
            {
                return;
            }

            message.IsSent = true;

            var json = JsonConvert.SerializeObject(new {
                message.Action, message.Data,
            });

            var toSend = Base64Helper.Encode(json);

            Device.BeginInvokeOnMainThread(async() => {
                // Exception "HRESULT: 0x80020101" on this line means that there is a syntax error in the JavaScript. Typically on Windows, when using IE.
                var res = await _webView.InjectJavascriptAsync($"Messages.parse('{toSend}')");
                OnMessageReturned?.Invoke(message, res);
            });

            if (message.Action == "init")
            {
                _webViewReaderInit = true;
            }
        }
Пример #2
0
        public void Send(string action, object data)
        {
            var message = new Model.WebViewMessages.Message {
                Action = action,
                Data   = data,
            };

            _queue.Add(message);
            this.ProcessQueue();
        }
Пример #3
0
        private void DoSendMessage(Model.WebViewMessages.Message message)
        {
            if (this.webViewLoaded && (message.Action == "init" || this.webViewReaderInit))
            {
                message.IsSent = true;

                var json = JsonConvert.SerializeObject(new {
                    Action = message.Action,
                    Data   = message.Data,
                });

                var toSend = Base64Helper.Encode(json);

                Device.BeginInvokeOnMainThread(async() => {
                    await _webView.InjectJavascriptAsync($"Messages.parse('{toSend}')");
                });

                if (message.Action == "init")
                {
                    this.webViewReaderInit = true;
                }
            }
        }