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

migrate enum strings to enums #28

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
75 changes: 75 additions & 0 deletions lib/src/enums.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ enum RecorderAudioChannel { INPUT, OUTPUT }
/// RTCDataChannelMessage type
enum MessageType { text, binary }

enum DataChannelProtocol { sctp , quic }

enum SdpType { offer, answer }

enum TrackType { audio, video }

enum DeviceInfoType { videoInput, audioInput, audioOutput }

enum RTCDataChannelState {
RTCDataChannelConnecting,
RTCDataChannelOpen,
Expand Down Expand Up @@ -204,3 +212,70 @@ RTCDegradationPreference degradationPreferenceforString(String? degradation) {
}
return RTCDegradationPreference.BALANCED;
}

SdpType? sdpTypeForString(String? type) {
switch (type) {
case 'offer':
return SdpType.offer;
case 'answer':
return SdpType.answer;
default:
return null;
}
}

final typeSdpTypeToString = <SdpType, String>{
SdpType.offer: 'offer',
SdpType.answer: 'answer',
};

TrackType? trackTypeForString(String? type) {
switch (type) {
case 'audio':
return TrackType.audio;
case 'video':
return TrackType.video;
default:
return null;
}
}

final typeTrackTypeToString = <TrackType, String>{
TrackType.audio: 'audio',
TrackType.video: 'video',
};

DeviceInfoType? deviceInfoTypeForString(String? type) {
switch (type) {
case 'audioinput':
return DeviceInfoType.audioInput;
case 'audiooutput':
return DeviceInfoType.audioOutput;
case 'videoinput':
return DeviceInfoType.videoInput;
default:
return null;
}
}

final typeDeviceInfoTypeToString = <DeviceInfoType, String>{
DeviceInfoType.audioInput: 'audioinput',
DeviceInfoType.audioOutput: 'audiooutput',
DeviceInfoType.videoInput: 'videoinput',
};

DataChannelProtocol? dataChannelProtocolForString(String? type) {
switch (type) {
case 'quic':
return DataChannelProtocol.quic;
case 'sctp':
return DataChannelProtocol.sctp;
default:
return null;
}
}

final typeDataChannelProtocolToString = <DataChannelProtocol, String>{
DataChannelProtocol.quic: 'quic',
DataChannelProtocol.sctp: 'sctp',
};
6 changes: 4 additions & 2 deletions lib/src/media_stream_track.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'dart:typed_data';

import 'package:webrtc_interface/src/enums.dart';

typedef StreamTrackCallback = Function();

abstract class MediaStreamTrack {
Expand All @@ -15,9 +17,9 @@ abstract class MediaStreamTrack {
/// If the corresponding source has or had no label, returns an empty string.
String? get label;

/// Returns the string 'audio' if this object represents an audio track
/// Returns the type 'audio' if this object represents an audio track
/// or 'video' if this object represents a video track.
String? get kind;
TrackType? get kind;

/// Callback for onmute event
StreamTrackCallback? onMute;
Expand Down
4 changes: 3 additions & 1 deletion lib/src/mediadevices.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'package:webrtc_interface/src/enums.dart';

import 'media_stream.dart';

class MediaStreamConstraints {
Expand Down Expand Up @@ -150,7 +152,7 @@ class MediaDeviceInfo {

/// Returns an enumerated value that is either 'videoinput', 'audioinput' or
/// 'audiooutput'.
final String? kind;
final DeviceInfoType? kind;

/// Returns a String that is a label describing this device
/// (for example "External USB Webcam").
Expand Down
6 changes: 3 additions & 3 deletions lib/src/rtc_data_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ class RTCDataChannelInit {
bool ordered = true;
int maxRetransmitTime = -1;
int maxRetransmits = -1;
String protocol = 'sctp'; //sctp | quic
String binaryType = 'text'; // "binary" || text
DataChannelProtocol protocol = DataChannelProtocol.sctp;
MessageType binaryType = MessageType.text;
bool negotiated = false;
int id = 0;
Map<String, dynamic> toMap() {
Expand All @@ -18,7 +18,7 @@ class RTCDataChannelInit {
//https://www.chromestatus.com/features/5198350873788416
'maxPacketLifeTime': maxRetransmitTime,
if (maxRetransmits > 0) 'maxRetransmits': maxRetransmits,
'protocol': protocol,
'protocol': typeDataChannelProtocolToString[protocol],
'negotiated': negotiated,
'id': id
};
Expand Down
6 changes: 4 additions & 2 deletions lib/src/rtc_session_description.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import 'enums.dart';

class RTCSessionDescription {
RTCSessionDescription(this.sdp, this.type);
String? sdp;
String? type;
SdpType? type;
dynamic toMap() {
return {'sdp': sdp, 'type': type};
return {'sdp': sdp, 'type': typeSdpTypeToString[type]};
}
}