Permalink
Browse files

refactored main respoke library to commonJS.

the library can now be compiled using `npm run build` which will output `respoke.min.js` and `respoke.min.map` in the root of the project. The mediaStats plugin still needs work.
  • Loading branch information...
chadxz committed Jun 24, 2014
1 parent ee9186f commit 85661274c84f688a91a1a4e363370dabb84d2c16
View
@@ -0,0 +1 @@
module.exports = require('./respoke/respoke');
View
@@ -2,9 +2,9 @@
"name": "transporter",
"version": "0.0.0",
"description": "Client-side JavaScript library for Collective.",
"main": "respoke.js",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "browserify respoke/respoke.js -s respoke --debug --detect-globals false -p [minifyify --map respoke.min.js.map --compressPath `pwd` --output respoke.min.js.map] > respoke.min.js",
"doc": "jsdoc -c jsdoc.json",
"doc-markdown": "jsdoc -c jsdoc.json -t ${JSDOC_TEMPLATES:=..}/jsdoc-markdown-template -d markdown",
"doc-confluence": "jsdoc -c jsdoc.json -p -t ${JSDOC_TEMPLATES:=..}/confluence-jsdoc-template -d confluence"
@@ -15,12 +15,19 @@
},
"author": "Erin Spiceland",
"license": "Proprietary",
"dependencies": {
"loglevel": "^0.3.1",
"q": "^1.0.1",
"socket.io-client": "^0.9.16"
},
"devDependencies": {
"uglify-js": "~2.4.0",
"async": "~0.9.0",
"browserify": "^4.1.11",
"chai": "^1.8.1",
"grunt": "~0.4.2",
"grunt-aws-s3": "~0.8.1",
"grunt-contrib-uglify": "~0.4.0",
"grunt-env": "~0.4.1",
"grunt-karma": "~0.8.3",
"grunt-mocha-test": "~0.10.2",
"grunt-stratos": "git+http://stash.digium.com/stash/scm/stratos/grunt-stratos.git",
@@ -30,9 +37,9 @@
"karma-junit-reporter": "^0.2.2",
"karma-mocha": "^0.1.3",
"karma-spec-reporter": "0.0.12",
"minifyify": "^3.0.9",
"mocha-bamboo-reporter": "^1.0.5",
"async": "~0.9.0",
"sinon": "^1.7.3",
"grunt-env": "~0.4.1"
"uglify-js": "~2.4.0"
}
}
@@ -6,6 +6,8 @@
* @authors : Tim Panton <tpanton@digium.com>
*/
var mediaStatsReport = require('./mediaStatsReport');
/**
* A handler for WebRTC statistics. This class takes an `onStats` callback which it calls every `interval` seconds
* with the latest live statistics.
@@ -16,8 +18,8 @@
* @augments respoke.Class
* @param {RTCPeerConnection} peerConnection
*/
/*global respoke: false */
respoke.MediaStatsParser = function (params) {
module.exports = function (params) {
"use strict";
params = params || {};
var that = respoke.Class(params);
@@ -149,7 +151,7 @@ respoke.MediaStatsParser = function (params) {
function initStats() {
var sdp = {};
if (!pc || !pc.remoteDescription || !pc.remoteDescription.sdp ||
!pc.localDescription || !pc.localDescription.sdp) {
!pc.localDescription || !pc.localDescription.sdp) {
log.warn("missing info.");
return;
}
@@ -227,7 +229,7 @@ respoke.MediaStatsParser = function (params) {
}
args.push(function successHandler(stats) {
deferred.resolve(respoke.MediaStats(buildStats(stats)));
deferred.resolve(mediaStatsReport(buildStats(stats)));
});
args.push(function errorHandler(err) {
log.error(err);
@@ -288,7 +290,7 @@ respoke.MediaStatsParser = function (params) {
}
if (deltas[key] && oldStats && oldStats[statType] &&
[null, undefined].indexOf(oldStats[statType][key]) === -1) {
[null, undefined].indexOf(oldStats[statType][key]) === -1) {
eachStat["period" + key.charAt(0).toUpperCase() + key.slice(1)] =
(eachStat[key] - oldStats[statType][key]);
}
@@ -304,200 +306,9 @@ respoke.MediaStatsParser = function (params) {
return that;
}; // End respoke.MediaStatsParser
/**
* Success handler for methods that generate stats.
* @callback respoke.MediaStatsParser.statsHandler
* @param {respoke.MediaStats}
*/
/**
* A report containing statistical information about the flow of media.
* with the latest live statistics.
* @author Erin Spiceland <espiceland@digium.com>
* @class respoke.MediaStats
* @constructor
* @param {object} params
*/
respoke.MediaStats = function (params) {
"use strict";
params = JSON.parse(JSON.stringify(params || {}));
/**
* Information about the connection.
* @memberof! respoke.MediaStats
* @type {object}
* @name connection
* @property {string} channelId - A string which identifies this media stream (which may contain several
* media stream tracks) to the browser.
* @property {boolean} foundIncomingNetworkPaths - Whether or not the ICE hole-punching process has found
* a suitable network path from the remote party to this client.
* @property {boolean} foundOutgoingNetworkPaths - Whether or not the ICE hole-punching process has found
* a suitable network path from this client to the remote party.
* @property {string} localHost - The local IP and port number of the media connection.
* @property {string} remoteHost - The remote IP and port number of the media connection.
* @property {string} localMediaPath - The type of network path the local media is taking to the remote
* party, one of "local", "srflx", "prflx", "relay".
* @property {string} remoteMediaPath - The type of network path the local media is taking to the remote
* party, one of "local", "srflx", "prflx", "relay".
* @property {string} roundTripTime - How long it takes media packets to traverse the network path.
* @property {string} transport - Whether the media is flowing via UDP or TCP
*/
/**
* Information about the local audio stream track.
* @memberof! respoke.MediaStats
* @type {object}
* @name localaudio
* @property {string} audioInputLevel - Microphone volume.
* @property {string} codec - Audio codec in use.
* @property {string} totalBytesSent - Total number of bytes sent since media first began flowing.
* @property {string} periodBytesSent - Number of bytes sent since the last stats event.
* @property {string} totalPacketsSent - Total number of packets sent since media first began flowing.
* @property {string} periodPacketsSent - Number of packets sent since the last stats event.
* @property {string} transportId - The identifer of the media stream to which this media stream track belongs.
*/
/**
* Information about the local video stream track.
* @memberof! respoke.MediaStats
* @type {object}
* @name localvideo
* @property {string} codec - Video codec in use.
* @property {string} totalBytesSent - Total number of bytes sent since media first began flowing.
* @property {string} periodBytesSent - Number of bytes sent since the last stats event.
* @property {string} totalPacketsSent - Total number of packets sent since media first began flowing.
* @property {string} periodPacketsSent - Number of packets sent since the last stats event.
* @property {string} transportId - The identifer of the media stream to which this media stream track belongs.
*/
/**
* Information about the remote audio stream track.
* @memberof! respoke.MediaStats
* @type {object}
* @name remoteaudio
* @property {string} audioOutputLevel
* @property {string} totalBytesReceived - Total number of bytes received since media first began flowing.
* @property {string} periodBytesReceived - Number of bytes received since the last stats event.
* @property {string} packetsLost - Total number of packets lost.
* @property {string} totalPacketsReceived - Total number of packets received since media first began flowing.
* @property {string} periodPacketsReceived - Number of packets received since the last stats event.
* @property {string} transportId - The identifer of the media stream to which this media stream track
* belongs.
*/
/**
* Information about the remote video stream track.
* @memberof! respoke.MediaStats
* @type {object}
* @name remotevideo
* @property {string} totalBytesReceived - Total number of bytes received since media first began flowing.
* @property {string} periodBytesReceived - Number of bytes received since the last stats event.
* @property {string} packetsLost - Total number of packets lost.
* @property {string} totalPacketsReceived - Total number of packets received since media first began flowing.
* @property {string} periodPacketsReceived - Number of packets received since the last stats event.
* @property {string} transportId - The identifer of the media stream to which this media stream track belongs.
*/
/**
* Information about connection state.
* @memberof! respoke.MediaStats
* @type {object}
* @name state
* @property {string} iceConnectionState - Indicates where we are in terms of ICE network negotiation -- "hole
* punching."
* @property {string} iceGatheringState - Indicates whether we have started or finished gathering ICE
* candidates from the browser.
*/
/**
* The date and time at which this stats snapshot was taken.
* @memberof! respoke.MediaStats
* @name timestamp
* @type {date}
*/
/**
* The time that has passed since the last stats snapshot was taken.
* @memberof! respoke.MediaStats
* @name periodLength
* @type {number}
*/
/**
* These aliases define what things should be renamed before report is sent.
* @memberof! respoke.MediaStats
* @private
* @name aliases
* @type {object}
*/
var aliases = {
cons: {
newname: 'connection',
members: {
googChannelId: 'channelId',
googLocalAddress: 'localHost',
googRemoteAddress: 'remoteHost',
googLocalCandidateType: 'localMediaPath',
googRemoteCandidateType: 'remoteMediaPath',
googReadable: 'foundIncomingNetworkPaths',
googRtt: 'roundTripTime',
googTransportType: 'transport',
googWritable: 'foundOutgoingNetworkPaths'
}
},
localaudio: {
members: {
googCodecName: 'codec',
bytesSent: 'totalBytesSent',
packetsSent: 'totalPacketsSent'
}
},
localvideo: {
members: {
googCodecName: 'codec',
bytesSent: 'totalBytesSent',
packetsSent: 'totalPacketsSent'
}
},
remoteaudio: {
members: {
googCodecName: 'codec',
bytesReceived: 'totalBytesReceived',
packetsReceived: 'totalPacketsReceived'
}
},
remotevideo: {
members: {
googCodecName: 'codec',
bytesReceived: 'totalBytesReceived',
packetsReceived: 'totalPacketsReceived'
}
}
};
/**
* Rename report attributes to have more readable, understandable names.
* @memberof! respoke.MediaStats
* @method respoke.MediaStats.format
* @param {object} report
* @param {object} aliases
* @returns {object}
* @private
*/
function format(report, aliases) {
Object.keys(aliases).forEach(function eachAttr(oldName) {
var name;
if (typeof aliases[oldName] === 'string') {
report[aliases[oldName]] = report[oldName];
delete report[oldName];
} else if (typeof aliases[oldName] === 'object') {
name = oldName;
if (aliases[oldName].newname) {
report[aliases[oldName].newname] = report[oldName];
name = aliases[oldName].newname;
delete report[oldName];
}
if (aliases[oldName].members) {
format(report[name], aliases[oldName].members);
}
}
});
if (report.connection) {
report.connection.foundIncomingNetworkPaths = ('true' === report.connection.foundIncomingNetworkPaths);
report.connection.foundOutgoingNetworkPaths = ('true' === report.connection.foundOutgoingNetworkPaths);
}
return report;
}
return format(params, aliases);
}; // End respoke.MediaStats
Oops, something went wrong.

0 comments on commit 8566127

Please sign in to comment.