|
@@ -1,10 +1,11 @@
|
|
/**
|
|
/**
|
|
* Wraps a DataChannel between two Peers.
|
|
* Wraps a DataChannel between two Peers.
|
|
*/
|
|
*/
|
|
-function DataConnection(peer, dc, options) {
|
|
|
|
- if (!(this instanceof DataConnection)) return new DataConnection(peer, dc, options);
|
|
|
|
|
|
+function DataConnection(peer, options) {
|
|
|
|
+ if (!(this instanceof DataConnection)) return new DataConnection(peer, options);
|
|
EventEmitter.call(this);
|
|
EventEmitter.call(this);
|
|
|
|
|
|
|
|
+ // TODO: perhaps default serialization should be binary-utf8?
|
|
options = util.extend({
|
|
options = util.extend({
|
|
serialization: 'binary'
|
|
serialization: 'binary'
|
|
}, options);
|
|
}, options);
|
|
@@ -18,17 +19,18 @@ function DataConnection(peer, dc, options) {
|
|
this.peer = peer;
|
|
this.peer = peer;
|
|
this.reliable = options.reliable;
|
|
this.reliable = options.reliable;
|
|
|
|
|
|
- this._dc = dc;
|
|
|
|
|
|
+ /*this._dc = dc;
|
|
if (this._dc) {
|
|
if (this._dc) {
|
|
this._configureDataChannel();
|
|
this._configureDataChannel();
|
|
- }
|
|
|
|
|
|
+ }*/
|
|
};
|
|
};
|
|
|
|
|
|
util.inherits(DataConnection, EventEmitter);
|
|
util.inherits(DataConnection, EventEmitter);
|
|
|
|
|
|
DataConnection.prototype._configureDataChannel = function() {
|
|
DataConnection.prototype._configureDataChannel = function() {
|
|
var self = this;
|
|
var self = this;
|
|
- if (util.browserisms !== 'Webkit') {
|
|
|
|
|
|
+ // TODO: util.supports.binary
|
|
|
|
+ if (util.supports.binary) {
|
|
// Webkit doesn't support binary yet
|
|
// Webkit doesn't support binary yet
|
|
this._dc.binaryType = 'arraybuffer';
|
|
this._dc.binaryType = 'arraybuffer';
|
|
}
|
|
}
|
|
@@ -39,7 +41,8 @@ DataConnection.prototype._configureDataChannel = function() {
|
|
};
|
|
};
|
|
|
|
|
|
// Use the Reliable shim for non Firefox browsers
|
|
// Use the Reliable shim for non Firefox browsers
|
|
- if (this.reliable && util.browserisms !== 'Firefox') {
|
|
|
|
|
|
+ // TODO: util.supports.reliable
|
|
|
|
+ if (!util.supports.reliable) {
|
|
this._reliable = new Reliable(this._dc, util.debug);
|
|
this._reliable = new Reliable(this._dc, util.debug);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -132,7 +135,7 @@ DataConnection.prototype.send = function(data) {
|
|
var utf8 = (this.serialization === 'binary-utf8');
|
|
var utf8 = (this.serialization === 'binary-utf8');
|
|
var blob = util.pack(data, utf8);
|
|
var blob = util.pack(data, utf8);
|
|
// DataChannel currently only supports strings.
|
|
// DataChannel currently only supports strings.
|
|
- if (util.browserisms === 'Webkit') {
|
|
|
|
|
|
+ if (!util.supports.binary) {
|
|
util.blobToBinaryString(blob, function(str){
|
|
util.blobToBinaryString(blob, function(str){
|
|
self._dc.send(str);
|
|
self._dc.send(str);
|
|
});
|
|
});
|