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.

multiremote.js 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. exports.MultiRemoteDriver = void 0;
  7. const lodash_zip_1 = __importDefault(require("lodash.zip"));
  8. const lodash_clonedeep_1 = __importDefault(require("lodash.clonedeep"));
  9. const utils_1 = require("@wdio/utils");
  10. const middlewares_1 = require("./middlewares");
  11. const utils_2 = require("./utils");
  12. class MultiRemote {
  13. constructor() {
  14. this.instances = {};
  15. }
  16. async addInstance(browserName, client) {
  17. this.instances[browserName] = await client;
  18. return this.instances[browserName];
  19. }
  20. modifier(wrapperClient) {
  21. const propertiesObject = {};
  22. propertiesObject.commandList = { value: wrapperClient.commandList };
  23. propertiesObject.options = { value: wrapperClient.options };
  24. for (const commandName of wrapperClient.commandList) {
  25. propertiesObject[commandName] = {
  26. value: this.commandWrapper(commandName),
  27. configurable: true
  28. };
  29. }
  30. propertiesObject['__propertiesObject__'] = {
  31. value: propertiesObject
  32. };
  33. this.baseInstance = new MultiRemoteDriver(this.instances, propertiesObject);
  34. const client = Object.create(this.baseInstance, propertiesObject);
  35. for (const [identifier, instance] of Object.entries(this.instances)) {
  36. client[identifier] = instance;
  37. }
  38. return client;
  39. }
  40. static elementWrapper(instances, result, propertiesObject) {
  41. const prototype = { ...propertiesObject, ...lodash_clonedeep_1.default(utils_2.getPrototype('element')), scope: { value: 'element' } };
  42. const element = utils_1.webdriverMonad({}, (client) => {
  43. for (const [i, identifier] of Object.entries(Object.keys(instances))) {
  44. client[identifier] = result[i];
  45. }
  46. client.instances = Object.keys(instances);
  47. delete client.sessionId;
  48. return client;
  49. }, prototype);
  50. return element(this.sessionId, middlewares_1.multiremoteHandler(utils_1.wrapCommand));
  51. }
  52. commandWrapper(commandName) {
  53. const instances = this.instances;
  54. return utils_1.wrapCommand(commandName, async function (...args) {
  55. const result = await Promise.all(Object.entries(instances).map(([, instance]) => instance[commandName](...args)));
  56. if (commandName === '$') {
  57. return MultiRemote.elementWrapper(instances, result, this.__propertiesObject__);
  58. }
  59. else if (commandName === '$$') {
  60. const zippedResult = lodash_zip_1.default(...result);
  61. return zippedResult.map((singleResult) => MultiRemote.elementWrapper(instances, singleResult, this.__propertiesObject__));
  62. }
  63. return result;
  64. });
  65. }
  66. }
  67. exports.default = MultiRemote;
  68. class MultiRemoteDriver {
  69. constructor(instances, propertiesObject) {
  70. this.isMultiremote = true;
  71. this.instances = Object.keys(instances);
  72. this.__propertiesObject__ = propertiesObject;
  73. }
  74. on(eventName, emitter) {
  75. this.instances.forEach((instanceName) => this[instanceName].on(eventName, emitter));
  76. return undefined;
  77. }
  78. once(eventName, emitter) {
  79. this.instances.forEach((instanceName) => this[instanceName].once(eventName, emitter));
  80. return undefined;
  81. }
  82. emit(eventName, emitter) {
  83. return this.instances.map((instanceName) => this[instanceName].emit(eventName, emitter)).some(Boolean);
  84. }
  85. eventNames() {
  86. return this.instances.map((instanceName) => this[instanceName].eventNames());
  87. }
  88. getMaxListeners() {
  89. return this.instances.map((instanceName) => this[instanceName].getMaxListeners());
  90. }
  91. listenerCount(eventName) {
  92. return this.instances.map((instanceName) => this[instanceName].listenerCount(eventName));
  93. }
  94. listeners(eventName) {
  95. return this.instances.map((instanceName) => this[instanceName].listeners(eventName)).reduce((prev, cur) => {
  96. prev.concat(cur);
  97. return prev;
  98. }, []);
  99. }
  100. removeListener(eventName, emitter) {
  101. this.instances.forEach((instanceName) => this[instanceName].removeListener(eventName, emitter));
  102. return undefined;
  103. }
  104. removeAllListeners(eventName) {
  105. this.instances.forEach((instanceName) => this[instanceName].removeAllListeners(eventName));
  106. return undefined;
  107. }
  108. }
  109. exports.MultiRemoteDriver = MultiRemoteDriver;