5

Apprtc.Follow 以下の言及ライブラリを使用してビデオ通話アプリに取り組んでいます。

  1. https://github.com/njovy/AppRTCDemo
  2. https://github.com/Piasy/AppRTC-Android

URL を apprtc サーバーではなくカスタム サーバーに変更すると、1 分後にビデオ通話が切断されます。サーバーとの接続が失われました。

サーバーとの接続が失われないようにするには、定期的に約 30 秒間隔でサーバーに ping を実行する必要があります。

ただし、上記のAppRTCプロジェクトはjarファイル(autobanh.jar)を使用してwebsocket接続を行っていますが、ライブラリではsendPing mentodはプライベートであるためアクセスできません。

質問 1 - Websocket サーバーに ping を実行する方法はありません。

websocket ライブラリを置き換えてから試してください websocket ライブラリを以下のライブラリで変更しました

  1. https://github.com/Koredotcom/android-kore-sdk/tree/master/BotsSDK/korebotsdklib/src/main/java/kore/botssdk/autobahn
  2. https://github.com/martindale/soundtrack.io-android/tree/master/src/de/tavendo/autobahn

websocket ライブラリを置き換えた後、sendPing メソッドにアクセスできるようになりました。しかし、ビデオ通話中に 60 秒後に接続が失われました。

Ping メソッド-

 public void sendPingMessageToServer() {
    try {
        WebSocketMessage.Ping ping = new WebSocketMessage.Ping();
//            ping.mPayload="ping to server".getBytes();
        mWebSocketWriter.sendPing(ping);

    } catch (Exception e) {
        e.printStackTrace();
    }
}

ping.mPayload 行のコメントを外すと、BufferOverflowException が発生します。

30秒のタイマー

  private void startConnectionCheckTimer() {
    timerInstance.scheduleAtFixedRate(new TimerTask() {
        @Override
        public void run() {
            try {
               ws.sendPingMessageToServer();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }, 0, 30 * 1000);
}

60 秒後に通話が切断されないようにする方法を提案してください。

4

1 に答える 1