LoginSignup
2
0

More than 1 year has passed since last update.

iOSの場合、正常動作でもiceconnectionStateがdisconnectの状態が返ってきてしまう

Last updated at Posted at 2021-11-10

どんな現象か?

リモートからのvideoストリームを受信して、クライアント側のvideoタグで出力しようとしたところ何故かconnectionStateがdisconnectになってしまって焦ったお話し。

発生したコード

videoストリームの取得は以下の様に至ってシンプル

peer = new RTCPeerConnection({ iceServers: iceservers });
    peer.ontrack = async (event: RTCTrackEvent) => {
    this.onAddVideoStream(event.streams[0]);
};

取得したstreamをvideoタグに紐付けた変数に代入します。

async onAddVideoStream(stream: MediaStream) {
    try {
      if (this.video) {
        this.video.srcObject = stream;
        video.play().catch(() => {});
        this.video.pause();
        setTimeout(() => {
          this.video.play().then((res: Response) => {
            console.log("playing start", res);
          })
            .catch((err: Error) => {
              console.log("error playing", err);
            });
        }, 0);
      }
    } catch (e) {
      console.log(e);
    }
}

結果

PCではvideoタグを使ったstream出力に成功するも、iOSだとpeer.oncoonectionstatechangeが発生してpeer.connectionStateがdisconnectになってしまう。

最初iOSのvideo再生の仕様なのかと疑ったが、どうやらdiconnectが返ってきてもそのままvideo出力をすると見事に成功している。

そもそもdisconectのステータスってどういうこと?と調べてみると以下のサイトでは

https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/iceConnectionState

disconnected
Checks to ensure that components are still connected failed for at least one component of the RTCPeerConnection. This is a less stringent test than failed and may trigger intermittently and resolve just as spontaneously on less reliable networks, or during temporary disconnections. When the problem resolves, the connection may return to the connected state.

「コンポーネントがまだ接続されていることを確認するチェックが、RTCPeerConnectionの少なくとも1つのコンポーネントで失敗しました。これは failed よりも厳しいテストではなく、信頼性の低いネットワークや一時的な切断の際に断続的に発生し、同じように自然に解決する可能性があります。問題が解決すると、接続は接続状態に戻ります。」

どうも一時的に切断されるだけで、peerをリリースするほどではないということらしい。failedに遷移するものだけ拾えばいいねと思ったら

どうもchromeではfailedに遷移することはないらしく・・・・致し方ないのでdisconnectが返却されても突き進むことで対応しました。この現象はどうも利用しているキャリア依存のようで、私のAU回線では発生していますが、Docomo回線では発生しない模様。

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0