davidliu
Committed by GitHub

debounce negotiations with a timer of 0.1s to fix failing connect (#13)

@@ -68,7 +68,14 @@ constructor( @@ -68,7 +68,14 @@ constructor(
68 return result 68 return result
69 } 69 }
70 70
71 - val negotiate = debounce<Unit, Unit>(100, coroutineScope) { createAndSendOffer() } 71 + val negotiate = debounce<MediaConstraints?, Unit>(100, coroutineScope) {
  72 + if (it != null) {
  73 + createAndSendOffer(it)
  74 + } else {
  75 + createAndSendOffer()
  76 + }
  77 + }
  78 +
72 suspend fun createAndSendOffer(constraints: MediaConstraints = MediaConstraints()) { 79 suspend fun createAndSendOffer(constraints: MediaConstraints = MediaConstraints()) {
73 if (listener == null) { 80 if (listener == null) {
74 return 81 return
@@ -272,7 +272,7 @@ internal constructor( @@ -272,7 +272,7 @@ internal constructor(
272 subscriber.prepareForIceRestart() 272 subscriber.prepareForIceRestart()
273 // only restart publisher if it's needed 273 // only restart publisher if it's needed
274 if (hasPublished) { 274 if (hasPublished) {
275 - publisher.createAndSendOffer( 275 + publisher.negotiate(
276 getPublisherOfferConstraints().apply { 276 getPublisherOfferConstraints().apply {
277 with(mandatory){ 277 with(mandatory){
278 add( 278 add(
@@ -294,7 +294,7 @@ internal constructor( @@ -294,7 +294,7 @@ internal constructor(
294 return 294 return
295 } 295 }
296 coroutineScope.launch { 296 coroutineScope.launch {
297 - publisher.createAndSendOffer(getPublisherOfferConstraints()) 297 + publisher.negotiate(getPublisherOfferConstraints())
298 } 298 }
299 } 299 }
300 300