blob: 33f503af025e869b572b3ed7bf553f4305299003 [file] [log] [blame]
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
part of $LIBRARYNAME;
$(ANNOTATIONS)$(NATIVESPEC)$(CLASS_MODIFIERS)class $CLASSNAME$EXTENDS$IMPLEMENTS {
factory $CLASSNAME(Map rtcIceServers, [Map mediaConstraints]) {
var constructorName = JS('RtcPeerConnection', 'window[#]',
'${Device.propertyPrefix}RTCPeerConnection');
if (mediaConstraints != null) {
return JS('RtcPeerConnection', 'new #(#,#)', constructorName,
convertDartToNative_SerializedScriptValue(rtcIceServers),
convertDartToNative_SerializedScriptValue(mediaConstraints));
} else {
return JS('RtcPeerConnection', 'new #(#)', constructorName,
convertDartToNative_SerializedScriptValue(rtcIceServers));
}
}
/**
* Checks if Real Time Communication (RTC) APIs are supported and enabled on
* the current platform.
*/
static bool get supported {
// Currently in Firefox some of the RTC elements are defined but throw an
// error unless the user has specifically enabled them in their
// about:config. So we have to construct an element to actually test if RTC
// is supported at the given time.
try {
new RtcPeerConnection(
{"iceServers": [ {"url":"stun:localhost"}]});
return true;
} catch (_) { return false;}
return false;
}
Future<RtcSessionDescription> createOffer([Map mediaConstraints]) {
var completer = new Completer<RtcSessionDescription>();
_createOffer(
(value) { completer.complete(value); },
(error) { completer.completeError(error); }, mediaConstraints);
return completer.future;
}
Future<RtcSessionDescription> createAnswer([Map mediaConstraints]) {
var completer = new Completer<RtcSessionDescription>();
_createAnswer(
(value) { completer.complete(value); },
(error) { completer.completeError(error); }, mediaConstraints);
return completer.future;
}
/**
* Temporarily exposes _getStats and old getStats as getLegacyStats until Chrome fully supports
* new getStats API.
*/
Future<RtcStatsResponse> getLegacyStats([MediaStreamTrack selector]) {
var completer = new Completer<RtcStatsResponse>();
_getStats((value) {
completer.complete(value);
}, selector);
return completer.future;
}
@JSName('getStats')
Future _getStats(
[RtcStatsCallback successCallback, MediaStreamTrack selector]) native;
static Future generateCertificate(/*AlgorithmIdentifier*/ keygenAlgorithm) =>
JS('dynamic', 'generateCertificate(#)', keygenAlgorithm);
$!MEMBERS
}