Files
client-sdk-flutter/lib/src/types.dart
T

162 lines
3.0 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import 'package:flutter/material.dart';
import 'extensions.dart';
import 'dart:math' as math;
typedef CancelListenFunc = Function();
enum ProtocolVersion {
v2,
v3,
v4,
v5,
}
enum ConnectionState {
disconnected,
connected,
reconnecting,
}
enum ConnectionQuality {
unknown,
poor,
good,
excellent,
}
enum Reliability {
reliable,
lossy,
}
enum TrackSource {
unknown,
camera,
microphone,
screenShareVideo,
screenShareAudio,
}
enum StreamState {
paused,
active,
}
enum CloseReason {
network,
// ...
}
enum TrackSubscribeFailReason {
invalidServerResponse,
notTrackMetadataFound,
unsupportedTrackType,
// ...
}
enum RTCIceTransportPolicy {
all,
relay,
}
@immutable
class RTCOfferOptions {
final bool iceRestart;
const RTCOfferOptions({
this.iceRestart = false,
});
Map<String, dynamic> toMap() => <String, dynamic>{
if (iceRestart) 'iceRestart': true,
};
}
@immutable
class RTCConfiguration {
final int? iceCandidatePoolSize;
final List<RTCIceServer>? iceServers;
final RTCIceTransportPolicy? iceTransportPolicy;
const RTCConfiguration({
this.iceCandidatePoolSize,
this.iceServers,
this.iceTransportPolicy,
});
Map<String, dynamic> toMap() {
final iceServersMap = <Map<String, dynamic>>[
if (iceServers != null)
for (final e in iceServers!) e.toMap()
];
return <String, dynamic>{
// only supports unified plan
'sdpSemantics': 'unified-plan',
if (iceServersMap.isNotEmpty) 'iceServers': iceServersMap,
if (iceCandidatePoolSize != null)
'iceCandidatePoolSize': iceCandidatePoolSize,
if (iceTransportPolicy != null)
'iceTransportPolicy': iceTransportPolicy!.toStringValue(),
};
}
// Returns new options with updated properties
RTCConfiguration copyWith({
int? iceCandidatePoolSize,
List<RTCIceServer>? iceServers,
RTCIceTransportPolicy? iceTransportPolicy,
}) =>
RTCConfiguration(
iceCandidatePoolSize: iceCandidatePoolSize ?? this.iceCandidatePoolSize,
iceServers: iceServers ?? this.iceServers,
iceTransportPolicy: iceTransportPolicy ?? this.iceTransportPolicy,
);
}
@immutable
class RTCIceServer {
final List<String>? urls;
final String? username;
final String? credential;
const RTCIceServer({
this.urls,
this.username,
this.credential,
});
Map<String, dynamic> toMap() => <String, dynamic>{
if (urls?.isNotEmpty ?? false) 'urls': urls,
if (username?.isNotEmpty ?? false) 'username': username,
if (credential?.isNotEmpty ?? false) 'credential': credential,
};
}
@immutable
class VideoDimensions {
final int width;
final int height;
const VideoDimensions(
this.width,
this.height,
);
@override
String toString() => 'VideoDimensions(${width}×${height})';
/// Returns the larger value
int max() => math.max(width, height);
VideoDimensions copyWith({
int? width,
int? height,
}) =>
VideoDimensions(
width ?? this.width,
height ?? this.height,
);
}