Skip to content

Commit aa65b57

Browse files
committed
WebRtc Client. Introduce Native engine based on WebRTC.rs and Gobley. Works only for jvm and separated into different submodule for now.
1 parent 5f39fed commit aa65b57

File tree

36 files changed

+8073
-28
lines changed

36 files changed

+8073
-28
lines changed

ktor-client/ktor-client-webrtc/android/src/io/ktor/client/webrtc/DataChannel.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ public class AndroidWebRtcDataChannel(
7272
bufferedAmountLowThreshold = threshold
7373
}
7474

75-
override fun close() {
76-
nativeChannel.close()
75+
override fun closeTransport() {
76+
nativeChannel.dispose()
7777
}
7878

7979
internal fun setupEvents(eventsEmitter: WebRtcConnectionEventsEmitter) {
@@ -116,7 +116,7 @@ public class AndroidWebRtcDataChannel(
116116

117117
override fun onBufferedAmountChange(previousAmount: Long) {
118118
coroutineScope.launch(start = CoroutineStart.UNDISPATCHED) {
119-
if (previousAmount > bufferedAmountLowThreshold && bufferedAmountLowThreshold > bufferedAmount) {
119+
if (bufferedAmountLowThreshold in (bufferedAmount + 1)..<previousAmount) {
120120
return@launch
121121
}
122122
val event = DataChannelEvent.BufferedAmountLow(this@AndroidWebRtcDataChannel)

ktor-client/ktor-client-webrtc/api/android/ktor-client-webrtc.api

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public final class io/ktor/client/webrtc/AndroidWebRtc : io/ktor/client/webrtc/W
3434

3535
public final class io/ktor/client/webrtc/AndroidWebRtcDataChannel : io/ktor/client/webrtc/WebRtcDataChannel {
3636
public fun <init> (Lorg/webrtc/DataChannel;Lorg/webrtc/DataChannel$Init;Lkotlinx/coroutines/CoroutineScope;Lio/ktor/client/webrtc/DataChannelReceiveOptions;)V
37-
public fun close ()V
37+
public fun closeTransport ()V
3838
public fun getBufferedAmount ()J
3939
public fun getBufferedAmountLowThreshold ()J
4040
public fun getId ()I
@@ -196,7 +196,8 @@ public final class io/ktor/client/webrtc/WebRtc$ConnectionState : java/lang/Enum
196196
}
197197

198198
public abstract interface class io/ktor/client/webrtc/WebRtc$DataChannel : java/lang/AutoCloseable {
199-
public abstract fun close ()V
199+
public fun close ()V
200+
public abstract fun closeTransport ()V
200201
public abstract fun getBufferedAmount ()J
201202
public abstract fun getBufferedAmountLowThreshold ()J
202203
public abstract fun getId ()I
@@ -218,6 +219,10 @@ public abstract interface class io/ktor/client/webrtc/WebRtc$DataChannel : java/
218219
public abstract fun tryReceiveText ()Ljava/lang/String;
219220
}
220221

222+
public final class io/ktor/client/webrtc/WebRtc$DataChannel$DefaultImpls {
223+
public static fun close (Lio/ktor/client/webrtc/WebRtc$DataChannel;)V
224+
}
225+
221226
public abstract interface class io/ktor/client/webrtc/WebRtc$DataChannel$Message {
222227
public fun binaryOrNull ()[B
223228
public fun binaryOrThrow ()[B
@@ -545,8 +550,32 @@ public abstract interface class io/ktor/client/webrtc/WebRtcConnectionEvents {
545550
public abstract fun getTrackEvents ()Lkotlinx/coroutines/flow/SharedFlow;
546551
}
547552

553+
public final class io/ktor/client/webrtc/WebRtcConnectionEventsEmitter : io/ktor/client/webrtc/WebRtcConnectionEvents {
554+
public fun <init> (Lio/ktor/client/webrtc/WebRtcConnectionConfig;)V
555+
public final fun emitAddTrack (Lio/ktor/client/webrtc/WebRtcMedia$Track;)V
556+
public final fun emitConnectionStateChange (Lio/ktor/client/webrtc/WebRtc$ConnectionState;)V
557+
public final fun emitDataChannelEvent (Lio/ktor/client/webrtc/DataChannelEvent;)V
558+
public final fun emitIceCandidate (Lio/ktor/client/webrtc/WebRtc$IceCandidate;)V
559+
public final fun emitIceConnectionStateChange (Lio/ktor/client/webrtc/WebRtc$IceConnectionState;)V
560+
public final fun emitIceGatheringStateChange (Lio/ktor/client/webrtc/WebRtc$IceGatheringState;)V
561+
public final fun emitNegotiationNeeded ()V
562+
public final fun emitRemoveTrack (Lio/ktor/client/webrtc/WebRtcMedia$Track;)V
563+
public final fun emitSignalingStateChange (Lio/ktor/client/webrtc/WebRtc$SignalingState;)V
564+
public final fun emitStats (Ljava/util/List;)V
565+
public fun getDataChannelEvents ()Lkotlinx/coroutines/flow/SharedFlow;
566+
public fun getIceCandidates ()Lkotlinx/coroutines/flow/SharedFlow;
567+
public fun getIceConnectionState ()Lkotlinx/coroutines/flow/StateFlow;
568+
public fun getIceGatheringState ()Lkotlinx/coroutines/flow/StateFlow;
569+
public fun getNegotiationNeeded ()Lkotlinx/coroutines/flow/SharedFlow;
570+
public fun getSignalingState ()Lkotlinx/coroutines/flow/StateFlow;
571+
public fun getState ()Lkotlinx/coroutines/flow/StateFlow;
572+
public fun getStats ()Lkotlinx/coroutines/flow/StateFlow;
573+
public fun getTrackEvents ()Lkotlinx/coroutines/flow/SharedFlow;
574+
}
575+
548576
public abstract class io/ktor/client/webrtc/WebRtcDataChannel : io/ktor/client/webrtc/WebRtc$DataChannel {
549577
public fun <init> (Lio/ktor/client/webrtc/DataChannelReceiveOptions;)V
578+
public fun close ()V
550579
protected final fun emitMessage-JP2dKIU (Lio/ktor/client/webrtc/WebRtc$DataChannel$Message;)Ljava/lang/Object;
551580
public fun receive (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
552581
public fun receiveBinary (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
@@ -712,13 +741,15 @@ public abstract class io/ktor/client/webrtc/WebRtcPeerConnection : io/ktor/clien
712741
public fun <init> (Lkotlin/coroutines/CoroutineContext;Lio/ktor/client/webrtc/WebRtcConnectionConfig;)V
713742
public abstract fun addIceCandidate (Lio/ktor/client/webrtc/WebRtc$IceCandidate;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
714743
public abstract fun addTrack (Lio/ktor/client/webrtc/WebRtcMedia$Track;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
744+
public final fun awaitIceGatheringComplete (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
715745
public fun close ()V
716746
public abstract fun createAnswer (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
717747
public abstract fun createDataChannel (Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
718748
public static synthetic fun createDataChannel$default (Lio/ktor/client/webrtc/WebRtcPeerConnection;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
719749
public abstract fun createOffer (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
720750
protected final fun getCoroutineScope ()Lkotlinx/coroutines/CoroutineScope;
721751
public fun getDataChannelEvents ()Lkotlinx/coroutines/flow/SharedFlow;
752+
protected final fun getEvents ()Lio/ktor/client/webrtc/WebRtcConnectionEventsEmitter;
722753
public fun getIceCandidates ()Lkotlinx/coroutines/flow/SharedFlow;
723754
public fun getIceConnectionState ()Lkotlinx/coroutines/flow/StateFlow;
724755
public fun getIceGatheringState ()Lkotlinx/coroutines/flow/StateFlow;

ktor-client/ktor-client-webrtc/api/jvm/ktor-client-webrtc.api

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ public final class io/ktor/client/webrtc/WebRtc$ConnectionState : java/lang/Enum
9494
}
9595

9696
public abstract interface class io/ktor/client/webrtc/WebRtc$DataChannel : java/lang/AutoCloseable {
97-
public abstract fun close ()V
97+
public fun close ()V
98+
public abstract fun closeTransport ()V
9899
public abstract fun getBufferedAmount ()J
99100
public abstract fun getBufferedAmountLowThreshold ()J
100101
public abstract fun getId ()I
@@ -116,6 +117,10 @@ public abstract interface class io/ktor/client/webrtc/WebRtc$DataChannel : java/
116117
public abstract fun tryReceiveText ()Ljava/lang/String;
117118
}
118119

120+
public final class io/ktor/client/webrtc/WebRtc$DataChannel$DefaultImpls {
121+
public static fun close (Lio/ktor/client/webrtc/WebRtc$DataChannel;)V
122+
}
123+
119124
public abstract interface class io/ktor/client/webrtc/WebRtc$DataChannel$Message {
120125
public fun binaryOrNull ()[B
121126
public fun binaryOrThrow ()[B
@@ -443,8 +448,32 @@ public abstract interface class io/ktor/client/webrtc/WebRtcConnectionEvents {
443448
public abstract fun getTrackEvents ()Lkotlinx/coroutines/flow/SharedFlow;
444449
}
445450

451+
public final class io/ktor/client/webrtc/WebRtcConnectionEventsEmitter : io/ktor/client/webrtc/WebRtcConnectionEvents {
452+
public fun <init> (Lio/ktor/client/webrtc/WebRtcConnectionConfig;)V
453+
public final fun emitAddTrack (Lio/ktor/client/webrtc/WebRtcMedia$Track;)V
454+
public final fun emitConnectionStateChange (Lio/ktor/client/webrtc/WebRtc$ConnectionState;)V
455+
public final fun emitDataChannelEvent (Lio/ktor/client/webrtc/DataChannelEvent;)V
456+
public final fun emitIceCandidate (Lio/ktor/client/webrtc/WebRtc$IceCandidate;)V
457+
public final fun emitIceConnectionStateChange (Lio/ktor/client/webrtc/WebRtc$IceConnectionState;)V
458+
public final fun emitIceGatheringStateChange (Lio/ktor/client/webrtc/WebRtc$IceGatheringState;)V
459+
public final fun emitNegotiationNeeded ()V
460+
public final fun emitRemoveTrack (Lio/ktor/client/webrtc/WebRtcMedia$Track;)V
461+
public final fun emitSignalingStateChange (Lio/ktor/client/webrtc/WebRtc$SignalingState;)V
462+
public final fun emitStats (Ljava/util/List;)V
463+
public fun getDataChannelEvents ()Lkotlinx/coroutines/flow/SharedFlow;
464+
public fun getIceCandidates ()Lkotlinx/coroutines/flow/SharedFlow;
465+
public fun getIceConnectionState ()Lkotlinx/coroutines/flow/StateFlow;
466+
public fun getIceGatheringState ()Lkotlinx/coroutines/flow/StateFlow;
467+
public fun getNegotiationNeeded ()Lkotlinx/coroutines/flow/SharedFlow;
468+
public fun getSignalingState ()Lkotlinx/coroutines/flow/StateFlow;
469+
public fun getState ()Lkotlinx/coroutines/flow/StateFlow;
470+
public fun getStats ()Lkotlinx/coroutines/flow/StateFlow;
471+
public fun getTrackEvents ()Lkotlinx/coroutines/flow/SharedFlow;
472+
}
473+
446474
public abstract class io/ktor/client/webrtc/WebRtcDataChannel : io/ktor/client/webrtc/WebRtc$DataChannel {
447475
public fun <init> (Lio/ktor/client/webrtc/DataChannelReceiveOptions;)V
476+
public fun close ()V
448477
protected final fun emitMessage-JP2dKIU (Lio/ktor/client/webrtc/WebRtc$DataChannel$Message;)Ljava/lang/Object;
449478
public fun receive (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
450479
public fun receiveBinary (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
@@ -610,13 +639,15 @@ public abstract class io/ktor/client/webrtc/WebRtcPeerConnection : io/ktor/clien
610639
public fun <init> (Lkotlin/coroutines/CoroutineContext;Lio/ktor/client/webrtc/WebRtcConnectionConfig;)V
611640
public abstract fun addIceCandidate (Lio/ktor/client/webrtc/WebRtc$IceCandidate;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
612641
public abstract fun addTrack (Lio/ktor/client/webrtc/WebRtcMedia$Track;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
642+
public final fun awaitIceGatheringComplete (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
613643
public fun close ()V
614644
public abstract fun createAnswer (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
615645
public abstract fun createDataChannel (Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
616646
public static synthetic fun createDataChannel$default (Lio/ktor/client/webrtc/WebRtcPeerConnection;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
617647
public abstract fun createOffer (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
618648
protected final fun getCoroutineScope ()Lkotlinx/coroutines/CoroutineScope;
619649
public fun getDataChannelEvents ()Lkotlinx/coroutines/flow/SharedFlow;
650+
protected final fun getEvents ()Lio/ktor/client/webrtc/WebRtcConnectionEventsEmitter;
620651
public fun getIceCandidates ()Lkotlinx/coroutines/flow/SharedFlow;
621652
public fun getIceConnectionState ()Lkotlinx/coroutines/flow/StateFlow;
622653
public fun getIceGatheringState ()Lkotlinx/coroutines/flow/StateFlow;

0 commit comments

Comments
 (0)