[Bug] WebRTC Connection Fails: SDP m-lines Order Mismatch in @livekit/react-native
[Bug] Failed to Set Remote Answer SDP Due to m-lines Order Mismatch on Android 13
Describe the bug
When attempting to set a remote answer SDP in a WebRTC connection, the process fails with the error: Failed to set remote answer sdp: The order of m-lines in answer doesn't match order in offer. Rejecting answer. This prevents the WebRTC connection from being established properly.
To Reproduce
Steps to reproduce the behavior:
- Set up a WebRTC peer connection using
@livekit/react-nativeand@livekit/react-native-webrtc. - Join a room (e.g.,
room-452a6def) with a participant (e.g.,test). - Attempt to set the remote answer SDP received from the server.
- See the error logged in the console.
Expected behavior
The remote answer SDP should be successfully applied, allowing the WebRTC connection to proceed without errors.
Screenshots
Device Info:
- Device: Xiaomi M2101K6G (Redmi Note 10 Pro)
- OS: Android 13
Dependencies Info:
-
@livekit/react-native: ^2.6.5 -
@livekit/react-native-expo-plugin: ^1.0.1 -
@livekit/react-native-webrtc: ^125.0.9
Additional context
The issue seems to stem from a mismatch in the m-lines order between the offer and answer SDPs. Below are the relevant logs and SDP details:
Observations:
- The answer SDP contains only one
m-line(m=applicationfor a data channel), which might not align with the offer SDP if it includes additional media types (e.g., audio or video). - This issue could be related to how
@livekit/react-nativeor@livekit/react-native-webrtchandles SDP negotiation on Android 13. - Note: While the error appears in development logs, it does not currently block functionality (e.g., joining and using the room). However, this has not been tested in a production environment, so potential impacts remain unknown.
I have the same issue.
logcat
Logcat
03-30 15:02:24.048 2268 2615 I ReactNativeJS: rn-webrtc:pc:DEBUG 1 createAnswer +3ms
03-30 15:02:24.075 2268 2615 I ReactNativeJS: 'publishing track', { room: '8199d8f2e0593b320d46d4530cc79a891ed',
03-30 15:02:24.075 2268 2615 I ReactNativeJS: roomID: 'RM_pYkeAVHKowUR',
03-30 15:02:24.075 2268 2615 I ReactNativeJS: participant: 'Sandu',
03-30 15:02:24.075 2268 2615 I ReactNativeJS: pID: 'PA_cFSJEkCGv2Mp',
03-30 15:02:24.075 2268 2615 I ReactNativeJS: trackID: undefined,
03-30 15:02:24.075 2268 2615 I ReactNativeJS: source: 'microphone',
03-30 15:02:24.075 2268 2615 I ReactNativeJS: muted: false,
03-30 15:02:24.075 2268 2615 I ReactNativeJS: enabled: true,
03-30 15:02:24.075 2268 2615 I ReactNativeJS: kind: 'audio',
03-30 15:02:24.075 2268 2615 I ReactNativeJS: streamID: '4478bce2-f5ab-4bfb-aabe-d324ded16e6e',
03-30 15:02:24.075 2268 2615 I ReactNativeJS: streamTrackID: '4478bce2-f5ab-4bfb-aabe-d324ded16e6e' }
03-30 15:02:24.100 2268 2615 I ReactNativeJS: rn-webrtc:pc:DEBUG 0 addTransceiver +52ms
03-30 15:02:24.131 2268 2615 I ReactNativeJS: rn-webrtc:pc:DEBUG 0 createOffer OK +32ms
03-30 15:02:24.139 2268 2615 I ReactNativeJS: rn-webrtc:pc:DEBUG 0 setLocalDescription +8ms
03-30 15:02:24.141 2268 2615 I ReactNativeJS: rn-webrtc:pc:DEBUG 1 setLocalDescription +2ms
03-30 15:02:24.147 2268 2619 I org.webrtc.Logging: NetworkMonitor: Start monitoring with native observer -5476376671632052496 fieldTrialsString:
03-30 15:02:24.151 1723 3137 D CompatibilityChangeReporter: Compat change id reported: 266524688; UID 12345; state: ENABLED
03-30 15:02:24.152 2268 2619 W org.webrtc.Logging: NetworkMonitorAutoDetect: Unable to obtain permission to request a cellular network.
03-30 15:02:24.154 1723 3137 D CompatibilityChangeReporter: Compat change id reported: 319212206; UID 12345; state: ENABLED
03-30 15:02:24.155 2268 2615 I ReactNativeJS: rn-webrtc:pc:DEBUG 0 createOffer +14ms
03-30 15:02:24.159 2268 2883 I org.webrtc.Logging: NetworkMonitorAutoDetect: Network handle: 450082295821 becomes available: 104
03-30 15:02:24.160 1723 2487 D ConnectivityService: NetReassign [no changes] [c 0] [a 1] [i 4]
03-30 15:02:24.161 2268 2621 D com.oney.WebRTCModule.WebRTCModule: onIceGatheringChangeGATHERING
03-30 15:02:24.165 2268 2883 I org.webrtc.Logging: NetworkMonitorAutoDetect: handle: 450082295821 capabilities changed: [ Transports: WIFI Capabilities: NOT_METERED&INTERNET&NOT_RESTRICTED&TRUSTED&NOT_VPN&VALIDATED&NOT_ROAMING&FOREGROUND&NOT_CONGESTED&NOT_SUSPENDED&NOT_VCN_MANAGED LinkUpBandwidth>=41226Kbps LinkDnBandwidth>=36556Kbps TransportInfo: <SSID: <unknown ssid>, BSSID: 02:00:00:00:00:00, MAC: 02:00:00:00:00:00, IP: /192.168.0.8, Security type: 2, Supplicant state: COMPLETED, Wi-Fi standard: 11n, RSSI: -65, Link speed: 144Mbps, Tx Link speed: 144Mbps, Max Supported Tx Link speed: 144Mbps, Rx Link speed: 65Mbps, Max Supported Rx Link speed: 144Mbps, Frequency: 2417MHz, Net ID: -1, Metered hint: false, score: 60, isUsable: true, CarrierMerged: false, SubscriptionId: -1, IsPrimary: -1, Trusted: true, Restricted: false, Ephemeral: false, OEM paid: false, OEM private: false, OSU AP: false, FQDN: <none>, Provider friendly name: <none>, Requesting package name: <none><none>MLO Information: , Is TID-To-Link negotiation supported by the AP: false, AP MLD Address: <none>, AP MLO Link Id: <none>, AP MLO Affiliated links: <none>, Vendor Data: <none>> SignalStrength: -65 UnderlyingNetworks: Null]
03-30 15:02:24.167 2268 2621 D com.oney.WebRTCModule.WebRTCModule: onIceCandidate
03-30 15:02:24.168 2268 2621 D com.oney.WebRTCModule.WebRTCModule: onIceCandidate
03-30 15:02:24.168 2268 2621 D com.oney.WebRTCModule.WebRTCModule: onIceGatheringChangeGATHERING
03-30 15:02:24.169 2268 2883 I org.webrtc.Logging: NetworkMonitorAutoDetect: handle: 450082295821 link properties changed
03-30 15:02:24.170 2268 2621 D com.oney.WebRTCModule.WebRTCModule: onIceCandidate
03-30 15:02:24.170 2268 2621 D com.oney.WebRTCModule.WebRTCModule: onIceCandidate
03-30 15:02:24.173 2268 2615 I ReactNativeJS: rn-webrtc:pc:DEBUG 0 setLocalDescription OK +18ms
03-30 15:02:24.177 2268 2615 I ReactNativeJS: rn-webrtc:pc:DEBUG 1 setLocalDescription OK +4ms
03-30 15:02:24.194 2268 2615 I ReactNativeJS: rn-webrtc:pc:DEBUG 0 createOffer OK +16ms
03-30 15:02:24.202 2268 2615 I ReactNativeJS: rn-webrtc:pc:DEBUG 0 setLocalDescription +9ms
03-30 15:02:24.206 2268 2621 D com.oney.WebRTCModule.WebRTCModule: onIceCandidate
03-30 15:02:24.207 2268 2621 D com.oney.WebRTCModule.WebRTCModule: onIceCandidate
03-30 15:02:24.209 2268 2615 I ReactNativeJS: rn-webrtc:pc:DEBUG 0 setLocalDescription OK +6ms
03-30 15:02:24.209 2268 2621 D com.oney.WebRTCModule.WebRTCModule: onIceCandidate
03-30 15:02:24.209 2268 2621 D com.oney.WebRTCModule.WebRTCModule: onIceCandidate
03-30 15:02:24.233 2268 2615 I ReactNativeJS: rn-webrtc:pc:DEBUG 0 setRemoteDescription +24ms
03-30 15:02:24.241 2268 2615 W ReactNativeJS: 'not able to set answer, falling back to unmodified sdp', { room: '8199d8f2e0593b320d46d4530cc79a891ed',
03-30 15:02:24.241 2268 2615 W ReactNativeJS: roomID: 'RM_pYkeAVHKowUR',
03-30 15:02:24.241 2268 2615 W ReactNativeJS: participant: 'Sandu',
03-30 15:02:24.241 2268 2615 W ReactNativeJS: pID: 'PA_cFSJEkCGv2Mp',
03-30 15:02:24.241 2268 2615 W ReactNativeJS: error:
03-30 15:02:24.241 2268 2615 W ReactNativeJS: { [Error: Failed to set remote answer sdp: The order of m-lines in answer doesn't match order in offer. Rejecting answer.]
03-30 15:02:24.241 2268 2615 W ReactNativeJS: nativeStackAndroid: [],
03-30 15:02:24.241 2268 2615 W ReactNativeJS: userInfo: null,
03-30 15:02:24.241 2268 2615 W ReactNativeJS: code: 'E_OPERATION_ERROR' },
03-30 15:02:24.241 2268 2615 W ReactNativeJS: sdp: 'v=0\r\no=- 7202846363982893381 1743336143 IN IP4 0.0.0.0\r\ns=-\r\nt=0 0\r\na=extmap-allow-mixed\r\na=ice-lite\r\na=fingerprint:sha-256 2E:CE:AB:6F:15:F4:DD:FD:35:CD:18:52:55:B8:7A:D5:15:36:11:E5:E7:B1:4C:6F:38:C2:A3:5B:92:1D:53:5E\r\na=group:BUNDLE 0\r\na=msid-semantic:WMS*\r\nm=application 9 UDP/DTLS/SCTP webrtc-datachannel\r\nc=IN IP4 0.0.0.0\r\na=setup:active\r\na=mid:0\r\na=sendrecv\r\na=ice-ufrag:kgIEpfbdQhLShepf\r\na=ice-pwd:jdRsnjUmmXKLkCivZJEWyWHIPPhywmjz\r\na=sctp-port:5000\r\n' }
03-30 15:02:24.242 2268 2615 I ReactNativeJS: rn-webrtc:pc:DEBUG 0 setRemoteDescription +9ms
03-30 15:02:24.243 2268 2621 D com.oney.WebRTCModule.WebRTCModule: onIceCandidate
03-30 15:02:24.251 2268 2615 E ReactNativeJS: 'unable to set answer', { room: '8199d8f2e0593b320d46d4530cc79a891ed',
03-30 15:02:24.251 2268 2615 E ReactNativeJS: roomID: 'RM_pYkeAVHKowUR',
03-30 15:02:24.251 2268 2615 E ReactNativeJS: participant: 'Sandu',
03-30 15:02:24.251 2268 2615 E ReactNativeJS: pID: 'PA_cFSJEkCGv2Mp',
03-30 15:02:24.251 2268 2615 E ReactNativeJS: fields:
03-30 15:02:24.251 2268 2615 E ReactNativeJS: { error: 'Failed to set remote answer sdp: The order of m-lines in answer doesn\'t match order in offer. Rejecting answer.',
03-30 15:02:24.251 2268 2615 E ReactNativeJS: sdp: 'v=0\r\no=- 7202846363982893381 1743336143 IN IP4 0.0.0.0\r\ns=-\r\nt=0 0\r\na=msid-semantic:WMS*\r\na=fingerprint:sha-256 2E:CE:AB:6F:15:F4:DD:FD:35:CD:18:52:55:B8:7A:D5:15:36:11:E5:E7:B1:4C:6F:38:C2:A3:5B:92:1D:53:5E\r\na=ice-lite\r\na=extmap-allow-mixed\r\na=group:BUNDLE 0\r\nm=application 9 UDP/DTLS/SCTP webrtc-datachannel\r\nc=IN IP4 0.0.0.0\r\na=setup:active\r\na=mid:0\r\na=sendrecv\r\na=sctp-port:5000\r\na=ice-ufrag:kgIEpfbdQhLShepf\r\na=ice-pwd:jdRsnjUmmXKLkCivZJEWyWHIPPhywmjz\r\n' } }
03-30 15:02:24.314 2268 2615 I ReactNativeJS: rn-webrtc:pc:DEBUG 0 setRemoteDescription +72ms
03-30 15:02:24.339 2268 2615 I ReactNativeJS: rn-webrtc:pc:DEBUG 0 setRemoteDescription OK +25ms
03-30 15:02:24.339 2268 2615 I ReactNativeJS: rn-webrtc:pc:DEBUG 0 addIceCandidate +1ms
03-30 15:02:24.341 2268 2615 I ReactNativeJS: rn-webrtc:pc:DEBUG 0 addIceCandidate +1ms
03-30 15:02:24.341 2268 2621 D com.oney.WebRTCModule.WebRTCModule: onIceCandidate
03-30 15:02:24.342 2268 2615 I ReactNativeJS: rn-webrtc:pc:DEBUG 0 addIceCandidate +1ms
03-30 15:02:24.343 2268 2615 I ReactNativeJS: rn-webrtc:pc:DEBUG 0 addIceCandidate +2ms
03-30 15:02:24.364 2268 2615 I ReactNativeJS: 'connecting', undefined
03-30 15:02:24.370 2268 2615 I ReactNativeJS: 'connecting', undefined
I have the same issue.
Console Log
console log
console.js:654 unable to set answer
{room: '1746437658417', roomID: 'RM_9W3wXg8o5yUu', participant: 'testUser', pID: 'PA_wMGYw9HPJmnP', fields: {…}}
fields
:
error
:
"Failed to set remote answer sdp: The order of m-lines in answer doesn't match order in offer. Rejecting answer."
sdp
:
"v=0\r\no=- 8549255068889549517 1746437721 IN IP4 0.0.0.0\r\ns=-\r\nt=0 0\r\na=msid-semantic:WMS*\r\na=fingerprint:sha-256 21:7B:FB:40:14:65:CB:CA:48:B3:7B:E5:8C:41:0D:E3:79:AB:B0:D6:CC:6A:C1:D4:AF:3F:4F:B1:B9:07:AD:9F\r\na=extmap-allow-mixed\r\na=group:BUNDLE 0\r\nm=application 9 UDP/DTLS/SCTP webrtc-datachannel\r\nc=IN IP4 0.0.0.0\r\na=setup:active\r\na=mid:0\r\na=sendrecv\r\na=sctp-port:5000\r\na=ice-ufrag:aNgUwzjeCzkxUljg\r\na=ice-pwd:xzfImMHNhxjFreLzeVPNJzFbcaCzVXql\r\n"
[[Prototype]]
:
constructor
:
ƒ Object()
hasOwnProperty
:
ƒ hasOwnProperty()
isPrototypeOf
:
ƒ isPrototypeOf()
propertyIsEnumerable
:
ƒ propertyIsEnumerable()
toLocaleString
:
ƒ toLocaleString()
toString
:
ƒ toString()
valueOf
:
ƒ valueOf()
__defineGetter__
:
ƒ __defineGetter__()
__defineSetter__
:
ƒ __defineSetter__()
__lookupGetter__
:
ƒ __lookupGetter__()
__lookupSetter__
:
ƒ __lookupSetter__()
__proto__
:
(…)
get __proto__
:
ƒ __proto__()
set __proto__
:
ƒ __proto__()
pID
:
"PA_wMGYw9HPJmnP"
participant
:
"testUser"
room
:
"1746437658417"
roomID
:
"RM_9W3wXg8o5yUu"
[[Prototype]]
:
constructor
:
ƒ Object()
hasOwnProperty
:
ƒ hasOwnProperty()
isPrototypeOf
:
ƒ isPrototypeOf()
propertyIsEnumerable
:
ƒ propertyIsEnumerable()
toLocaleString
:
ƒ toLocaleString()
toString
:
ƒ toString()
valueOf
:
ƒ valueOf()
__defineGetter__
:
ƒ __defineGetter__()
__defineSetter__
:
ƒ __defineSetter__()
__lookupGetter__
:
ƒ __lookupGetter__()
__lookupSetter__
:
ƒ __lookupSetter__()
__proto__
:
(…)
get __proto__
:
ƒ __proto__()
set __proto__
:
ƒ __proto__()
length
:
1
name
:
"set __proto__"
[[Prototype]]
:
ƒ ()
Any fixes on this bug. I have got the same issue
Same Issue
Same issue
Did anyone fixed it ? I'm having the same issue.
@davidliu can you please look into this one, this may be the reason of livestream going black screen for the users after certain point of time
The log here doesn't necessarily mean anything has gone wrong. It's caused by a server answer coming back while we've started a new negotiation (i.e. publishing a track); this commonly will occur on startup when negotiations happen in succession.
However, the log by itself doesn't mean it failed to connect, just that this particular offer from the server didn't match the local state. In normal cases, a subsequent answer from the server will match against the local state and establish the final connection.
@davidliu You mean this issue is not a problem ?? Is it okay to continue to production ?
@davidliu You mean this issue is not a problem ?? Is it okay to continue to production ?
Yes, this is just a noisy log.