diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index eb639d8a..d354a97b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -77,7 +77,6 @@ jobs: name: - raspbian-buster_armv6 - raspbian-buster_armv7 - - ubuntu-16.04_armv7_ros - ubuntu-16.04_x86_64_ros - ubuntu-18.04_armv8_jetson_nano - ubuntu-18.04_x86_64 @@ -146,7 +145,6 @@ jobs: - macos - raspbian-buster_armv6 - raspbian-buster_armv7 - - ubuntu-16.04_armv7_ros - ubuntu-16.04_x86_64_ros - ubuntu-18.04_armv8_jetson_nano - ubuntu-18.04_x86_64 diff --git a/.github/workflows/daily_build.yml b/.github/workflows/daily_build.yml index ee2a0b30..f4de0731 100644 --- a/.github/workflows/daily_build.yml +++ b/.github/workflows/daily_build.yml @@ -30,7 +30,6 @@ jobs: name: - raspbian-buster_armv6 - raspbian-buster_armv7 - - ubuntu-16.04_armv7_ros - ubuntu-16.04_x86_64_ros - ubuntu-18.04_armv8_jetson_nano - ubuntu-18.04_x86_64 diff --git a/CHANGES.md b/CHANGES.md index b2346209..2eeeaca1 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -11,6 +11,15 @@ ## develop +## 2020.6 + +- [UPDATE] `libwebrtc` を `M84.4127@{#0}` に上げる + - @voluntas +- [ADD] test モードの Momo と Ayame モードの Momo の相互接続を可能とする + - @tnoho +- [CHANGE] ubuntu-16.04_armv7_ros ビルドを削除 + - @melpon + ## 2020.5.2 - [FIX] AV1 が利用できなかったのを修正する diff --git a/CMakeLists.txt b/CMakeLists.txt index 600c6b16..31d23756 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -119,26 +119,6 @@ elseif(MOMO_PACKAGE_NAME STREQUAL "raspbian-buster_armv7") list(APPEND CMAKE_PREFIX_PATH /root/rootfs/usr/lib/arm-linux-gnueabihf/cmake/SDL2) -elseif(MOMO_PACKAGE_NAME STREQUAL "ubuntu-16.04_armv7_ros") - - set(TARGET_OS "linux") - set(TARGET_OS_LINUX "ubuntu-16.04") - set(TARGET_ARCH "arm") - set(TARGET_ARCH_ARM "armv7") - set(USE_ROS ON) - set(USE_MMAL_ENCODER ON) - set(USE_H264 ON) - set(BOOST_ROOT_DIR /root/boost) - set(JSON_ROOT_DIR /root/json) - set(CLI11_ROOT_DIR /root/CLI11) - set(WEBRTC_INCLUDE_DIR /root/webrtc/include) - set(WEBRTC_LIBRARY_DIR /root/webrtc/lib) - set(WEBRTC_LIBRARY_NAME "webrtc_nolibcxx") - set(CLANG_ROOT /root/llvm/clang) - set(SYSROOT /root/rootfs) - - set(Boost_ARCHITECTURE 32) - elseif(MOMO_PACKAGE_NAME STREQUAL "ubuntu-18.04_armv8_jetson_nano") set(TARGET_OS "linux") diff --git a/README.md b/README.md index 0562cc31..85c41e2a 100644 --- a/README.md +++ b/README.md @@ -87,9 +87,6 @@ https://github.com/shiguredo/momo/releases - Ubuntu 16.04 x86_64 ROS Kinetic - http://wiki.ros.org/kinetic -- Ubuntu 16.04 ARMv7 ROS Kinetic - - 今後削除予定 - - Raspberry Pi 3 B+ ## 使ってみる diff --git a/VERSION b/VERSION index d5b8926a..6772da1a 100644 --- a/VERSION +++ b/VERSION @@ -1,5 +1,5 @@ -MOMO_VERSION=2020.5.2 -WEBRTC_BUILD_VERSION=84.4104.0.1 +MOMO_VERSION=2020.6 +WEBRTC_BUILD_VERSION=84.4127.0.1 BOOST_VERSION=1.72.0 JSON_VERSION=3.7.3 CLI11_VERSION=1.9.0 diff --git a/build/build.sh b/build/build.sh index 32f9c446..eea3241b 100755 --- a/build/build.sh +++ b/build/build.sh @@ -11,7 +11,6 @@ _PACKAGES=" \ macos \ raspbian-buster_armv6 \ raspbian-buster_armv7 \ - ubuntu-16.04_armv7_ros \ ubuntu-16.04_x86_64_ros \ ubuntu-18.04_armv8_jetson_nano \ ubuntu-18.04_x86_64 \ diff --git a/build/ubuntu-16.04_armv7_ros/Dockerfile b/build/ubuntu-16.04_armv7_ros/Dockerfile deleted file mode 100644 index 6987ae1e..00000000 --- a/build/ubuntu-16.04_armv7_ros/Dockerfile +++ /dev/null @@ -1,85 +0,0 @@ -# syntax = docker/dockerfile:1.1.1-experimental -FROM ubuntu:16.04 - -ARG PACKAGE_NAME - -LABEL jp.shiguredo.momo=$PACKAGE_NAME - -RUN rm -f /etc/apt/apt.conf.d/docker-clean; echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache - -# パッケージのインストール - -COPY script/apt_install_arm.sh /root/ -RUN --mount=type=cache,id=$PACKAGE_NAME,target=/var/cache/apt --mount=type=cache,id=$PACKAGE_NAME,target=/var/lib/apt \ - /root/apt_install_arm.sh - -# RootFS の構築 - -COPY script/init_rootfs_armhf.sh /root/ -COPY rpi-xenial-ros.conf /root/ -RUN --mount=type=cache,id=$PACKAGE_NAME,target=/var/cache/apt --mount=type=cache,id=$PACKAGE_NAME,target=/var/lib/apt \ - /root/init_rootfs_armhf.sh /root/rootfs /root/rpi-xenial-ros.conf - -# WebRTC の取得 - -ARG WEBRTC_BUILD_VERSION - -COPY script/get_webrtc.sh /root/ -RUN /root/get_webrtc.sh "$WEBRTC_BUILD_VERSION" ubuntu-16.04_armv7 /root -# COPY webrtc/ /root/webrtc/ - -# コンパイラの取得 - -COPY script/get_llvm.sh /root/ -RUN /root/get_llvm.sh /root/webrtc /root - -# Boost のビルド - -ARG BOOST_VERSION - -COPY script/setup_boost.sh /root/ -RUN \ - set -ex \ - && /root/setup_boost.sh "$BOOST_VERSION" /root/boost-source \ - && cd /root/boost-source/source \ - && echo 'using clang : : /root/llvm/clang/bin/clang++ : ;' > project-config.jam \ - && ./b2 \ - cxxflags=' \ - --target=arm-linux-gnueabihf \ - --sysroot=/root/rootfs \ - -march=armv7-a \ - -mfloat-abi=hard \ - -mtune=generic-armv7-a \ - -mfpu=neon \ - -mthumb \ - ' \ - linkflags=' \ - ' \ - toolset=clang \ - visibility=global \ - target-os=linux \ - architecture=arm \ - address-model=32 \ - link=static \ - variant=release \ - install \ - -j`nproc` \ - --ignore-site-config \ - --prefix=/root/boost \ - --with-filesystem - -# nlohmann/json の取得 - -ARG JSON_VERSION -RUN git clone --branch v$JSON_VERSION --depth 1 https://github.com/nlohmann/json.git /root/json - -# CLI11 の取得 - -ARG CLI11_VERSION -RUN git clone --branch v$CLI11_VERSION --depth 1 https://github.com/CLIUtils/CLI11.git /root/CLI11 - -# CMake のインストール -ARG CMAKE_VERSION -COPY script/get_cmake.sh /root/ -RUN /root/get_cmake.sh "$CMAKE_VERSION" Linux /root -ENV PATH "/root/cmake/bin:$PATH" diff --git a/build/ubuntu-16.04_armv7_ros/rpi-xenial-ros.conf b/build/ubuntu-16.04_armv7_ros/rpi-xenial-ros.conf deleted file mode 100644 index cbc483a0..00000000 --- a/build/ubuntu-16.04_armv7_ros/rpi-xenial-ros.conf +++ /dev/null @@ -1,23 +0,0 @@ -[General] -unpack=true -bootstrap=Ports Rasp ROS -aptsources=Ports Rasp ROS - -[Ports] -packages=g++ libasound2-dev libpulse-dev libudev-dev libexpat1-dev libnss3-dev python-dev libgtk-3-dev libconsole-bridge0.2v5 libboost-all-dev libconsole-bridge-dev -source=http://ports.ubuntu.com -keyring=ubuntu-keyring -suite=xenial -components=main universe - -[Rasp] -packages=libraspberrypi-bin libraspberrypi-bin-nonfree libraspberrypi-dev -source=http://ppa.launchpad.net/ubuntu-raspi2/ppa/ubuntu -keyring=ubuntu-keyring -suite=xenial - -[ROS] -packages=ros-kinetic-sensor-msgs ros-kinetic-message-filters ros-kinetic-roscpp ros-kinetic-rosconsole ros-kinetic-roscpp-serialization ros-kinetic-rostime ros-kinetic-xmlrpcpp ros-kinetic-cpp-common ros-kinetic-audio-common -source=http://packages.ros.org/ros/ubuntu -keyring=ubuntu-keyring -suite=xenial \ No newline at end of file diff --git a/doc/BUILD_LINUX.md b/doc/BUILD_LINUX.md index 37eeee7c..b1857a99 100644 --- a/doc/BUILD_LINUX.md +++ b/doc/BUILD_LINUX.md @@ -58,17 +58,6 @@ $ ./build.sh ubuntu-18.04_x86_64 うまくいかない場合は `./build.sh --clean ubuntu-18.04_x86_64 && ./build.sh ubuntu-18.04_x86_64` を試してみてください。それでもだめな場合は Discord にお願いします。 -## Ubuntu 16.04 (armv7) 向け ROS 対応バイナリを作成する - -build ディレクトリ以下で ./build.sh ubuntu-16.04_armv7_ros と打つことで Momo の Ubuntu 16.04 armv7 ROS 向けバイナリが生成されます。 - -```shell -$ ./build.sh ubuntu-16.04_armv7_ros -``` - -うまくいかない場合は `./build.sh --clean ubuntu-16.04_armv7_ros && ./build.sh ubuntu-16.04_armv7_ros` を試してみてください。それでもだめな場合は Discord にお願いします。 - - ## Ubuntu 16.04 (x86_64) 向け ROS 対応バイナリを作成する build ディレクトリ以下で ./build.sh ubuntu-16.04_x86_64_ros と打つことで Momo の Ubuntu 16.04 x86_64 ROS 向けバイナリが生成されます。 diff --git a/doc/PACKAGE.md b/doc/PACKAGE.md index b67dabe7..bd332f81 100644 --- a/doc/PACKAGE.md +++ b/doc/PACKAGE.md @@ -24,7 +24,6 @@ Windows の場合は以下のコマンドになります。 - raspbian-buster_armv7 - ubuntu-18.04_armv8_jetson_nano - ubuntu-18.04_x86_64 -- ubuntu-16.04_armv7_ros - ubuntu-16.04_x86_64_ros ## パッケージ解凍後の構成 diff --git a/doc/USE.md b/doc/USE.md index d9f09e91..c4a01c12 100644 --- a/doc/USE.md +++ b/doc/USE.md @@ -55,7 +55,6 @@ Momo では SDL (Simple DirectMedia Layer) を利用して音声や映像を出 ### ROS ノードとして Momo を使ってみる - Momo を ROS ノードとして使ってみたい人は [USE_ROS.md](USE_ROS.md) をお読みください。 -- ARM 対応版の Momo を ROS ノードとして使ってみたい人は [USE_ARM_ROS.md](USE_ARM_ROS.md) をお読みください。 ## Q&A diff --git a/doc/USE_ARM_ROS.md b/doc/USE_ARM_ROS.md deleted file mode 100644 index fd35f450..00000000 --- a/doc/USE_ARM_ROS.md +++ /dev/null @@ -1,164 +0,0 @@ -# ARM ROS 版 Momo を使ってみる - -動作確認済み環境は下記の通り - -- Board: Raspberry Pi 3 Model B+ -- OS: Ubuntu 16.04 -- ROS: Kinetic - -検証にあたっては、こちらのブログを参考に環境を構築しました。謝意を表します。 -[RaspberryPi 3B+でUbuntu 16.04を起動させる方法](https://www.asrobot.me/entry/2018/07/11/001603/) - -## Momo の準備 - -### Momo のビルド - -[BUILD.md](./BUILD.md)を確認してUbuntu 16.04 (armv7) 向け ROS 対応パッケージを作成してください。 - -```shell -$ make ubuntu-16.04_armv7_ros.package -``` - -#### Raspberry Pi への配置 - -下記のような構成で Raspberry Pi 内にビルドした Momo を配置します。 - -``` -$ tree -. -├── html -│   ├── test.html -│   └── webrtc.js -└── ビルドした momo -``` - - -Momo のパッケージを https://github.com/shiguredo/momo/releases からダウンロードした場合は、パッケージを展開すると既に上記と同じ構成で配置されています。 - -``` -$ tree -. -├── html -│   ├── test.html -│   └── webrtc.js -├── LICENSE -├── momo -└── NOTICE -``` - - -#### ライブラリのインストール - -次のパッケージをイストールします。 - -``` -$ sudo apt -y install libnss3 libasound2 gstreamer1.0-alsa -``` - -また H264 ハードウェアエンコーダに対応するため、下記のリポジトリを追加し、パッケージをインストールします。 - -``` -$ sudo add-apt-repository ppa:ubuntu-raspi2/ppa -$ sudo apt-get update -$ sudo apt-get install libraspberrypi-bin libraspberrypi-dev -``` - -Raspberry Pi の場合はハードウェアエンコーダを利用することで、非常に少ない CPU 消費で配信を行うことが可能です。 - -## 実行する - -Momo を実行する前に下記のように rosrun を使用して Web カメラ、マイクを起動しておきます。 - -事前に、apt で ros-kinetic-usb-cam, ros-kinetic-audio-common をインストールした上で実行します。 - -``` -$ rosrun usb_cam usb_cam_node -``` - -Raspberry Pi の場合は非常にリソースが限られていますので、Image topic は無圧縮での利用をお勧めします。 - -``` -$ rosrun audio_capture audio_capture _format:=wave _channels=1 _same_rate:=16000 -``` - -### Test で動作を確認する - -- 実行例 - -```shell -$ ./momo _use_test:=true \ - _compressed:=false \ - image:=/usb_cam/image_raw \ - audio:=/audio \ - _audio_topic_ch:=1 \ - _audio_topic_rate:=16000 -``` - -http://[momo の IP アドレス]:8080/html/test.html にアクセスしてください。 - -image には Web カメラから送られてくる画像データの topic を指定してください。 -audio にはマイクから送られてくる音声データの topic を指定してください。 - -- 変更可能なパラメータ - - image - - topic - - _compressed - - JPEG 圧縮済みイメージ topic か [true,false] - - _test_port - - test モードで利用するポート番号 [0 - 65535] - - _sora_port - - sora モードで利用するポート番号 [-1 - 65535] - - -1 の場合は Listen しない - - _log_level - - ログレベル [0 - 5] - - audio - - audio topic - - _audio_topic_ch - - チャネル数 [1] - - _audio_topic_rate - - サンプリングレート - - -### WebRTC SFU Sora で動作を確認する - -**この機能を利用する場合は WebRTC SFU Sora のライセンス契約が必要です** - -```shell -$ ./momo _use_sora:=true \ - _compressed:=false \ - _SIGNALING_URL:="wss://example.com/signaling" \ - _CHANNEL_ID:="sora" \ - _video_codec:=H264 \ - _log_level:=5 \ - _video_bitrate:=300 \ - image:=/usb_cam/image_raw \ - audio:=/audio \ - _audio_topic_ch:=1 \ - _audio_topic_rate:=16000 -``` - -image には Web カメラから送られてくる画像データの topic を指定してください。 -audio にはマイクから送られてくる音声データの topic を指定してください。 - - -- 変更可能なパラメータ - - _SIGNALING_URL - - シグナリング URL - - _CHANNEL_ID - - チャネル ID - - image - - topic - - _compressed - - JPEG 圧縮済みイメージ topic か [true,false] - - _video_codec - - ビデオコーデック [H264,VP8,VP9] - - _video_bitrate - - ビデオビットレート [1 - 30000] - - _log_level - - ログレベル [0 - 5] - - audio - - audio topic - - _audio_topic_ch - - チャネル数 [1] - - _audio_topic_rate - - サンプリングレート diff --git a/src/ayame/ayame_websocket_client.cpp b/src/ayame/ayame_websocket_client.cpp index e8c61c7a..5863b20b 100644 --- a/src/ayame/ayame_websocket_client.cpp +++ b/src/ayame/ayame_websocket_client.cpp @@ -140,6 +140,9 @@ bool AyameWebsocketClient::connect() { void AyameWebsocketClient::reconnectAfter() { int interval = 5 * (2 * retry_count_); + if (interval > 30) { + interval = 30; + } RTC_LOG(LS_INFO) << __FUNCTION__ << " reconnect after " << interval << " sec"; watchdog_.enable(interval); @@ -283,7 +286,7 @@ void AyameWebsocketClient::setIceServersFromConfig(json json_message) { } } } - if (ice_servers_.empty()) { + if (ice_servers_.empty() && !conn_settings_.no_google_stun) { // accept 時に iceServers が返却されてこなかった場合 google の stun server を用いる webrtc::PeerConnectionInterface::IceServer ice_server; ice_server.uri = "stun:stun.l.google.com:19302"; diff --git a/src/connection_settings.h b/src/connection_settings.h index 4c15e552..27fd85ec 100644 --- a/src/connection_settings.h +++ b/src/connection_settings.h @@ -16,6 +16,7 @@ struct ConnectionSettings { int audio_topic_ch = 1; #endif + bool no_google_stun = false; bool no_video_device = false; bool no_audio_device = false; bool force_i420 = false; @@ -106,6 +107,8 @@ struct ConnectionSettings { friend std::ostream& operator<<(std::ostream& os, const ConnectionSettings& cs) { + os << "no_google_stun: " << (cs.no_google_stun ? "true" : "false") + << "\n"; os << "no_video_device: " << (cs.no_video_device ? "true" : "false") << "\n"; os << "no_audio_device: " << (cs.no_audio_device ? "true" : "false") diff --git a/src/p2p/p2p_connection.cpp b/src/p2p/p2p_connection.cpp index 05b7409c..4cd29fde 100644 --- a/src/p2p/p2p_connection.cpp +++ b/src/p2p/p2p_connection.cpp @@ -9,13 +9,16 @@ using json = nlohmann::json; using IceConnectionState = webrtc::PeerConnectionInterface::IceConnectionState; P2PConnection::P2PConnection(RTCManager* rtc_manager, + ConnectionSettings conn_settings, std::function send) : _send(send) { webrtc::PeerConnectionInterface::RTCConfiguration rtc_config; webrtc::PeerConnectionInterface::IceServers servers; - webrtc::PeerConnectionInterface::IceServer ice_server; - ice_server.uri = "stun:stun.l.google.com:19302"; - servers.push_back(ice_server); + if (!conn_settings.no_google_stun) { + webrtc::PeerConnectionInterface::IceServer ice_server; + ice_server.uri = "stun:stun.l.google.com:19302"; + servers.push_back(ice_server); + } rtc_config.servers = servers; _connection = rtc_manager->createConnection(rtc_config, this); } diff --git a/src/p2p/p2p_connection.h b/src/p2p/p2p_connection.h index df0d004e..9f50ce96 100644 --- a/src/p2p/p2p_connection.h +++ b/src/p2p/p2p_connection.h @@ -11,7 +11,9 @@ class P2PConnection : public RTCMessageSender { public: - P2PConnection(RTCManager* rtc_manager, std::function send); + P2PConnection(RTCManager* rtc_manager, + ConnectionSettings conn_settings, + std::function send); ~P2PConnection() {} webrtc::PeerConnectionInterface::IceConnectionState getRTCConnectionState() { diff --git a/src/p2p/p2p_server.cpp b/src/p2p/p2p_server.cpp index 3d23017f..1b7337e5 100644 --- a/src/p2p/p2p_server.cpp +++ b/src/p2p/p2p_server.cpp @@ -8,7 +8,8 @@ P2PServer::P2PServer(boost::asio::io_context& ioc, std::shared_ptr const& doc_root, RTCManager* rtc_manager, ConnectionSettings conn_settings) - : acceptor_(ioc), + : ioc_(ioc), + acceptor_(ioc), socket_(ioc), doc_root_(doc_root), rtc_manager_(rtc_manager), @@ -60,7 +61,7 @@ void P2PServer::onAccept(boost::system::error_code ec) { if (ec) { MOMO_BOOST_ERROR(ec, "accept"); } else { - std::make_shared(std::move(socket_), doc_root_, rtc_manager_, + std::make_shared(ioc_, std::move(socket_), doc_root_, rtc_manager_, conn_settings_) ->run(); } diff --git a/src/p2p/p2p_server.h b/src/p2p/p2p_server.h index 9556ed4a..d1165607 100644 --- a/src/p2p/p2p_server.h +++ b/src/p2p/p2p_server.h @@ -12,6 +12,7 @@ #include "util.h" class P2PServer : public std::enable_shared_from_this { + boost::asio::io_context& ioc_; boost::asio::ip::tcp::acceptor acceptor_; boost::asio::ip::tcp::socket socket_; std::shared_ptr doc_root_; diff --git a/src/p2p/p2p_session.cpp b/src/p2p/p2p_session.cpp index 974fac45..fb17452d 100644 --- a/src/p2p/p2p_session.cpp +++ b/src/p2p/p2p_session.cpp @@ -15,11 +15,13 @@ #include "util.h" -P2PSession::P2PSession(boost::asio::ip::tcp::socket socket, +P2PSession::P2PSession(boost::asio::io_context& ioc, + boost::asio::ip::tcp::socket socket, std::shared_ptr const& doc_root, RTCManager* rtc_manager, ConnectionSettings conn_settings) - : socket_(std::move(socket)), + : ioc_(ioc), + socket_(std::move(socket)), strand_(socket_.get_executor()), doc_root_(doc_root), rtc_manager_(rtc_manager), @@ -57,7 +59,7 @@ void P2PSession::onRead(boost::system::error_code ec, // WebSocket の upgrade リクエスト if (req_.target() == "/ws") { if (boost::beast::websocket::is_upgrade(req_)) { - P2PWebsocketSession::make_shared(std::move(socket_), rtc_manager_, + P2PWebsocketSession::make_shared(ioc_, std::move(socket_), rtc_manager_, conn_settings_) ->run(std::move(req_)); return; diff --git a/src/p2p/p2p_session.h b/src/p2p/p2p_session.h index 16e7e153..fcf2fc42 100644 --- a/src/p2p/p2p_session.h +++ b/src/p2p/p2p_session.h @@ -20,6 +20,7 @@ // 1つの HTTP リクエストを処理するためのクラス class P2PSession : public std::enable_shared_from_this { + boost::asio::io_context& ioc_; boost::asio::ip::tcp::socket socket_; boost::asio::strand strand_; boost::beast::flat_buffer buffer_; @@ -31,7 +32,8 @@ class P2PSession : public std::enable_shared_from_this { ConnectionSettings conn_settings_; public: - P2PSession(boost::asio::ip::tcp::socket socket, + P2PSession(boost::asio::io_context& ioc, + boost::asio::ip::tcp::socket socket, std::shared_ptr const& doc_root, RTCManager* rtc_manager, ConnectionSettings conn_settings); diff --git a/src/p2p/p2p_websocket_session.cpp b/src/p2p/p2p_websocket_session.cpp index f1e8b4dd..6e785143 100644 --- a/src/p2p/p2p_websocket_session.cpp +++ b/src/p2p/p2p_websocket_session.cpp @@ -9,9 +9,12 @@ using json = nlohmann::json; -P2PWebsocketSession::P2PWebsocketSession(RTCManager* rtc_manager, +P2PWebsocketSession::P2PWebsocketSession(boost::asio::io_context& ioc, + RTCManager* rtc_manager, ConnectionSettings conn_settings) - : rtc_manager_(rtc_manager), conn_settings_(conn_settings) { + : rtc_manager_(rtc_manager), conn_settings_(conn_settings), + watchdog_(ioc, + std::bind(&P2PWebsocketSession::onWatchdogExpired, this)) { RTC_LOG(LS_INFO) << __FUNCTION__; } @@ -20,10 +23,11 @@ P2PWebsocketSession::~P2PWebsocketSession() { } std::shared_ptr P2PWebsocketSession::make_shared( + boost::asio::io_context& ioc, boost::asio::ip::tcp::socket socket, RTCManager* rtc_manager, ConnectionSettings conn_settings) { - auto p = std::make_shared(rtc_manager, conn_settings); + auto p = std::make_shared(ioc, rtc_manager, conn_settings); p->ws_ = std::unique_ptr(new Websocket(std::move(socket))); return p; } @@ -34,6 +38,14 @@ void P2PWebsocketSession::run( doAccept(std::move(req)); } +void P2PWebsocketSession::onWatchdogExpired() { + json ping_message = { + {"type", "ping"}, + }; + ws_->sendText(std::move(ping_message.dump())); + watchdog_.reset(); +} + void P2PWebsocketSession::doAccept( boost::beast::http::request req) { RTC_LOG(LS_INFO) << __FUNCTION__; @@ -98,7 +110,7 @@ void P2PWebsocketSession::onRead(boost::system::error_code ec, auto send = std::bind([](P2PWebsocketSession* session, std::string str) { session->ws_->sendText(str); }, this, std::placeholders::_1); - connection_ = std::make_shared(rtc_manager_, send); + connection_ = std::make_shared(rtc_manager_, conn_settings_, send); std::shared_ptr rtc_conn = connection_->getRTCConnection(); rtc_conn->setOffer(sdp); } else if (type == "answer") { @@ -131,8 +143,15 @@ void P2PWebsocketSession::onRead(boost::system::error_code ec, } std::shared_ptr rtc_conn = p2p_conn->getRTCConnection(); rtc_conn->addIceCandidate(sdp_mid, sdp_mlineindex, candidate); - } else if (type == "close") { + } else if (type == "close" || type == "bye") { connection_ = nullptr; + } else if (type == "register") { + json accept_message = { + {"type", "accept"}, + {"isExistUser", true}, + }; + ws_->sendText(std::move(accept_message.dump())); + watchdog_.enable(30); } else { return; } diff --git a/src/p2p/p2p_websocket_session.h b/src/p2p/p2p_websocket_session.h index 9f11c13a..d57fdce2 100644 --- a/src/p2p/p2p_websocket_session.h +++ b/src/p2p/p2p_websocket_session.h @@ -14,6 +14,7 @@ #include "p2p_connection.h" #include "rtc/manager.h" #include "util.h" +#include "watchdog.h" #include "ws/websocket.h" class P2PWebsocketSession @@ -21,21 +22,26 @@ class P2PWebsocketSession std::unique_ptr ws_; boost::beast::multi_buffer sending_buffer_; + WatchDog watchdog_; + RTCManager* rtc_manager_; ConnectionSettings conn_settings_; std::shared_ptr connection_; public: - P2PWebsocketSession(RTCManager* rtc_manager, + P2PWebsocketSession(boost::asio::io_context& ioc, + RTCManager* rtc_manager, ConnectionSettings conn_settings); ~P2PWebsocketSession(); static std::shared_ptr make_shared( + boost::asio::io_context& ioc, boost::asio::ip::tcp::socket socket, RTCManager* rtc_manager, ConnectionSettings conn_settings); void run(boost::beast::http::request req); private: + void onWatchdogExpired(); void doAccept( boost::beast::http::request req); void onAccept(boost::system::error_code ec); diff --git a/src/util.cpp b/src/util.cpp index 750aab4f..9aa235e2 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -54,6 +54,8 @@ void Util::parseArgs(int argc, local_nh.param("use_ayame", use_ayame, use_ayame); local_nh.param("use_sora", use_sora, use_sora); + local_nh.param("no_google_stun", cs.no_google_stun, + cs.no_google_stun); local_nh.param("no_video_device", cs.no_video_device, cs.no_video_device); local_nh.param("no_audio_device", cs.no_audio_device, @@ -206,6 +208,8 @@ void Util::parseArgs(int argc, }, ""); + app.add_flag("--no-google-stun", cs.no_google_stun, + "Do not use google stun"); app.add_flag("--no-video-device", cs.no_video_device, "Do not use video device"); app.add_flag("--no-audio-device", cs.no_audio_device,