qt.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. This file is part of ethereum.js.
  3. ethereum.js is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU Lesser General Public License as published by
  5. the Free Software Foundation, either version 3 of the License, or
  6. (at your option) any later version.
  7. ethereum.js is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public License
  12. along with ethereum.js. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. /** @file qt.js
  15. * @authors:
  16. * Jeffrey Wilcke <jeff@ethdev.com>
  17. * Marek Kotewicz <marek@ethdev.com>
  18. * @date 2014
  19. */
  20. var QtProvider = function() {
  21. this.handlers = [];
  22. var self = this;
  23. navigator.qt.onmessage = function (message) {
  24. self.handlers.forEach(function (handler) {
  25. handler.call(self, JSON.parse(message.data));
  26. });
  27. };
  28. };
  29. QtProvider.prototype.send = function(payload) {
  30. navigator.qt.postMessage(JSON.stringify(payload));
  31. };
  32. Object.defineProperty(QtProvider.prototype, "onmessage", {
  33. set: function(handler) {
  34. this.handlers.push(handler);
  35. }
  36. });
  37. module.exports = QtProvider;