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

Commit

Permalink
don't compile browserscripts with babel anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-bromann committed Aug 18, 2016
1 parent 6eee186 commit e0a0177
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 71 deletions.
28 changes: 21 additions & 7 deletions gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = function (grunt) {
files: [{
expand: true,
cwd: './lib',
src: ['**/*.js'],
src: ['**/*.js', '!browser/*.js'],
dest: 'build',
ext: '.js'
}]
Expand Down Expand Up @@ -42,11 +42,24 @@ module.exports = function (grunt) {
},
watch: {
commands: {
files: ['index.js', 'lib/**/*.js'],
tasks: ['babel:commands'],
options: {
spawn: false
}
files: ['lib/*.js', 'lib/helpers/*.js'],
tasks: ['babel'],
options: { spawn: false }
},
browserscripts: {
files: ['lib/browser/*.js'],
tasks: ['copy:browserscripts'],
options: { spawn: false }
}
},
copy: {
browserscripts: {
files: [{
expand: true,
cwd: 'lib',
src: 'browser/*.js',
dest: 'build'
}]
}
}
})
Expand All @@ -57,7 +70,8 @@ module.exports = function (grunt) {
grunt.task.run([
'eslint',
'clean',
'babel'
'babel',
'copy'
])
})
grunt.registerTask('release', 'Bump and tag version', function (type) {
Expand Down
3 changes: 3 additions & 0 deletions lib/browser/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"env": {
"browser": true
},
rules: {
semi: ["error", "always", { "omitLastInOneLineBlock": true}]
}
}
16 changes: 8 additions & 8 deletions lib/browser/getStats.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
export default function getStats (from, to, interval) {
var recordedStats = Object.keys(window._webdriverrtc || {})
var snapshots = []
module.exports = function getStats (from, to, interval) {
var recordedStats = Object.keys(window._webdriverrtc || {});
var snapshots = [];

/**
* if no appropiate parameter was given return the last stat
*/
if (!from) {
return window._webdriverrtc[recordedStats[recordedStats.length - 1]]
return window._webdriverrtc[recordedStats[recordedStats.length - 1]];
}

recordedStats.forEach(function (timestamp) {
timestamp = parseInt(timestamp, 10)
timestamp = parseInt(timestamp, 10);
if (timestamp > (from - interval / 2) && (timestamp - interval / 2) < to) {
snapshots.push(window._webdriverrtc[timestamp])
snapshots.push(window._webdriverrtc[timestamp]);
}
})
});

return snapshots
return snapshots;
};
86 changes: 43 additions & 43 deletions lib/browser/startAnalyzing.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
/**
* this script gets executed in the browser
*/
export default function startAnalyzing (_, pcSelectorMethod, interval) {
var cb = arguments[arguments.length - 1]
module.exports = function startAnalyzing (_, pcSelectorMethod, interval) {
var cb = arguments[arguments.length - 1];

/**
* merge objects (copied from deepmerge)
*/
function merge (target, src) {
var dst = {}
var dst = {};

if (target && typeof target === 'object') {
Object.keys(target).forEach(function (key) {
dst[key] = target[key]
})
dst[key] = target[key];
});
}
Object.keys(src).forEach(function (key) {
if (typeof src[key] !== 'object' || !src[key]) {
dst[key] = src[key]
dst[key] = src[key];
} else {
if (!target[key]) {
dst[key] = src[key]
dst[key] = src[key];
} else {
dst[key] = merge(target[key], src[key])
dst[key] = merge(target[key], src[key]);
}
}
})
});

return dst
return dst;
}

/**
* sanitize stat values
*/
function sanitize (val) {
if (typeof val !== 'string' && typeof val !== 'number') {
return undefined
return undefined;
}

return parseInt(val, 10)
return parseInt(val, 10);
}

/**
Expand All @@ -49,10 +49,10 @@ export default function startAnalyzing (_, pcSelectorMethod, interval) {
audio: {},
video: {},
results: results
}
};

for (var i = 0; i < results.length; ++i) {
var res = results[i]
var res = results[i];

/**
* RTCOutboundRTPStreamStats
Expand All @@ -65,7 +65,7 @@ export default function startAnalyzing (_, pcSelectorMethod, interval) {
inputLevel: sanitize(res.audioInputLevel),
packetsLost: sanitize(res.packetsLost),
jitter: sanitize(res.googJitterReceived)
}
};

/**
* RTCInboundRTPStreamStats
Expand All @@ -77,7 +77,7 @@ export default function startAnalyzing (_, pcSelectorMethod, interval) {
outputLevel: sanitize(res.audioOutputLevel),
packetsLost: sanitize(res.packetsLost),
jitter: sanitize(res.googJitterReceived)
}
};
}

if (res.googCodecName === 'VP8') {
Expand All @@ -96,7 +96,7 @@ export default function startAnalyzing (_, pcSelectorMethod, interval) {
captureJitterMs: sanitize(res.googCaptureJitterMs),
captureQueueDelayMsPerS: sanitize(res.googCaptureQueueDelayMsPerS),
encodeUsagePercent: sanitize(res.googEncodeUsagePercent)
})
});
}

if (res.type === 'VideoBwe') {
Expand All @@ -108,30 +108,30 @@ export default function startAnalyzing (_, pcSelectorMethod, interval) {
targetEncBitrate: sanitize(res.googTargetEncBitrate),
bucketDelay: sanitize(res.googBucketDelay),
transmitBitrate: sanitize(res.googTransmitBitrate)
}
};
}
}

var timestamp = new Date().getTime()
window._webdriverrtc[timestamp] = result
var timestamp = new Date().getTime();
window._webdriverrtc[timestamp] = result;
}

/**
* get RTCStatsReports
*/
function getStats () {
pc.getStats(function (res) {
var items = []
var connectionType = {}
var items = [];
var connectionType = {};

res.result().forEach(function (result) {
var item = {}
var item = {};
result.names().forEach(function (name) {
item[name] = result.stat(name)
})
item.id = result.id
item.type = result.type
item.timestamp = result.timestamp
item[name] = result.stat(name);
});
item.id = result.id;
item.type = result.type;
item.timestamp = result.timestamp;

if (item.type === 'googCandidatePair' && item.googActiveConnection === 'true') {
connectionType = {
Expand All @@ -144,31 +144,31 @@ export default function startAnalyzing (_, pcSelectorMethod, interval) {
ipAddress: item.googRemoteAddress
},
transport: item.googTransportType
}
};

return
return;
}

items.push(item)
})
items.push(item);
});

traceStats(items)
window._webdriverrtcTimeout = setTimeout(getStats.bind(window, items), interval)
traceStats(items);
window._webdriverrtcTimeout = setTimeout(getStats.bind(window, items), interval);

if (typeof cb === 'function') {
cb(connectionType)
cb = undefined
cb(connectionType);
cb = undefined;
}
})
});
}

var pc = pcSelectorMethod() || window.webdriverRTCPeerConnectionBucket
var pc = pcSelectorMethod() || window.webdriverRTCPeerConnectionBucket;

if (!pc || pc.constructor.name !== 'RTCPeerConnection') {
throw new Error('RTCPeerConnection not found')
throw new Error('RTCPeerConnection not found');
}

window._webdriverrtc = {}
window._webdriverrtcTimeout = null
getStats()
}
window._webdriverrtc = {};
window._webdriverrtcTimeout = null;
getStats();
};
26 changes: 13 additions & 13 deletions lib/browser/url.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
export default function url () {
var OriginalRTCPeerConnection
module.exports = function url () {
var OriginalRTCPeerConnection;

/**
* method to masquerade RTCPeerConnection
*/
var masqueradeFunction = function (param1, param2, param3) {
var pc = new OriginalRTCPeerConnection(param1, param2, param3)
window.webdriverRTCPeerConnectionBucket = pc
return pc
}
var pc = new OriginalRTCPeerConnection(param1, param2, param3);
window.webdriverRTCPeerConnectionBucket = pc;
return pc;
};

if (window.RTCPeerConnection) {
OriginalRTCPeerConnection = window.RTCPeerConnection
window.RTCPeerConnection = masqueradeFunction
OriginalRTCPeerConnection = window.RTCPeerConnection;
window.RTCPeerConnection = masqueradeFunction;
} else if (window.webkitRTCPeerConnection) {
OriginalRTCPeerConnection = window.webkitRTCPeerConnection
window.webkitRTCPeerConnection = masqueradeFunction
OriginalRTCPeerConnection = window.webkitRTCPeerConnection;
window.webkitRTCPeerConnection = masqueradeFunction;
} else if (window.mozRTCPeerConnection) {
OriginalRTCPeerConnection = window.mozRTCPeerConnection
window.mozRTCPeerConnection = masqueradeFunction
OriginalRTCPeerConnection = window.mozRTCPeerConnection;
window.mozRTCPeerConnection = masqueradeFunction;
}
}
};

0 comments on commit e0a0177

Please sign in to comment.