feat: Working VoIP calling implementation (Flutter + Android)
Working video and audio calls, as well as android integration
This commit is contained in:
commit
96a7e211a0
60 changed files with 2445 additions and 0 deletions
9
android/.gitignore
vendored
Normal file
9
android/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
*.iml
|
||||
.gradle
|
||||
/local.properties
|
||||
/.idea/workspace.xml
|
||||
/.idea/libraries
|
||||
.DS_Store
|
||||
/build
|
||||
/captures
|
||||
.cxx
|
||||
68
android/build.gradle
Normal file
68
android/build.gradle
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
group = "xyz.nuark.liblinphone_flutter"
|
||||
version = "1.0-SNAPSHOT"
|
||||
|
||||
buildscript {
|
||||
ext.kotlin_version = "2.1.0"
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
classpath("com.android.tools.build:gradle:8.9.1")
|
||||
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version")
|
||||
}
|
||||
}
|
||||
|
||||
allprojects {
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: "com.android.library"
|
||||
apply plugin: "kotlin-android"
|
||||
|
||||
android {
|
||||
namespace = "xyz.nuark.liblinphone_flutter"
|
||||
|
||||
compileSdk = 36
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility = JavaVersion.VERSION_11
|
||||
targetCompatibility = JavaVersion.VERSION_11
|
||||
}
|
||||
|
||||
kotlinOptions {
|
||||
jvmTarget = JavaVersion.VERSION_11
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
main.java.srcDirs += "src/main/kotlin"
|
||||
test.java.srcDirs += "src/test/kotlin"
|
||||
}
|
||||
|
||||
defaultConfig {
|
||||
minSdk = 24
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(files("libs/linphone-sdk-android-5.2.0.aar"))
|
||||
|
||||
testImplementation("org.jetbrains.kotlin:kotlin-test")
|
||||
testImplementation("org.mockito:mockito-core:5.0.0")
|
||||
}
|
||||
|
||||
testOptions {
|
||||
unitTests.all {
|
||||
useJUnitPlatform()
|
||||
|
||||
testLogging {
|
||||
events "passed", "skipped", "failed", "standardOut", "standardError"
|
||||
outputs.upToDateWhen {false}
|
||||
showStandardStreams = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
android/gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
BIN
android/gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
Binary file not shown.
7
android/gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
7
android/gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-9.0-milestone-1-bin.zip
|
||||
networkTimeout=10000
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
251
android/gradlew
vendored
Normal file
251
android/gradlew
vendored
Normal file
|
|
@ -0,0 +1,251 @@
|
|||
#!/bin/sh
|
||||
|
||||
#
|
||||
# Copyright © 2015-2021 the original authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# Gradle start up script for POSIX generated by Gradle.
|
||||
#
|
||||
# Important for running:
|
||||
#
|
||||
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
|
||||
# noncompliant, but you have some other compliant shell such as ksh or
|
||||
# bash, then to run this script, type that shell name before the whole
|
||||
# command line, like:
|
||||
#
|
||||
# ksh Gradle
|
||||
#
|
||||
# Busybox and similar reduced shells will NOT work, because this script
|
||||
# requires all of these POSIX shell features:
|
||||
# * functions;
|
||||
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
|
||||
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
|
||||
# * compound commands having a testable exit status, especially «case»;
|
||||
# * various built-in commands including «command», «set», and «ulimit».
|
||||
#
|
||||
# Important for patching:
|
||||
#
|
||||
# (2) This script targets any POSIX shell, so it avoids extensions provided
|
||||
# by Bash, Ksh, etc; in particular arrays are avoided.
|
||||
#
|
||||
# The "traditional" practice of packing multiple parameters into a
|
||||
# space-separated string is a well documented source of bugs and security
|
||||
# problems, so this is (mostly) avoided, by progressively accumulating
|
||||
# options in "$@", and eventually passing that to Java.
|
||||
#
|
||||
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
|
||||
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
|
||||
# see the in-line comments for details.
|
||||
#
|
||||
# There are tweaks for specific operating systems such as AIX, CygWin,
|
||||
# Darwin, MinGW, and NonStop.
|
||||
#
|
||||
# (3) This script is generated from the Groovy template
|
||||
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# within the Gradle project.
|
||||
#
|
||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
|
||||
# Resolve links: $0 may be a link
|
||||
app_path=$0
|
||||
|
||||
# Need this for daisy-chained symlinks.
|
||||
while
|
||||
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
|
||||
[ -h "$app_path" ]
|
||||
do
|
||||
ls=$( ls -ld "$app_path" )
|
||||
link=${ls#*' -> '}
|
||||
case $link in #(
|
||||
/*) app_path=$link ;; #(
|
||||
*) app_path=$APP_HOME$link ;;
|
||||
esac
|
||||
done
|
||||
|
||||
# This is normally unused
|
||||
# shellcheck disable=SC2034
|
||||
APP_BASE_NAME=${0##*/}
|
||||
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
||||
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD=maximum
|
||||
|
||||
warn () {
|
||||
echo "$*"
|
||||
} >&2
|
||||
|
||||
die () {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
} >&2
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
nonstop=false
|
||||
case "$( uname )" in #(
|
||||
CYGWIN* ) cygwin=true ;; #(
|
||||
Darwin* ) darwin=true ;; #(
|
||||
MSYS* | MINGW* ) msys=true ;; #(
|
||||
NONSTOP* ) nonstop=true ;;
|
||||
esac
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||
# IBM's JDK on AIX uses strange locations for the executables
|
||||
JAVACMD=$JAVA_HOME/jre/sh/java
|
||||
else
|
||||
JAVACMD=$JAVA_HOME/bin/java
|
||||
fi
|
||||
if [ ! -x "$JAVACMD" ] ; then
|
||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
else
|
||||
JAVACMD=java
|
||||
if ! command -v java >/dev/null 2>&1
|
||||
then
|
||||
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||
case $MAX_FD in #(
|
||||
max*)
|
||||
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
||||
# shellcheck disable=SC2039,SC3045
|
||||
MAX_FD=$( ulimit -H -n ) ||
|
||||
warn "Could not query maximum file descriptor limit"
|
||||
esac
|
||||
case $MAX_FD in #(
|
||||
'' | soft) :;; #(
|
||||
*)
|
||||
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
||||
# shellcheck disable=SC2039,SC3045
|
||||
ulimit -n "$MAX_FD" ||
|
||||
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||
esac
|
||||
fi
|
||||
|
||||
# Collect all arguments for the java command, stacking in reverse order:
|
||||
# * args from the command line
|
||||
# * the main class name
|
||||
# * -classpath
|
||||
# * -D...appname settings
|
||||
# * --module-path (only if needed)
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
|
||||
|
||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||
if "$cygwin" || "$msys" ; then
|
||||
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
||||
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
|
||||
|
||||
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
||||
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
for arg do
|
||||
if
|
||||
case $arg in #(
|
||||
-*) false ;; # don't mess with options #(
|
||||
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
|
||||
[ -e "$t" ] ;; #(
|
||||
*) false ;;
|
||||
esac
|
||||
then
|
||||
arg=$( cygpath --path --ignore --mixed "$arg" )
|
||||
fi
|
||||
# Roll the args list around exactly as many times as the number of
|
||||
# args, so each arg winds up back in the position where it started, but
|
||||
# possibly modified.
|
||||
#
|
||||
# NB: a `for` loop captures its iteration list before it begins, so
|
||||
# changing the positional parameters here affects neither the number of
|
||||
# iterations, nor the values presented in `arg`.
|
||||
shift # remove old arg
|
||||
set -- "$@" "$arg" # push replacement arg
|
||||
done
|
||||
fi
|
||||
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
|
||||
# Collect all arguments for the java command:
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
||||
# and any embedded shellness will be escaped.
|
||||
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
|
||||
# treated as '${Hostname}' itself on the command line.
|
||||
|
||||
set -- \
|
||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||
-classpath "$CLASSPATH" \
|
||||
org.gradle.wrapper.GradleWrapperMain \
|
||||
"$@"
|
||||
|
||||
# Stop when "xargs" is not available.
|
||||
if ! command -v xargs >/dev/null 2>&1
|
||||
then
|
||||
die "xargs is not available"
|
||||
fi
|
||||
|
||||
# Use "xargs" to parse quoted args.
|
||||
#
|
||||
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
||||
#
|
||||
# In Bash we could simply go:
|
||||
#
|
||||
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
|
||||
# set -- "${ARGS[@]}" "$@"
|
||||
#
|
||||
# but POSIX shell has neither arrays nor command substitution, so instead we
|
||||
# post-process each arg (as a line of input to sed) to backslash-escape any
|
||||
# character that might be a shell metacharacter, then use eval to reverse
|
||||
# that process (while maintaining the separation between arguments), and wrap
|
||||
# the whole thing up as a single "set" statement.
|
||||
#
|
||||
# This will of course break if any of these variables contains a newline or
|
||||
# an unmatched quote.
|
||||
#
|
||||
|
||||
eval "set -- $(
|
||||
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
|
||||
xargs -n1 |
|
||||
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
|
||||
tr '\n' ' '
|
||||
)" '"$@"'
|
||||
|
||||
exec "$JAVACMD" "$@"
|
||||
94
android/gradlew.bat
vendored
Normal file
94
android/gradlew.bat
vendored
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
@rem
|
||||
@rem Copyright 2015 the original author or authors.
|
||||
@rem
|
||||
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@rem you may not use this file except in compliance with the License.
|
||||
@rem You may obtain a copy of the License at
|
||||
@rem
|
||||
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||
@rem
|
||||
@rem Unless required by applicable law or agreed to in writing, software
|
||||
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
@rem SPDX-License-Identifier: Apache-2.0
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%"=="" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%"=="" set DIRNAME=.
|
||||
@rem This is normally unused
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
||||
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if %ERRORLEVEL% equ 0 goto execute
|
||||
|
||||
echo. 1>&2
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
|
||||
echo. 1>&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||
echo location of your Java installation. 1>&2
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto execute
|
||||
|
||||
echo. 1>&2
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
|
||||
echo. 1>&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||
echo location of your Java installation. 1>&2
|
||||
|
||||
goto fail
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if %ERRORLEVEL% equ 0 goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
set EXIT_CODE=%ERRORLEVEL%
|
||||
if %EXIT_CODE% equ 0 set EXIT_CODE=1
|
||||
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
|
||||
exit /b %EXIT_CODE%
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
||||
BIN
android/libs/linphone-sdk-android-5.2.0.aar
Normal file
BIN
android/libs/linphone-sdk-android-5.2.0.aar
Normal file
Binary file not shown.
1
android/settings.gradle
Normal file
1
android/settings.gradle
Normal file
|
|
@ -0,0 +1 @@
|
|||
rootProject.name = 'liblinphone_flutter'
|
||||
18
android/src/main/AndroidManifest.xml
Normal file
18
android/src/main/AndroidManifest.xml
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="xyz.nuark.liblinphone_flutter">
|
||||
<!-- Permissions for SIP calling -->
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.RECORD_AUDIO" />
|
||||
<uses-permission android:name="android.permission.CAMERA" />
|
||||
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||
<uses-permission android:name="android.permission.VIBRATE" />
|
||||
|
||||
<!-- Camera features -->
|
||||
<uses-feature android:name="android.hardware.camera" android:required="false" />
|
||||
<uses-feature android:name="android.hardware.camera.autofocus" android:required="false" />
|
||||
|
||||
<!-- Microphone feature -->
|
||||
<uses-feature android:name="android.hardware.microphone" android:required="true" />
|
||||
</manifest>
|
||||
|
|
@ -0,0 +1,228 @@
|
|||
package xyz.nuark.liblinphone_flutter
|
||||
|
||||
import android.app.Activity
|
||||
import android.util.Log
|
||||
import android.util.SparseArray
|
||||
import android.view.TextureView
|
||||
import android.view.View
|
||||
import androidx.core.util.isNotEmpty
|
||||
import androidx.core.util.size
|
||||
import io.flutter.embedding.engine.plugins.FlutterPlugin
|
||||
import io.flutter.embedding.engine.plugins.activity.ActivityAware
|
||||
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding
|
||||
import io.flutter.plugin.common.EventChannel
|
||||
import io.flutter.plugin.common.MethodCall
|
||||
import io.flutter.plugin.common.MethodChannel
|
||||
import io.flutter.plugin.common.MethodChannel.MethodCallHandler
|
||||
import io.flutter.plugin.common.MethodChannel.Result
|
||||
import org.linphone.mediastream.video.capture.CaptureTextureView
|
||||
import xyz.nuark.liblinphone_flutter.views.LocalViewFactory
|
||||
import xyz.nuark.liblinphone_flutter.views.RemoteViewFactory
|
||||
|
||||
/** LiblinphoneFlutterPlugin */
|
||||
class LiblinphoneFlutterPlugin : FlutterPlugin, ActivityAware, MethodCallHandler {
|
||||
private lateinit var channel: MethodChannel
|
||||
|
||||
private var registrationEventsChannel: EventChannel.EventSink? = null
|
||||
private var callEventsChannel: EventChannel.EventSink? = null
|
||||
|
||||
private lateinit var activity: Activity
|
||||
|
||||
private var remoteViewCache = SparseArray<View>(1);
|
||||
private var localViewCache = SparseArray<View>(1);
|
||||
|
||||
private lateinit var linphoneBridge: LinphoneBridge
|
||||
|
||||
override fun onAttachedToEngine(flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
|
||||
flutterPluginBinding
|
||||
.platformViewRegistry
|
||||
.registerViewFactory("liblinphone_flutter.nuark.xyz/remote_view", RemoteViewFactory {
|
||||
Log.i(TAG, "onAttachedToEngine: caching RemoteView ${it.id}")
|
||||
remoteViewCache.put(0, it)
|
||||
})
|
||||
flutterPluginBinding
|
||||
.platformViewRegistry
|
||||
.registerViewFactory("liblinphone_flutter.nuark.xyz/local_view", LocalViewFactory {
|
||||
Log.i(TAG, "onAttachedToEngine: caching LocalView ${it.id}")
|
||||
localViewCache.put(0, it)
|
||||
})
|
||||
|
||||
channel = MethodChannel(flutterPluginBinding.binaryMessenger, "liblinphone_flutter")
|
||||
channel.setMethodCallHandler(this)
|
||||
|
||||
EventChannel(
|
||||
flutterPluginBinding.binaryMessenger,
|
||||
"liblinphone_flutter.nuark.xyz/registration_events"
|
||||
).setStreamHandler(object : EventChannel.StreamHandler {
|
||||
override fun onListen(
|
||||
arguments: Any?,
|
||||
events: EventChannel.EventSink?
|
||||
) {
|
||||
registrationEventsChannel = events
|
||||
}
|
||||
|
||||
override fun onCancel(arguments: Any?) {
|
||||
registrationEventsChannel = null
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
EventChannel(
|
||||
flutterPluginBinding.binaryMessenger,
|
||||
"liblinphone_flutter.nuark.xyz/call_events"
|
||||
).setStreamHandler(object : EventChannel.StreamHandler {
|
||||
override fun onListen(
|
||||
arguments: Any?,
|
||||
events: EventChannel.EventSink?
|
||||
) {
|
||||
callEventsChannel = events
|
||||
}
|
||||
|
||||
override fun onCancel(arguments: Any?) {
|
||||
callEventsChannel = null
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
override fun onMethodCall(
|
||||
call: MethodCall,
|
||||
result: Result
|
||||
) {
|
||||
when (call.method) {
|
||||
"checkPermissions" -> {
|
||||
result.success(linphoneBridge.checkPermissions())
|
||||
}
|
||||
|
||||
"initialize" -> {
|
||||
try {
|
||||
linphoneBridge = LinphoneBridge(
|
||||
activity,
|
||||
this::acquireRemoteView,
|
||||
this::acquireLocalView,
|
||||
{ registrationState ->
|
||||
registrationEventsChannel?.success(registrationState)
|
||||
},
|
||||
{ callState ->
|
||||
callEventsChannel?.success(callState)
|
||||
}
|
||||
)
|
||||
linphoneBridge.initializeLinphone()
|
||||
result.success(true)
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "initialize: ${e.message}")
|
||||
result.error("error", e.message, e)
|
||||
}
|
||||
}
|
||||
|
||||
"register" -> {
|
||||
try {
|
||||
val username = call.argument<String>("username")!!
|
||||
val password = call.argument<String>("password")!!
|
||||
val serverIp = call.argument<String>("serverIp")!!
|
||||
val serverPort = call.argument<Int>("serverPort")!!
|
||||
linphoneBridge.register(username, password, serverIp, serverPort)
|
||||
result.success(true)
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "register: ${e.message}")
|
||||
result.error("error", e.message, e)
|
||||
}
|
||||
}
|
||||
|
||||
"unregister" -> {
|
||||
linphoneBridge.unregister()
|
||||
result.success(true)
|
||||
}
|
||||
|
||||
"makeCall" -> {
|
||||
try {
|
||||
val callTo = call.argument<String>("callTo")!!
|
||||
val isVideoEnabled = call.argument<Boolean>("isVideoEnabled")!!
|
||||
linphoneBridge.makeCall(callTo, isVideoEnabled)
|
||||
result.success(true)
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "makeCall: ${e.message}")
|
||||
result.error("error", e.message, e)
|
||||
}
|
||||
}
|
||||
|
||||
"answerCall" -> {
|
||||
val res = linphoneBridge.answerCall()
|
||||
result.success(res)
|
||||
}
|
||||
|
||||
"hangupCall" -> {
|
||||
val res = linphoneBridge.hangupCall()
|
||||
result.success(res)
|
||||
}
|
||||
|
||||
"inCall" -> {
|
||||
val inCall = linphoneBridge.inCall()
|
||||
result.success(inCall)
|
||||
}
|
||||
|
||||
"callType" -> {
|
||||
val callType = linphoneBridge.callType()
|
||||
result.success(callType.ordinal)
|
||||
}
|
||||
|
||||
"toggleVideo" -> {
|
||||
val enabled = linphoneBridge.toggleVideo()
|
||||
result.success(enabled)
|
||||
}
|
||||
|
||||
"toggleMicrophone" -> {
|
||||
val enabled = linphoneBridge.toggleMicrophone()
|
||||
result.success(enabled)
|
||||
}
|
||||
|
||||
"stop" -> {
|
||||
linphoneBridge.stop()
|
||||
result.success(true)
|
||||
}
|
||||
|
||||
else -> {
|
||||
result.notImplemented()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDetachedFromEngine(binding: FlutterPlugin.FlutterPluginBinding) {
|
||||
channel.setMethodCallHandler(null)
|
||||
}
|
||||
|
||||
override fun onAttachedToActivity(binding: ActivityPluginBinding) {
|
||||
activity = binding.activity
|
||||
}
|
||||
|
||||
override fun onDetachedFromActivityForConfigChanges() {
|
||||
}
|
||||
|
||||
override fun onReattachedToActivityForConfigChanges(binding: ActivityPluginBinding) {
|
||||
activity = binding.activity
|
||||
}
|
||||
|
||||
override fun onDetachedFromActivity() {
|
||||
}
|
||||
|
||||
internal fun acquireLocalView(): CaptureTextureView? {
|
||||
Log.i(TAG, "acquireLocalView: ${localViewCache.size}")
|
||||
if (localViewCache.isNotEmpty()) {
|
||||
val widget = localViewCache.get(0)
|
||||
return widget as CaptureTextureView
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
internal fun acquireRemoteView(): TextureView? {
|
||||
Log.i(TAG, "acquireRemoteView: ${remoteViewCache.size}")
|
||||
if (remoteViewCache.isNotEmpty()) {
|
||||
val widget = remoteViewCache.get(0)
|
||||
return widget as TextureView
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val TAG = "LiblinphoneFlutterPlugin"
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,357 @@
|
|||
package xyz.nuark.liblinphone_flutter
|
||||
|
||||
import android.Manifest
|
||||
import android.app.Activity
|
||||
import android.content.pm.PackageManager
|
||||
import android.util.Log
|
||||
import android.view.TextureView
|
||||
import androidx.core.content.ContextCompat
|
||||
import org.linphone.core.Account
|
||||
import org.linphone.core.Call
|
||||
import org.linphone.core.Core
|
||||
import org.linphone.core.CoreListenerStub
|
||||
import org.linphone.core.Factory
|
||||
import org.linphone.core.MediaDirection
|
||||
import org.linphone.core.PayloadType
|
||||
import org.linphone.core.ProxyConfig
|
||||
import org.linphone.core.RegistrationState
|
||||
import org.linphone.mediastream.video.capture.CaptureTextureView
|
||||
import kotlin.properties.Delegates
|
||||
|
||||
class LinphoneBridge(
|
||||
private val activity: Activity,
|
||||
private val remoteViewAcquisitor: () -> TextureView?,
|
||||
private val localViewAcquisitor: () -> CaptureTextureView?,
|
||||
private val onRegistrationStateChanged: (Int) -> Unit,
|
||||
private val onCallStateChanged: (Int) -> Unit
|
||||
) {
|
||||
private lateinit var core: Core
|
||||
private var isRegistered = false
|
||||
private var currentCall: Call? = null
|
||||
|
||||
private var registrationState: RegistrationState by Delegates.observable(RegistrationState.None) { _, oldValue, newValue ->
|
||||
Log.i(
|
||||
LiblinphoneFlutterPlugin.TAG,
|
||||
"registrationState delegate: oldValue: $oldValue, newValue: $newValue"
|
||||
)
|
||||
onRegistrationStateChanged(newValue.ordinal)
|
||||
}
|
||||
private var callState: Call.State by Delegates.observable(Call.State.Idle) { _, oldValue, newValue ->
|
||||
Log.i(
|
||||
LiblinphoneFlutterPlugin.TAG,
|
||||
"callState delegate: oldValue: $oldValue, newValue: $newValue"
|
||||
)
|
||||
onCallStateChanged(newValue.ordinal)
|
||||
}
|
||||
|
||||
private val coreListener = object : CoreListenerStub() {
|
||||
// override fun onRegistrationStateChanged(
|
||||
// core: Core,
|
||||
// proxyConfig: ProxyConfig,
|
||||
// state: RegistrationState,
|
||||
// message: String
|
||||
// ) {
|
||||
// registrationState = state
|
||||
// when (state) {
|
||||
// RegistrationState.Ok -> {
|
||||
// isRegistered = true
|
||||
// }
|
||||
//
|
||||
// RegistrationState.Failed -> {
|
||||
// isRegistered = false
|
||||
// }
|
||||
//
|
||||
// RegistrationState.None -> {
|
||||
// isRegistered = false
|
||||
// }
|
||||
//
|
||||
// RegistrationState.Progress -> {
|
||||
// isRegistered = false
|
||||
// }
|
||||
//
|
||||
// else -> {}
|
||||
// }
|
||||
// }
|
||||
|
||||
override fun onAccountRegistrationStateChanged(
|
||||
core: Core,
|
||||
account: Account,
|
||||
state: RegistrationState?,
|
||||
message: String
|
||||
) {
|
||||
registrationState = state ?: RegistrationState.None
|
||||
when (state) {
|
||||
RegistrationState.Ok -> {
|
||||
isRegistered = true
|
||||
}
|
||||
|
||||
RegistrationState.Failed -> {
|
||||
isRegistered = false
|
||||
}
|
||||
|
||||
RegistrationState.None -> {
|
||||
isRegistered = false
|
||||
}
|
||||
|
||||
RegistrationState.Progress -> {
|
||||
isRegistered = false
|
||||
}
|
||||
|
||||
else -> {}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCallStateChanged(
|
||||
core: Core,
|
||||
call: Call,
|
||||
state: Call.State,
|
||||
message: String
|
||||
) {
|
||||
callState = state
|
||||
when (state) {
|
||||
Call.State.IncomingReceived -> {
|
||||
currentCall = call
|
||||
Log.i(
|
||||
LiblinphoneFlutterPlugin.TAG,
|
||||
"onCallStateChanged: INCOMING_RECEIVED $call"
|
||||
)
|
||||
}
|
||||
|
||||
Call.State.Connected -> {
|
||||
Log.i(LiblinphoneFlutterPlugin.TAG, "onCallStateChanged: CONNECTED $call")
|
||||
|
||||
remoteViewAcquisitor()?.let {
|
||||
call.nativeVideoWindowId = it
|
||||
} ?: run {
|
||||
Log.i(
|
||||
LiblinphoneFlutterPlugin.TAG,
|
||||
"onCallStateChanged: CONNECTED remoteViewAcquisitor found nothing"
|
||||
)
|
||||
}
|
||||
localViewAcquisitor()?.let {
|
||||
core.nativePreviewWindowId = it
|
||||
} ?: run {
|
||||
Log.i(
|
||||
LiblinphoneFlutterPlugin.TAG,
|
||||
"onCallStateChanged: CONNECTED localViewAcquisitor found nothing"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Call.State.StreamsRunning -> {
|
||||
Log.i(LiblinphoneFlutterPlugin.TAG, "onCallStateChanged: STREAMS_RUNNING $call")
|
||||
remoteViewAcquisitor()?.let {
|
||||
call.nativeVideoWindowId = it
|
||||
} ?: run {
|
||||
Log.i(
|
||||
LiblinphoneFlutterPlugin.TAG,
|
||||
"onCallStateChanged: STREAMS_RUNNING remoteViewAcquisitor found nothing"
|
||||
)
|
||||
}
|
||||
localViewAcquisitor()?.let {
|
||||
core.nativePreviewWindowId = it
|
||||
} ?: run {
|
||||
Log.i(
|
||||
LiblinphoneFlutterPlugin.TAG,
|
||||
"onCallStateChanged: STREAMS_RUNNING localViewAcquisitor found nothing"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Call.State.End -> {
|
||||
currentCall = null
|
||||
}
|
||||
|
||||
Call.State.Error -> {
|
||||
currentCall = null
|
||||
}
|
||||
|
||||
Call.State.Released -> {
|
||||
currentCall = null
|
||||
}
|
||||
|
||||
else -> {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private val neededPermissions = arrayOf(
|
||||
Manifest.permission.RECORD_AUDIO,
|
||||
Manifest.permission.CAMERA,
|
||||
Manifest.permission.MODIFY_AUDIO_SETTINGS
|
||||
)
|
||||
|
||||
fun checkPermissions(): Boolean {
|
||||
val missingPermissions = neededPermissions.filter { permission ->
|
||||
ContextCompat.checkSelfPermission(
|
||||
activity,
|
||||
permission
|
||||
) != PackageManager.PERMISSION_GRANTED
|
||||
}.toTypedArray()
|
||||
if (missingPermissions.isNotEmpty()) {
|
||||
activity.requestPermissions(missingPermissions, 1)
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
fun initializeLinphone() {
|
||||
val factory = Factory.instance()
|
||||
core = factory.createCore(null, null, activity.baseContext)
|
||||
core.addListener(coreListener)
|
||||
|
||||
// Enable video
|
||||
core.isVideoCaptureEnabled = true
|
||||
core.isVideoDisplayEnabled = true
|
||||
core.videoActivationPolicy.automaticallyInitiate = true
|
||||
core.videoActivationPolicy.automaticallyAccept = true
|
||||
|
||||
// https://www.cisco.com/c/en/us/td/docs/switches/datacenter/nexus1000/sw/4_0/qos/configuration/guide/nexus1000v_qos/qos_6dscp_val.pdf
|
||||
core.sipDscp = 26 // AF31
|
||||
core.audioDscp = 46 // EF
|
||||
core.videoDscp = 36 // AF42
|
||||
|
||||
core.isVideoAdaptiveJittcompEnabled = true
|
||||
// core.isEchoCancellationEnabled = true // eh results, bad for audio
|
||||
|
||||
// good enough default
|
||||
core.uploadBandwidth = 512
|
||||
core.downloadBandwidth = 1500
|
||||
|
||||
val preferredAudio = listOf("opus", "pcmu", "pcma") // in order of preference
|
||||
val preferredVideo = listOf("h264", "vp8")
|
||||
|
||||
core.audioPayloadTypes.forEach { pt: PayloadType ->
|
||||
val mime = pt.mimeType.lowercase()
|
||||
val enable = preferredAudio.contains(mime)
|
||||
pt.enable(enable)
|
||||
}
|
||||
core.videoPayloadTypes.forEach { pt: PayloadType ->
|
||||
val mime = pt.mimeType.lowercase()
|
||||
val enable = preferredVideo.contains(mime)
|
||||
pt.enable(enable)
|
||||
}
|
||||
|
||||
core.getPayloadType("opus", -1, 0)?.let { it.normalBitrate = 32 } // 32 kbps for Opus
|
||||
core.getPayloadType("h264", -1, 0)?.let { it.normalBitrate = 600 } // 600 kbps for H264
|
||||
core.getPayloadType("vp8", -1, 0)?.let { it.normalBitrate = 600 } // 600 kbps for VP8
|
||||
|
||||
val preferredVidDef = factory.createVideoDefinition(720, 1280)
|
||||
core.preferredVideoDefinition = preferredVidDef
|
||||
core.preferredFramerate = 30f
|
||||
|
||||
core.start()
|
||||
}
|
||||
|
||||
fun register(username: String, password: String, serverIp: String, serverPort: Int) {
|
||||
val factory = Factory.instance()
|
||||
val authInfo = factory.createAuthInfo(username, null, password, null, null, serverIp)
|
||||
core.addAuthInfo(authInfo)
|
||||
|
||||
val identity = factory.createAddress("sip:$username@$serverIp")
|
||||
val server = factory.createAddress("sip:$serverIp:$serverPort")
|
||||
|
||||
val accountParams = core.createAccountParams().let {
|
||||
it.identityAddress = identity
|
||||
it.serverAddress = server
|
||||
it.isRegisterEnabled = true
|
||||
it
|
||||
}
|
||||
|
||||
val account = core.createAccount(accountParams)
|
||||
core.addAccount(account)
|
||||
core.defaultAccount = account
|
||||
}
|
||||
|
||||
fun unregister() {
|
||||
core.clearAccounts()
|
||||
core.clearAllAuthInfo()
|
||||
}
|
||||
|
||||
fun makeCall(callTo: String, isVideoEnabled: Boolean) {
|
||||
if (!isRegistered) {
|
||||
throw IllegalStateException("Not registered")
|
||||
}
|
||||
|
||||
val factory = Factory.instance()
|
||||
val remoteAddress = factory.createAddress(callTo)
|
||||
val callParams = core.createCallParams(null)
|
||||
if (remoteAddress == null) {
|
||||
throw IllegalStateException("Failed to create remote address")
|
||||
}
|
||||
if (callParams == null) {
|
||||
throw IllegalStateException("Failed to create call params")
|
||||
}
|
||||
|
||||
callParams.let {
|
||||
it.isVideoEnabled = isVideoEnabled
|
||||
it.videoDirection =
|
||||
if (isVideoEnabled) MediaDirection.SendRecv else MediaDirection.Inactive
|
||||
}
|
||||
|
||||
currentCall = core.inviteAddressWithParams(remoteAddress, callParams)
|
||||
}
|
||||
|
||||
fun answerCall(): Boolean {
|
||||
val res = currentCall?.let { call ->
|
||||
val callParams = core.createCallParams(call)
|
||||
callParams?.let {
|
||||
it.isVideoEnabled = true
|
||||
it.videoDirection = MediaDirection.SendRecv
|
||||
}
|
||||
call.acceptWithParams(callParams)
|
||||
|
||||
return@let true
|
||||
}
|
||||
|
||||
return res ?: false
|
||||
}
|
||||
|
||||
fun hangupCall(): Boolean {
|
||||
return currentCall?.terminate() == 0
|
||||
}
|
||||
|
||||
fun toggleVideo(): Boolean {
|
||||
currentCall?.let { call ->
|
||||
val params = core.createCallParams(call)
|
||||
params?.isVideoEnabled = !call.currentParams.isVideoEnabled
|
||||
call.update(params)
|
||||
}
|
||||
|
||||
return currentCall?.currentParams?.isVideoEnabled == true
|
||||
}
|
||||
|
||||
fun toggleMicrophone(): Boolean {
|
||||
core.isMicEnabled = !core.isMicEnabled
|
||||
return core.isMicEnabled
|
||||
}
|
||||
|
||||
fun stop() {
|
||||
core.stop()
|
||||
}
|
||||
|
||||
fun inCall(): Boolean {
|
||||
return currentCall != null
|
||||
}
|
||||
|
||||
enum class CallType {
|
||||
Audio,
|
||||
Video,
|
||||
Unknown
|
||||
}
|
||||
|
||||
fun callType(): CallType {
|
||||
if (currentCall?.currentParams != null) {
|
||||
if (currentCall?.currentParams?.isVideoEnabled == true) {
|
||||
return CallType.Video
|
||||
} else {
|
||||
return CallType.Audio
|
||||
}
|
||||
}
|
||||
if (currentCall?.currentParams?.isVideoEnabled == true) {
|
||||
return CallType.Video
|
||||
}
|
||||
return CallType.Unknown
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
package xyz.nuark.liblinphone_flutter.views
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Color
|
||||
import android.view.TextureView
|
||||
import android.view.View
|
||||
import io.flutter.plugin.platform.PlatformView
|
||||
import org.linphone.mediastream.video.capture.CaptureTextureView
|
||||
|
||||
internal class LocalView(context: Context, id: Int, creationParams: Map<String?, Any?>?) : PlatformView {
|
||||
private val textureView: CaptureTextureView
|
||||
|
||||
override fun getView(): View {
|
||||
return textureView
|
||||
}
|
||||
|
||||
override fun dispose() {
|
||||
textureView.surfaceTexture?.release()
|
||||
}
|
||||
|
||||
init {
|
||||
textureView = CaptureTextureView(context)
|
||||
textureView.id = id
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
package xyz.nuark.liblinphone_flutter.views
|
||||
|
||||
import android.content.Context
|
||||
import android.view.View
|
||||
import io.flutter.plugin.common.StandardMessageCodec
|
||||
import io.flutter.plugin.platform.PlatformView
|
||||
import io.flutter.plugin.platform.PlatformViewFactory
|
||||
|
||||
class LocalViewFactory(internal val cacher: (View) -> Unit) : PlatformViewFactory(StandardMessageCodec.INSTANCE) {
|
||||
override fun create(context: Context, viewId: Int, args: Any?): PlatformView {
|
||||
val creationParams = args as Map<String?, Any?>?
|
||||
return LocalView(context, viewId, creationParams).also {
|
||||
cacher(it.view)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
package xyz.nuark.liblinphone_flutter.views
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Color
|
||||
import android.view.TextureView
|
||||
import android.view.View
|
||||
import io.flutter.plugin.platform.PlatformView
|
||||
|
||||
internal class RemoteView(context: Context, id: Int, creationParams: Map<String?, Any?>?) : PlatformView {
|
||||
private val textureView: TextureView
|
||||
|
||||
override fun getView(): View {
|
||||
return textureView
|
||||
}
|
||||
|
||||
override fun dispose() {
|
||||
textureView.surfaceTexture?.release()
|
||||
}
|
||||
|
||||
init {
|
||||
textureView = TextureView(context)
|
||||
textureView.id = id
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
package xyz.nuark.liblinphone_flutter.views
|
||||
|
||||
import android.content.Context
|
||||
import android.view.View
|
||||
import io.flutter.plugin.common.StandardMessageCodec
|
||||
import io.flutter.plugin.platform.PlatformView
|
||||
import io.flutter.plugin.platform.PlatformViewFactory
|
||||
|
||||
class RemoteViewFactory(internal val cacher: (View) -> Unit) : PlatformViewFactory(StandardMessageCodec.INSTANCE) {
|
||||
override fun create(context: Context, viewId: Int, args: Any?): PlatformView {
|
||||
val creationParams = args as Map<String?, Any?>?
|
||||
return RemoteView(context, viewId, creationParams).also {
|
||||
cacher(it.view)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
package com.example.liblinphone_flutter
|
||||
|
||||
import io.flutter.plugin.common.MethodCall
|
||||
import io.flutter.plugin.common.MethodChannel
|
||||
import org.mockito.Mockito
|
||||
import kotlin.test.Test
|
||||
|
||||
/*
|
||||
* This demonstrates a simple unit test of the Kotlin portion of this plugin's implementation.
|
||||
*
|
||||
* Once you have built the plugin's example app, you can run these tests from the command
|
||||
* line by running `./gradlew testDebugUnitTest` in the `example/android/` directory, or
|
||||
* you can run them directly from IDEs that support JUnit such as Android Studio.
|
||||
*/
|
||||
|
||||
internal class LiblinphoneFlutterPluginTest {
|
||||
@Test
|
||||
fun onMethodCall_getPlatformVersion_returnsExpectedValue() {
|
||||
val plugin = LiblinphoneFlutterPlugin()
|
||||
|
||||
val call = MethodCall("getPlatformVersion", null)
|
||||
val mockResult: MethodChannel.Result = Mockito.mock(MethodChannel.Result::class.java)
|
||||
plugin.onMethodCall(call, mockResult)
|
||||
|
||||
Mockito.verify(mockResult).success("Android " + android.os.Build.VERSION.RELEASE)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue