From f7c9c8928eaca89a7bd02d7cc2e53049d7c43fef Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Wed, 22 Oct 2014 16:12:41 +0200 Subject: messageHandler expects object instead of string --- qt.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'qt.js') diff --git a/qt.js b/qt.js index 39c0a89a9..1b146c30d 100644 --- a/qt.js +++ b/qt.js @@ -1,12 +1,22 @@ (function() { - var QtProvider = function() {}; + var QtProvider = function() { + this.handlers = []; + + var self = this; + navigator.qt.onmessage = function (message) { + self.handlers.forEach(function (handler) { + handler.call(self, JSON.parse(message)); + }); + } + }; + QtProvider.prototype.send = function(payload) { navigator.qt.postData(JSON.stringify(payload)); }; Object.defineProperty(QtProvider.prototype, "onmessage", { set: function(handler) { - navigator.qt.onmessage = handler; + this.handlers.push(handler); }, }); -- cgit v1.2.3