Best JavaScript code snippet using devicefarmer-stf
devices-controller.js
Source:devices-controller.js
...113 )114 }115 }116 $scope.removeDevices = function(search, filteredDevices, askConfirmation) {117 function removeDevices() {118 CommonService.errorWrapper(119 DevicesService.removeDevices120 , search ?121 [$scope.removingFilters, filteredDevices.map(function(device) {122 return device.serial123 })124 .join()] :125 [$scope.removingFilters]126 )127 }128 if (askConfirmation) {129 GenericModalService.open({130 message: 'Really delete this selection of devices?'131 , type: 'Warning'132 , size: 'sm'133 , cancel: true134 })135 .then(function() {136 removeDevices()137 })138 }139 else {140 removeDevices()141 }142 }143 $scope.$on('user.settings.devices.created', function(event, message) {144 addDevice(publishDevice(message.device), message.timeStamp)145 })146 $scope.$on('user.settings.devices.deleted', function(event, message) {147 deleteDevice(message.device.serial, message.timeStamp)148 })149 $scope.$on('user.settings.devices.updated', function(event, message) {150 updateDevice(publishDevice(message.device), message.timeStamp)151 })152 initScope()...
listenDevices.ts
Source:listenDevices.ts
1import EventEmitter from "events";2import { getDevices } from "@ledgerhq/hw-transport-node-hid-noevents";3import { log } from "@ledgerhq/logs";4import usb from "usb";5import debounce from "lodash/debounce";6export default (7 delay: number,8 listenDevicesPollingSkip: () => boolean9): {10 events: EventEmitter;11 stop: () => void;12} => {13 const events = new EventEmitter();14 events.setMaxListeners(0);15 let listDevices = getDevices();16 const flatDevice = (d) => d.path;17 const getFlatDevices = () => [18 ...new Set(getDevices().map((d) => flatDevice(d))),19 ];20 const getDeviceByPaths = (paths) =>21 listDevices.find((d) => paths.includes(flatDevice(d)));22 let lastDevices = getFlatDevices();23 const poll = () => {24 if (!listenDevicesPollingSkip()) {25 log("hid-listen", "Polling for added or removed devices");26 let changeFound = false;27 const currentDevices = getFlatDevices();28 const newDevices = currentDevices.filter((d) => !lastDevices.includes(d));29 if (newDevices.length > 0) {30 log("hid-listen", "New device found:", newDevices);31 listDevices = getDevices();32 events.emit("add", getDeviceByPaths(newDevices));33 changeFound = true;34 } else {35 log("hid-listen", "No new device found");36 }37 const removeDevices = lastDevices.filter(38 (d) => !currentDevices.includes(d)39 );40 if (removeDevices.length > 0) {41 log("hid-listen", "Removed device found:", removeDevices);42 events.emit("remove", getDeviceByPaths(removeDevices));43 listDevices = listDevices.filter(44 (d) => !removeDevices.includes(flatDevice(d))45 );46 changeFound = true;47 } else {48 log("hid-listen", "No removed device found");49 }50 if (changeFound) {51 lastDevices = currentDevices;52 }53 } else {54 log("hid-listen", "Polling skipped, re-debouncing");55 debouncedPoll();56 }57 };58 const debouncedPoll = debounce(poll, delay);59 const attachDetected = (device) => {60 log("hid-listen", "Device add detected:", device);61 debouncedPoll();62 };63 usb.on("attach", attachDetected);64 log("hid-listen", "attach listener added");65 const detachDetected = (device) => {66 log("hid-listen", "Device removal detected:", device);67 debouncedPoll();68 };69 usb.on("detach", detachDetected);70 log("hid-listen", "detach listener added");71 return {72 stop: () => {73 log(74 "hid-listen",75 "Stop received, removing listeners and cancelling pending debounced polls"76 );77 debouncedPoll.cancel();78 usb.removeListener("attach", attachDetected);79 usb.removeListener("detach", detachDetected);80 },81 events,82 };...
listenDevices.js
Source:listenDevices.js
1// @flow2import EventEmitter from "events";3import usb from "usb";4import debounce from "lodash/debounce";5import getDevices from "./getDevices";6export default (7 delay: number,8 listenDevicesPollingSkip: () => boolean,9 debug: (...any) => void10): {11 events: EventEmitter,12 stop: () => void13} => {14 const events = new EventEmitter();15 events.setMaxListeners(0);16 let listDevices = getDevices();17 const flatDevice = d => d.path;18 const getFlatDevices = () => [19 ...new Set(getDevices().map(d => flatDevice(d)))20 ];21 const getDeviceByPaths = paths =>22 listDevices.find(d => paths.includes(flatDevice(d)));23 let lastDevices = getFlatDevices();24 const poll = () => {25 if (!listenDevicesPollingSkip()) {26 debug("Polling for added or removed devices");27 let changeFound = false;28 const currentDevices = getFlatDevices();29 const newDevices = currentDevices.filter(d => !lastDevices.includes(d));30 if (newDevices.length > 0) {31 debug("New device found:", newDevices);32 listDevices = getDevices();33 events.emit("add", getDeviceByPaths(newDevices));34 changeFound = true;35 } else {36 debug("No new device found");37 }38 const removeDevices = lastDevices.filter(39 d => !currentDevices.includes(d)40 );41 if (removeDevices.length > 0) {42 debug("Removed device found:", removeDevices);43 events.emit("remove", getDeviceByPaths(removeDevices));44 listDevices = listDevices.filter(45 d => !removeDevices.includes(flatDevice(d))46 );47 changeFound = true;48 } else {49 debug("No removed device found");50 }51 if (changeFound) {52 lastDevices = currentDevices;53 }54 } else {55 debug("Polling skipped, re-debouncing");56 debouncedPoll();57 }58 };59 const debouncedPoll = debounce(poll, delay);60 const attachDetected = device => {61 debug("Device add detected:", device);62 debouncedPoll();63 };64 usb.on("attach", attachDetected);65 debug("attach listener added");66 const detachDetected = device => {67 debug("Device removal detected:", device);68 debouncedPoll();69 };70 usb.on("detach", detachDetected);71 debug("detach listener added");72 return {73 stop: () => {74 debug(75 "Stop received, removing listeners and cancelling pending debounced polls"76 );77 debouncedPoll.cancel();78 usb.removeListener("attach", attachDetected);79 usb.removeListener("detach", detachDetected);80 },81 events82 };...
Using AI Code Generation
1var stf = require('devicefarmer-stf-client');2var devices = ['device1', 'device2'];3stfClient.removeDevices(devices, function(err, data) {4 if (err) {5 console.log('Error: ' + err);6 } else {7 console.log('Data: ' + data);8 }9});10getDevices(callback)11function (err, devices) {}12removeDevices(devices, callback)13function (err, data) {}14addDevices(devices, callback)15function (err, data) {}16getDeviceGroups(callback)17function (err, groups) {}18createDeviceGroup(group, callback)19function (err, data) {}20removeDeviceGroup(group, callback)
Using AI Code Generation
1var stf = require('devicefarmer-stf');2client.removeDevices('serialNumber').then(function (data) {3 console.log(data);4}).catch(function (err) {5 console.log(err);6});7: serial number of the device. (required)8client.removeDevices('serialNumber').then(function (data) {9 console.log(data);10}).catch(function (err) {11 console.log(err);12});13{14}
Using AI Code Generation
1var stf = require('devicefarmer-stf');2client.removeDevices('serial1,serial2');3var stf = require('devicefarmer-stf');4client.removeDevices('device1,device2');5var stf = require('devicefarmer-stf');6client.removeDevices('serial1,serial2,device1,device2');7var stf = require('devicefarmer-stf');8client.removeDevices(['serial1','serial2','device1','device2']);9var stf = require('devicefarmer-stf');10client.removeDevices({serials:['serial1','serial2'],devices:['device1','device2']});11var stf = require('devicefarmer-stf');
Using AI Code Generation
1var devicefarm = require('devicefarmer-stf-client');2client.removeDevices([1, 2, 3], function(error, result) {3 if (error) {4 console.log('Error: ' + error.message);5 } else {6 console.log('Result: ' + result);7 }8});
Using AI Code Generation
1const client = require('devicefarmer-stf-client');2var stf = new client();3var devices = ["device1", "device2", "device3"];4stf.removeDevices(devices).then(function(result){5 console.log(result);6}, function(error){7 console.log(error);8});9const client = require('devicefarmer-stf-client');10var stf = new client();11var devices = ["device1", "device2", "device3"];12stf.addDevices(devices).then(function(result){13 console.log(result);14}, function(error){15 console.log(error);16});
Using AI Code Generation
1var stf = require('devicefarmer-stf');2api.removeDevices('c9c9b4e4', function(err, data){3 if(err){4 console.log(err);5 }else{6 console.log(data);7 }8});9var stf = require('devicefarmer-stf');10api.addDevices('c9c9b4e4', function(err, data){11 if(err){12 console.log(err);13 }else{14 console.log(data);15 }16});17var stf = require('devicefarmer-stf');18api.listDevices(function(err, data){19 if(err){20 console.log(err);21 }else{22 console.log(data);23 }24});25var stf = require('devicefarmer-stf');26api.listDevices(function(err, data){27 if(err){28 console.log(err);29 }else{30 console.log(data);31 }32});
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!