Flexisip + Account Manager + Firebase : Push notification

Push Notification

相手方呼び出し時、相手方の端末がスリープモード等により呼出しリクエストに応答しないケースで、Firebaseからのプッシュ通知を利用して接続を確立。Flexisipサーバ側の設定が必要です。

Push notification configration


Push Gateway

600px-Pushgateway_incoming_call

ContactRouterInserter

FlexisipがSBCゲートウェイとして使用される場合、このモジュールは登録情報の経路を調整し、正しい送り先に着信呼び出しをルーティングできるようにします。

SBC (Session Border Controller) (セッション・ボーダー・コントローラ)の略で、通信ネットワークにおいてセッション(通話やデータ転送などの通信セッション)の境界で制御を行う装置やソフトウェア

アカウントマネージャのAPIでFirebaseによるプッシュ通知を利用する場合、アカウントマネージャを稼働しているphp-fpmコンテナ経由でflexisipサーバコンテナへコマンド送信する必要があるため、php-fpmコンテナにSSH接続などによる機能追加・PHPコードの変更などが必要になります。LaravelのフレームワークにSSHライブラリを追加することで対応できますがデバックなどに時間を要します。

このため、flexisipイメージにphp-fpmの機能を追加した新たなイメージを作成し、このイメージからflexisipサーバとphp-fpmを同時に立ち上げることにします。

PHPとその機能拡張、Composerのインストールを追加

flex-from-ubuntu-apt-repo

FROM ubuntu:22.04
MAINTAINER  Takanobu Fuse <[email protected]>

ARG DEBIAN_FRONTEND=noninteractive

# Prepare dependencies
RUN apt-get update
RUN apt-get install -y nano xsdcxx gdb libmariadb3 snmp-mibs-downloader snmp snmpd iproute2 iptables wget gnupg2 \ 
    php8.1-fpm libpng-dev libfreetype-dev libjpeg-turbo8-dev libxml2-dev curl zip unzip \
    php8.1-cli php8.1-common php8.1-mysql php8.1-zip php8.1-gd php8.1-mbstring php8.1-curl php8.1-xml php8.1-xmlrpc \
    php8.1-bcmath php8.1-redis
    
RUN echo 'deb [arch=amd64] http://linphone.org/snapshots/ubuntu jammy stable' > /etc/apt/sources.list.d/belledonne.list
RUN wget https://www.linphone.org/snapshots/ubuntu/pubkey.gpg -O - | apt-key add -
RUN apt-get update && apt-get install -y bc-flexisip

# Set working directory
WORKDIR /var/www/html

# Installing composer
COPY composer_installer.sh ./
RUN chmod +x composer_installer.sh
RUN echo 'precedence ::ffff:0:0/96 100' >> /etc/gai.conf \
    && ./composer_installer.sh && mv composer.phar /usr/local/bin/composer
    
# Installing Laravel
RUN chown -R www-data:www-data /var/www/html
RUN composer global require laravel/installer \
    && ln -s /root/.config/composer/vendor/laravel/installer/bin/laravel /usr/local/bin/laravel
###### for fleisip-account-manager until the above line

# Add it to the default path
ENV PATH=$PATH:/opt/belledonne-communications/bin

WORKDIR /opt/belledonne-communications

# Generate a default configuration
RUN flexisip --dump-default all > /etc/flexisip/flexisip.conf

VOLUME /etc/opt/belledonne-communications/flexisip
VOLUME /var/opt/belledonne-communications/log/flexisip
COPY flexisip-entrypoint.sh /
COPY backtrace.gdb /
RUN chmod a+x /flexisip-entrypoint.sh

# Script to wait db before launch flexisip [Licence Apache2]
ADD https://github.com/ufoscout/docker-compose-wait/releases/download/2.2.1/wait /wait
RUN chmod +x /wait

ENTRYPOINT ["/flexisip-entrypoint.sh"]
CMD flexisip

起動スクリプトにphp-fpmの起動コマンド"/etc/init.d/php8.1-fpm start"を追加

flexisip-entrypoint.sh

#!/bin/bash
ulimit -c unlimited
set -- flexisip "$@"

# Wait for needed container startup
/wait || exit $?

echo "Flexisip docker params : $*"

if [[ $@ == *"--server"* ]]; then
  echo "--server param found, starting only one Flexisip instance"
  "$@" &
else
  echo "Server param not found, starting 3 Flexisip instances (proxy, presence, conference)"
  ( "$@" --server proxy 2>&1| tee /var/opt/belledonne-communications/log/flexisip/flexisip_proxy_stdout.log ) &
  ( "$@" --server presence 2>&1| tee /var/opt/belledonne-communications/log/flexisip/flexisip_presence_stdout.log ) &
  ( "$@" --server conference 2>&1| tee /var/opt/belledonne-communications/log/flexisip/flexisip_conference_stdout.log ) &
fi

/etc/init.d/php8.1-fpm start

wait -n

echo "At least one server crashed, stopping every sub process that is still alive"
pkill -P $$

# coredump management, used in unit tests
# we execute gdb on each coredump, with the options given in backtrace.gdb file
# we search in /root because it's the workdir set in Dockerfile and because by default our coredumps are generated by default in the working directory
if [ -n "$(find /root -type f -name "core*")" ]; then
	find /root -type f -name "core*" | xargs -L1 gdb flexisip -x /backtrace.gdb;
fi

Nginxのfastcgi_passを変更

Dockerネットワークのゲートウェイアドレス:172.17.0.1などに変更

default.conf

    location = /index.php {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_keep_conn on;
        fastcgi_param  HTTPS 'on';
        fastcgi_pass   xx.xx.xx.xx:9000;
        fastcgi_index  index.php;
        include        fastcgi_params;
        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

PHP-FPM設定ファイル:接続方法の変更

ListenがデフォルトでUnixソケットなので、ポートに変更します。このファイルをコンテナ起動時に読み込ませるため、下記ディレクトリから抜き出してDocker Composeファイルで読み込むように設定して下さい。

/etc/php/8.1/fpm/pool.d/www.conf

.....
.....

; The address on which to accept FastCGI requests.
; Valid syntaxes are:
;   'ip.add.re.ss:port'    - to listen on a TCP socket to a specific IPv4 address on
;                            a specific port;
;   '[ip:6:addr:ess]:port' - to listen on a TCP socket to a specific IPv6 address on
;                            a specific port;
;   'port'                 - to listen on a TCP socket to all addresses
;                            (IPv6 and IPv4-mapped) on a specific port;
;   '/path/to/unix/socket' - to listen on a unix socket.
; Note: This value is mandatory.
listen = 9000
.....
.....

アカウントマネージャ.envの変更

php-fpmコンテナのネットワークをブリッジからホストへ変更したため、アカウントマネージャの.envファイル内で指定したサービス名によるホスト指定をIPアドレスによるものに変更します。

flexiapi/.env

.....
.....
DB_CONNECTION=mysql
DB_HOST=172.xx.xx.xx
.....
.....
REDIS_CLIENT=phpredis # Use phpredis-sentinel and uncomment the REDIS_SENTINEL variable bellow
REDIS_HOST=172.xx.xx.xx
.....
.....

注)ポート9000へのアクセスがufwによって制限されていると504エラーが発生します。
ブリッジネットワークからのアクセスを許可します。

$ sudo ufw allow proto tcp from 172.xx.0.0/12 

PostmanによるFlexisipアカウントマネージャAPIテスト

Postmanでは各種APIの動作を検証できるウェブサービスが提供されています。

https://www.postman.com/

専用デスクトップアプリのダウンロード

Flexisip Account Manager API

1) Account Creation Request Tokens:アカウント作成リクエストトークン

このトークンはアカウント作成トークンを取得するために利用されます。
JSONフォーマットにより、アカウント作成リクエストトークンと認証URLが返されます。

2) Account Creation Tokens:アカウント作成トークン

アカウント作成トークンを取得するAPIは以下二通り用意されています。

  • 上記 1) で取得したアカウントリクエストトークンを利用するAPI
  • プッシュトークンを利用したAPI