[sr-dev] Implementation of ios/android push notifications module or similar

Henning Westerholt hw at skalatan.de
Tue Jun 29 16:15:10 CEST 2021


Hi,

thanks for bringing this topic up, appreciated. As I said, it would be definitely good to add some examples for this use case and will help people implementing this kind of services.

Cheers,

Henning

From: javier falbo <javier_falbo at hotmail.com>
Sent: Tuesday, June 29, 2021 4:14 PM
To: Henning Westerholt <hw at skalatan.de>; Kamailio (SER) - Development Mailing List <sr-dev at lists.kamailio.org>
Subject: RE: Implementation of ios/android push notifications module or similar

Thanks Henning,

There are many voip application now that uses kamailio server on both app store/google play.

From my experience, i would recommend:

Android:  Baresip & Baresip video  (with ZRTP 🙂)
Iphone: Linphone  or Acrobits (paid)
PC Windows Computer: i love http://tomeko.net/software/SIPclient/
(easy and stable)
Centos/Debian:  Linphone appimage (linux)

I think Kamailio must add internally push notification feature, this will increase the attraction of the kamailio platform to many many mobile coders in the world.

Adding the ios push notification fix, seems very complicate and few people could do it, i added a code snippet of a kamailio.cfg file that works (it uses a push.php)

What i see recently is integration of gateways on mobile voips, such as telegram. You could a telegram number and it is routed to a sip server.

Javier

________________________________
De: Henning Westerholt <hw at skalatan.de<mailto:hw at skalatan.de>>
Enviado: martes, 29 de junio de 2021 11:04
Para: Kamailio (SER) - Development Mailing List <sr-dev at lists.kamailio.org<mailto:sr-dev at lists.kamailio.org>>
Cc: javier falbo <javier_falbo at hotmail.com<mailto:javier_falbo at hotmail.com>>
Asunto: RE: Implementation of ios/android push notifications module or similar


Hi Javier,



can you list a few app names, this would be great. 😊



Regarding inclusion of this logic in the default cfg – we usually try to keep the default cfg to cover the basic use cases for VoIP infrastructure. I am not sure if push notifications are already there yet, but other people on this list might have another opinion.



What definitely could be done is to add a dedicated example configuration in the misc/examples directory. If you are interested in contributing something, just create a pull request for it.



Cheers,



Henning



From: sr-dev <sr-dev-bounces at lists.kamailio.org<mailto:sr-dev-bounces at lists.kamailio.org>> On Behalf Of javier falbo
Sent: Tuesday, June 29, 2021 3:56 PM
To: sr-dev at lists.kamailio.org<mailto:sr-dev at lists.kamailio.org>
Subject: [sr-dev] Implementation of ios/android push notifications module or similar



Hello,



As mobile applications based on kamailio are growing exponentially on Play Store and App Store, i would suggest if you could add by default the code for ios/android push notifications.



I have problems mainly for incoming call (phone wakeup) on linphone iphone app, as kamailio is missing the push solution. On Android i am using Baresip and works perfect without push.



Navigating on the web, i found some uncomplete or minimum tutorials to implement this.

Like: https://denys-pozniak.medium.com/apple-push-notification-with-kamailio-eeca2f8e08d



And also some code snippets of a modification of "kamailio.cfg" to add support for ios push notifications. (see below).

Could someone have this already working? Or kamailio official developers could add this by default inside source code?



# keep a record of an IPhone for 4 hours
modparam("htable", "htable", "iphone_remote=>size=10;autoexpire=14400;")
modparam("htable", "htable", "iphone_voip=>size=10;autoexpire=14400;")
modparam("htable", "htable", "iphone_check=>size=10;autoexpire=14400;")
modparam("htable", "htable", "vtp=>size=10;autoexpire=120;")



route[REGISTRAR] {

...

...

        if (save("location")) {

            # user registered, now look at the useragent header for iPhone string
            if ($hdr(User-Agent)=~"LinphoneiOS.*") {


                $var(uri) = @contact.uri;                               # select the uri from contact header
                $var(pn-prid) = $(var(uri){uri.param,pn-prid});         # get the uri param pn-prid from the uri, i.e. 1DF26BC10F597676B
                xlog("!!!! - $var(pn-prid)");
                $var(i) = 0;
                $var(n) = $(var(pn-prid){s.count,&});

                while( $var(i) <= $var(n)) {
                    $var(pn-prid_item) = $(var(pn-prid){s.select,$var(i),&});
                    $var(pn-prid_type) = $(var(pn-prid_item){s.select,1,:});
                    $var(pn-prid_token) = $(var(pn-prid_item){s.select,0,:});

                    if ( $var(pn-prid_type) == "remote" ) {
                        $var(pn-prid_remote) = $(var(pn-prid_item){s.select,0,:}) ;
                    }
                    if ( $var(pn-prid_type) == "voip" ) {
                        $var(pn-prid_voip) = $(var(pn-prid_item){s.select,0,:}) ;
                    }
                    $var(i) = $var(i) + 1;
                }

                xlog("L_INFO","iPhone PUSH tokens for user $fU - remote: $var(pn-prid_remote), voip: $var(pn-prid_voip)");

                # store the values of tokens to htable with fromUser as key
                $sht(iphone_remote=>$fU) = $var(pn-prid_remote);
                $sht(iphone_voip=>$fU) = $var(pn-prid_voip);
                $sht(iphone_check=>$fU) = 1;

                if ( $sht(vtp=>id_index::$tU) != $null ) {
                    xlog("L_INFO", "New $rm ru=$ru tu=$tu \n");
                    route(JOIN);
                }

            } else {
                # no iphone
                $sht(iphone_check=>$fU) = 0;
            }

...

...

}





route[LOCATION] {

...

...

        if (!lookup("location")) {
            $var(rc) = $rc;

            # handle PUSH notifications for iPhone
            # iphones should not be registered and contacts stored in database
            # hence lookup should fail and we need to try to push iphone first
            if ($sht(iphone_check=>$tU) == 1) {
                xlog("L_ERR", "[PUSH] The to user has already used iPhone, trying push notifications");
                xlog("L_ERR", "[PUSH] No registration to try, suspending.");
                sl_send_reply("100", "Suspending");
                route(SUSPEND);
                route(RELAY);
                exit;
            }
...

...

        if (is_method("INVITE")) {
            setflag(FLT_ACCMISSED);

            # handle PUSH notifications for iPhone
            # in some cases, iphone does not send de-register when going to background
            # for these circumstances, push iphone even if it has an active registration
            if ($sht(iphone_check=>$tU) == 1) {
                xlog("L_ERR", "[PUSH] The to user has already used iPhone, trying push notifications");
                xlog("L_ERR", "[PUSH] No registration to try, suspending.");
                sl_send_reply("100", "Suspending");
                route(SUSPEND);
            }

        }
        route(RELAY);
        exit;
}





route[SUSPEND] {
  if ( !t_suspend() ) {
    xlog("L_ERROR","[SUSPEND]  failed suspending trasaction [$T(id_index):$T(id_label)]\n");
    send_reply("501", "Suspending error");
    exit;
  } else {
    xlog("L_INFO","[SUSPEND]  suspended transaction [$T(id_index):$T(id_label)] $fU=> $rU\n");
    $sht(vtp=>id_index::$rU) = $T(id_index);
    $sht(vtp=>id_label::$rU) = $T(id_label);
    xlog("L_INFO","[SUSPEND] htable key value [$sht(vtp=>id_index::$rU)   --   $sht(vtp=>id_label::$rU)]\n");
    route(SENDPUSH);
    exit;
  }
}

route[SENDPUSH] {
    #http_client_query("http://url/push.php"<http://url/push.php>, "user=$rU\r\npn-tok=$sht(tokens=>$rU)\r\n","Content-Type: text/plain", "$var(result)");
    xlog("!!!!!!!!!!!!!!!!!!!!!! PUSH !!!!!!!!!!!!!!!!!!!");
    xlog("/opt/push/push.sh $ci $sht(iphone_voip=>$tU)");
    exec_avp("/opt/push/push.sh $ci $sht(iphone_voip=>$tU)");
    xlog("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
    sl_send_reply("100", "Pushing");
}

route[JOIN] {
    xlog("L_WARN","[JOIN] htable key value [$sht(vtp=>id_index::$tU)   --   $sht(vtp=>id_label::$tU)]\n");
    t_continue("$sht(vtp=>id_index::$tU)", "$sht(vtp=>id_label::$tU)", "RESUME");
    $sht(vtp=>joined::$tU) = 1;
}

route[RESUME] {
    lookup("location");
    xlog("L_INFO","[RESUME] rm=$rm ru=$ru du=$du \n");
    t_relay();
    $sht(vtp=>id_index::$tU) = $null;
    $sht(vtp=>id_label::$tU) = $null;
    exit; }


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.kamailio.org/pipermail/sr-dev/attachments/20210629/4c02142b/attachment-0001.htm>


More information about the sr-dev mailing list