Freeswitch sip Push notifications
PUSH SIP freeswitch Notifications
2023-06-13 09:17:09 时间
不管是安卓还是ios现在多数的app都无法长时间在后台运行(特殊权限以及应用除外),如果要想在app没有激活或者被冻结的情况下接收到来电,那么就需要先推送一条通知。
搜了一下有这么个插件:https://github.com/sem32/freeswitch-PushNotificator 尝试了一下发现编译起来比较麻烦,后来发现了这篇文章:https://www.zoiper.com/en/tutorials/push-notifications参考里面的关键代码,包含一个push.sh,代码如下:
#!/bin/bash
printResult() {
echo "<root>"
echo -e "\t<code>"$1"</code>"
echo -e "\t<X_NotificationStatus>"$2"</X_NotificationStatus>"
echo -e "\t<X_DeviceConnectionStatus>"$3"</X_DeviceConnectionStatus>"
echo -e "\t<X_SubscriptionStatus>"$4"</X_SubscriptionStatus>"
echo "</root>"
}
CURL=`which curl`
if [ -z $CURL ]; then
echo "Curl not found"
exit 1
fi
if [ -z $1 ]; then
echo "Url is not set"
exit 1
fi
URL=$1
i=0
max_i=3
while [ 1 ]
do
if [ $i -ge $max_i ]; then
exit 0;
fi
let i++
headers=`$CURL -s --data '
<?xml version="1.0" encoding="utf-8"?>
<root>
<Value1>Zoiper</Value1>
<Value2>Incoming</Value2>
<Value3>Call</Value3>
</root>
' -D - $URL --header "Content-Type: text/xml" --header "X-NotificationClass: 4" | tr -d '\r' `
code=`echo "$headers" | head -n 1`
X_NotificationStatus=`echo "$headers" | grep "X-NotificationStatus" | sed 's#X-NotificationStatus: ##' | sed -e 's/^\s*//g' -e 's/\s*$//g' `
X_DeviceConnectionStatus=`echo "$headers" | grep "X-DeviceConnectionStatus" | sed 's#X-DeviceConnectionStatus: ##' | sed -e 's/^\s*//g' -e 's/\s*$//g' `
X_SubscriptionStatus=`echo "$headers" | grep "X-SubscriptionStatus" | sed 's#X-SubscriptionStatus: ##' | sed -e 's/^\s*//g' -e 's/\s*$//g' `
if [ "$code" != "HTTP/1.1 200 OK" ]; then
break;
fi
if [ "$X_NotificationStatus" != "Suppressed" ]; then
break;
fi
if [ "$X_DeviceConnectionStatus" != "Connected" ]; then
break;
fi
if [ "$X_SubscriptionStatus" != "Active" ]; then
break;
fi
done
printResult "$code" "$X_NotificationStatus" "$X_DeviceConnectionStatus" "$X_SubscriptionStatus"
除此之外freeswitch还需要配置dialplan逻辑:
<action application="set" data="result=${sofia_contact(1001)}"/>
<action application="set" data="push=${regex(${result}|^(?:.*)X-PUSH-URI=(.*)|%1)}"/>"
<action application="set" data="result=${system /usr/bin/push.sh ${push}}"/>
<action application="sleep" data="2000"/>
所以整体的一个逻辑就是修改拨号逻辑,在接收到呼叫的时候首先发送通知,2s之后开始正式呼叫。但是单纯基于上面的逻辑是无法进行push的,需要第三方推送服务支持,可以使用个推等服务。如果要通知呼叫号码,目标号码等,可以使用下面的代码:
<action application="set" data="result=${system /root/sh/push_notice.sh ${caller_id_number} ${destination_number}}"/>
<action application="sleep" data="2000"/>
☆文章版权声明☆
* 网站名称:obaby@mars * 网址:https://h4ck.org.cn/ * 本文标题: 《Freeswitch sip Push notifications》 * 本文链接:https://h4ck.org.cn/2021/10/freeswitch-sip-push-notifications/ * 转载文章请标明文章来源,原文标题以及原文链接。请遵从 《署名-非商业性使用-相同方式共享 2.5 中国大陆 (CC BY-NC-SA 2.5 CN) 》许可协议。
分享文章:
相关文章:
相关文章
- 国网B接口资源上报(Push_Resourse)接口描述和消息示例
- 数组方法底层实现:push pop map遍历 个人理解实现方法
- 【错误记录】GitHub 错误 ( Push failed Unable to access xx:OpenSSL SSL_read: SSL_ERROR_SYSCALL, errno 10054 )
- 【错误记录】Android Studio 向 GitHub 提交代码报错 ( Push failed: Failed with error: Could not read from remote )
- ORA-23385: replication parallel push string argument not valid ORACLE 报错 故障修复 远程处理
- ORA-23386: replication parallel push cannot create slave processes ORACLE 报错 故障修复 远程处理
- mongodb 修改器($inc/$set/$unset/$push/$pop/upsert)
- Redis Push:高效实时消息推送的利器(redispush)
- 如何关闭macOS的SIP保护?25字:关闭macOS的SIP保护方法(macOS关闭sip)
- Oracle 带来新机遇推动行业变革(oracle push)
- PHParray_push数组函数
- javascript使用数组的push方法完成快速排序