Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export default async function startAnalyzing (selectorMethod = () => false) {
if (this.analyzingScriptIsInjected) {
throw new ErrorHandler('CommandError', 'analyzing already started')
}
await this.browser.timeouts('script', 1000)
let res = await this.browser.selectorExecuteAsync(
'body',
startAnalyzingScript,
selectorMethod,
this.interval
)
if (!res || Object.keys(res).length === 0) {
throw new ErrorHandler('CommandError', 'WebRTC connection didn\'t get established')
}
const ipAddressLocal = res.local.ipAddress.split(/:/)
const ipAddressRemote = res.remote.ipAddress.split(/:/)
res.local.ipAddress = ipAddressLocal[0]
res.local.port = ipAddressLocal[1]
res.remote.ipAddress = ipAddressRemote[0]
res.remote.port = ipAddressRemote[1]
this.connection = res
this.analyzingScriptIsInjected = true
return this.connection
}
export default async function startAnalyzing (selectorMethod = () => false) {
if (this.analyzingScriptIsInjected) {
throw new ErrorHandler('CommandError', 'analyzing already started')
}
await this.browser.timeouts('script', 1000)
let res = await this.browser.selectorExecuteAsync(
'body',
startAnalyzingScript,
selectorMethod,
this.interval
)
if (!res || Object.keys(res).length === 0) {
throw new ErrorHandler('CommandError', 'WebRTC connection didn\'t get established')
}
const ipAddressLocal = res.local.ipAddress.split(/:/)
const ipAddressRemote = res.remote.ipAddress.split(/:/)
export default function getConnectionInformation () {
if (!this.connection) {
throw new ErrorHandler('CommandError',
'No information got recoreded yet. Please run the startAnalyzing command first'
)
}
return this.connection
};
const rawData = []
let from = now
let to = now
if (typeof duration === 'number') {
from = now - duration
to = now
} else if (typeof duration === 'object' && typeof duration.from === 'number' && duration.to === 'number') {
from = duration.from
to = duration.to
}
const stats = (await this.browser.execute(getStatsScript, from, to, this.interval)).value
if (!stats) {
throw new ErrorHandler('CommandError', 'There was a problem receiving the results')
}
stats.forEach((result, i) => {
rawData.push(result.results)
delete stats[i].results
})
if (stats.length === 1) {
return stats[0]
}
let mean = calcResult['+'](stats)
mean = calcResult['/'](mean, stats.length)
let median = calcResult['[]'](stats)
median = calcResult['-|-'](median)