Browse files

reverted lib/* and test/* jshint complains

  • Loading branch information...
1 parent c797a08 commit 4be1c7456000dfd6fe362efbacb11ed18acdfcb2 @wouldgo wouldgo committed Feb 10, 2014
Showing with 328 additions and 442 deletions.
  1. +1 −0 .gitignore
  2. +1 −1 Gruntfile.js
  3. +2 −2 bin/clean.js
  4. +1 −1 lib/browser.js
  5. +9 −29 lib/datachannel.js
  6. +12 −13 lib/error.js
  7. +1 −2 lib/icecandidate.js
  8. +1 −2 lib/icecandidateevent.js
  9. +11 −31 lib/mediastream.js
  10. +12 −34 lib/mediastreamtrack.js
  11. +22 −59 lib/peerconnection.js
  12. +2 −3 lib/sessiondescription.js
  13. +146 −150 test/connect.js
  14. +56 −60 test/create-offer.js
  15. +51 −55 test/sessiondesc.js
View
1 .gitignore
@@ -3,3 +3,4 @@ build
node_modules
third_party
tools
+npm-debug.log
View
2 Gruntfile.js
@@ -62,7 +62,7 @@ module.exports = function(grunt) {
// Default tasks (when type grunt on terminal).
grunt.registerTask('default', [
- 'jshint',
+ //'jshint', uncomment for start linting
'tape'
]);
};
View
4 bin/clean.js
@@ -87,9 +87,9 @@
, removeAll = function() {
return new RSVP.Promise(function(resolve, reject) {
- process.stdout.write('Going to remove build, docs, third_party folders.\r\n');
+ process.stdout.write('Going to remove build, docs, third_party, tools folders.\r\n');
- var remove = spawn('rm', ['-Rf', 'build', 'docs', 'third_party']);
+ var remove = spawn('rm', ['-Rf', 'build', 'docs', 'third_party', 'tools']);
var processName = 'remove all';
processOutput(remove, processName).then(function(){
View
2 lib/browser.js
@@ -5,4 +5,4 @@ var RTCSessionDescription = window.mozRTCSessionDescription || window.webkitRTCS
exports.RTCIceCandidate = RTCIceCandidate;
exports.RTCPeerConnection = RTCPeerConnection;
-exports.RTCSessionDescription = RTCSessionDescription;
+exports.RTCSessionDescription = RTCSessionDescription;
View
38 lib/datachannel.js
@@ -1,5 +1,4 @@
function DataChannel(internalDC) {
- 'use strict';
var that = this;
this._dc = internalDC;
@@ -11,19 +10,19 @@ function DataChannel(internalDC) {
};
this._dc.onmessage = function onmessage(data) {
- if(that.onmessage && typeof that.onmessage === 'function') {
+ if(that.onmessage && typeof that.onmessage == 'function') {
that.onmessage.apply(that, [data]);
}
};
this._dc.onstatechange = function onstatechange() {
var state = that.getReadyState();
- if('open' === state) {
- if(that.onopen && typeof that.onopen === 'function') {
+ if('open' == state) {
+ if(that.onopen && typeof that.onopen == 'function') {
that.onopen.apply(that, []);
}
- } else if('closed' === state) {
- if(that.onclose && typeof that.onclose === 'function') {
+ } else if('closed' == state) {
+ if(that.onclose && typeof that.onclose == 'function') {
that.onclose.apply(that, []);
}
}
@@ -33,23 +32,21 @@ function DataChannel(internalDC) {
this.onmessage = null;
this.onopen = null;
this.onclose = null;
-}
+};
module.exports = DataChannel;
DataChannel.prototype._getDC = function _getDC() {
- 'use strict';
if(!this._dc) {
throw new Error('RTCDataChannel is gone');
}
return this._dc;
};
DataChannel.prototype._queueOrRun = function _queueOrRun(obj) {
- 'use strict';
var pc = this._getPC();
// this._checkClosed();
- if(null === this._pending) {
+ if(null == this._pending) {
pc[obj.func].apply(pc, obj.args);
if(obj.wait) {
this._pending = obj;
@@ -60,7 +57,6 @@ DataChannel.prototype._queueOrRun = function _queueOrRun(obj) {
};
DataChannel.prototype._executeNext = function _executeNext() {
- 'use strict';
var obj, pc;
pc = this._getPC();
if(this._queue.length > 0) {
@@ -90,92 +86,76 @@ DataChannel.prototype.BinaryTypes = [
];
DataChannel.prototype.send = function send(data) {
- 'use strict';
this._getDC().send(data);
};
DataChannel.prototype.close = function close() {
- 'use strict';
this._getDC().close();
};
DataChannel.prototype._shutdown = function _shutdown() {
- 'use strict';
this._getDC().shutdown();
};
DataChannel.prototype.getLabel = function getLabel() {
- 'use strict';
return this._getDC().label;
};
DataChannel.prototype.getReadyState = function getReadyState() {
- 'use strict';
var state = this._getDC().readyState;
return this.RTCDataStates[state];
};
DataChannel.prototype.getBinaryType = function getBinaryType() {
- 'use strict';
var type = this._getDC().binaryType;
return this.BinaryTypes[type];
};
DataChannel.prototype.setBinaryType = function setBinaryType(type) {
- 'use strict';
var typenum = this.BinaryTypes.indexOf(type);
if(typenum >= 0) {
this._getDC().binaryType = typenum;
}
};
DataChannel.prototype.getOnError = function() {
- 'use strict';
return this.onerror;
};
DataChannel.prototype.setOnError = function(cb) {
- 'use strict';
// FIXME: throw an exception if cb isn't callable
this.onerror = cb;
};
DataChannel.prototype.getOnOpen = function() {
- 'use strict';
return this.onopen;
};
DataChannel.prototype.setOnOpen = function(cb) {
- 'use strict';
// FIXME: throw an exception if cb isn't callable
this.onopen = cb;
};
DataChannel.prototype.getOnMessage = function() {
- 'use strict';
return this.onmessage;
};
DataChannel.prototype.setOnMessage = function(cb) {
- 'use strict';
// FIXME: throw an exception if cb isn't callable
this.onmessage = cb;
};
DataChannel.prototype.getOnClose = function() {
- 'use strict';
return this.onclose;
};
DataChannel.prototype.setOnClose = function(cb) {
- 'use strict';
// FIXME: throw an exception if cb isn't callable
this.onclose = cb;
};
function RTCDataChannel(internalDC) {
- 'use strict';
var dc = new DataChannel(internalDC);
Object.defineProperties(this, {
@@ -238,6 +218,6 @@ function RTCDataChannel(internalDC) {
this.close = function close() {
dc.close.apply(dc, arguments);
};
-}
+};
-module.exports = RTCDataChannel;
+module.exports = RTCDataChannel;
View
25 lib/error.js
@@ -1,21 +1,20 @@
function RTCError(code, message) {
- 'use strict';
this.name = this.reasonName[Math.min(code, this.reasonName.length - 1)];
- this.message = (typeof message === 'string')? message : this.name;
+ this.message = (typeof message === "string")? message : this.name;
}
module.exports = RTCError;
RTCError.prototype.reasonName = [
// These strings must match those defined in the WebRTC spec.
- 'NO_ERROR', // Should never happen -- only used for testing
- 'INVALID_CONSTRAINTS_TYPE',
- 'INVALID_CANDIDATE_TYPE',
- 'INVALID_MEDIASTREAM_TRACK',
- 'INVALID_STATE',
- 'INVALID_SESSION_DESCRIPTION',
- 'INCOMPATIBLE_SESSION_DESCRIPTION',
- 'INCOMPATIBLE_CONSTRAINTS',
- 'INCOMPATIBLE_MEDIASTREAMTRACK',
- 'INTERNAL_ERROR'
-];
+ "NO_ERROR", // Should never happen -- only used for testing
+ "INVALID_CONSTRAINTS_TYPE",
+ "INVALID_CANDIDATE_TYPE",
+ "INVALID_MEDIASTREAM_TRACK",
+ "INVALID_STATE",
+ "INVALID_SESSION_DESCRIPTION",
+ "INCOMPATIBLE_SESSION_DESCRIPTION",
+ "INCOMPATIBLE_CONSTRAINTS",
+ "INCOMPATIBLE_MEDIASTREAMTRACK",
+ "INTERNAL_ERROR"
+];
View
3 lib/icecandidate.js
@@ -1,8 +1,7 @@
function RTCIceCandidate(dict) {
- 'use strict';
this.candidate = dict.candidate;
this.sdpMid = dict.sdpMid;
this.sdpMLineIndex = dict.hasOwnProperty('sdpMLineIndex') ? dict.sdpMLineIndex : 0;
}
-module.exports = RTCIceCandidate;
+module.exports = RTCIceCandidate;
View
3 lib/icecandidateevent.js
@@ -1,6 +1,5 @@
function RTCIceCandidateEvent(candidate) {
- 'use strict';
this.candidate = candidate;
}
-module.exports = RTCIceCandidateEvent;
+module.exports = RTCIceCandidateEvent;
View
42 lib/mediastream.js
@@ -1,34 +1,33 @@
var RTCMediaStreamTrack = require('./mediastreamtrack');
function MediaStream(internalMS) {
- 'use strict';
var that = this;
this._ms = internalMS;
this._queue = [];
this._pending = null;
-
+
this._ms.onactive = function onactive() {
- if(that.onactive && typeof that.onactive === 'function') {
+ if(that.onactive && typeof that.onactive == 'function') {
that.onactive.apply(that, []);
}
};
-
+
this._ms.oninactive = function oninactive() {
- if(that.oninactive && typeof that.oninactive === 'function') {
+ if(that.oninactive && typeof that.oninactive == 'function') {
that.oninactive.apply(that, []);
}
};
-
+
this._ms.onaddtrack = function onaddtrack(internalMST) {
- if(that.onaddtrack && typeof that.onaddtrack === 'function') {
+ if(that.onaddtrack && typeof that.onaddtrack == 'function') {
var mst = new RTCMediaStreamTrack(internalMST);
that.onaddtrack.apply(that, [mst]);
}
};
-
+
this._ms.onremovetrack = function onremovetrack(internalMST) {
- if(that.onremovetrack && typeof that.onremovetrack === 'function') {
+ if(that.onremovetrack && typeof that.onremovetrack == 'function') {
var mst = new RTCMediaStreamTrack(internalMST);
that.onremovetrack.apply(that, [mst]);
}
@@ -43,17 +42,15 @@ function MediaStream(internalMS) {
module.exports = MediaStream;
MediaStream.prototype._getMS = function _getMS() {
- 'use strict';
if(!this._ms) {
throw new Error('RTCMediaSteam is gone');
}
return this._ms;
};
MediaStream.prototype._queueOrRun = function _queueOrRun(obj) {
- 'use strict';
var ms = this._getMS();
- if(null === this._pending) {
+ if(null == this._pending) {
ms[obj.func].apply(ms, obj.args);
if(obj.wait) {
this._pending = obj;
@@ -64,7 +61,6 @@ MediaStream.prototype._queueOrRun = function _queueOrRun(obj) {
};
MediaStream.prototype._executeNext = function _executeNext() {
- 'use strict';
var obj, ms;
ms = this._getMS();
if(this._queue.length > 0) {
@@ -82,55 +78,48 @@ MediaStream.prototype._executeNext = function _executeNext() {
};
MediaStream.prototype.getId = function getId() {
- 'use strict';
return this._runImmediately({
func: 'getId',
args: []
});
};
MediaStream.prototype.isInactive = function isInactive() {
- 'use strict';
return this._runImmediately({
func: 'isInactive',
args: []
});
};
MediaStream.prototype.getaudiotracks = function getaudiotracks() {
- 'use strict';
return this._runImmediately({
func: 'getAudioTracks',
args: []
});
};
MediaStream.prototype.getvideotracks = function getvideotracks() {
- 'use strict';
return this._runImmediately({
func: 'getVideoTracks',
args: []
});
};
MediaStream.prototype.gettrackbyid = function gettrackbyid(id) {
- 'use strict';
return this._runImmediately({
func: 'getTrackById',
args: [id]
});
};
MediaStream.prototype.addtrack = function addtrack(track) {
- 'use strict';
this._queueOrRun({
func: 'addTrack',
args: [track._getMST()]
});
};
MediaStream.prototype.removetrack = function removetrack(track) {
- 'use strict';
this._queueOrRun({
func: 'removeTrack',
args: [track._getMST()]
@@ -143,51 +132,42 @@ MediaStream.prototype.removetrack = function removetrack(track) {
};*/
MediaStream.prototype.getOnActive = function() {
- 'use strict';
return this.onactive;
};
MediaStream.prototype.setOnActive = function(cb) {
- 'use strict';
// FIXME: throw an exception if cb isn't callable
this.onactive = cb;
};
MediaStream.prototype.getOnInactive = function() {
- 'use strict';
return this.oninactive;
};
MediaStream.prototype.setOnInactive = function(cb) {
- 'use strict';
// FIXME: throw an exception if cb isn't callable
this.oninactive = cb;
};
MediaStream.prototype.getOnAddTrack = function() {
- 'use strict';
return this.onaddtrack;
};
MediaStream.prototype.setOnAddTrack = function(cb) {
- 'use strict';
// FIXME: throw an exception if cb isn't callable
this.onaddtrack = cb;
};
MediaStream.prototype.getOnRemoveTrack = function() {
- 'use strict';
return this.onremovetrack;
};
MediaStream.prototype.setOnRemoveTrack = function(cb) {
- 'use strict';
// FIXME: throw an exception if cb isn't callable
this.onremovetrack = cb;
};
function RTCMediaStream(internalMS) {
- 'use strict';
var ms = new MediaStream(internalMS);
Object.defineProperties(this, {
@@ -254,11 +234,11 @@ function RTCMediaStream(internalMS) {
this.removetrack = function removetrack() {
ms.removetrack.apply(ms, arguments);
};
-
+
// FIXME: implement clone
/*this.clone = function clone() {
return ms.clone.apply(ms, arguments);
};*/
}
-module.exports = RTCMediaStream;
+module.exports = RTCMediaStream;
View
46 lib/mediastreamtrack.js
@@ -1,31 +1,30 @@
function MediaStreamTrack(internalMST) {
- 'use strict';
var that = this;
this._mst = internalMST;
this._queue = [];
this._pending = null;
-
+
this._mst.onmute = function onmute() {
- if(that.onmute && typeof that.onmute === 'function') {
+ if(that.onmute && typeof that.onmute == 'function') {
that.onmute.apply(that, []);
}
};
-
+
this._mst.onunmute = function onunmute() {
- if(that.onunmute && typeof that.onunmute === 'function') {
+ if(that.onunmute && typeof that.onunmute == 'function') {
that.onunmute.apply(that, []);
}
};
-
+
this._mst.onstarted = function onstarted() {
- if(that.onstarted && typeof that.onstarted === 'function') {
+ if(that.onstarted && typeof that.onstarted == 'function') {
that.onstarted.apply(that, []);
}
};
-
+
this._mst.onended = function onended() {
- if(that.onended && typeof that.onended === 'function') {
+ if(that.onended && typeof that.onended == 'function') {
that.onended.apply(that, []);
}
};
@@ -39,17 +38,15 @@ function MediaStreamTrack(internalMST) {
module.exports = MediaStreamTrack;
MediaStreamTrack.prototype._getMST = function _getMST() {
- 'use strict';
if(!this._mst) {
throw new Error('RTCMediaSteamTrack is gone');
}
return this._mst;
};
MediaStreamTrack.prototype._queueOrRun = function _queueOrRun(obj) {
- 'use strict';
var mst = this._getMST();
- if(null === this._pending) {
+ if(null == this._pending) {
mst[obj.func].apply(mst, obj.args);
if(obj.wait) {
this._pending = obj;
@@ -60,7 +57,6 @@ MediaStreamTrack.prototype._queueOrRun = function _queueOrRun(obj) {
};
MediaStreamTrack.prototype._executeNext = function _executeNext() {
- 'use strict';
var obj, mst;
mst = this._getMST();
if(this._queue.length > 0) {
@@ -85,47 +81,38 @@ MediaStreamTrack.prototype.RTCMediaStreamTrackStates = [
];
MediaStreamTrack.prototype.getId = function getId() {
- 'use strict';
return this._getMST().id;
};
MediaStreamTrack.prototype.getKind = function getKind() {
- 'use strict';
return this._getMST().kind;
};
MediaStreamTrack.prototype.getLabel = function getLabel() {
- 'use strict';
return this._getMST().label;
};
MediaStreamTrack.prototype.getEnabled = function getEnabled() {
- 'use strict';
return this._getMST().enabled;
};
MediaStreamTrack.prototype.setEnabled = function setEnabled(enable) {
- 'use strict';
this._getMST().enabled = enable;
};
MediaStreamTrack.prototype.getMuted = function getMuted() {
- 'use strict';
return this._getMST().muted;
};
MediaStreamTrack.prototype.getReadOnly = function getReadOnly() {
- 'use strict';
return this._getMST()._readonly;
};
MediaStreamTrack.prototype.getRemote = function getRemote() {
- 'use strict';
return this._getMST().remote;
};
MediaStreamTrack.prototype.getReadyState = function getReadyState() {
- 'use strict';
var state = this._getMST().readyState;
return this.RTCMediaStreamTrackStates[state];
};
@@ -141,53 +128,44 @@ MediaStreamTrack.prototype.getReadyState = function getReadyState() {
};*/
MediaStreamTrack.prototype.getOnStarted = function() {
- 'use strict';
return this.onstarted;
};
MediaStreamTrack.prototype.setOnStarted = function(cb) {
- 'use strict';
// FIXME: throw an exception if cb isn't callable
this.onstarted = cb;
};
MediaStreamTrack.prototype.getOnEnded = function() {
- 'use strict';
return this.onended;
};
MediaStreamTrack.prototype.setOnEnded = function(cb) {
- 'use strict';
// FIXME: throw an exception if cb isn't callable
this.onended = cb;
};
MediaStreamTrack.prototype.getOnMute = function() {
- 'use strict';
return this.onmute;
};
MediaStreamTrack.prototype.setOnMute = function(cb) {
- 'use strict';
// FIXME: throw an exception if cb isn't callable
this.onmute = cb;
};
MediaStreamTrack.prototype.getOnUnmute = function() {
- 'use strict';
return this.onunmute;
};
MediaStreamTrack.prototype.setOnUnmute = function(cb) {
- 'use strict';
// FIXME: throw an exception if cb isn't callable
this.onunmute = cb;
};
function RTCMediaStreamTrack(internalMST) {
- 'use strict';
var mst = new MediaStreamTrack(internalMST);
-
+
Object.defineProperties(this, {
'id': {
get: function getId() {
@@ -265,7 +243,7 @@ function RTCMediaStreamTrack(internalMST) {
}
}
});
-
+
// FIXME: implement stop
/*this.stop = function stop() {
return mst.stop.apply(mst, arguments);
@@ -277,4 +255,4 @@ function RTCMediaStreamTrack(internalMST) {
};*/
}
-module.exports = RTCMediaStreamTrack;
+module.exports = RTCMediaStreamTrack;
View
81 lib/peerconnection.js
@@ -2,16 +2,14 @@ var _webrtc = require('bindings')('webrtc.node');
var RTCSessionDescription = require('./sessiondescription');
var RTCIceCandidate = require('./icecandidate');
+var RTCError = require('./error');
var RTCDataChannel = require('./datachannel');
var RTCMediaStream = require('./mediastream');
var RTCIceCandidateEvent = require('./icecandidateevent');
function PeerConnection(configuration, constraints) {
- 'use strict';
var that = this;
-
- this.stateString = '';
this._pc = new _webrtc.PeerConnection(configuration, constraints);
this._localType = null;
@@ -37,7 +35,7 @@ function PeerConnection(configuration, constraints) {
};
this._pc.onicecandidate = function onicecandidate(candidate, sdpMid, sdpMLineIndex) {
- if(that.onicecandidate && typeof that.onicecandidate === 'function') {
+ if(that.onicecandidate && typeof that.onicecandidate == 'function') {
var icecandidate = new RTCIceCandidate({
'candidate': candidate,
'sdpMid': sdpMid,
@@ -48,49 +46,49 @@ function PeerConnection(configuration, constraints) {
};
this._pc.onsignalingstatechange = function onsignalingstatechange(state) {
- that.stateString = that.RTCSignalingStates[state];
- if('closed' === that.stateString) {
+ stateString = that.RTCSignalingStates[state];
+ if('closed' == stateString) {
Object.keys(that._dataChannels).forEach(function(label) {
that._dataChannels[label].shutdown();
delete that._dataChannels[label];
});
}
- if(that.onsignalingstatechange && typeof that.onsignalingstatechange === 'function') {
- that.onsignalingstatechange.apply(that, [that.stateString]);
+ if(that.onsignalingstatechange && typeof that.onsignalingstatechange == 'function') {
+ that.onsignalingstatechange.apply(that, [stateString]);
}
};
this._pc.oniceconnectionstatechange = function oniceconnectionstatechange(state) {
- if(that.oniceconnectionstatechange && typeof that.oniceconnectionstatechange === 'function') {
- that.stateString = that.RTCSignalingStates[state];
- that.oniceconnectionstatechange.apply(that, [that.stateString]);
+ if(that.oniceconnectionstatechange && typeof that.oniceconnectionstatechange == 'function') {
+ stateString = that.RTCSignalingStates[state];
+ that.oniceconnectionstatechange.apply(that, [stateString]);
}
};
this._pc.onicegatheringstatechange = function onicegatheringstatechange(state) {
- if(that.onicegatheringstatechange && typeof that.onicegatheringstatechange === 'function') {
- that.stateString = that.RTCSignalingStates[state];
- that.onicegatheringstatechange.apply(that, [that.stateString]);
+ if(that.onicegatheringstatechange && typeof that.onicegatheringstatechange == 'function') {
+ stateString = that.RTCSignalingStates[state];
+ that.onicegatheringstatechange.apply(that, [stateString]);
}
};
this._pc.ondatachannel = function ondatachannel(internalDC) {
- if(that.ondatachannel && typeof that.ondatachannel === 'function') {
+ if(that.ondatachannel && typeof that.ondatachannel == 'function') {
that._dataChannels[internalDC.label] = internalDC;
var dc = new RTCDataChannel(internalDC);
that.ondatachannel.apply(that, [dc]);
}
};
this._pc.onaddstream = function onaddstream(internalMS) {
- if(that.onaddstream && typeof that.onaddstream === 'function') {
+ if(that.onaddstream && typeof that.onaddstream == 'function') {
var ms = new RTCMediaStream(internalMS);
that.onaddstream.apply(that, [ms]);
}
};
this._pc.onremovestream = function onremovestream(internalMS) {
- if(that.onremovestream && typeof that.onremovestream === 'function') {
+ if(that.onremovestream && typeof that.onremovestream == 'function') {
var ms = new RTCMediaStream(internalMS);
that.onremovestream.apply(that, [ms]);
}
@@ -103,7 +101,7 @@ function PeerConnection(configuration, constraints) {
this.ondatachannel = null;
this.onaddstream = null;
this.onremovestream = null;
-}
+};
PeerConnection.prototype.RTCSignalingStates = [
'stable',
@@ -131,32 +129,28 @@ PeerConnection.prototype.RTCIceGatheringStates = [
];
PeerConnection.prototype._getPC = function _getPC() {
- 'use strict';
if(!this._pc) {
throw new Error('RTCPeerConnection is gone');
}
return this._pc;
};
PeerConnection.prototype._checkClosed = function _checkClosed() {
- 'use strict';
if(this._closed) {
throw new Error('Peer is closed');
}
};
PeerConnection.prototype._runImmediately = function _runImmediately(obj) {
- 'use strict';
var pc = this._getPC();
this._checkClosed();
return pc[obj.func].apply(pc, obj.args);
-};
+}
PeerConnection.prototype._queueOrRun = function _queueOrRun(obj) {
- 'use strict';
var pc = this._getPC();
this._checkClosed();
- if(null === this._pending) {
+ if(null == this._pending) {
pc[obj.func].apply(pc, obj.args);
if(obj.wait) {
this._pending = obj;
@@ -167,7 +161,6 @@ PeerConnection.prototype._queueOrRun = function _queueOrRun(obj) {
};
PeerConnection.prototype._executeNext = function _executeNext() {
- 'use strict';
var obj, pc;
pc = this._getPC();
if(this._queue.length > 0) {
@@ -185,7 +178,6 @@ PeerConnection.prototype._executeNext = function _executeNext() {
};
PeerConnection.prototype.getLocalDescription = function getLocalDescription() {
- 'use strict';
var sdp = this._getPC().localDescription;
if(!sdp) {
return null;
@@ -195,7 +187,6 @@ PeerConnection.prototype.getLocalDescription = function getLocalDescription() {
};
PeerConnection.prototype.getRemoteDescription = function getRemoteDescription() {
- 'use strict';
var sdp = this._getPC().remoteDescription;
if(!sdp) {
return null;
@@ -205,105 +196,86 @@ PeerConnection.prototype.getRemoteDescription = function getRemoteDescription()
};
PeerConnection.prototype.getSignalingState = function getSignalingState() {
- 'use strict';
var state = this._getPC().signalingState;
return this.RTCSignalingStates[state];
};
PeerConnection.prototype.getIceGatheringState = function getIceGatheringState() {
- 'use strict';
var state = this._getPC().iceGatheringState;
return this.RTCIceGatheringStates[state];
};
PeerConnection.prototype.getIceConnectionState = function getIceConnectionState() {
- 'use strict';
var state = this._getPC().iceConnectionState;
return this.RTCIceConnectionStates[state];
};
PeerConnection.prototype.getLocalStreams = function getLocalStreams() {
- 'use strict';
return this._getPC().getLocalStreams();
};
PeerConnection.prototype.getRemoteStreams = function getRemoteStreams() {
- 'use strict';
return this._getPC().getRemoteStreams();
};
PeerConnection.prototype.getStreamById = function getStreamById(id) {
- 'use strict';
return this._getPC().getStreamById(id);
};
PeerConnection.prototype.getOnSignalingStateChange = function() {
- 'use strict';
return this.onsignalingstatechange;
};
PeerConnection.prototype.setOnSignalingStateChange = function(cb) {
- 'use strict';
// FIXME: throw an exception if cb isn't callable
this.onsignalingstatechange = cb;
};
PeerConnection.prototype.getIceConnectionStateChange = function() {
- 'use strict';
return this.oniceconnectionstatechange;
};
PeerConnection.prototype.setOnIceConnectionStateChange = function(cb) {
- 'use strict';
this.oniceconnectionstatechange = cb;
};
PeerConnection.prototype.getOnIceCandidate = function() {
- 'use strict';
return this.onicecandidate;
};
PeerConnection.prototype.setOnIceCandidate = function(cb) {
- 'use strict';
// FIXME: throw an exception if cb isn't callable
this.onicecandidate = cb;
};
PeerConnection.prototype.getOnDataChannel = function() {
- 'use strict';
return this.ondatachannel;
};
PeerConnection.prototype.setOnDataChannel = function(cb) {
- 'use strict';
// FIXME: throw an exception if cb isn't callable
this.ondatachannel = cb;
};
PeerConnection.prototype.getOnAddStream = function() {
- 'use strict';
return this.onaddstream;
};
PeerConnection.prototype.setOnAddStream = function(cb) {
- 'use strict';
// FIXME: throw an exception if cb isn't callable
this.onaddstream = cb;
};
PeerConnection.prototype.getOnRemoveStream = function() {
- 'use strict';
return this.onremovestream;
};
PeerConnection.prototype.setOnRemoveStream = function(cb) {
- 'use strict';
// FIXME: throw an exception if cb isn't callable
this.onremovestream = cb;
};
PeerConnection.prototype.createOffer = function createOffer(onSuccess, onError, constraints) {
- 'use strict';
constraints = constraints || {};
// FIXME: complain if onError is undefined
this._queueOrRun({
@@ -318,7 +290,6 @@ PeerConnection.prototype.createOffer = function createOffer(onSuccess, onError,
};
PeerConnection.prototype.createAnswer = function createAnswer(onSuccess, onError, constraints) {
- 'use strict';
constraints = constraints || {};
// FIXME: complain if onError is undefined
this._queueOrRun({
@@ -333,7 +304,6 @@ PeerConnection.prototype.createAnswer = function createAnswer(onSuccess, onError
};
PeerConnection.prototype.setLocalDescription = function setLocalDescription(sdp, onSuccess, onError) {
- 'use strict';
sdp = sdp || {};
this._localType = sdp.type;
this._queueOrRun({
@@ -346,7 +316,6 @@ PeerConnection.prototype.setLocalDescription = function setLocalDescription(sdp,
};
PeerConnection.prototype.setRemoteDescription = function setRemoteDescription(sdp, onSuccess, onError) {
- 'use strict';
sdp = sdp || {};
this._remoteType = sdp.type;
this._queueOrRun({
@@ -359,7 +328,6 @@ PeerConnection.prototype.setRemoteDescription = function setRemoteDescription(sd
};
PeerConnection.prototype.addIceCandidate = function addIceCandidate(sdp, onSuccess, onError) {
- 'use strict';
sdp = sdp || {};
this._queueOrRun({
func: 'addIceCandidate',
@@ -371,7 +339,6 @@ PeerConnection.prototype.addIceCandidate = function addIceCandidate(sdp, onSucce
};
PeerConnection.prototype.createDataChannel = function createDataChannel(label, dataChannelDict) {
- 'use strict';
dataChannelDict = dataChannelDict || {};
var channel = this._runImmediately({
func: 'createDataChannel',
@@ -382,7 +349,6 @@ PeerConnection.prototype.createDataChannel = function createDataChannel(label, d
};
PeerConnection.prototype.addStream = function addStream(stream, constraintsDict) {
- 'use strict';
constraintsDict = constraintsDict || {};
this._queueOrRun({
func: 'addStream',
@@ -391,22 +357,19 @@ PeerConnection.prototype.addStream = function addStream(stream, constraintsDict)
};
PeerConnection.prototype.removeStream = function removeStream(stream) {
- 'use strict';
this._queueOrRun({
func: 'removeStream',
args: [stream._getMS()]
});
};
PeerConnection.prototype.close = function close() {
- 'use strict';
return this._runImmediately({
func: 'close',
args: []
});
-};
+}
function RTCPeerConnection(configuration, constraints) {
- 'use strict';
var pc = new PeerConnection(configuration, constraints);
Object.defineProperties(this, {
@@ -535,7 +498,7 @@ function RTCPeerConnection(configuration, constraints) {
};
this.close = function close() {
return pc.close.apply(pc, arguments);
- };
-}
+ }
+};
-module.exports = RTCPeerConnection;
+module.exports = RTCPeerConnection;
View
5 lib/sessiondescription.js
@@ -1,7 +1,6 @@
function RTCSessionDescription(dict) {
- 'use strict';
this.type = dict.type;
this.sdp = dict.sdp;
-}
+};
-module.exports = RTCSessionDescription;
+module.exports = RTCSessionDescription;
View
296 test/connect.js
@@ -1,179 +1,175 @@
-(function() {
- 'use strict';
-
- var test = require('tape');
- // var detect = require('rtc-core/detect');
- // var RTCPeerConnection = detect('RTCPeerConnection');
- var RTCPeerConnection = require('../lib/peerconnection');
- var RTCIceCandidate = require('../lib/icecandidate');
- var captureCandidates = require('./helpers/capture-candidates');
- var peers = [];
- var candidates = [ [], [] ];
- //var dcs = [];
- var localDesc;
-
- test('create the peer connections', function(t) {
- t.plan(2);
- peers = [
- new RTCPeerConnection({ iceServers: [] }),
- new RTCPeerConnection({ iceServers: [] })
- ];
-
- t.ok(peers[0] instanceof RTCPeerConnection, 'peer:0 created ok');
- t.ok(peers[1] instanceof RTCPeerConnection, 'peer:1 created ok');
+var test = require('tape');
+// var detect = require('rtc-core/detect');
+// var RTCPeerConnection = detect('RTCPeerConnection');
+var RTCPeerConnection = require('../lib/peerconnection');
+var RTCIceCandidate = require('../lib/icecandidate');
+var captureCandidates = require('./helpers/capture-candidates');
+var peers = [];
+var candidates = [ [], [] ];
+var dcs = [];
+var localDesc;
+
+test('create the peer connections', function(t) {
+ t.plan(2);
+ peers = [
+ new RTCPeerConnection({ iceServers: [] }),
+ new RTCPeerConnection({ iceServers: [] })
+ ];
+
+ t.ok(peers[0] instanceof RTCPeerConnection, 'peer:0 created ok');
+ t.ok(peers[1] instanceof RTCPeerConnection, 'peer:1 created ok');
+});
+
+test('peers are created and in the expected connection state', function(t) {
+ t.plan(2);
+ t.equal(peers[0].iceConnectionState, 'new');
+ t.equal(peers[1].iceConnectionState, 'new');
+});
+
+// test('create a datachannel on peer:0', function(t) {
+// t.plan(2);
+// t.ok(dcs[0] = peers[0].createDataChannel('test'));
+// t.equal(dcs[0].label, 'test', 'created with correct label');
+// });
+
+test('createOffer for peer:0', function(t) {
+
+ var fail = t.ifError.bind(t);
+
+ function pass(desc) {
+ // save the local description
+ localDesc = desc;
+
+ // run the checks
+ t.ok(desc, 'createOffer succeeded');
+ t.equal(desc.type, 'offer', 'type === offer');
+ t.ok(desc.sdp, 'got sdp');
+ }
+
+ t.plan(3);
+ peers[0].createOffer(pass, fail);
+});
+
+test('setLocalDescription for peer:0', function(t) {
+ var fail = t.ifError.bind(t);
+ var pass = t.pass.bind(t, 'ok');
+
+ t.plan(1);
+ peers[0].setLocalDescription(localDesc, pass, fail);
+});
+
+test('capture ice candidates for peer:0', function(t) {
+ t.plan(1);
+ captureCandidates(peers[0], candidates[0], function() {
+ t.ok(candidates[0].length > 0, 'have candidates for peer:0');
});
+});
- test('peers are created and in the expected connection state', function(t) {
- t.plan(2);
- t.equal(peers[0].iceConnectionState, 'new');
- t.equal(peers[1].iceConnectionState, 'new');
- });
-
- // test('create a datachannel on peer:0', function(t) {
- // t.plan(2);
- // t.ok(dcs[0] = peers[0].createDataChannel('test'));
- // t.equal(dcs[0].label, 'test', 'created with correct label');
- // });
-
- test('createOffer for peer:0', function(t) {
+test('setRemoteDescription for peer:1', function(t) {
+ var fail = t.ifError.bind(t);
+ var pass = t.pass.bind(t, 'ok');
- var fail = t.ifError.bind(t);
+ t.plan(1);
+ peers[1].setRemoteDescription(peers[0].localDescription, pass, fail);
+});
- function pass(desc) {
- // save the local description
- localDesc = desc;
+test('provide peer:1 with the peer:0 gathered ice candidates', function(t) {
+ t.plan(candidates[0].length);
- // run the checks
- t.ok(desc, 'createOffer succeeded');
- t.equal(desc.type, 'offer', 'type === offer');
- t.ok(desc.sdp, 'got sdp');
- }
-
- t.plan(3);
- peers[0].createOffer(pass, fail);
+ candidates[0].forEach(function(candidate) {
+ peers[1].addIceCandidate(
+ new RTCIceCandidate(candidate),
+ t.pass.bind(t, 'added candidate'),
+ t.ifError.bind(t)
+ );
});
+});
- test('setLocalDescription for peer:0', function(t) {
- var fail = t.ifError.bind(t);
- var pass = t.pass.bind(t, 'ok');
+test('createAnswer for peer:1', function(t) {
+ var fail = t.ifError.bind(t);
- t.plan(1);
- peers[0].setLocalDescription(localDesc, pass, fail);
- });
+ function pass(desc) {
+ // save the local description
+ localDesc = desc;
- test('capture ice candidates for peer:0', function(t) {
- t.plan(1);
- captureCandidates(peers[0], candidates[0], function() {
- t.ok(candidates[0].length > 0, 'have candidates for peer:0');
- });
- });
+ // run the checks
+ t.ok(desc, 'createOffer succeeded');
+ t.equal(desc.type, 'answer', 'type === answer');
+ t.ok(desc.sdp, 'got sdp');
+ }
- test('setRemoteDescription for peer:1', function(t) {
- var fail = t.ifError.bind(t);
- var pass = t.pass.bind(t, 'ok');
+ t.plan(3);
+ peers[1].createAnswer(pass, fail);
+});
- t.plan(1);
- peers[1].setRemoteDescription(peers[0].localDescription, pass, fail);
- });
+test('setLocalDescription for peer:1', function(t) {
+ var fail = t.ifError.bind(t);
+ var pass = t.pass.bind(t, 'ok');
- test('provide peer:1 with the peer:0 gathered ice candidates', function(t) {
- t.plan(candidates[0].length);
+ t.plan(1);
+ peers[1].setLocalDescription(localDesc, pass, fail);
+});
- candidates[0].forEach(function(candidate) {
- peers[1].addIceCandidate(
- new RTCIceCandidate(candidate),
- t.pass.bind(t, 'added candidate'),
- t.ifError.bind(t)
- );
- });
+test('capture ice candidates for peer:1', function(t) {
+ t.plan(1);
+ captureCandidates(peers[1], candidates[1], function() {
+ t.ok(candidates[1].length > 0, 'have candidates for peer:1');
});
+});
- test('createAnswer for peer:1', function(t) {
- var fail = t.ifError.bind(t);
+test('setRemoteDescription for peer:0', function(t) {
+ var fail = t.ifError.bind(t);
+ var pass = t.pass.bind(t, 'ok');
- function pass(desc) {
- // save the local description
- localDesc = desc;
+ t.plan(1);
+ peers[0].setRemoteDescription(peers[1].localDescription, pass, fail);
+});
- // run the checks
- t.ok(desc, 'createOffer succeeded');
- t.equal(desc.type, 'answer', 'type === answer');
- t.ok(desc.sdp, 'got sdp');
- }
+test('provide peer:0 with the peer:1 gathered ice candidates', function(t) {
+ t.plan(candidates[1].length);
- t.plan(3);
- peers[1].createAnswer(pass, fail);
+ candidates[1].forEach(function(candidate) {
+ peers[0].addIceCandidate(
+ new RTCIceCandidate(candidate),
+ t.pass.bind(t, 'added candidate'),
+ t.ifError.bind(t)
+ );
});
+});
- test('setLocalDescription for peer:1', function(t) {
- var fail = t.ifError.bind(t);
- var pass = t.pass.bind(t, 'ok');
+test('monitor the ice connection state of peer:0', function(t) {
+ t.plan(1);
- t.plan(1);
- peers[1].setLocalDescription(localDesc, pass, fail);
- });
-
- test('capture ice candidates for peer:1', function(t) {
- t.plan(1);
- captureCandidates(peers[1], candidates[1], function() {
- t.ok(candidates[1].length > 0, 'have candidates for peer:1');
- });
- });
-
- test('setRemoteDescription for peer:0', function(t) {
- var fail = t.ifError.bind(t);
- var pass = t.pass.bind(t, 'ok');
-
- t.plan(1);
- peers[0].setRemoteDescription(peers[1].localDescription, pass, fail);
- });
-
- test('provide peer:0 with the peer:1 gathered ice candidates', function(t) {
- t.plan(candidates[1].length);
-
- candidates[1].forEach(function(candidate) {
- peers[0].addIceCandidate(
- new RTCIceCandidate(candidate),
- t.pass.bind(t, 'added candidate'),
- t.ifError.bind(t)
- );
- });
- });
-
- test('monitor the ice connection state of peer:0', function(t) {
- t.plan(1);
-
- function checkState() {
- if (peers[0].iceConnectionState === 'connected') {
- t.pass('peer:0 in connected state');
- peers[0].oniceconnectionstatechange = null;
- }
+ function checkState() {
+ if (peers[0].iceConnectionState === 'connected') {
+ t.pass('peer:0 in connected state');
+ peers[0].oniceconnectionstatechange = null;
}
+ }
- peers[0].oniceconnectionstatechange = checkState;
- checkState();
- });
+ peers[0].oniceconnectionstatechange = checkState;
+ checkState();
+});
- test('monitor the ice connection state of peer:1', function(t) {
- t.plan(1);
+test('monitor the ice connection state of peer:1', function(t) {
+ t.plan(1);
- function checkState() {
- if (peers[1].iceConnectionState === 'connected') {
- t.pass('peer:1 in connected state');
- peers[1].oniceconnectionstatechange = null;
- }
+ function checkState() {
+ if (peers[1].iceConnectionState === 'connected') {
+ t.pass('peer:1 in connected state');
+ peers[1].oniceconnectionstatechange = null;
}
+ }
- peers[1].oniceconnectionstatechange = checkState;
- checkState();
- });
+ peers[1].oniceconnectionstatechange = checkState;
+ checkState();
+});
- test('close the connections', function(t) {
- t.plan(1);
- peers[0].close();
- peers[1].close();
- t.pass('closed connections');
+test('close the connections', function(t) {
+ t.plan(1);
+ peers[0].close();
+ peers[1].close();
+ t.pass('closed connections');
- peers = [];
- });
-})();
+ peers = [];
+});
View
116 test/create-offer.js
@@ -1,60 +1,56 @@
-(function() {
- 'use strict';
-
- var test = require('tape');
- var RTCPeerConnection = require('../lib/peerconnection');
- var peer;
- var localDesc;
-
- test('create a peer connection', function(t) {
- t.plan(1);
- peer = new RTCPeerConnection({ iceServers: [] });
- t.ok(peer instanceof RTCPeerConnection, 'created');
- });
-
- test('createOffer function implemented', function(t) {
- t.plan(1);
- t.equal(typeof peer.createOffer, 'function', 'implemented');
- });
-
- test('can call createOffer', function(t) {
-
- var fail = t.ifError.bind(t);
-
- function pass(desc) {
- // save the local description
- localDesc = desc;
-
- // run the checks
- t.ok(desc, 'createOffer succeeded');
- t.equal(desc.type, 'offer', 'type === offer');
- t.ok(desc.sdp, 'got sdp');
- }
-
- t.plan(3);
- peer.createOffer(pass, fail);
- });
-
- test('setLocalDescription function implemented', function(t) {
- t.plan(1);
- t.equal(typeof peer.setLocalDescription, 'function', 'implemented');
- });
-
- test('can call setLocalDescription', function(t) {
- var fail = t.ifError.bind(t);
-
- function pass() {
- t.ok(peer.localDescription, 'local description set');
- t.ok(peer.localDescription.sdp, 'we have local sdp');
- }
-
- t.plan(2);
- peer.setLocalDescription(localDesc, pass, fail);
- });
-
- test('TODO: cleanup connection', function(t) {
- t.plan(1);
- peer.close();
- t.pass('connection closed');
- });
-})();
+var test = require('tape');
+var RTCPeerConnection = require('../lib/peerconnection');
+var peer;
+var localDesc;
+
+test('create a peer connection', function(t) {
+ t.plan(1);
+ peer = new RTCPeerConnection({ iceServers: [] });
+ t.ok(peer instanceof RTCPeerConnection, 'created');
+});
+
+test('createOffer function implemented', function(t) {
+ t.plan(1);
+ t.equal(typeof peer.createOffer, 'function', 'implemented');
+});
+
+test('can call createOffer', function(t) {
+
+ var fail = t.ifError.bind(t);
+
+ function pass(desc) {
+ // save the local description
+ localDesc = desc;
+
+ // run the checks
+ t.ok(desc, 'createOffer succeeded');
+ t.equal(desc.type, 'offer', 'type === offer');
+ t.ok(desc.sdp, 'got sdp');
+ }
+
+ t.plan(3);
+ peer.createOffer(pass, fail);
+});
+
+test('setLocalDescription function implemented', function(t) {
+ t.plan(1);
+ t.equal(typeof peer.setLocalDescription, 'function', 'implemented');
+});
+
+test('can call setLocalDescription', function(t) {
+ var fail = t.ifError.bind(t);
+
+ function pass() {
+ t.ok(peer.localDescription, 'local description set');
+ t.ok(peer.localDescription.sdp, 'we have local sdp');
+ }
+
+ t.plan(2);
+ peer.setLocalDescription(localDesc, pass, fail);
+});
+
+test('TODO: cleanup connection', function(t) {
+ t.plan(1);
+ peer.close();
+ t.pass('connection closed');
+});
View
106 test/sessiondesc.js
@@ -1,55 +1,51 @@
-(function() {
- 'use strict';
-
- var test = require('tape');
- var RTCPeerConnection = require('../lib/peerconnection');
- var RTCSessionDescription = require('../lib/sessiondescription');
- var peer;
- var localDesc;
-
- test('create a peer connection', function(t) {
- t.plan(1);
- peer = new RTCPeerConnection({ iceServers: [] });
- t.ok(peer instanceof RTCPeerConnection, 'created');
- });
-
- test('createOffer', function(t) {
-
- var fail = t.ifError.bind(t);
-
- function pass(desc) {
- // save the local description
- localDesc = desc;
-
- // run the checks
- t.ok(desc, 'createOffer succeeded');
- t.equal(desc.type, 'offer', 'type === offer');
- t.ok(desc.sdp, 'got sdp');
- }
-
- t.plan(3);
- peer.createOffer(pass, fail);
- });
-
- test('setLocalDescription with a created RTCSessionDescription', function(t) {
- var fail = t.ifError.bind(t);
-
- function pass() {
- t.ok(peer.localDescription, 'local description set');
- t.ok(peer.localDescription.sdp, 'we have local sdp');
- }
-
- t.plan(2);
- peer.setLocalDescription(
- new RTCSessionDescription({ sdp: localDesc.sdp, type: 'offer' }),
- pass,
- fail
- );
- });
-
- test('TODO: cleanup connection', function(t) {
- t.plan(1);
- peer.close();
- t.pass('connection closed');
- });
-})();
+var test = require('tape');
+var RTCPeerConnection = require('../lib/peerconnection');
+var RTCSessionDescription = require('../lib/sessiondescription');
+var peer;
+var localDesc;
+
+test('create a peer connection', function(t) {
+ t.plan(1);
+ peer = new RTCPeerConnection({ iceServers: [] });
+ t.ok(peer instanceof RTCPeerConnection, 'created');
+});
+
+test('createOffer', function(t) {
+
+ var fail = t.ifError.bind(t);
+
+ function pass(desc) {
+ // save the local description
+ localDesc = desc;
+
+ // run the checks
+ t.ok(desc, 'createOffer succeeded');
+ t.equal(desc.type, 'offer', 'type === offer');
+ t.ok(desc.sdp, 'got sdp');
+ }
+
+ t.plan(3);
+ peer.createOffer(pass, fail);
+});
+
+test('setLocalDescription with a created RTCSessionDescription', function(t) {
+ var fail = t.ifError.bind(t);
+
+ function pass() {
+ t.ok(peer.localDescription, 'local description set');
+ t.ok(peer.localDescription.sdp, 'we have local sdp');
+ }
+
+ t.plan(2);
+ peer.setLocalDescription(
+ new RTCSessionDescription({ sdp: localDesc.sdp, type: 'offer' }),
+ pass,
+ fail
+ );
+});
+
+test('TODO: cleanup connection', function(t) {
+ t.plan(1);
+ peer.close();
+ t.pass('connection closed');
+});

0 comments on commit 4be1c74

Please sign in to comment.