From ef2c379b4a65828be2d1ac27ef623baf4509f346 Mon Sep 17 00:00:00 2001 From: damencho Date: Mon, 30 Sep 2019 12:20:25 +0100 Subject: [PATCH 1/5] Waits for leave to finish. --- .../org/jitsi/jibri/selenium/pageobjects/CallPage.kt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/kotlin/org/jitsi/jibri/selenium/pageobjects/CallPage.kt b/src/main/kotlin/org/jitsi/jibri/selenium/pageobjects/CallPage.kt index b84da920..ffe11922 100644 --- a/src/main/kotlin/org/jitsi/jibri/selenium/pageobjects/CallPage.kt +++ b/src/main/kotlin/org/jitsi/jibri/selenium/pageobjects/CallPage.kt @@ -222,6 +222,13 @@ class CallPage(driver: RemoteWebDriver) : AbstractPageObject(driver) { return e.message; } """.trimMargin()) + + // Let's wait till we are alone in the room + // (give time for the js Promise to finish before quiting selenium) + WebDriverWait(driver, 2).until { + getNumParticipants() == 1 + } + return when (result) { is String -> false else -> true From 9d3fdf595d46f4077e61cdd8bccc69e0db3e24fb Mon Sep 17 00:00:00 2001 From: damencho Date: Mon, 30 Sep 2019 12:25:49 +0100 Subject: [PATCH 2/5] Adds auto-answer mode to sipgw, activated through http-api. --- .../org/jitsi/jibri/service/impl/SipGatewayJibriService.kt | 2 +- src/main/kotlin/org/jitsi/jibri/sipgateway/SipClient.kt | 7 ++++++- .../kotlin/org/jitsi/jibri/sipgateway/pjsua/PjsuaClient.kt | 4 +++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/org/jitsi/jibri/service/impl/SipGatewayJibriService.kt b/src/main/kotlin/org/jitsi/jibri/service/impl/SipGatewayJibriService.kt index 19f5b877..d547d163 100644 --- a/src/main/kotlin/org/jitsi/jibri/service/impl/SipGatewayJibriService.kt +++ b/src/main/kotlin/org/jitsi/jibri/service/impl/SipGatewayJibriService.kt @@ -44,7 +44,7 @@ data class SipGatewayServiceParams( /** * A [JibriService] responsible for joining both a web call * and a SIP call, capturing the audio and video from each, and - * forwarding thenm to the other side. + * forwarding them to the other side. */ class SipGatewayJibriService( private val sipGatewayServiceParams: SipGatewayServiceParams diff --git a/src/main/kotlin/org/jitsi/jibri/sipgateway/SipClient.kt b/src/main/kotlin/org/jitsi/jibri/sipgateway/SipClient.kt index 2f104676..33ac1c81 100644 --- a/src/main/kotlin/org/jitsi/jibri/sipgateway/SipClient.kt +++ b/src/main/kotlin/org/jitsi/jibri/sipgateway/SipClient.kt @@ -29,7 +29,12 @@ data class SipClientParams( * The display name we'll use for the web conference * in the pjsua call */ - val displayName: String = "" + val displayName: String = "", + /** + * Whether auto-answer is enabled, if it is, the client will listen for + * incoming invites and will auto answer the first one. + */ + val autoAnswer: Boolean = false ) abstract class SipClient : StatusPublisher() { diff --git a/src/main/kotlin/org/jitsi/jibri/sipgateway/pjsua/PjsuaClient.kt b/src/main/kotlin/org/jitsi/jibri/sipgateway/pjsua/PjsuaClient.kt index 945efd3e..27e1357a 100644 --- a/src/main/kotlin/org/jitsi/jibri/sipgateway/pjsua/PjsuaClient.kt +++ b/src/main/kotlin/org/jitsi/jibri/sipgateway/pjsua/PjsuaClient.kt @@ -66,7 +66,9 @@ class PjsuaClient(private val pjsuaClientParams: PjsuaClientParams) : SipClient( "--id", "${pjsuaClientParams.sipClientParams.displayName} ", "--config-file", CONFIG_FILE_LOCATION, "--log-file", "/tmp/pjsua.out", - "sip:${pjsuaClientParams.sipClientParams.sipAddress}" + "--max-calls=1", + if (pjsuaClientParams.sipClientParams.autoAnswer) + "--auto-answer=200" else "sip:${pjsuaClientParams.sipClientParams.sipAddress}" ) pjsua.launch(command, mapOf("DISPLAY" to X_DISPLAY)) } From f3c0a968eea93313035a4bf88b0ad12573a1ec1e Mon Sep 17 00:00:00 2001 From: damencho Date: Fri, 4 Oct 2019 14:10:58 +0100 Subject: [PATCH 3/5] Adds auto-answer-timer parameter. --- .../jitsi/jibri/sipgateway/pjsua/PjsuaClient.kt | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/org/jitsi/jibri/sipgateway/pjsua/PjsuaClient.kt b/src/main/kotlin/org/jitsi/jibri/sipgateway/pjsua/PjsuaClient.kt index 27e1357a..846fae31 100644 --- a/src/main/kotlin/org/jitsi/jibri/sipgateway/pjsua/PjsuaClient.kt +++ b/src/main/kotlin/org/jitsi/jibri/sipgateway/pjsua/PjsuaClient.kt @@ -59,17 +59,23 @@ class PjsuaClient(private val pjsuaClientParams: PjsuaClientParams) : SipClient( } override fun start() { - val command = listOf( + val command = mutableListOf( "pjsua", "--capture-dev=$CAPTURE_DEVICE", "--playback-dev=$PLAYBACK_DEVICE", "--id", "${pjsuaClientParams.sipClientParams.displayName} ", "--config-file", CONFIG_FILE_LOCATION, "--log-file", "/tmp/pjsua.out", - "--max-calls=1", - if (pjsuaClientParams.sipClientParams.autoAnswer) - "--auto-answer=200" else "sip:${pjsuaClientParams.sipClientParams.sipAddress}" + "--max-calls=1" ) + + if (pjsuaClientParams.sipClientParams.autoAnswer) { + command.add("--auto-answer-timer=30") + command.add("--auto-answer=200") + } else { + command.add("sip:${pjsuaClientParams.sipClientParams.sipAddress}") + } + pjsua.launch(command, mapOf("DISPLAY" to X_DISPLAY)) } From c34b6a6f0a6422ef6244f10d7166212e93989910 Mon Sep 17 00:00:00 2001 From: damencho Date: Tue, 15 Oct 2019 15:16:51 +0100 Subject: [PATCH 4/5] Start pjsua as quick as possible when in autoAnswer mode. We try to start pjsua even before http api start call returns. --- .../jitsi/jibri/service/impl/SipGatewayJibriService.kt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/org/jitsi/jibri/service/impl/SipGatewayJibriService.kt b/src/main/kotlin/org/jitsi/jibri/service/impl/SipGatewayJibriService.kt index d547d163..0eac1acb 100644 --- a/src/main/kotlin/org/jitsi/jibri/service/impl/SipGatewayJibriService.kt +++ b/src/main/kotlin/org/jitsi/jibri/service/impl/SipGatewayJibriService.kt @@ -85,8 +85,15 @@ class SipGatewayJibriService( override fun start() { jibriSelenium.joinCall( sipGatewayServiceParams.callParams.callUrlInfo.copy(urlParams = SIP_GW_URL_OPTIONS)) - whenever(jibriSelenium).transitionsTo(ComponentState.Running) { + + // when in auto-answer mode we want to start as quick as possible as + // we will be waiting for a sip call to come + if (sipGatewayServiceParams.sipClientParams.autoAnswer) { pjsuaClient.start() + } else { + whenever(jibriSelenium).transitionsTo(ComponentState.Running) { + pjsuaClient.start() + } } } From a4c679d9d61634d3800cab852ff1feff31d5f867 Mon Sep 17 00:00:00 2001 From: damencho Date: Wed, 16 Oct 2019 12:40:16 +0100 Subject: [PATCH 5/5] Waits alone in the call for 30 minutes for sip calls. --- .../org/jitsi/jibri/service/impl/SipGatewayJibriService.kt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/kotlin/org/jitsi/jibri/service/impl/SipGatewayJibriService.kt b/src/main/kotlin/org/jitsi/jibri/service/impl/SipGatewayJibriService.kt index 0eac1acb..f60a7513 100644 --- a/src/main/kotlin/org/jitsi/jibri/service/impl/SipGatewayJibriService.kt +++ b/src/main/kotlin/org/jitsi/jibri/service/impl/SipGatewayJibriService.kt @@ -27,6 +27,7 @@ import org.jitsi.jibri.sipgateway.pjsua.PjsuaClient import org.jitsi.jibri.sipgateway.pjsua.PjsuaClientParams import org.jitsi.jibri.status.ComponentState import org.jitsi.jibri.util.whenever +import java.time.Duration import java.util.concurrent.ScheduledFuture data class SipGatewayServiceParams( @@ -55,6 +56,8 @@ class SipGatewayJibriService( private val jibriSelenium = JibriSelenium( JibriSeleniumOptions( displayName = sipGatewayServiceParams.sipClientParams.displayName, + // by default we wait 30 minutes alone in the call before deciding to hangup + emptyCallTimeout = Duration.ofMinutes(30), extraChromeCommandLineFlags = listOf("--alsa-input-device=plughw:1,1")) ) /**