Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

monad.js 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. "use strict";
  2. var __importDefault = (this && this.__importDefault) || function (mod) {
  3. return (mod && mod.__esModule) ? mod : { "default": mod };
  4. };
  5. Object.defineProperty(exports, "__esModule", { value: true });
  6. const events_1 = require("events");
  7. const logger_1 = __importDefault(require("@wdio/logger"));
  8. const utils_1 = require("./utils");
  9. const SCOPE_TYPES = {
  10. browser: function Browser() { },
  11. element: function Element() { }
  12. };
  13. function WebDriver(options, modifier, propertiesObject = {}) {
  14. var _a;
  15. const scopeType = SCOPE_TYPES[((_a = propertiesObject.scope) === null || _a === void 0 ? void 0 : _a.value) || 'browser'];
  16. delete propertiesObject.scope;
  17. const prototype = Object.create(scopeType.prototype);
  18. const log = logger_1.default('webdriver');
  19. const eventHandler = new events_1.EventEmitter();
  20. const EVENTHANDLER_FUNCTIONS = Object.getPrototypeOf(eventHandler);
  21. function unit(sessionId, commandWrapper) {
  22. propertiesObject.commandList = { value: Object.keys(propertiesObject) };
  23. propertiesObject.options = { value: options };
  24. propertiesObject.requestedCapabilities = { value: options.requestedCapabilities };
  25. if (typeof commandWrapper === 'function') {
  26. for (const [commandName, { value }] of Object.entries(propertiesObject)) {
  27. if (typeof value !== 'function') {
  28. continue;
  29. }
  30. propertiesObject[commandName].value = commandWrapper(commandName, value);
  31. propertiesObject[commandName].configurable = true;
  32. }
  33. }
  34. utils_1.overwriteElementCommands.call(this, propertiesObject);
  35. const { puppeteer, ...propertiesObjectWithoutPuppeteer } = propertiesObject;
  36. propertiesObject['__propertiesObject__'] = { value: propertiesObjectWithoutPuppeteer };
  37. let client = Object.create(prototype, propertiesObject);
  38. client.sessionId = sessionId;
  39. if (scopeType.name === 'Browser') {
  40. client.capabilities = options.capabilities;
  41. }
  42. if (typeof modifier === 'function') {
  43. client = modifier(client, options);
  44. }
  45. client.addCommand = function (name, func, attachToElement = false, proto, instances) {
  46. const customCommand = typeof commandWrapper === 'function'
  47. ? commandWrapper(name, func)
  48. : func;
  49. if (attachToElement) {
  50. if (instances) {
  51. Object.values(instances).forEach(instance => {
  52. instance.__propertiesObject__[name] = {
  53. value: customCommand
  54. };
  55. });
  56. }
  57. this.__propertiesObject__[name] = { value: customCommand };
  58. }
  59. else {
  60. unit.lift(name, customCommand, proto);
  61. }
  62. };
  63. client.overwriteCommand = function (name, func, attachToElement = false, proto, instances) {
  64. let customCommand = typeof commandWrapper === 'function'
  65. ? commandWrapper(name, func)
  66. : func;
  67. if (attachToElement) {
  68. if (instances) {
  69. Object.values(instances).forEach(instance => {
  70. instance.__propertiesObject__.__elementOverrides__.value[name] = customCommand;
  71. });
  72. }
  73. else {
  74. this.__propertiesObject__.__elementOverrides__.value[name] = customCommand;
  75. }
  76. }
  77. else if (client[name]) {
  78. const origCommand = client[name];
  79. delete client[name];
  80. unit.lift(name, customCommand, proto, (...args) => origCommand.apply(this, args));
  81. }
  82. else {
  83. throw new Error('overwriteCommand: no command to be overwritten: ' + name);
  84. }
  85. };
  86. return client;
  87. }
  88. unit.lift = function (name, func, proto, origCommand) {
  89. (proto || prototype)[name] = function next(...args) {
  90. log.info('COMMAND', utils_1.commandCallStructure(name, args));
  91. Object.defineProperty(func, 'name', {
  92. value: name,
  93. writable: false,
  94. });
  95. const result = func.apply(this, origCommand ? [origCommand, ...args] : args);
  96. Promise.resolve(result).then((res) => {
  97. log.info('RESULT', res);
  98. this.emit('result', { name, result: res });
  99. }).catch(() => { });
  100. return result;
  101. };
  102. };
  103. for (let eventCommand in EVENTHANDLER_FUNCTIONS) {
  104. prototype[eventCommand] = function (...args) {
  105. eventHandler[eventCommand](...args);
  106. return this;
  107. };
  108. }
  109. return unit;
  110. }
  111. exports.default = WebDriver;