OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 part of $LIBRARYNAME; | 5 part of $LIBRARYNAME; |
6 | 6 |
7 $(ANNOTATIONS)$(NATIVESPEC)$(CLASS_MODIFIERS)class $CLASSNAME$EXTENDS$IMPLEMENTS
{ | 7 $(ANNOTATIONS)$(NATIVESPEC)$(CLASS_MODIFIERS)class $CLASSNAME$EXTENDS$IMPLEMENTS
{ |
8 $if DART2JS | |
9 factory $CLASSNAME(Map rtcIceServers, [Map mediaConstraints]) { | 8 factory $CLASSNAME(Map rtcIceServers, [Map mediaConstraints]) { |
10 var constructorName = JS('RtcPeerConnection', 'window[#]', | 9 var constructorName = JS('RtcPeerConnection', 'window[#]', |
11 '${Device.propertyPrefix}RTCPeerConnection'); | 10 '${Device.propertyPrefix}RTCPeerConnection'); |
12 if (mediaConstraints != null) { | 11 if (mediaConstraints != null) { |
13 return JS('RtcPeerConnection', 'new #(#,#)', constructorName, | 12 return JS('RtcPeerConnection', 'new #(#,#)', constructorName, |
14 convertDartToNative_SerializedScriptValue(rtcIceServers), | 13 convertDartToNative_SerializedScriptValue(rtcIceServers), |
15 convertDartToNative_SerializedScriptValue(mediaConstraints)); | 14 convertDartToNative_SerializedScriptValue(mediaConstraints)); |
16 } else { | 15 } else { |
17 return JS('RtcPeerConnection', 'new #(#)', constructorName, | 16 return JS('RtcPeerConnection', 'new #(#)', constructorName, |
18 convertDartToNative_SerializedScriptValue(rtcIceServers)); | 17 convertDartToNative_SerializedScriptValue(rtcIceServers)); |
19 } | 18 } |
20 } | 19 } |
21 $endif | |
22 | 20 |
23 /** | 21 /** |
24 * Checks if Real Time Communication (RTC) APIs are supported and enabled on | 22 * Checks if Real Time Communication (RTC) APIs are supported and enabled on |
25 * the current platform. | 23 * the current platform. |
26 */ | 24 */ |
27 $if DART2JS | |
28 static bool get supported { | 25 static bool get supported { |
29 // Currently in Firefox some of the RTC elements are defined but throw an | 26 // Currently in Firefox some of the RTC elements are defined but throw an |
30 // error unless the user has specifically enabled them in their | 27 // error unless the user has specifically enabled them in their |
31 // about:config. So we have to construct an element to actually test if RTC | 28 // about:config. So we have to construct an element to actually test if RTC |
32 // is supported at the given time. | 29 // is supported at the given time. |
33 try { | 30 try { |
34 new RtcPeerConnection( | 31 new RtcPeerConnection( |
35 {"iceServers": [ {"url":"stun:localhost"}]}); | 32 {"iceServers": [ {"url":"stun:localhost"}]}); |
36 return true; | 33 return true; |
37 } catch (_) { return false;} | 34 } catch (_) { return false;} |
38 return false; | 35 return false; |
39 } | 36 } |
40 $else | |
41 static bool get supported => true; | |
42 $endif | |
43 Future<RtcSessionDescription> createOffer([Map mediaConstraints]) { | 37 Future<RtcSessionDescription> createOffer([Map mediaConstraints]) { |
44 var completer = new Completer<RtcSessionDescription>(); | 38 var completer = new Completer<RtcSessionDescription>(); |
45 _createOffer( | 39 _createOffer( |
46 (value) { completer.complete(value); }, | 40 (value) { completer.complete(value); }, |
47 (error) { completer.completeError(error); }, mediaConstraints); | 41 (error) { completer.completeError(error); }, mediaConstraints); |
48 return completer.future; | 42 return completer.future; |
49 } | 43 } |
50 | 44 |
51 Future<RtcSessionDescription> createAnswer([Map mediaConstraints]) { | 45 Future<RtcSessionDescription> createAnswer([Map mediaConstraints]) { |
52 var completer = new Completer<RtcSessionDescription>(); | 46 var completer = new Completer<RtcSessionDescription>(); |
53 _createAnswer( | 47 _createAnswer( |
54 (value) { completer.complete(value); }, | 48 (value) { completer.complete(value); }, |
55 (error) { completer.completeError(error); }, mediaConstraints); | 49 (error) { completer.completeError(error); }, mediaConstraints); |
56 return completer.future; | 50 return completer.future; |
57 } | 51 } |
58 | 52 |
59 @DomName('RTCPeerConnection.getStats') | 53 @DomName('RTCPeerConnection.getStats') |
60 Future<RtcStatsResponse> getStats(MediaStreamTrack selector) { | 54 Future<RtcStatsResponse> getStats(MediaStreamTrack selector) { |
61 var completer = new Completer<RtcStatsResponse>(); | 55 var completer = new Completer<RtcStatsResponse>(); |
62 _getStats((value) { completer.complete(value); }, selector); | 56 _getStats((value) { completer.complete(value); }, selector); |
63 return completer.future; | 57 return completer.future; |
64 } | 58 } |
65 | 59 |
66 @DomName('RTCPeerConnection.generateCertificate') | 60 @DomName('RTCPeerConnection.generateCertificate') |
67 @DocsEditable() | 61 @DocsEditable() |
68 @Experimental() // untriaged | 62 @Experimental() // untriaged |
69 static Future generateCertificate(/*AlgorithmIdentifier*/ keygenAlgorithm) => | 63 static Future generateCertificate(/*AlgorithmIdentifier*/ keygenAlgorithm) => |
70 $if DART2JS | |
71 JS('dynamic', 'generateCertificate(#)', keygenAlgorithm); | 64 JS('dynamic', 'generateCertificate(#)', keygenAlgorithm); |
72 $else | |
73 convertNativePromiseToDartFuture(_blink.BlinkRTCPeerConnection.instance | |
74 .generateCertificate_Callback_1_(keygenAlgorithm)); | |
75 $endif | |
76 | 65 |
77 $!MEMBERS | 66 $!MEMBERS |
78 } | 67 } |
OLD | NEW |