|
@@ -1121,8 +1121,8 @@ var util = {
|
|
var data = true;
|
|
var data = true;
|
|
var audioVideo = true;
|
|
var audioVideo = true;
|
|
|
|
|
|
- var binary = false;
|
|
|
|
- var reliable = false;
|
|
|
|
|
|
+ var binaryBlob = false;
|
|
|
|
+ var sctp = false;
|
|
var onnegotiationneeded = !!window.webkitRTCPeerConnection;
|
|
var onnegotiationneeded = !!window.webkitRTCPeerConnection;
|
|
|
|
|
|
var pc, dc;
|
|
var pc, dc;
|
|
@@ -1145,7 +1145,7 @@ var util = {
|
|
// Binary test
|
|
// Binary test
|
|
try {
|
|
try {
|
|
dc.binaryType = 'blob';
|
|
dc.binaryType = 'blob';
|
|
- binary = true;
|
|
|
|
|
|
+ binaryBlob = true;
|
|
} catch (e) {
|
|
} catch (e) {
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1155,7 +1155,7 @@ var util = {
|
|
var reliablePC = new RTCPeerConnection(defaultConfig, {});
|
|
var reliablePC = new RTCPeerConnection(defaultConfig, {});
|
|
try {
|
|
try {
|
|
var reliableDC = reliablePC.createDataChannel('_PEERJSRELIABLETEST', {});
|
|
var reliableDC = reliablePC.createDataChannel('_PEERJSRELIABLETEST', {});
|
|
- reliable = reliableDC.reliable;
|
|
|
|
|
|
+ sctp = reliableDC.reliable;
|
|
} catch (e) {
|
|
} catch (e) {
|
|
}
|
|
}
|
|
reliablePC.close();
|
|
reliablePC.close();
|
|
@@ -1192,8 +1192,10 @@ var util = {
|
|
return {
|
|
return {
|
|
audioVideo: audioVideo,
|
|
audioVideo: audioVideo,
|
|
data: data,
|
|
data: data,
|
|
- binary: binary,
|
|
|
|
- reliable: reliable,
|
|
|
|
|
|
+ binaryBlob: binaryBlob,
|
|
|
|
+ binary: sctp, // deprecated; sctp implies binary support.
|
|
|
|
+ reliable: sctp, // deprecated; sctp implies reliable data.
|
|
|
|
+ sctp: sctp,
|
|
onnegotiationneeded: onnegotiationneeded
|
|
onnegotiationneeded: onnegotiationneeded
|
|
};
|
|
};
|
|
}()),
|
|
}()),
|
|
@@ -1741,7 +1743,6 @@ DataConnection.prototype.initialize = function(dc) {
|
|
DataConnection.prototype._configureDataChannel = function() {
|
|
DataConnection.prototype._configureDataChannel = function() {
|
|
var self = this;
|
|
var self = this;
|
|
if (util.supports.binary) {
|
|
if (util.supports.binary) {
|
|
- // Webkit doesn't support binary yet
|
|
|
|
this._dc.binaryType = 'arraybuffer';
|
|
this._dc.binaryType = 'arraybuffer';
|
|
}
|
|
}
|
|
this._dc.onopen = function() {
|
|
this._dc.onopen = function() {
|
|
@@ -1751,7 +1752,7 @@ DataConnection.prototype._configureDataChannel = function() {
|
|
}
|
|
}
|
|
|
|
|
|
// Use the Reliable shim for non Firefox browsers
|
|
// Use the Reliable shim for non Firefox browsers
|
|
- if (!util.supports.reliable && this.reliable) {
|
|
|
|
|
|
+ if (!util.supports.sctp && this.reliable) {
|
|
this._reliable = new Reliable(this._dc, util.debug);
|
|
this._reliable = new Reliable(this._dc, util.debug);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1830,9 +1831,15 @@ DataConnection.prototype.send = function(data) {
|
|
var blob = util.pack(data, utf8);
|
|
var blob = util.pack(data, utf8);
|
|
// DataChannel currently only supports strings.
|
|
// DataChannel currently only supports strings.
|
|
if (!util.supports.binary) {
|
|
if (!util.supports.binary) {
|
|
- util.blobToBinaryString(blob, function(str){
|
|
|
|
|
|
+ util.blobToBinaryString(blob, function(str) {
|
|
self._dc.send(str);
|
|
self._dc.send(str);
|
|
});
|
|
});
|
|
|
|
+ } else if (!util.supports.binaryBlob) {
|
|
|
|
+ // We only do this if we really need to (e.g. blobs are not supported),
|
|
|
|
+ // because this conversion is costly.
|
|
|
|
+ util.blobToArrayBuffer(blob, function(ab) {
|
|
|
|
+ self._dc.send(ab);
|
|
|
|
+ });
|
|
} else {
|
|
} else {
|
|
this._dc.send(blob);
|
|
this._dc.send(blob);
|
|
}
|
|
}
|
|
@@ -1978,12 +1985,12 @@ Negotiator.startConnection = function(connection, options) {
|
|
var config = {};
|
|
var config = {};
|
|
// Dropping reliable:false support, since it seems to be crashing
|
|
// Dropping reliable:false support, since it seems to be crashing
|
|
// Chrome.
|
|
// Chrome.
|
|
- /*if (util.supports.reliable && !options.reliable) {
|
|
|
|
|
|
+ /*if (util.supports.sctp && !options.reliable) {
|
|
// If we have canonical reliable support...
|
|
// If we have canonical reliable support...
|
|
config = {maxRetransmits: 0};
|
|
config = {maxRetransmits: 0};
|
|
}*/
|
|
}*/
|
|
// Fallback to ensure older browsers don't crash.
|
|
// Fallback to ensure older browsers don't crash.
|
|
- if (!util.supports.reliable) {
|
|
|
|
|
|
+ if (!util.supports.sctp) {
|
|
config = {reliable: options.reliable};
|
|
config = {reliable: options.reliable};
|
|
}
|
|
}
|
|
var dc = pc.createDataChannel(connection.label, config);
|
|
var dc = pc.createDataChannel(connection.label, config);
|
|
@@ -2049,7 +2056,7 @@ Negotiator._startPeerConnection = function(connection) {
|
|
var id = Negotiator._idPrefix + util.randomToken();
|
|
var id = Negotiator._idPrefix + util.randomToken();
|
|
var optional = {};
|
|
var optional = {};
|
|
|
|
|
|
- if (connection.type === 'data' && !util.supports.reliable) {
|
|
|
|
|
|
+ if (connection.type === 'data' && !util.supports.sctp) {
|
|
optional = {optional: [{RtpDataChannels: true}]};
|
|
optional = {optional: [{RtpDataChannels: true}]};
|
|
} else if (connection.type === 'media') {
|
|
} else if (connection.type === 'media') {
|
|
// Interop req for chrome.
|
|
// Interop req for chrome.
|
|
@@ -2150,7 +2157,7 @@ Negotiator._makeOffer = function(connection) {
|
|
pc.createOffer(function(offer) {
|
|
pc.createOffer(function(offer) {
|
|
util.log('Created offer.');
|
|
util.log('Created offer.');
|
|
|
|
|
|
- if (!util.supports.reliable && connection.type === 'data' && connection.reliable) {
|
|
|
|
|
|
+ if (!util.supports.sctp && connection.type === 'data' && connection.reliable) {
|
|
offer.sdp = Reliable.higherBandwidthSDP(offer.sdp);
|
|
offer.sdp = Reliable.higherBandwidthSDP(offer.sdp);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -2166,7 +2173,7 @@ Negotiator._makeOffer = function(connection) {
|
|
serialization: connection.serialization,
|
|
serialization: connection.serialization,
|
|
metadata: connection.metadata,
|
|
metadata: connection.metadata,
|
|
connectionId: connection.id,
|
|
connectionId: connection.id,
|
|
- sctp: util.supports.reliable
|
|
|
|
|
|
+ sctp: util.supports.sctp
|
|
},
|
|
},
|
|
dst: connection.peer,
|
|
dst: connection.peer,
|
|
});
|
|
});
|
|
@@ -2186,7 +2193,7 @@ Negotiator._makeAnswer = function(connection) {
|
|
pc.createAnswer(function(answer) {
|
|
pc.createAnswer(function(answer) {
|
|
util.log('Created answer.');
|
|
util.log('Created answer.');
|
|
|
|
|
|
- if (!util.supports.reliable && connection.type === 'data' && connection.reliable) {
|
|
|
|
|
|
+ if (!util.supports.sctp && connection.type === 'data' && connection.reliable) {
|
|
answer.sdp = Reliable.higherBandwidthSDP(answer.sdp);
|
|
answer.sdp = Reliable.higherBandwidthSDP(answer.sdp);
|
|
}
|
|
}
|
|
|
|
|