2

使用 SipJs 0.17.1 和 freeswitch 1.10.5。Debian 10. stun:stun.l.google.com:19302 <param name="apply-candidate-acl" value="wan.auto"/>

如果用户使用任何家庭或办公室互联网并在接到电话时,音频会在约 0.2 秒内出现。

9bd6fc2d-fe49-4a05-8a43-b400e4ce3565 2021-01-16 21:39:29.103910 [NOTICE] switch_rtp.c:4952 Activating RTP audio ICE: UpI7:gafAlEO8WSw1T9B3 109.201.xxx.xxx:9646
9bd6fc2d-fe49-4a05-8a43-b400e4ce3565 2021-01-16 21:39:29.103910 [INFO] switch_core_media.c:8896 Skipping RTCP ICE (Same as RTP)
9bd6fc2d-fe49-4a05-8a43-b400e4ce3565 2021-01-16 21:39:29.103910 [INFO] switch_rtp.c:3764 Activate RTP/RTCP audio DTLS client
9bd6fc2d-fe49-4a05-8a43-b400e4ce3565 2021-01-16 21:39:29.103910 [INFO] switch_rtp.c:3927 Changing audio DTLS state from OFF to HANDSHAKE
9bd6fc2d-fe49-4a05-8a43-b400e4ce3565 2021-01-16 21:39:29.243916 [INFO] switch_rtp.c:3282 Changing audio DTLS state from HANDSHAKE to SETUP
9bd6fc2d-fe49-4a05-8a43-b400e4ce3565 2021-01-16 21:39:29.263910 [INFO] switch_rtp.c:3189 audio Fingerprint Verified.
9bd6fc2d-fe49-4a05-8a43-b400e4ce3565 2021-01-16 21:39:29.263910 [INFO] switch_rtp.c:4254 Activating audio Secure RTP SEND
9bd6fc2d-fe49-4a05-8a43-b400e4ce3565 2021-01-16 21:39:29.263910 [INFO] switch_rtp.c:4232 Activating audio Secure RTP RECV
9bd6fc2d-fe49-4a05-8a43-b400e4ce3565 2021-01-16 21:39:29.263910 [INFO] switch_rtp.c:3231 Changing audio DTLS state from SETUP to READY

但是当用户使用移动互联网和接听电话时,音频会在大约 1.5 秒内出现(主观上更长)。

7518c5c2-a045-4535-9630-97a20c4cd980 2021-01-16 23:37:40.003922 [NOTICE] switch_rtp.c:4952 Activating RTP audio ICE: rzCc:NJN0su78A6fbnv6q 89.42.xxx.xxx:45466
7518c5c2-a045-4535-9630-97a20c4cd980 2021-01-16 23:37:40.003922 [INFO] switch_core_media.c:8896 Skipping RTCP ICE (Same as RTP)
7518c5c2-a045-4535-9630-97a20c4cd980 2021-01-16 23:37:40.003922 [INFO] switch_rtp.c:3764 Activate RTP/RTCP audio DTLS client
7518c5c2-a045-4535-9630-97a20c4cd980 2021-01-16 23:37:40.003922 [INFO] switch_rtp.c:3927 Changing audio DTLS state from OFF to HANDSHAKE
7518c5c2-a045-4535-9630-97a20c4cd980 2021-01-16 23:37:41.243907 [NOTICE] switch_rtp.c:1301 Auto Changing audio stun/rtp/dtls port from 89.42.xxx.xxx:45466 to 89.42.xxx.xxx:63930 idx:1
7518c5c2-a045-4535-9630-97a20c4cd980 2021-01-16 23:37:41.403925 [INFO] switch_rtp.c:3282 Changing audio DTLS state from HANDSHAKE to SETUP
7518c5c2-a045-4535-9630-97a20c4cd980 2021-01-16 23:37:41.423918 [INFO] switch_rtp.c:3189 audio Fingerprint Verified.
7518c5c2-a045-4535-9630-97a20c4cd980 2021-01-16 23:37:41.423918 [INFO] switch_rtp.c:4254 Activating audio Secure RTP SEND
7518c5c2-a045-4535-9630-97a20c4cd980 2021-01-16 23:37:41.423918 [INFO] switch_rtp.c:4232 Activating audio Secure RTP RECV
7518c5c2-a045-4535-9630-97a20c4cd980 2021-01-16 23:37:41.423918 [INFO] switch_rtp.c:3231 Changing audio DTLS state from SETUP to READY

为什么会出现线条Auto Changing audio stun/rtp/dtls?是什么让端口发生变化?如何避免耗时的端口切换?

4

1 回答 1

0

WebRTC 中的连接建立使用称为 ICE 的协议 ( https://www.rfc-editor.org/rfc/rfc8445 )。ICE 首先尝试在对等方之间建立直接连接,只有在此失败后才回退到使用 TURN 中继。

在您的情况下,很可能从您的办公室网络直接连接成功,但移动客户端需要使用 TURN 服务器,这仅在超时后发生。如果您知道需要 TURN 服务器,则可以通过指定{iceTransportPolicy: 'relay'}何时建立对等连接来避免超时。

于 2021-01-17T15:29:13.023 回答