2014-10-20 22:26:34 +00:00
|
|
|
(function() {
|
2014-10-22 14:12:41 +00:00
|
|
|
var QtProvider = function() {
|
|
|
|
this.handlers = [];
|
|
|
|
|
|
|
|
var self = this;
|
|
|
|
navigator.qt.onmessage = function (message) {
|
|
|
|
self.handlers.forEach(function (handler) {
|
|
|
|
handler.call(self, JSON.parse(message));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-10-20 22:26:34 +00:00
|
|
|
QtProvider.prototype.send = function(payload) {
|
|
|
|
navigator.qt.postData(JSON.stringify(payload));
|
|
|
|
};
|
2014-10-20 22:37:58 +00:00
|
|
|
|
2014-10-20 22:26:34 +00:00
|
|
|
Object.defineProperty(QtProvider.prototype, "onmessage", {
|
|
|
|
set: function(handler) {
|
2014-10-22 14:12:41 +00:00
|
|
|
this.handlers.push(handler);
|
2014-10-20 22:26:34 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
if(typeof(web3) !== "undefined" && web3.providers !== undefined) {
|
2014-10-20 22:37:58 +00:00
|
|
|
web3.providers.QtProvider = QtProvider;
|
2014-10-20 22:26:34 +00:00
|
|
|
}
|
|
|
|
})();
|
2014-10-20 22:37:58 +00:00
|
|
|
|