Permalink
Browse files

rewritten project into ES2016

  • Loading branch information...
1 parent cbcbfd7 commit 41f6b884b976b9fc804e0b0fe7610cbac54ccc37 @christian-bromann christian-bromann committed Aug 11, 2016
View
@@ -0,0 +1,9 @@
+{
+ "presets": ["es2015", "stage-0"],
+ "plugins": [
+ "syntax-async-functions",
+ "transform-regenerator",
+ "transform-runtime",
+ "add-module-exports"
+ ]
+}
View
@@ -0,0 +1,15 @@
+# EditorConfig helps developers define and maintain consistent
+# coding styles between different editors and IDEs
+# editorconfig.org
+
+root = true
+
+[*]
+
+indent_style = space
+indent_size = 4
+
+end_of_line = lf
+charset = utf-8
+trim_trailing_whitespace = true
+insert_final_newline = true
View
@@ -0,0 +1,4 @@
+build/
+examples/
+bin/
+./*.js
View
@@ -0,0 +1,8 @@
+{
+ "extends": "standard",
+ "parser": "babel-eslint",
+ "rules": {
+ "indent": [2, 4],
+ "generator-star-spacing": 0
+ }
+}
View
@@ -23,6 +23,7 @@ build/Release
# Commenting this out is preferred by some people, see
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git-
node_modules
+build
# Users Environment Variables
.lock-wscript
View
No changes.
File renamed without changes.
View
@@ -0,0 +1,60 @@
+module.exports = function (grunt) {
+ grunt.initConfig({
+ pkgFile: 'package.json',
+ clean: ['build'],
+ babel: {
+ dist: {
+ files: [{
+ expand: true,
+ cwd: './lib',
+ src: ['**/*.js'],
+ dest: 'build',
+ ext: '.js'
+ }]
+ }
+ },
+ eslint: {
+ options: {
+ parser: 'babel-eslint'
+ },
+ target: ['index.js', 'lib/**/*.js', 'examples/**/*.js'] //, 'test/**/*.js']
+ },
+ contributors: {
+ options: {
+ commitMessage: 'update contributors'
+ }
+ },
+ bump: {
+ options: {
+ commitMessage: 'v%VERSION%',
+ pushTo: 'upstream'
+ }
+ },
+ watch: {
+ commands: {
+ files: ['index.js', 'lib/**/*.js'],
+ tasks: ['babel:commands'],
+ options: {
+ spawn: false
+ }
+ }
+ }
+ })
+
+ require('load-grunt-tasks')(grunt)
+ grunt.registerTask('default', ['build'])
+ grunt.registerTask('build', 'Build webdriverrtc', function () {
+ grunt.task.run([
+ 'eslint',
+ 'clean',
+ 'babel'
+ ])
+ })
+ grunt.registerTask('release', 'Bump and tag version', function (type) {
+ grunt.task.run([
+ 'build',
+ 'contributors',
+ 'bump:' + (type || 'patch')
+ ])
+ })
+}
View
@@ -1,11 +0,0 @@
-/**
- * WebdriverRTC
- * WebRTC testing tool for WebdriverIO
- *
- * @author Christian Bromann <christian@saucelabs.com>
- * @author Thomas Fett <mail@thomasfett.de>
- *
- * @license Licensed under the MIT license.
- */
-
-module.exports = require('./lib/webdriverrtc');
@@ -0,0 +1,5 @@
+{
+ "env": {
+ "browser": true
+ }
+}
@@ -1,21 +1,20 @@
-module.exports = function(from, to, interval) {
- var recordedStats = Object.keys(window._webdriverrtc || {}),
- snapshots = [];
+export default 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]];
+ if (!from) {
+ return window._webdriverrtc[recordedStats[recordedStats.length - 1]]
}
- recordedStats.forEach(function(timestamp) {
- timestamp = parseInt(timestamp, 10);
-
- if(timestamp > (from - interval / 2) && (timestamp - interval / 2) < to) {
- snapshots.push(window._webdriverrtc[timestamp]);
+ recordedStats.forEach(function (timestamp) {
+ timestamp = parseInt(timestamp, 10)
+ if (timestamp > (from - interval / 2) && (timestamp - interval / 2) < to) {
+ snapshots.push(window._webdriverrtc[timestamp])
}
- });
+ })
- return snapshots;
+ return snapshots
};
@@ -1,70 +1,63 @@
/**
* this script gets executed in the browser
*/
-module.exports = function(_, pcSelectorMethod, interval) {
-
- var cb = arguments[arguments.length - 1];
-
- var globalObject = {
- audio: {},
- video: {}
- };
+export default function startAnalyzing (_, pcSelectorMethod, interval) {
+ var cb = arguments[arguments.length - 1]
/**
- * merge objects
+ * merge objects (copied from deepmerge)
*/
- function merge(target, src) {
- var dst = {};
+ function merge (target, src) {
+ 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];
- }
- else {
+ 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;
+ function sanitize (val) {
+ if (typeof val !== 'string' && typeof val !== 'number') {
+ return undefined
}
- return parseInt(val, 10);
+ return parseInt(val, 10)
}
/**
* record stats
*/
- function traceStats(results) {
+ function traceStats (results) {
var result = {
audio: {},
video: {},
results: results
- };
+ }
for (var i = 0; i < results.length; ++i) {
- var res = results[i];
+ var res = results[i]
/**
* RTCOutboundRTPStreamStats
*/
- if (res.googCodecName == 'opus' && res.bytesSent && res.packetsSent) {
+ if (res.googCodecName === 'opus' && res.bytesSent && res.packetsSent) {
result.audio.outbound = {
bytesSent: sanitize(res.bytesSent),
packetsSent: sanitize(res.packetsSent),
@@ -73,12 +66,11 @@ module.exports = function(_, pcSelectorMethod, interval) {
packetsLost: sanitize(res.packetsLost),
jitter: sanitize(res.googJitterReceived)
}
- }
/**
* RTCInboundRTPStreamStats
*/
- else if(res.googCodecName == 'opus' && res.bytesReceived && res.packetsReceived) {
+ } else if (res.googCodecName === 'opus' && res.bytesReceived && res.packetsReceived) {
result.audio.inbound = {
bytesReceived: sanitize(res.bytesReceived),
packetsReceived: sanitize(res.packetsReceived),
@@ -88,7 +80,7 @@ module.exports = function(_, pcSelectorMethod, interval) {
}
}
- if (res.googCodecName == 'VP8') {
+ if (res.googCodecName === 'VP8') {
result.video = merge(result.video, {
bytesSent: sanitize(res.bytesSent),
packetsSent: sanitize(res.packetsSent),
@@ -104,10 +96,10 @@ module.exports = function(_, pcSelectorMethod, interval) {
captureJitterMs: sanitize(res.googCaptureJitterMs),
captureQueueDelayMsPerS: sanitize(res.googCaptureQueueDelayMsPerS),
encodeUsagePercent: sanitize(res.googEncodeUsagePercent)
- });
+ })
}
- if (res.type == 'VideoBwe') {
+ if (res.type === 'VideoBwe') {
result.video.bandwidth = {
actualEncBitrate: sanitize(res.googActualEncBitrate),
availableSendBandwidth: sanitize(res.googAvailableSendBandwidth),
@@ -116,32 +108,32 @@ module.exports = function(_, 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() {
+ function getStats () {
pc.getStats(function (res) {
- var items = [],
- 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') {
+ if (item.type === 'googCandidatePair' && item.googActiveConnection === 'true') {
connectionType = {
local: {
candidateType: item.googLocalCandidateType,
@@ -152,32 +144,31 @@ module.exports = function(_, 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;
+ if (typeof cb === 'function') {
+ 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');
+ if (!pc || pc.constructor.name !== 'RTCPeerConnection') {
+ throw new Error('RTCPeerConnection not found')
}
- window._webdriverrtc = {};
- window._webdriverrtcTimeout = null;
- getStats();
-
-};
+ window._webdriverrtc = {}
+ window._webdriverrtcTimeout = null
+ getStats()
+}
Oops, something went wrong.

0 comments on commit 41f6b88

Please sign in to comment.