Skip to content
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

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

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
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
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
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;
}
11 changes: 11 additions & 0 deletions lib/src/rtc_peerconnection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,16 @@ abstract class RTCPeerConnection {
Function(RTCIceGatheringState state)? onIceGatheringState;
Function(RTCIceConnectionState state)? onIceConnectionState;
Function(RTCIceCandidate candidate)? onIceCandidate;

@Deprecated('Deprecated API')
Function(MediaStream stream)? onAddStream;
@Deprecated('Deprecated API')
Function(MediaStream stream)? onRemoveStream;
@Deprecated('Deprecated API')
Function(MediaStream stream, MediaStreamTrack track)? onAddTrack;
@Deprecated('Deprecated API')
Function(MediaStream stream, MediaStreamTrack track)? onRemoveTrack;

Function(RTCDataChannel channel)? onDataChannel;
Function()? onRenegotiationNeeded;

Expand Down Expand Up @@ -67,8 +73,10 @@ abstract class RTCPeerConnection {
Future<RTCSessionDescription> createAnswer(
[Map<String, dynamic> constraints]);

@Deprecated('Deprecated API')
Future<void> addStream(MediaStream stream);

@Deprecated('Deprecated API')
Future<void> removeStream(MediaStream stream);

Future<RTCSessionDescription?> getLocalDescription();
Expand All @@ -83,8 +91,10 @@ abstract class RTCPeerConnection {

Future<List<StatsReport>> getStats([MediaStreamTrack? track]);

@Deprecated('Deprecated API')
List<MediaStream?> getLocalStreams();

@Deprecated('Deprecated API')
List<MediaStream?> getRemoteStreams();

Future<RTCDataChannel> createDataChannel(
Expand All @@ -94,6 +104,7 @@ abstract class RTCPeerConnection {

Future<void> close();

@Deprecated('Deprecated API, use RTCRtpSender.dtmf instead')
RTCDTMFSender createDtmfSender(MediaStreamTrack track);

/// Unified-Plan.
Expand Down
2 changes: 2 additions & 0 deletions lib/webrtc_interface.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ library webrtc_interface;
export 'src/enums.dart';
export 'src/factory.dart';
export 'src/frame_cryptor.dart';
export 'src/media_constraints.dart';
export 'src/media_recorder.dart';
export 'src/media_stream.dart';
export 'src/media_stream_track.dart';
export 'src/mediadevices.dart';
export 'src/navigator.dart';
export 'src/rtc_configuration.dart';
export 'src/rtc_data_channel.dart';
export 'src/rtc_dtmf_sender.dart';
export 'src/rtc_ice_candidate.dart';
Expand Down