|
@@ -75,9 +75,17 @@ var util = {
|
|
|
|
|
|
// Lists which features are supported
|
|
// Lists which features are supported
|
|
supports: (function() {
|
|
supports: (function() {
|
|
|
|
+ if (typeof RTCPeerConnection === 'undefined') {
|
|
|
|
+ return {};
|
|
|
|
+ }
|
|
|
|
+
|
|
var data = true;
|
|
var data = true;
|
|
var audioVideo = true;
|
|
var audioVideo = true;
|
|
|
|
|
|
|
|
+ var binary = false;
|
|
|
|
+ var reliable = false;
|
|
|
|
+ var onnegotiationneeded = false;
|
|
|
|
+
|
|
var pc, dc;
|
|
var pc, dc;
|
|
try {
|
|
try {
|
|
pc = new RTCPeerConnection(defaultConfig, {optional: [{RtpDataChannels: true}]});
|
|
pc = new RTCPeerConnection(defaultConfig, {optional: [{RtpDataChannels: true}]});
|
|
@@ -88,79 +96,65 @@ var util = {
|
|
|
|
|
|
if (data) {
|
|
if (data) {
|
|
try {
|
|
try {
|
|
- dc = pc.createDataChannel('_PEERJSDATATEST');
|
|
|
|
|
|
+ dc = pc.createDataChannel('_PEERJSTEST');
|
|
} catch (e) {
|
|
} catch (e) {
|
|
data = false;
|
|
data = false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ if (data) {
|
|
|
|
+ try {
|
|
|
|
+ dc.binaryType = 'blob';
|
|
|
|
+ binary = true;
|
|
|
|
+ } catch (e) {
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ var reliablePC = new RTCPeerConnection(defaultConfig, {});
|
|
|
|
+ try {
|
|
|
|
+ var reliableDC = reliablePC.createDataChannel('_PEERJSRELIABLETEST', {maxRetransmits: 0});
|
|
|
|
+ reliable = true;
|
|
|
|
+ } catch (e) {
|
|
|
|
+ }
|
|
|
|
+ reliablePC.close();
|
|
|
|
+ }
|
|
|
|
+
|
|
// FIXME: not really the best check...
|
|
// FIXME: not really the best check...
|
|
if (audioVideo) {
|
|
if (audioVideo) {
|
|
audioVideo = !!pc.addStream;
|
|
audioVideo = !!pc.addStream;
|
|
}
|
|
}
|
|
|
|
|
|
- pc.close();
|
|
|
|
- dc.close();
|
|
|
|
-
|
|
|
|
- return {
|
|
|
|
- audioVideo: audioVideo,
|
|
|
|
- data: data,
|
|
|
|
- binary: data && (function() {
|
|
|
|
- var pc = new RTCPeerConnection(defaultConfig, {optional: [{RtpDataChannels: true}]});
|
|
|
|
- var dc = pc.createDataChannel('_PEERJSBINARYTEST');
|
|
|
|
-
|
|
|
|
- try {
|
|
|
|
- dc.binaryType = 'blob';
|
|
|
|
- } catch (e) {
|
|
|
|
- pc.close();
|
|
|
|
- if (e.name === 'NotSupportedError') {
|
|
|
|
- return false
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- pc.close();
|
|
|
|
- dc.close();
|
|
|
|
-
|
|
|
|
- return true;
|
|
|
|
- })(),
|
|
|
|
-
|
|
|
|
- reliable: data && (function() {
|
|
|
|
- // Reliable (not RTP).
|
|
|
|
- var pc = new RTCPeerConnection(defaultConfig, {});
|
|
|
|
- var dc;
|
|
|
|
- try {
|
|
|
|
- dc = pc.createDataChannel('_PEERJSRELIABLETEST', {maxRetransmits: 0});
|
|
|
|
- } catch (e) {
|
|
|
|
- pc.close();
|
|
|
|
- if (e.name === 'NotSupportedError') {
|
|
|
|
- return false
|
|
|
|
- }
|
|
|
|
|
|
+ if (/** audioVideo || */data) {
|
|
|
|
+ // sync default check.
|
|
|
|
+ var negotiationPC = new RTCPeerConnection(defaultConfig, {optional: [{RtpDataChannels: true}]});
|
|
|
|
+ negotiationPC.onnegotiationneeded = function() {
|
|
|
|
+ onnegotiationneeded = true;
|
|
|
|
+ // async check.
|
|
|
|
+ if (util && util.supports) {
|
|
|
|
+ util.supports.onnegotiationneeded = true;
|
|
}
|
|
}
|
|
- pc.close();
|
|
|
|
- dc.close();
|
|
|
|
|
|
+ };
|
|
|
|
+ // FIXME: this is not great because in theory it doesn't work for
|
|
|
|
+ // av-only browsers (?).
|
|
|
|
+ var negotiationDC = negotiationPC.createDataChannel('_PEERJSRELIABLETEST');
|
|
|
|
|
|
- return true;
|
|
|
|
- })(),
|
|
|
|
-
|
|
|
|
- onnegotiationneeded: (data || audioVideo) && (function() {
|
|
|
|
- var pc = new RTCPeerConnection(defaultConfig, {});
|
|
|
|
- // sync default check.
|
|
|
|
- var called = false;
|
|
|
|
- var pc = new RTCPeerConnection(defaultConfig, {optional: [{RtpDataChannels: true}]});
|
|
|
|
- pc.onnegotiationneeded = function() {
|
|
|
|
- called = true;
|
|
|
|
- // async check.
|
|
|
|
- if (util && util.supports) {
|
|
|
|
- util.supports.onnegotiationneeded = true;
|
|
|
|
- }
|
|
|
|
- };
|
|
|
|
- // FIXME: this is not great because in theory it doesn't work for
|
|
|
|
- // av-only browsers (?).
|
|
|
|
- var dc = pc.createDataChannel('_PEERJSRELIABLETEST');
|
|
|
|
|
|
+ negotiationPC.close();
|
|
|
|
+ negotiationDC.close();
|
|
|
|
+ }
|
|
|
|
|
|
- pc.close();
|
|
|
|
- dc.close();
|
|
|
|
|
|
+ // FIXME: Make SURE these are closed.
|
|
|
|
+ if (pc) {
|
|
|
|
+ pc.close();
|
|
|
|
+ }
|
|
|
|
+ if (dc) {
|
|
|
|
+ dc.close();
|
|
|
|
+ }
|
|
|
|
|
|
- return called;
|
|
|
|
- })()
|
|
|
|
|
|
+ return {
|
|
|
|
+ audioVideo: audioVideo,
|
|
|
|
+ data: data,
|
|
|
|
+ binary: binary,
|
|
|
|
+ reliable: reliable,
|
|
|
|
+ onnegotiationneeded: onnegotiationneeded
|
|
};
|
|
};
|
|
}()),
|
|
}()),
|
|
//
|
|
//
|