How to use ForwardManager method in devicefarmer-stf

Best JavaScript code snippet using devicefarmer-stf

forward-manager.js

Source:forward-manager.js Github

copy

Full Screen

1const EventEmitter = require('events')2const { join: pJoin } = require('path')3const net = require('net')4const { URL } = require('url')5const fs = require('fs-extra')6const jsonBeautify = require("json-beautify")7const exErr = require('./extend-error')8const { isObject, isFunction, callbackHandler } = require('./misc')9const ConfigManager = require('./config-manager')10const ForwardService = require('./forward-service')11const ForwardConnection = require('./forward-connection')12class ForwardManager extends EventEmitter {13 constructor (configPath, logger, callback) {14 // init15 super()16 /*17 * version infomation18 * [major version].[minor version].[snapshot]19 */20 Object.defineProperties(this, {21 version: { get () { return 'v3.1.2' } }22 })23 callbackHandler(this, 'ready', 'error', callback)24 this.status = 025 this.notiList = []26 this.notiCount = 027 this.notiMaxCount = 10028 this._cm = new ConfigManager(configPath)29 this.logger = logger || console30 this.loggerPrefix = 'manager>'31 this._services = {}32 this._profiles = {33 // TODO: remove default setting34 ssh: {35 source: 8080,36 dest: 'localhost:22',37 idleTimeout: 0,38 }39 }40 // async init41 ;(async () => {42 // handle config43 try {44 this._profiles = await this._cm.loadAsync()45 } catch (err) {46 if (isObject(err), err.code === 'ENOENT') {47 this.i('Config file not exists. Creating.')48 this._saveConfig()49 } else {50 const msg = `Unexpected error occur during load config. All changes will be lost!: ${err.stack}`51 this.e(msg)52 this._addNoti('error', msg)53 }54 }55 // instance initialize from config56 for (let name in this._profiles) {57 this._services[name] = new ForwardService(this, name, this._profiles[name])58 this._initProfile(name)59 }60 })().then(() => {61 this.i('ready')62 this.emit('ready')63 }).catch(err => {64 const msg = `init error: ${err.stack}`65 this.e(msg)66 this._addNoti('error', msg)67 this.emit('error', err)68 })69 }70 // logger controls71 d () { this.logger.debug(this.loggerPrefix, ...arguments) }72 i () { this.logger.info(this.loggerPrefix, ...arguments) }73 w () { this.logger.warn(this.loggerPrefix, ...arguments) }74 e () { this.logger.error(this.loggerPrefix, ...arguments) }75 // destory instance recursivly76 destroy () {77 // TODO78 }79 // ConfigManager controls80 // save config non-blocking81 _saveConfig () {82 this._cm.save(this._profiles, err => {83 if (err) {84 const msg = `Can't save config file. All changes will be lost!: ${err.stack}`85 this.w(msg)86 this._addNoti('warn', msg)87 }88 })89 }90 // notification controls91 _addNoti (level, message) {92 this.notiList.push({93 l: level,94 m: message,95 i: this.notiCount96 })97 this.status |= this.ManagerStatus.NOTIFICATION98 while (this.notiList.length > this._notiMaxCount) this.notiList.shift()99 this.emit('notificationAdd', this.notiCount++)100 }101 clearNoti (index) {102 for (var i in this.notiList) if (this.notiList[i].i === index) {103 this.notiList[i].splice(i, 1)104 break105 }106 if (!this.notiList.length && (this.status & this.ManagerStatus.NOTIFICATION))107 this.status -= this.ManagerStatus.NOTIFICATION108 }109 clearAllNoti () {110 this.notiList = []111 this.notiCount = 0112 if (this.status & this.ManagerStatus.NOTIFICATION)113 this.status -= this.ManagerStatus.NOTIFICATION114 }115 // profile controls116 _initProfile (name) {117 this._services[name].on('error', err => {118 this.w(`service[${name}] unhandled exception:`, err)119 })120 this._services[name].on('optionsChanged',121 profile => { this._saveService(name, profile) }122 )123 this.emit('profileInitialized', name)124 }125 _saveService (name, profile) {126 this._profiles[name] = profile127 this._saveConfig()128 }129 async createProfile (name, profile) {130 // valid check131 if (this.getService(name)) {132 throw exErr({133 message: 'Profile name is already taken.',134 code: 'ERR_OCCUPIED_PROFILE_NAME'135 })136 }137 profile = ForwardService.optionsFilter(profile)138 // save profile (none-blocking)139 this._profiles[name] = profile140 this._saveConfig()141 // create instance142 this._services[name] = new ForwardService(this, name, profile)143 this._initProfile(name)144 // finalize145 this.i(`Profile created: ${name}`)146 this.emit('profileCreated', name)147 }148 async removeProfile (name, timeout) {149 // valid check150 if (!this.getService(name)) {151 throw exErr({152 message: 'Profile not exists.',153 code: 'ERR_PROFILE_NOT_EXISTS'154 })155 }156 // destroy & remove instance157 this.d(`Profile removing: ${name}`)158 this.emit('profileRemove', name)159 // close service160 if (this.getService(name).isOpen()) await this.getService(name).close(timeout)161 delete this._services[name]162 // save profile (none-blocking)163 delete this._profiles[name]164 this._saveConfig()165 this.i(`Profile removed: ${name}`)166 this.emit('profileRemoved', name)167 }168 async startProfile (name) {169 // valid check170 if (!this.getService(name)) {171 throw exErr({172 message: 'Profile not exists.',173 code: 'ERR_PROFILE_NOT_EXISTS'174 })175 }176 // start service177 await this.getService(name).open()178 }179 async stopProfile (name, timeout) {180 // valid check181 if (!this.getService(name)) {182 throw exErr({183 message: 'Profile not exists.',184 code: 'ERR_PROFILE_NOT_EXISTS'185 })186 }187 await this.getService(name).close(timeout)188 }189 // service controls190 getService (name) { return this._services[name] }191 // export control192 toPlainData () {193 const services = {}194 Object.keys(this._services).forEach(name => {195 services[name] = this._services[name].toPlainData()196 })197 return {198 status: this.status,199 services200 }201 }202}203ForwardManager.ManagerStatus = {204 'READY': 1,205 'NOTIFICATION': 2206}207ForwardManager.prototype.ManagerStatus = ForwardManager.ManagerStatus208ForwardManager.ForwardService = ForwardService209ForwardManager.ForwardConnection = ForwardConnection...

Full Screen

Full Screen

manager.js

Source:manager.js Github

copy

Full Screen

...88 events.EventEmitter.call(this)89}90util.inherits(ForwardHandler, events.EventEmitter)91// Handles multiple ports92function ForwardManager() {93 var handlersById = Object.create(null)94 this.has = function(id) {95 return !!handlersById[id]96 }97 this.add = function(id, conn, options) {98 function endListener() {99 delete handlersById[id]100 this.emit('remove', id, options)101 }102 if (this.has(id)) {103 this.remove(id)104 }105 var handler = new ForwardHandler(conn, options)106 handler.on('end', endListener.bind(this))...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var ForwardManager = require('devicefarmer-stf').ForwardManager;2var forwardManager = new ForwardManager();3forwardManager.forward(5555, 5556, function (err) {4 if (err) {5 console.log(err);6 }7});8forwardManager.removeForward(5555, 5556, function (err) {9 if (err) {10 console.log(err);11 }12});13forwardManager.listForwards(function (err, forwards) {14 if (err) {15 console.log(err);16 } else {17 console.log(forwards);18 }19});20forwardManager.removeAllForwards(function (err) {21 if (err) {22 console.log(err);23 }24});25forwardManager.forward(5555, 5556, function (err) {26 if (err) {27 console.log(err);28 } else {29 forwardManager.removeForward(5555, 5556, function (err) {30 if (err) {31 console.log(err);32 } else {33 forwardManager.listForwards(function (err, forwards) {34 if (err) {35 console.log(err);36 } else {37 console.log(forwards);38 }39 });40 }41 });42 }43});44forwardManager.removeAllForwards(function (err) {45 if (err) {46 console.log(err);47 } else {48 forwardManager.listForwards(function (err, forwards) {49 if (err) {50 console.log(err);51 } else {52 console.log(forwards);53 }54 });55 }56});57forwardManager.forward(5555, 5556, function (err) {58 if (err) {59 console.log(err);60 } else {61 forwardManager.removeAllForwards(function (err) {62 if (err) {63 console.log(err);64 } else {65 forwardManager.listForwards(function (err, forwards) {66 if (err) {67 console.log(err);68 } else {69 console.log(forwards);70 }71 });72 }73 });74 }75});76forwardManager.forward(5555, 5556, function (err) {77 if (err) {78 console.log(err);79 } else {80 forwardManager.forward(5556, 5557, function (err) {81 if (err) {82 console.log(err);83 } else {84 forwardManager.listForwards(function (err, forwards) {

Full Screen

Using AI Code Generation

copy

Full Screen

1var ForwardManager = require('stf').util.forward.ForwardManager;2var forwardManager = new ForwardManager();3forwardManager.forward(5555, 5555, function(err, result) {4 if (err) {5 console.log(err);6 }7 else {8 console.log(result);9 }10});11var ForwardManager = require('stf').util.forward.ForwardManager;12var forwardManager = new ForwardManager();13forwardManager.unforward(5555, 5555, function(err, result) {14 if (err) {15 console.log(err);16 }17 else {18 console.log(result);19 }20});21var ForwardManager = require('stf').util.forward.ForwardManager;22var forwardManager = new ForwardManager();23forwardManager.forward(5555, 5555, function(err, result) {24 if (err) {25 console.log(err);26 }27 else {28 console.log(result);29 }30});31var ForwardManager = require('stf').util.forward.ForwardManager;32var forwardManager = new ForwardManager();33forwardManager.unforward(5555, 5555, function(err, result) {34 if (err) {35 console.log(err);36 }37 else {38 console.log(result);39 }40});41var ForwardManager = require('stf').util.forward.ForwardManager;42var forwardManager = new ForwardManager();43forwardManager.forward(5555, 5555, function(err, result) {44 if (err) {45 console.log(err);46 }47 else {48 console.log(result);49 }50});51var ForwardManager = require('stf').util.forward.ForwardManager;52var forwardManager = new ForwardManager();53forwardManager.unforward(5555, 5555, function(err, result) {54 if (err) {55 console.log(err);56 }57 else {58 console.log(result);59 }60});

Full Screen

Using AI Code Generation

copy

Full Screen

1var ForwardManager = require('stf').util.forward.ForwardManager;2var forwardManager = new ForwardManager();3forwardManager.forward('emulator-5554', 8080, 8080);4var ForwardManager = require('appium-android-driver').ForwardManager;5var forwardManager = new ForwardManager();6forwardManager.forward('emulator-5554', 8080, 8080);7Error: Error executing adbExec. Original error: 'Command '/home/username/Android/Sdk/platform-tools/adb -P 5037 -s emulator-5554 forward tcp:8080 tcp:8080' exited with code 1'; Stderr: 'adb: error: failed to get feature set: more than one device/emulator'; Code: '1'8Error: Error executing adbExec. Original error: 'Command '/home/username/Android/Sdk/platform-tools/adb -P 5037 -s emulator-5554 forward tcp:8080 tcp:8080' exited with code 1'; Stderr: 'adb: error: failed to get feature set: more than one device/emulator'; Code: '1'

Full Screen

Using AI Code Generation

copy

Full Screen

1var forward = require('devicefarmer-stf').forward;2forward({ serial: 'emulator-5554', localPort: 1234, remotePort: 5678 }, function(err) {3 if (err) {4 console.log(err);5 }6});7var forward = require('devicefarmer-stf').forward;8forward({ serial: 'emulator-5554', localPort: 1234, remotePort: 5678 }, function(err) {9 if (err) {10 console.log(err);11 }12});13var forward = require('devicefarmer-stf').forward;14forward({ serial: 'emulator-5554', localPort: 1234, remotePort: 5678 }, function(err) {15 if (err) {16 console.log(err);17 }18});19var forward = require('devicefarmer-stf').forward;20forward({ serial: 'emulator-5554', localPort: 1234, remotePort: 5678 }, function(err) {21 if (err) {22 console.log(err);23 }24});25var forward = require('devicefarmer-stf').forward;26forward({ serial: 'emulator-5554', localPort: 1234, remotePort: 5678 }, function(err) {27 if (err) {28 console.log(err);29 }30});31var forward = require('devicefarmer-stf').forward;32forward({ serial: 'emulator-5554', localPort: 1234, remotePort: 5678 }, function(err) {33 if (err) {34 console.log(err);35 }36});37var forward = require('devicefarmer-stf').forward;38forward({ serial: 'emulator-5554', localPort: 1234, remotePort:

Full Screen

Using AI Code Generation

copy

Full Screen

1var stf = require('stf-client');2var forwardManager = new stf.ForwardManager();3forwardManager.forward('tcp:8080', 'localabstract:webview_devtools_remote_12345');4var stf = require('stf-client');5var forwardManager = new stf.ForwardManager();6forwardManager.forward('tcp:8080', 'localabstract:webview_devtools_remote_12345');7var stf = require('stf-client');8var forwardManager = new stf.ForwardManager();9forwardManager.forward('tcp:8080', 'localabstract:webview_devtools_remote_12345');10var stf = require('stf-client');11var forwardManager = new stf.ForwardManager();12forwardManager.forward('tcp:8080', 'localabstract:webview_devtools_remote_12345');13var stf = require('stf-client');14var forwardManager = new stf.ForwardManager();15forwardManager.forward('tcp:8080', 'localabstract:webview_devtools_remote_12345');16var stf = require('stf-client');17var forwardManager = new stf.ForwardManager();18forwardManager.forward('tcp:8080', 'localabstract:webview_devtools_remote_12345');19var stf = require('stf-client');20var forwardManager = new stf.ForwardManager();21forwardManager.forward('tcp:8080', 'localabstract:webview_devtools_remote_12345');22var stf = require('stf-client');23var forwardManager = new stf.ForwardManager();24forwardManager.forward('tcp:8080', 'localabstract:webview_devtools_remote_12345');

Full Screen

Using AI Code Generation

copy

Full Screen

1var devicefarmer = require('devicefarmer-stf');2var forwardManager = new devicefarmer.ForwardManager();3forwardManager.list(function(err, devices) {4 console.log(devices);5});6forwardManager.forward('emulator-5554', 'tcp:8000', 'tcp:8000', function(err, devices) {7 console.log(devices);8});9forwardManager.remove('emulator-5554', 'tcp:8000', 'tcp:8000', function(err, devices) {10 console.log(devices);11});12forwardManager.remove('emulator-5554', 'tcp:8000', 'tcp:8000', function(err, devices) {13 console.log(devices);14});15forwardManager.remove('emulator-5554', 'tcp:8000', 'tcp:8000', function(err, devices) {16 console.log(devices);17});18forwardManager.remove('emulator-5554', 'tcp:8000', 'tcp:8000', function(err, devices) {19 console.log(devices);20});21forwardManager.remove('emulator-5554', 'tcp:8000', 'tcp:8000', function(err, devices) {22 console.log(devices);23});24forwardManager.remove('emulator-5554', 'tcp:8000', 'tcp:8000', function(err, devices) {25 console.log(devices);26});27forwardManager.remove('emulator-5554', 'tcp:8000', 'tcp:8000', function(err, devices) {28 console.log(devices);29});30forwardManager.remove('emulator-5554', 'tcp:8000', 'tcp:8000', function(err, devices) {31 console.log(devices);32});33forwardManager.remove('emulator-5554', 'tcp:8000', 'tcp:8000', function(err, devices) {34 console.log(devices);35});36forwardManager.remove('emulator-5554', 'tcp:8000', 'tcp:8000', function(err, devices) {37 console.log(devices);38});39forwardManager.remove('emulator-5554', 'tcp:8000', 'tcp:8000', function(err, devices) {40 console.log(devices);41});42forwardManager.remove('emulator-5554', 'tcp:8000', 'tcp:8000', function(err, devices) {43 console.log(devices);44});

Full Screen

Using AI Code Generation

copy

Full Screen

1var stf = require('devicefarmer-stf-client');2var device = new stf.Device();3device.forwardManager('tcp:1234', 'tcp:4321');4var stf = require('devicefarmer-stf-client');5var device = new stf.Device();6device.forwardManager('tcp:1234', 'tcp:4321', function(error, result) {7 if (error) {8 console.log('error', error);9 } else {10 console.log('result', result);11 }12});13var stf = require('devicefarmer-stf-client');14var device = new stf.Device();15device.forwardManager('tcp:1234', 'tcp:4321')16 .then(function(result) {17 console.log('result', result);18 })19 .catch(function(error) {20 console.log('error', error);21 });22var stf = require('devicefarmer-stf-client');23var device = new stf.Device();24device.forwardManager('tcp:1234', 'tcp:4321')25 .then(function(result) {26 console.log('result', result);27 })28 .catch(function(error) {29 console.log('error', error);30 });31var stf = require('devicefarmer-stf-client');32var device = new stf.Device();33device.forwardManager('tcp:1234', 'tcp:4321')34 .then(function(result) {35 console.log('result', result);36 })37 .catch(function(error) {38 console.log('error', error);39 });40var stf = require('devicefarmer-stf-client');41var device = new stf.Device();42device.forwardManager('tcp:1234', 'tcp:4321')43 .then(function(result) {44 console.log('result', result);45 })46 .catch(function(error) {47 console.log('error', error);48 });

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run devicefarmer-stf automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful