Skip to content

Commit e65eb5b

Browse files
PerondasPerondas
andauthored
Add sdp transformers (#350)
* Added custom options to call() * Added offer modification ability to _createLocalDescription() --------- Co-authored-by: Perondas <Pperondas@gmail.com>
1 parent 1f7a3e6 commit e65eb5b

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

lib/src/map_helper.dart

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class MapHelper {
2+
/// Merge two maps recursively. If the same key exists in both maps, the value
3+
/// from the second map will be used. If the value is a map, the merge will be
4+
/// recursive. Sub-maps also have to have their keys be of type [K].
5+
static Map<K, dynamic> merge<K>(Map<K, dynamic> a, Map<K, dynamic> b) {
6+
for (K key in b.keys) {
7+
if (a.containsKey(key)) {
8+
if (a[key] is Map && b[key] is Map) {
9+
a[key] = merge(a[key] as Map<K, dynamic>, b[key] as Map<K, dynamic>);
10+
} else {
11+
a[key] = b[key]!;
12+
}
13+
} else {
14+
a[key] = b[key]!;
15+
}
16+
}
17+
18+
return a;
19+
}
20+
}

lib/src/rtc_session.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1608,6 +1608,12 @@ class RTCSession extends EventManager implements Owner {
16081608
Completer<RTCSessionDescription> completer =
16091609
Completer<RTCSessionDescription>();
16101610

1611+
List<Future<RTCSessionDescription> Function(RTCSessionDescription)>
1612+
_modifiers = constraints?['offerModifiers'] ??
1613+
<Future<RTCSessionDescription> Function(RTCSessionDescription)>[];
1614+
1615+
constraints?['offerModifier'] = null;
1616+
16111617
if (type != 'offer' && type != 'answer') {
16121618
completer.completeError(Exceptions.TypeError(
16131619
'createLocalDescription() | invalid type "$type"'));
@@ -1638,6 +1644,11 @@ class RTCSession extends EventManager implements Owner {
16381644
// Add 'pc.onicencandidate' event handler to resolve on last candidate.
16391645
bool finished = false;
16401646

1647+
for (Future<RTCSessionDescription> Function(RTCSessionDescription) modifier
1648+
in _modifiers) {
1649+
desc = await modifier(desc);
1650+
}
1651+
16411652
Future<void> ready() async {
16421653
if (!finished && _status != C.STATUS_TERMINATED) {
16431654
finished = true;

lib/src/sip_ua_helper.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'dart:async';
22

33
import 'package:flutter_webrtc/flutter_webrtc.dart';
44
import 'package:logger/logger.dart';
5+
import 'package:sip_ua/src/map_helper.dart';
56

67
import 'config.dart';
78
import 'constants.dart' as DartSIP_C;
@@ -84,9 +85,13 @@ class SIPUAHelper extends EventManager {
8485
Future<bool> call(String target,
8586
{bool voiceonly = false,
8687
MediaStream? mediaStream,
87-
List<String>? headers}) async {
88+
List<String>? headers,
89+
Map<String, dynamic>? customOptions}) async {
8890
if (_ua != null && _ua!.isConnected()) {
8991
Map<String, dynamic> options = buildCallOptions(voiceonly);
92+
if (customOptions != null) {
93+
options = MapHelper.merge(options, customOptions);
94+
}
9095
if (mediaStream != null) {
9196
options['mediaStream'] = mediaStream;
9297
}

0 commit comments

Comments
 (0)