diff --git a/lib/src/enums.dart b/lib/src/enums.dart index 9024bc6..6ffcd3b 100644 --- a/lib/src/enums.dart +++ b/lib/src/enums.dart @@ -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, @@ -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.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.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.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.quic: 'quic', + DataChannelProtocol.sctp: 'sctp', +}; \ No newline at end of file diff --git a/lib/src/media_stream_track.dart b/lib/src/media_stream_track.dart index c7f9b8f..b3477b5 100644 --- a/lib/src/media_stream_track.dart +++ b/lib/src/media_stream_track.dart @@ -1,5 +1,7 @@ import 'dart:typed_data'; +import 'package:webrtc_interface/src/enums.dart'; + typedef StreamTrackCallback = Function(); abstract class MediaStreamTrack { @@ -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; diff --git a/lib/src/mediadevices.dart b/lib/src/mediadevices.dart index 9e43527..2b78553 100644 --- a/lib/src/mediadevices.dart +++ b/lib/src/mediadevices.dart @@ -1,3 +1,5 @@ +import 'package:webrtc_interface/src/enums.dart'; + import 'media_stream.dart'; class MediaStreamConstraints { @@ -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"). diff --git a/lib/src/rtc_data_channel.dart b/lib/src/rtc_data_channel.dart index de5692f..70e746a 100644 --- a/lib/src/rtc_data_channel.dart +++ b/lib/src/rtc_data_channel.dart @@ -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 toMap() { @@ -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 }; diff --git a/lib/src/rtc_session_description.dart b/lib/src/rtc_session_description.dart index 07b390d..3edb8e5 100644 --- a/lib/src/rtc_session_description.dart +++ b/lib/src/rtc_session_description.dart @@ -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]}; } }