Call Analytics SDK
这个可选库允许 Sipfront 测试在应用运行时捕获额外的数据和统计信息,并将其发送到我们的服务器。
当前捕获的数据
- SIP 消息
- SDP 消息
- RTCP 消息
- 呼叫状态消息
Call Analytics SDK 支持以各种方式提取这些数据,并将在未来进行扩展
支持的平台
- Android
- Java
- JavaScript(浏览器、NodeJs)
- iOS(Arm64、X64、Arm64-Simulator)
- MacOS(Arm64、X64)
要求
- Android 5.0+ (API 级别 21+)和 Java 8+
- iOS 14.1
设置
基本设置
您可以在不指定平台的情况下导入依赖,Gradle 将为您的项目选择正确的版本
implementation 'com.sipfront.sdk:call-analytics:1.0.2'
指定平台设置
您也可以指定平台,这对于提供发布和调试构建版本的库的 Android 平台来说尤其有意义
implementation 'com.sipfront.sdk:call-analytics-android:1.0.2' //Android release
implementation 'com.sipfront.sdk:call-analytics-android-debug:1.0.2' //Android debug
implementation 'com.sipfront.sdk:call-analytics-jvm:1.0.2' //Java
implementation 'com.sipfront.sdk:call-analytics-js:1.0.2' //JavaScript
您可以在以下位置找到所有支持的平台列表:https://central.sonatype.com/namespace/com.sipfront.sdk
Android 发布/调试构建类型
- 发布版本:没有调试日志,代码混淆且压缩,以使文件大小更小。适用于大多数使用场景
- 调试版本:带有调试日志,代码未混淆或压缩
从您应用程序的发布构建中排除呼叫分析SDK
尽管呼叫分析SDK在Sipfront测试之外将无法初始化,因此不会向我们的服务器发送任何数据,但排除我们的SDK以优化应用程序大小是有意义的。
// Include only in debug builds
debugImplementation 'com.sipfront.sdk:call-analytics:1.0.2'
// Or include only in a custom build flavor
customFlavorImplementation 'com.sipfront.sdk:call-analytics:1.0.2'
使用呼叫分析SDK
初始化呼叫分析SDK
当应用程序在Sipfront测试中启动时,它将在应用程序启动时向应用程序提供凭据和其他所需信息。您通过在应用程序启动时向SDK提供这些数据来在您的应用程序中初始化SDK。
Android
// In onCreate() of your apps Launcher Activity add this code
override fun onCreate(savedInstanceState: Bundle?) {
if (savedInstanceState == null) {
try {
val initialized = CallAnalytics.init(
// custom Intent arguments provided to app by Sipfront test
SessionParams(intent),
// optional configuration
Config.Builder()
.enableDebugLogs(enable = true)
.build()
)
if(initialized) {
Log.i("CallAnalytics initialized")
}
} catch (e: Exception) {
Log.e("Could not initialise CallAnalytics, cause: ${e.message}")
}
}
}
iOS
// In init() of your SwiftUI.App
struct MyApp: SwiftUI.App {
init() {
do {
let initialized = try CallAnalytics.shared.initialize(
// custom processInfo provided to app by Sipfront test
params: SessionParams(json: ProcessInfo.processInfo.environment[SipfrontIntent.Extra.config.value]!),
// optional configuration of Sdk
config: Config.Builder()
.enableDebugLogs(true)
.trustAllCerts(true)
.build()
)
if initialized {
Logger.info("CallAnalytics initialized")
}
} catch {
Logger.notifications.error("CallAnalytics init error: \(error)")
}
}
}
使用配置初始化呼叫分析SDK
CallAnalytics.init(
intent,
Config.Builder()
.enableLogParser(true) // enables automatic parsing of Logs for SIP/SDP messages
.enableDebugLogs(true) // enables debug logging
.trustAllCerts(true) // accepts all certs on SDK HTTPs requests if true
.build()
)
SIP或SDP发送
使用CallAnalytics.sendSip()或CallAnalytics.sendSdp()
Android
CallAnalytics.sendSip(
SdpMessage.Builder()
.message(message = sipMessage)
.type(type = MessageType.Sip.INCOMING)
.build()
)
iOS
do {
try CallAnalytics.shared.send(sip: SipMessage.Builder()
.message(sipMessage)
.type(MessageSip.incoming)
.build())
} catch {
Logger.notifications.error("CallAnalytics request error: \(error)")
}
另外,SDK支持从应用日志中解析(可以通过SipfrontSdkConfig启用)
发送RTCP
使用CallAnalytics.sendRtcp()
Android
CallAnalytics.sendRtcp(
RtcpMessage.Builder()
.callId(callId)
.callDirection(CallDirection.INCOMING)
.addressLocal("+4912311111")
.addressRemote("+4912322222")
.displayNameRemote("John Doe")
.audioDirection(MediaDirection.SEND_RECEIVE)
.rtt(rtt) //round trip time in milliseconds
.rxJitter(jitter) //jitter in milliseconds
.rxLost(lost) //lost packets total
.rxBytes(bytes) //bytes received total
.rxPackets(packets) //packets received total
.txBytes(bytes) //bytes sent total
.txPackets(packets) //packets sent total
.build()
)
iOS
do {
try CallAnalytics.shared.send(rtcp: RtcpMessage.Builder()
.address(local: "+4912311111")
.address(remote: "+4912322222")
.displayName(remote: "John Doe")
.audio(direction: Media.sendOnly)
.video(direction: Media.receiveOnly)
.call(id: "MyCallId")
.call(direction: Call.incoming)
.rtt(1.0) //round trip time in milliseconds
.rx(lost: 0) //lost packets total
.rx(bytes: 99) //bytes received total
.rx(packets: 9) //packets received total
.rx(jitter: 9) //jitter in milliseconds
.tx(packets: 10) //packets sent total
.tx(bytes: 100) //bytes sent total
.build())
} catch {
Logger.notifications.error("CallAnalytics request error: \(error)")
}
发送通话状态
使用CallAnalytics.sendState()
Android
CallAnalytics.sendState(
StateMessage.Builder()
.type(type = MessageType.State.CALL_ESTABLISHED)
.callId(id = callId)
.callDirection(direction = CallDirection.OUTGOING)
.addressLocal(address = "+4912311111")
.addressRemote(address = "+4912322222")
.displayNameRemote(displayName = "John Doe")
.audioDirection(direction = MediaDirection.SEND_RECEIVE)
)
iOS
do {
try CallAnalytics.shared.send(state: StateMessage.Builder()
.type(MessageState.callEstablished)
.address(local: "+4912311111")
.address(remote: "+4912322222")
.displayName(remote: "John Doe")
.audio(direction: Media.sendOnly)
.video(direction: Media.receiveOnly)
.call(id: "MyCallId")
.call(direction: Call.incoming)
.build())
} catch {
Logger.notifications.error("CallAnalytics request error: \(error)")
}
许可证
MIT License
Copyright (c) 2023 Sipfront
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.