Skip to content

fix/migrate-dart-html-to-web-pkg. #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix/migrate-dart-html-to-web-pkg.
  • Loading branch information
cloudwebrtc committed Apr 8, 2024
commit cc470d345343ceac25624bb3835e93065f6411b9
5 changes: 5 additions & 0 deletions lib/src/factory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,20 @@ import 'frame_cryptor.dart';
import 'media_recorder.dart';
import 'media_stream.dart';
import 'navigator.dart';
import 'rtc_configuration.dart';
import 'rtc_peerconnection.dart';
import 'rtc_rtp_capabilities.dart';
import 'rtc_video_renderer.dart';

abstract class RTCFactory {
@Deprecated('use newPeerConnection() instead')
Future<RTCPeerConnection> createPeerConnection(
Map<String, dynamic> configuration,
[Map<String, dynamic> constraints]);

Future<RTCPeerConnection> newPeerConnection(RTCConfiguration configuration) =>
throw UnimplementedError();

Future<MediaStream> createLocalMediaStream(String label);

Future<RTCRtpCapabilities> getRtpSenderCapabilities(String kind);
Expand Down
22 changes: 22 additions & 0 deletions lib/src/frame_cryptor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,19 @@ class KeyProviderOptions {
required this.ratchetWindowSize,
this.uncryptedMagicBytes,
this.failureTolerance = -1,
this.key_ring_size = 16,
this.discard_frame_when_cryptor_not_ready = false,
});
bool sharedKey;
Uint8List ratchetSalt;
Uint8List? uncryptedMagicBytes;
int ratchetWindowSize;
int failureTolerance;

/// key ring size should be between 1 and 255
/// default is 16
int key_ring_size;
bool discard_frame_when_cryptor_not_ready;
Map<String, dynamic> toJson() {
return {
'sharedKey': sharedKey,
Expand All @@ -30,6 +37,8 @@ class KeyProviderOptions {
'uncryptedMagicBytes': uncryptedMagicBytes,
'ratchetWindowSize': ratchetWindowSize,
'failureTolerance': failureTolerance,
'keyRingSize': key_ring_size,
'discardFrameWhenCryptorNotReady': discard_frame_when_cryptor_not_ready,
};
}
}
Expand Down Expand Up @@ -84,6 +93,19 @@ enum FrameCryptorState {
FrameCryptorStateInternalError,
}

class FrameCryptorOptions {
FrameCryptorOptions({
this.discardUnableDecryptedFrames = false,
});

/// Discard frames when frame crypto is disabled.
/// Because of the wrong key or decoding the encrypted frame or outputting
/// garbled audio
/// when called FrameCryptor.setEnabled(false); if this parameter is true, the
/// frame will discarded
final bool discardUnableDecryptedFrames;
}

/// Frame encryption/decryption.
///
abstract class FrameCryptor {
Expand Down
150 changes: 150 additions & 0 deletions lib/src/media_constraints.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
class MediaTrackConstraints {
MediaTrackConstraints({this.deviceId, this.groupId});
factory MediaTrackConstraints.fromMap(Map<String, dynamic> map) {
return MediaTrackConstraints(
deviceId: map['deviceId'] as String?,
groupId: map['groupId'] as String?,
);
}
final String? deviceId;
final String? groupId;

Map<String, dynamic> toMap() {
return <String, dynamic>{
if (deviceId != null) 'deviceId': deviceId,
if (groupId != null) 'groupId': groupId,
};
}
}

class AudioTrackConstraints extends MediaTrackConstraints {
AudioTrackConstraints({
required String deviceId,
required String groupId,
this.autoGainControl,
this.channelCount,
this.echoCancellation,
this.latency,
this.noiseSuppression,
this.sampleRate,
this.sampleSize,
this.volume,
}) : super(deviceId: deviceId, groupId: groupId);

factory AudioTrackConstraints.fromMap(Map<String, dynamic> map) {
return AudioTrackConstraints(
deviceId: map['deviceId'] as String,
groupId: map['groupId'] as String,
autoGainControl: map['autoGainControl'] as bool?,
channelCount: map['channelCount'] as bool?,
echoCancellation: map['echoCancellation'] as bool?,
latency: map['latency'] as bool?,
noiseSuppression: map['noiseSuppression'] as bool?,
sampleRate: map['sampleRate'] as bool?,
sampleSize: map['sampleSize'] as bool?,
volume: map['volume'] as bool?,
);
}

bool? autoGainControl;
bool? channelCount;
bool? echoCancellation;
bool? latency;
bool? noiseSuppression;
bool? sampleRate;
bool? sampleSize;
bool? volume;

@override
Map<String, dynamic> toMap() {
return <String, dynamic>{
if (deviceId != null) 'deviceId': deviceId,
if (groupId != null) 'groupId': groupId,
if (autoGainControl != null) 'autoGainControl': autoGainControl,
if (channelCount != null) 'channelCount': channelCount,
if (echoCancellation != null) 'echoCancellation': echoCancellation,
if (latency != null) 'latency': latency,
if (noiseSuppression != null) 'noiseSuppression': noiseSuppression,
if (sampleRate != null) 'sampleRate': sampleRate,
if (sampleSize != null) 'sampleSize': sampleSize,
if (volume != null) 'volume': volume,
};
}
}

class VideoTrackConstraints extends MediaTrackConstraints {
VideoTrackConstraints({
required String deviceId,
required String groupId,
this.aspectRatio,
this.frameRate,
this.facingMode,
this.height,
this.width,
}) : super(deviceId: deviceId, groupId: groupId);

factory VideoTrackConstraints.fromMap(Map<String, dynamic> map) {
return VideoTrackConstraints(
deviceId: map['deviceId'] as String,
groupId: map['groupId'] as String,
aspectRatio: map['aspectRatio'] as bool?,
frameRate: map['frameRate'] as bool?,
facingMode: map['facingMode'] as bool?,
height: map['height'] as bool?,
width: map['width'] as bool?,
);
}

bool? aspectRatio;
bool? frameRate;
bool? facingMode;
bool? height;
bool? width;

@override
Map<String, dynamic> toMap() {
return <String, dynamic>{
if (deviceId != null) 'deviceId': deviceId,
if (groupId != null) 'groupId': groupId,
if (aspectRatio != null) 'aspectRatio': aspectRatio,
if (frameRate != null) 'frameRate': frameRate,
if (facingMode != null) 'facingMode': facingMode,
if (height != null) 'height': height,
if (width != null) 'width': width,
};
}
}

class MediaStreamConstraints {
MediaStreamConstraints({
this.audio,
this.video,
});

factory MediaStreamConstraints.fromMap(Map<String, dynamic> map) {
return MediaStreamConstraints(
audio: map['audio'] is bool
? map['audio']
: AudioTrackConstraints.fromMap(map['audio']),
video: map['video'] is bool
? map['video']
: VideoTrackConstraints.fromMap(map['video']),
);
}

// bool or AudioTrackConstraints
dynamic audio;
// bool or VideoTrackConstraints
dynamic video;

Map<String, dynamic> toMap() {
return <String, dynamic>{
if (audio != null)
'audio':
audio is bool ? audio : (audio as AudioTrackConstraints).toMap(),
if (video != null)
'video':
video is bool ? video : (video as VideoTrackConstraints).toMap(),
};
}
}
18 changes: 0 additions & 18 deletions lib/src/mediadevices.dart
Original file line number Diff line number Diff line change
@@ -1,23 +1,5 @@
import 'media_stream.dart';

class MediaStreamConstraints {
MediaStreamConstraints({this.audio, this.video});

/// Either a bool (which indicates whether or not an audio track is requested)
/// or a MediaTrackConstraints object providing the constraints which must be
/// met by the audio track included in the returned MediaStream.
///
/// If constraints are specified, an audio track is inherently requested.
dynamic audio;

/// Either a bool (which indicates whether or not a video track is requested)
/// or a MediaTrackConstraints object providing the constraints which must be
/// met by the video track included in the returned MediaStream.
///
/// If constraints are specified, a video track is inherently requested.
dynamic video;
}

/// [MediaTrackSupportedConstraints] represents the list of constraints
/// controlling the capabilities of a [MediaStreamTrack].
class MediaTrackSupportedConstraints {
Expand Down
120 changes: 66 additions & 54 deletions lib/src/rtc_configuration.dart
Original file line number Diff line number Diff line change
@@ -1,54 +1,66 @@
// abstract class RTCOfferOptions {
// RTCOfferOptions({
// bool iceRestart,
// bool offerToReceiveAudio,
// bool offerToReceiveVideo,
// bool voiceActivityDetection,
// });
// bool get iceRestart;
// bool get offerToReceiveAudio;
// bool get offerToReceiveVideo;
// bool get voiceActivityDetection;
// }

// abstract class RTCAnswerOptions {
// RTCAnswerOptions({bool voiceActivityDetection});
// bool get voiceActivityDetection;
// }

// abstract class RTCConfiguration {
// RTCConfiguration({
// List<RTCIceServer> iceServers,
// String rtcpMuxPolicy,
// String iceTransportPolicy,
// String bundlePolicy,
// String peerIdentity,
// int iceCandidatePoolSize,
// });
// List<RTCIceServer> get iceServers;

// ///Optional: 'negotiate' or 'require'
// String get rtcpMuxPolicy;

// ///Optional: 'relay' or 'all'
// String get iceTransportPolicy;

// /// A DOMString which specifies the target peer identity for the
// /// RTCPeerConnection. If this value is set (it defaults to null),
// /// the RTCPeerConnection will not connect to a remote peer unless
// /// it can successfully authenticate with the given name.
// String get peerIdentity;

// int get iceCandidatePoolSize;

// ///Optional: 'balanced' | 'max-compat' | 'max-bundle'
// String get bundlePolicy;
// }

// abstract class RTCIceServer {
// RTCIceServer({String urls, String username, String credential});
// // String or List<String>
// dynamic get urls;
// String get username;
// String get credential;
// }
class RTCOfferOptions {
bool? iceRestart;
bool? offerToReceiveAudio;
bool? offerToReceiveVideo;
bool? voiceActivityDetection;
}

class RTCAnswerOptions {
bool? voiceActivityDetection;
}

class RTCConfiguration {
RTCConfiguration(
{this.iceServers,
this.rtcpMuxPolicy,
this.iceTransportPolicy,
this.peerIdentity,
this.iceCandidatePoolSize,
this.bundlePolicy});
factory RTCConfiguration.fromMap(Map<String, dynamic> map) {
return RTCConfiguration(
iceServers: map['iceServers'] != null
? (map['iceServers'] as List)
.map((e) => RTCIceServer.fromMap(e))
.toList()
: null,
rtcpMuxPolicy: map['rtcpMuxPolicy'],
iceTransportPolicy: map['iceTransportPolicy'],
peerIdentity: map['peerIdentity'],
iceCandidatePoolSize: map['iceCandidatePoolSize'],
bundlePolicy: map['bundlePolicy'],
);
}
List<RTCIceServer>? iceServers;

///Optional: 'negotiate' or 'require'
String? rtcpMuxPolicy;

///Optional: 'relay' or 'all'
String? iceTransportPolicy;

/// A DOMString which specifies the target peer identity for the
/// RTCPeerConnection. If this value is set (it defaults to null),
/// the RTCPeerConnection will not connect to a remote peer unless
/// it can successfully authenticate with the given name.
String? peerIdentity;

int? iceCandidatePoolSize;

///Optional: 'balanced' | 'max-compat' | 'max-bundle'
String? bundlePolicy;
}

class RTCIceServer {
RTCIceServer({this.urls, this.username, this.credential});
factory RTCIceServer.fromMap(Map<String, dynamic> map) {
return RTCIceServer(
urls: map['urls'] != null ? List<String>.from(map['urls']) : null,
username: map['username'],
credential: map['credential'],
);
}
List<String>? urls;
String? username;
String? credential;
}
Loading