Skip to content
This repository has been archived by the owner on Sep 10, 2021. It is now read-only.

Commit

Permalink
make it compatible with current multiremote
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-bromann committed Aug 18, 2016
1 parent e0a0177 commit e1c380e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 25 deletions.
16 changes: 3 additions & 13 deletions lib/startAnalyzing.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,20 @@
import merge from 'deepmerge'
import { ErrorHandler } from 'webdriverio'
import startAnalyzingScript from './browser/startAnalyzing'

/**
* initiate WebRTC analyzing
*/
export default async function startAnalyzing (options) {
export default async function startAnalyzing (selectorMethod = () => false) {
if (this.analyzingScriptIsInjected) {
throw new ErrorHandler.CommandError('analyzing already started')
}

const params = merge({
instance: this.instance.getInstances()[0],
interval: this.interval,
selectorMethod: () => false
}, typeof options === 'object' ? options : {})

this.interval = params.interval
this.browser = params.instance

await this.browser.timeouts('script', 1000)
let res = await this.browser.selectorExecuteAsync(
'body',
startAnalyzingScript,
params.selectorMethod,
params.interval
selectorMethod,
this.interval
)

if (!res || Object.keys(res).length === 0) {
Expand Down
36 changes: 24 additions & 12 deletions lib/webdriverrtc.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,50 @@
import startAnalyzing from './startAnalyzing'
import stopAnalyzing from './stopAnalyzing'
import getStats from './getStats'
import url from './url'
import url from 'webdriverio/build/lib/protocol/url'
import getConnectionInformation from './getConnectionInformation'
import urlScript from './browser/url'

/**
* WebdriverRTC
*/
class WebdriverRTC {
constructor (webdriverInstance, options) {
/**
* instance need to have addCommand method
* browser that measures connection required
*/
if (typeof webdriverInstance.addCommand !== 'function') {
throw new Error('you can\'t use WebdriverRTC with this version of WebdriverIO')
if (typeof options.browser !== 'string') {
throw new Error('Please specify the browser to measure connection data with!')
}

/**
* check if browser name exists in matrix
*/
if (webdriverInstance.getInstances().indexOf(options.browser) === -1) {
throw new Error('Specified browser was not found in browser matrix!')
}

this.interval = 1000
this.instance = webdriverInstance
this.browser = webdriverInstance.select(options.browser)
this.analyzingScriptIsInjected = false

/**
* add WebdriverRTC commands to WebdriverIO instance
* add WebdriverRTC commands to choosen matrix browser
*/
this.instance.addCommand('startAnalyzing', startAnalyzing.bind(this))
this.instance.addCommand('stopAnalyzing', stopAnalyzing.bind(this))
this.instance.addCommand('getStats', getStats.bind(this))
this.instance.addCommand('getConnectionInformation', getConnectionInformation.bind(this))
this.browser.addCommand('startAnalyzing', startAnalyzing.bind(this))
this.browser.addCommand('stopAnalyzing', stopAnalyzing.bind(this))
this.browser.addCommand('getStats', getStats.bind(this))
this.browser.addCommand('getConnectionInformation', getConnectionInformation.bind(this))

/**
* overwrite url command in order to masquarade RTCPeerConnection objects
*/
var urlCommand = this.instance.url
this.instance.addCommand('url', url.bind(this, urlCommand), true)
this.browser.addCommand('_url', url)
this.browser.addCommand('url', async function (...args) {
const res = await this._url.apply(this, args)
await this.execute(urlScript)
return res
}, true)
}
}

Expand Down

0 comments on commit e1c380e

Please sign in to comment.