overlay_module.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. "use strict";
  2. var Overlay = require('./discord_overlay2_'+process.platform+'.node'); // [adill] when the module was converted to use N-API we lost the ability to
  3. // parse json into javascript objects trivially so our event handler simply
  4. // returns event json
  5. if (!Overlay._setEventHandler && Overlay._setEventHandlerJson) {
  6. Overlay._setEventHandler = function (handler) {
  7. var wrappedHandler = function wrappedHandler(pid, eventJson) {
  8. var event = JSON.parse(eventJson);
  9. handler(pid, event);
  10. };
  11. Overlay._setEventHandlerJson(wrappedHandler);
  12. };
  13. } // [adill] when the module was converted to use N-API we lost the ability to
  14. // stringify javascript objects into json trivially sendCommand and
  15. // broadcastCommand were removed and replaced with {}Json variants that accept
  16. // command json
  17. if (!Overlay.sendCommand && Overlay.sendCommandJson) {
  18. Overlay.sendCommand = function (pid, command) {
  19. Overlay.sendCommandJson(pid, JSON.stringify(command));
  20. };
  21. }
  22. if (!Overlay.broadcastCommand && Overlay.broadcastCommandJson) {
  23. Overlay.broadcastCommand = function (command) {
  24. Overlay.broadcastCommandJson(JSON.stringify(command));
  25. };
  26. }
  27. module.exports = Overlay;