|
@@ -12,7 +12,7 @@ function DataConnection(id, peer, socket, cb, options) {
|
|
|
|
|
|
this._id = id;
|
|
|
this._peer = peer;
|
|
|
- this._originator = (options.sdp == undefined);
|
|
|
+ this._originator = (options.sdp === undefined);
|
|
|
this._cb = cb;
|
|
|
|
|
|
this.metadata = options.metadata;
|
|
@@ -21,7 +21,7 @@ function DataConnection(id, peer, socket, cb, options) {
|
|
|
this._socket = socket;
|
|
|
|
|
|
// Firefoxism: connectDataConnection ports.
|
|
|
- if (browserisms == 'Firefox') {
|
|
|
+ if (util.browserisms === 'Firefox') {
|
|
|
this._firefoxPortSetup();
|
|
|
}
|
|
|
//
|
|
@@ -34,7 +34,7 @@ function DataConnection(id, peer, socket, cb, options) {
|
|
|
|
|
|
// Listen for negotiation needed
|
|
|
// ** Chrome only.
|
|
|
- if (browserisms === 'Webkit') {
|
|
|
+ if (util.browserisms === 'Webkit') {
|
|
|
this._setupOffer();
|
|
|
}
|
|
|
|
|
@@ -44,12 +44,12 @@ function DataConnection(id, peer, socket, cb, options) {
|
|
|
var self = this;
|
|
|
if (options.sdp) {
|
|
|
this.handleSDP({type: 'OFFER', sdp: options.sdp});
|
|
|
- if (browserisms !== 'Firefox') {
|
|
|
+ if (util.browserisms !== 'Firefox') {
|
|
|
this._makeAnswer();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if (browserisms === 'Firefox') {
|
|
|
+ if (util.browserisms === 'Firefox') {
|
|
|
this._firefoxAdditional();
|
|
|
}
|
|
|
};
|
|
@@ -83,14 +83,14 @@ DataConnection.prototype._setupDataChannel = function() {
|
|
|
|
|
|
DataConnection.prototype.handleSDP = function(message) {
|
|
|
var sdp = message.sdp;
|
|
|
- if (browserisms != 'Firefox') {
|
|
|
+ if (util.browserisms != 'Firefox') {
|
|
|
sdp = new RTCSessionDescription(sdp);
|
|
|
}
|
|
|
var self = this;
|
|
|
this._pc.setRemoteDescription(sdp, function() {
|
|
|
util.log('Set remoteDescription: ' + message.type);
|
|
|
// Firefoxism
|
|
|
- if (message.type == 'ANSWER' && browserisms == 'Firefox') {
|
|
|
+ if (message.type === 'ANSWER' && util.browserisms === 'Firefox') {
|
|
|
self._pc.connectDataConnection(self.localPort, self.remotePort);
|
|
|
self._socket.send(JSON.stringify({
|
|
|
type: 'PORT',
|
|
@@ -159,7 +159,7 @@ DataConnection.prototype._setupDataChannel = function() {
|
|
|
var self = this;
|
|
|
if (this._originator) {
|
|
|
|
|
|
- if (browserisms == 'Webkit') {
|
|
|
+ if (util.browserisms === 'Webkit') {
|
|
|
|
|
|
// TODO: figure out the right thing to do with this.
|
|
|
this._pc.onstatechange = function() {
|
|
@@ -197,7 +197,7 @@ DataConnection.prototype._firefoxPortSetup = function() {
|
|
|
this.localPort = util.randomPort();
|
|
|
}
|
|
|
this.remotePort = util.randomPort();
|
|
|
- while (this.remotePort == this.localPort ||
|
|
|
+ while (this.remotePort === this.localPort ||
|
|
|
DataConnection.usedPorts.indexOf(this.localPort) != -1) {
|
|
|
this.remotePort = util.randomPort();
|
|
|
}
|
|
@@ -208,7 +208,7 @@ DataConnection.prototype._firefoxPortSetup = function() {
|
|
|
DataConnection.prototype._configureDataChannel = function() {
|
|
|
var self = this;
|
|
|
|
|
|
- if (browserisms === 'Firefox') {
|
|
|
+ if (util.browserisms === 'Firefox') {
|
|
|
this._dc.binaryType = 'blob';
|
|
|
}
|
|
|
this._dc.onopen = function() {
|
|
@@ -308,7 +308,7 @@ DataConnection.prototype.close = function() {
|
|
|
DataConnection.prototype.send = function(data) {
|
|
|
var self = this;
|
|
|
var blob = BinaryPack.pack(data);
|
|
|
- if (browserisms == 'Webkit') {
|
|
|
+ if (util.browserisms === 'Webkit') {
|
|
|
util.blobToBinaryString(blob, function(str){
|
|
|
self._dc.send(str);
|
|
|
});
|
|
@@ -321,15 +321,15 @@ DataConnection.prototype.send = function(data) {
|
|
|
// Handles a DataChannel message.
|
|
|
DataConnection.prototype._handleDataMessage = function(e) {
|
|
|
var self = this;
|
|
|
- if (e.data.constructor == Blob) {
|
|
|
+ if (e.data.constructor === Blob) {
|
|
|
util.blobToArrayBuffer(e.data, function(ab) {
|
|
|
var data = BinaryPack.unpack(ab);
|
|
|
self.emit('data', data);
|
|
|
});
|
|
|
- } else if (e.data.constructor == ArrayBuffer) {
|
|
|
+ } else if (e.data.constructor === ArrayBuffer) {
|
|
|
var data = BinaryPack.unpack(e.data);
|
|
|
self.emit('data', data);
|
|
|
- } else if (e.data.constructor == String) {
|
|
|
+ } else if (e.data.constructor === String) {
|
|
|
var ab = util.binaryStringToArrayBuffer(e.data);
|
|
|
var data = BinaryPack.unpack(ab);
|
|
|
self.emit('data', data);
|