Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds auto-answer mode to sipgw, activated through http-api. #225

Merged
merged 5 commits into from Oct 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -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 {
bbaldino marked this conversation as resolved.
Show resolved Hide resolved
getNumParticipants() == 1
}

return when (result) {
is String -> false
else -> true
Expand Down
Expand Up @@ -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(
Expand All @@ -44,7 +45,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
Expand All @@ -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"))
)
/**
Expand Down Expand Up @@ -85,8 +88,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 {
bbaldino marked this conversation as resolved.
Show resolved Hide resolved
whenever(jibriSelenium).transitionsTo(ComponentState.Running) {
pjsuaClient.start()
}
}
}

Expand Down
7 changes: 6 additions & 1 deletion src/main/kotlin/org/jitsi/jibri/sipgateway/SipClient.kt
Expand Up @@ -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<ComponentState>() {
Expand Down
12 changes: 10 additions & 2 deletions src/main/kotlin/org/jitsi/jibri/sipgateway/pjsua/PjsuaClient.kt
Expand Up @@ -59,15 +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} <sip:jibri@127.0.0.1>",
"--config-file", CONFIG_FILE_LOCATION,
"--log-file", "/tmp/pjsua.out",
"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))
}

Expand Down