Skip to content

Commit cc470d3

Browse files
committedApr 8, 2024
fix/migrate-dart-html-to-web-pkg.

7 files changed

+256
-72
lines changed
 

Diff for: ‎lib/src/factory.dart

+5
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,20 @@ import 'frame_cryptor.dart';
22
import 'media_recorder.dart';
33
import 'media_stream.dart';
44
import 'navigator.dart';
5+
import 'rtc_configuration.dart';
56
import 'rtc_peerconnection.dart';
67
import 'rtc_rtp_capabilities.dart';
78
import 'rtc_video_renderer.dart';
89

910
abstract class RTCFactory {
11+
@Deprecated('use newPeerConnection() instead')
1012
Future<RTCPeerConnection> createPeerConnection(
1113
Map<String, dynamic> configuration,
1214
[Map<String, dynamic> constraints]);
1315

16+
Future<RTCPeerConnection> newPeerConnection(RTCConfiguration configuration) =>
17+
throw UnimplementedError();
18+
1419
Future<MediaStream> createLocalMediaStream(String label);
1520

1621
Future<RTCRtpCapabilities> getRtpSenderCapabilities(String kind);

Diff for: ‎lib/src/frame_cryptor.dart

+22
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,19 @@ class KeyProviderOptions {
1616
required this.ratchetWindowSize,
1717
this.uncryptedMagicBytes,
1818
this.failureTolerance = -1,
19+
this.key_ring_size = 16,
20+
this.discard_frame_when_cryptor_not_ready = false,
1921
});
2022
bool sharedKey;
2123
Uint8List ratchetSalt;
2224
Uint8List? uncryptedMagicBytes;
2325
int ratchetWindowSize;
2426
int failureTolerance;
27+
28+
/// key ring size should be between 1 and 255
29+
/// default is 16
30+
int key_ring_size;
31+
bool discard_frame_when_cryptor_not_ready;
2532
Map<String, dynamic> toJson() {
2633
return {
2734
'sharedKey': sharedKey,
@@ -30,6 +37,8 @@ class KeyProviderOptions {
3037
'uncryptedMagicBytes': uncryptedMagicBytes,
3138
'ratchetWindowSize': ratchetWindowSize,
3239
'failureTolerance': failureTolerance,
40+
'keyRingSize': key_ring_size,
41+
'discardFrameWhenCryptorNotReady': discard_frame_when_cryptor_not_ready,
3342
};
3443
}
3544
}
@@ -84,6 +93,19 @@ enum FrameCryptorState {
8493
FrameCryptorStateInternalError,
8594
}
8695

96+
class FrameCryptorOptions {
97+
FrameCryptorOptions({
98+
this.discardUnableDecryptedFrames = false,
99+
});
100+
101+
/// Discard frames when frame crypto is disabled.
102+
/// Because of the wrong key or decoding the encrypted frame or outputting
103+
/// garbled audio
104+
/// when called FrameCryptor.setEnabled(false); if this parameter is true, the
105+
/// frame will discarded
106+
final bool discardUnableDecryptedFrames;
107+
}
108+
87109
/// Frame encryption/decryption.
88110
///
89111
abstract class FrameCryptor {

Diff for: ‎lib/src/media_constraints.dart

+150
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
class MediaTrackConstraints {
2+
MediaTrackConstraints({this.deviceId, this.groupId});
3+
factory MediaTrackConstraints.fromMap(Map<String, dynamic> map) {
4+
return MediaTrackConstraints(
5+
deviceId: map['deviceId'] as String?,
6+
groupId: map['groupId'] as String?,
7+
);
8+
}
9+
final String? deviceId;
10+
final String? groupId;
11+
12+
Map<String, dynamic> toMap() {
13+
return <String, dynamic>{
14+
if (deviceId != null) 'deviceId': deviceId,
15+
if (groupId != null) 'groupId': groupId,
16+
};
17+
}
18+
}
19+
20+
class AudioTrackConstraints extends MediaTrackConstraints {
21+
AudioTrackConstraints({
22+
required String deviceId,
23+
required String groupId,
24+
this.autoGainControl,
25+
this.channelCount,
26+
this.echoCancellation,
27+
this.latency,
28+
this.noiseSuppression,
29+
this.sampleRate,
30+
this.sampleSize,
31+
this.volume,
32+
}) : super(deviceId: deviceId, groupId: groupId);
33+
34+
factory AudioTrackConstraints.fromMap(Map<String, dynamic> map) {
35+
return AudioTrackConstraints(
36+
deviceId: map['deviceId'] as String,
37+
groupId: map['groupId'] as String,
38+
autoGainControl: map['autoGainControl'] as bool?,
39+
channelCount: map['channelCount'] as bool?,
40+
echoCancellation: map['echoCancellation'] as bool?,
41+
latency: map['latency'] as bool?,
42+
noiseSuppression: map['noiseSuppression'] as bool?,
43+
sampleRate: map['sampleRate'] as bool?,
44+
sampleSize: map['sampleSize'] as bool?,
45+
volume: map['volume'] as bool?,
46+
);
47+
}
48+
49+
bool? autoGainControl;
50+
bool? channelCount;
51+
bool? echoCancellation;
52+
bool? latency;
53+
bool? noiseSuppression;
54+
bool? sampleRate;
55+
bool? sampleSize;
56+
bool? volume;
57+
58+
@override
59+
Map<String, dynamic> toMap() {
60+
return <String, dynamic>{
61+
if (deviceId != null) 'deviceId': deviceId,
62+
if (groupId != null) 'groupId': groupId,
63+
if (autoGainControl != null) 'autoGainControl': autoGainControl,
64+
if (channelCount != null) 'channelCount': channelCount,
65+
if (echoCancellation != null) 'echoCancellation': echoCancellation,
66+
if (latency != null) 'latency': latency,
67+
if (noiseSuppression != null) 'noiseSuppression': noiseSuppression,
68+
if (sampleRate != null) 'sampleRate': sampleRate,
69+
if (sampleSize != null) 'sampleSize': sampleSize,
70+
if (volume != null) 'volume': volume,
71+
};
72+
}
73+
}
74+
75+
class VideoTrackConstraints extends MediaTrackConstraints {
76+
VideoTrackConstraints({
77+
required String deviceId,
78+
required String groupId,
79+
this.aspectRatio,
80+
this.frameRate,
81+
this.facingMode,
82+
this.height,
83+
this.width,
84+
}) : super(deviceId: deviceId, groupId: groupId);
85+
86+
factory VideoTrackConstraints.fromMap(Map<String, dynamic> map) {
87+
return VideoTrackConstraints(
88+
deviceId: map['deviceId'] as String,
89+
groupId: map['groupId'] as String,
90+
aspectRatio: map['aspectRatio'] as bool?,
91+
frameRate: map['frameRate'] as bool?,
92+
facingMode: map['facingMode'] as bool?,
93+
height: map['height'] as bool?,
94+
width: map['width'] as bool?,
95+
);
96+
}
97+
98+
bool? aspectRatio;
99+
bool? frameRate;
100+
bool? facingMode;
101+
bool? height;
102+
bool? width;
103+
104+
@override
105+
Map<String, dynamic> toMap() {
106+
return <String, dynamic>{
107+
if (deviceId != null) 'deviceId': deviceId,
108+
if (groupId != null) 'groupId': groupId,
109+
if (aspectRatio != null) 'aspectRatio': aspectRatio,
110+
if (frameRate != null) 'frameRate': frameRate,
111+
if (facingMode != null) 'facingMode': facingMode,
112+
if (height != null) 'height': height,
113+
if (width != null) 'width': width,
114+
};
115+
}
116+
}
117+
118+
class MediaStreamConstraints {
119+
MediaStreamConstraints({
120+
this.audio,
121+
this.video,
122+
});
123+
124+
factory MediaStreamConstraints.fromMap(Map<String, dynamic> map) {
125+
return MediaStreamConstraints(
126+
audio: map['audio'] is bool
127+
? map['audio']
128+
: AudioTrackConstraints.fromMap(map['audio']),
129+
video: map['video'] is bool
130+
? map['video']
131+
: VideoTrackConstraints.fromMap(map['video']),
132+
);
133+
}
134+
135+
// bool or AudioTrackConstraints
136+
dynamic audio;
137+
// bool or VideoTrackConstraints
138+
dynamic video;
139+
140+
Map<String, dynamic> toMap() {
141+
return <String, dynamic>{
142+
if (audio != null)
143+
'audio':
144+
audio is bool ? audio : (audio as AudioTrackConstraints).toMap(),
145+
if (video != null)
146+
'video':
147+
video is bool ? video : (video as VideoTrackConstraints).toMap(),
148+
};
149+
}
150+
}

Diff for: ‎lib/src/mediadevices.dart

-18
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,5 @@
11
import 'media_stream.dart';
22

3-
class MediaStreamConstraints {
4-
MediaStreamConstraints({this.audio, this.video});
5-
6-
/// Either a bool (which indicates whether or not an audio track is requested)
7-
/// or a MediaTrackConstraints object providing the constraints which must be
8-
/// met by the audio track included in the returned MediaStream.
9-
///
10-
/// If constraints are specified, an audio track is inherently requested.
11-
dynamic audio;
12-
13-
/// Either a bool (which indicates whether or not a video track is requested)
14-
/// or a MediaTrackConstraints object providing the constraints which must be
15-
/// met by the video track included in the returned MediaStream.
16-
///
17-
/// If constraints are specified, a video track is inherently requested.
18-
dynamic video;
19-
}
20-
213
/// [MediaTrackSupportedConstraints] represents the list of constraints
224
/// controlling the capabilities of a [MediaStreamTrack].
235
class MediaTrackSupportedConstraints {

Diff for: ‎lib/src/rtc_configuration.dart

+66-54
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,66 @@
1-
// abstract class RTCOfferOptions {
2-
// RTCOfferOptions({
3-
// bool iceRestart,
4-
// bool offerToReceiveAudio,
5-
// bool offerToReceiveVideo,
6-
// bool voiceActivityDetection,
7-
// });
8-
// bool get iceRestart;
9-
// bool get offerToReceiveAudio;
10-
// bool get offerToReceiveVideo;
11-
// bool get voiceActivityDetection;
12-
// }
13-
14-
// abstract class RTCAnswerOptions {
15-
// RTCAnswerOptions({bool voiceActivityDetection});
16-
// bool get voiceActivityDetection;
17-
// }
18-
19-
// abstract class RTCConfiguration {
20-
// RTCConfiguration({
21-
// List<RTCIceServer> iceServers,
22-
// String rtcpMuxPolicy,
23-
// String iceTransportPolicy,
24-
// String bundlePolicy,
25-
// String peerIdentity,
26-
// int iceCandidatePoolSize,
27-
// });
28-
// List<RTCIceServer> get iceServers;
29-
30-
// ///Optional: 'negotiate' or 'require'
31-
// String get rtcpMuxPolicy;
32-
33-
// ///Optional: 'relay' or 'all'
34-
// String get iceTransportPolicy;
35-
36-
// /// A DOMString which specifies the target peer identity for the
37-
// /// RTCPeerConnection. If this value is set (it defaults to null),
38-
// /// the RTCPeerConnection will not connect to a remote peer unless
39-
// /// it can successfully authenticate with the given name.
40-
// String get peerIdentity;
41-
42-
// int get iceCandidatePoolSize;
43-
44-
// ///Optional: 'balanced' | 'max-compat' | 'max-bundle'
45-
// String get bundlePolicy;
46-
// }
47-
48-
// abstract class RTCIceServer {
49-
// RTCIceServer({String urls, String username, String credential});
50-
// // String or List<String>
51-
// dynamic get urls;
52-
// String get username;
53-
// String get credential;
54-
// }
1+
class RTCOfferOptions {
2+
bool? iceRestart;
3+
bool? offerToReceiveAudio;
4+
bool? offerToReceiveVideo;
5+
bool? voiceActivityDetection;
6+
}
7+
8+
class RTCAnswerOptions {
9+
bool? voiceActivityDetection;
10+
}
11+
12+
class RTCConfiguration {
13+
RTCConfiguration(
14+
{this.iceServers,
15+
this.rtcpMuxPolicy,
16+
this.iceTransportPolicy,
17+
this.peerIdentity,
18+
this.iceCandidatePoolSize,
19+
this.bundlePolicy});
20+
factory RTCConfiguration.fromMap(Map<String, dynamic> map) {
21+
return RTCConfiguration(
22+
iceServers: map['iceServers'] != null
23+
? (map['iceServers'] as List)
24+
.map((e) => RTCIceServer.fromMap(e))
25+
.toList()
26+
: null,
27+
rtcpMuxPolicy: map['rtcpMuxPolicy'],
28+
iceTransportPolicy: map['iceTransportPolicy'],
29+
peerIdentity: map['peerIdentity'],
30+
iceCandidatePoolSize: map['iceCandidatePoolSize'],
31+
bundlePolicy: map['bundlePolicy'],
32+
);
33+
}
34+
List<RTCIceServer>? iceServers;
35+
36+
///Optional: 'negotiate' or 'require'
37+
String? rtcpMuxPolicy;
38+
39+
///Optional: 'relay' or 'all'
40+
String? iceTransportPolicy;
41+
42+
/// A DOMString which specifies the target peer identity for the
43+
/// RTCPeerConnection. If this value is set (it defaults to null),
44+
/// the RTCPeerConnection will not connect to a remote peer unless
45+
/// it can successfully authenticate with the given name.
46+
String? peerIdentity;
47+
48+
int? iceCandidatePoolSize;
49+
50+
///Optional: 'balanced' | 'max-compat' | 'max-bundle'
51+
String? bundlePolicy;
52+
}
53+
54+
class RTCIceServer {
55+
RTCIceServer({this.urls, this.username, this.credential});
56+
factory RTCIceServer.fromMap(Map<String, dynamic> map) {
57+
return RTCIceServer(
58+
urls: map['urls'] != null ? List<String>.from(map['urls']) : null,
59+
username: map['username'],
60+
credential: map['credential'],
61+
);
62+
}
63+
List<String>? urls;
64+
String? username;
65+
String? credential;
66+
}

0 commit comments

Comments
 (0)
Please sign in to comment.