Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IOS] PeerConnection not found on IOS when Android and Web work #1453

Closed
OlliePugh opened this issue Oct 2, 2023 · 14 comments
Closed

[IOS] PeerConnection not found on IOS when Android and Web work #1453

OlliePugh opened this issue Oct 2, 2023 · 14 comments

Comments

@OlliePugh
Copy link

I am using WebRTC in a less than normal manner. I use it alongside Janus to stream a video feed to my application, this is a one way stream, the client will only ever recieve video, no audio.

I have integrated janus.js and this library to get my stream appearing. It works fine on Web and Android, but on iOS an error is thrown shortly after

I have tried debugging this problem but can't see where the issue is (especially when the janus.js library is unbeliebably unreadable)

My knowledge of WebRTC isn't great which may be why I am facing this issue! It might be to the point where I need to write my own library for janus.js as it can be a little tricky to get it to interface correctly (But I can't see the Janus code being platform dependant).

I have attached the logs below.

LOG  Initializing library
 LOG  Library initialized: true
 LOG  Using WebSockets to contact Janus: wss://janus.conf.meetecho.com/ws
 DEBUG  Got a success on session null
 DEBUG  {"data": {"id": 3601432129862135}, "janus": "success", "transaction": "ZqGCSDK1K28u"}
 DEBUG  {"data": {"id": 3601432129862135}, "janus": "success", "transaction": "ZqGCSDK1K28u"}
 LOG  Created session: 3601432129862135
 LOG  attaching plugin
 DEBUG  Got a success on session 3601432129862135
 DEBUG  {"data": {"id": 6393118362476376}, "janus": "success", "session_id": 3601432129862135, "transaction": "hQu4tCvfn2rS"}
 DEBUG  {"data": {"id": 6393118362476376}, "janus": "success", "session_id": 3601432129862135, "transaction": "hQu4tCvfn2rS"}
 LOG  Created handle: 6393118362476376
 LOG  Plugin attached! (janus.plugin.streaming, id=6393118362476376)
 LOG  setting plugin handle
 DEBUG  Sending message to plugin (handle=6393118362476376):
 DEBUG  {"body": {"id": 1, "request": "watch"}, "janus": "message", "transaction": "LyXBmqgRZ9kV"}
 DEBUG  Got an ack on session 3601432129862135
 DEBUG  {"janus": "ack", "session_id": 3601432129862135, "transaction": "LyXBmqgRZ9kV"}
 DEBUG  Message sent!
 DEBUG  {"janus": "ack", "session_id": 3601432129862135, "transaction": "LyXBmqgRZ9kV"}
 DEBUG  Got a plugin event on session 3601432129862135
 DEBUG  {"janus": "event", "jsep": {"sdp": "v=0
o=- 1696259004503643 1 IN IP4 217.61.26.125
s=Mountpoint 1
t=0 0
a=group:BUNDLE a v
a=ice-options:trickle
a=fingerprint:sha-256 FC:26:E6:EC:E9:91:3B:65:B3:93:EC:D9:65:C4:90:D2:6D:2E:23:6E:D5:F5:4D:1A:0B:14:84:CF:B6:35:C5:A3
a=extmap-allow-mixed
a=msid-semantic: WMS *
m=audio 9 UDP/TLS/RTP/SAVPF 111
c=IN IP4 217.61.26.125
a=sendonly
a=mid:a
a=rtcp-mux
a=ice-ufrag:6qSP
a=ice-pwd:qS7jl/dyNVujl+Zs3bkPNX
a=ice-options:trickle
a=setup:actpass
a=rtpmap:111 opus/48000/2
a=rtcp-fb:111 transport-cc
a=extmap:2 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time
a=extmap:4 urn:ietf:params:rtp-hdrext:sdes:mid
a=msid:janus janusa
a=ssrc:1741135762 cname:janus
a=candidate:1 1 udp 2015363327 217.61.26.125 58519 typ host
a=end-of-candidates
m=video 9 UDP/TLS/RTP/SAVPF 100 101
c=IN IP4 217.61.26.125
a=sendonly
a=mid:v
a=rtcp-mux
a=ice-ufrag:6qSP
a=ice-pwd:qS7jl/dyNVujl+Zs3bkPNX
a=ice-options:trickle
a=setup:actpass
a=rtpmap:100 VP8/90000
a=rtcp-fb:100 ccm fir
a=rtcp-fb:100 nack
a=rtcp-fb:100 nack pli
a=rtcp-fb:100 goog-remb
a=rtcp-fb:100 transport-cc
a=extmap:2 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time
a=extmap:4 urn:ietf:params:rtp-hdrext:sdes:mid
a=rtpmap:101 rtx/90000
a=fmtp:101 apt=100
a=ssrc-group:FID 3984012780 438015001
a=msid:janus janusv
a=ssrc:3984012780 cname:janus
a=ssrc:438015001 cname:janus
a=candidate:1 1 udp 2015363327 217.61.26.125 58519 typ host
a=end-of-candidates
", "type": "offer"}, "plugindata": {"data": {"result": [Object], "streaming": "event"}, "plugin": "janus.plugin.streaming"}, "sender": 6393118362476376, "session_id": 3601432129862135, "transaction": "LyXBmqgRZ9kV"}
 DEBUG    -- Event is coming from 6393118362476376 (janus.plugin.streaming)
 DEBUG  {"result": {"status": "preparing"}, "streaming": "event"}
 DEBUG  Handling SDP as well...
 DEBUG  {"sdp": "v=0
o=- 1696259004503643 1 IN IP4 217.61.26.125
s=Mountpoint 1
t=0 0
a=group:BUNDLE a v
a=ice-options:trickle
a=fingerprint:sha-256 FC:26:E6:EC:E9:91:3B:65:B3:93:EC:D9:65:C4:90:D2:6D:2E:23:6E:D5:F5:4D:1A:0B:14:84:CF:B6:35:C5:A3
a=extmap-allow-mixed
a=msid-semantic: WMS *
m=audio 9 UDP/TLS/RTP/SAVPF 111
c=IN IP4 217.61.26.125
a=sendonly
a=mid:a
a=rtcp-mux
a=ice-ufrag:6qSP
a=ice-pwd:qS7jl/dyNVujl+Zs3bkPNX
a=ice-options:trickle
a=setup:actpass
a=rtpmap:111 opus/48000/2
a=rtcp-fb:111 transport-cc
a=extmap:2 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time
a=extmap:4 urn:ietf:params:rtp-hdrext:sdes:mid
a=msid:janus janusa
a=ssrc:1741135762 cname:janus
a=candidate:1 1 udp 2015363327 217.61.26.125 58519 typ host
a=end-of-candidates
m=video 9 UDP/TLS/RTP/SAVPF 100 101
c=IN IP4 217.61.26.125
a=sendonly
a=mid:v
a=rtcp-mux
a=ice-ufrag:6qSP
a=ice-pwd:qS7jl/dyNVujl+Zs3bkPNX
a=ice-options:trickle
a=setup:actpass
a=rtpmap:100 VP8/90000
a=rtcp-fb:100 ccm fir
a=rtcp-fb:100 nack
a=rtcp-fb:100 nack pli
a=rtcp-fb:100 goog-remb
a=rtcp-fb:100 transport-cc
a=extmap:2 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time
a=extmap:4 urn:ietf:params:rtp-hdrext:sdes:mid
a=rtpmap:101 rtx/90000
a=fmtp:101 apt=100
a=ssrc-group:FID 3984012780 438015001
a=msid:janus janusv
a=ssrc:3984012780 cname:janus
a=ssrc:438015001 cname:janus
a=candidate:1 1 udp 2015363327 217.61.26.125 58519 typ host
a=end-of-candidates
", "type": "offer"}
 DEBUG  Notifying application...
 DEBUG   ::: Got a message :::
 DEBUG  {"result": {"status": "preparing"}, "streaming": "event"}
 DEBUG  Handling SDP as well...
 DEBUG  {"sdp": "v=0
o=- 1696259004503643 1 IN IP4 217.61.26.125
s=Mountpoint 1
t=0 0
a=group:BUNDLE a v
a=ice-options:trickle
a=fingerprint:sha-256 FC:26:E6:EC:E9:91:3B:65:B3:93:EC:D9:65:C4:90:D2:6D:2E:23:6E:D5:F5:4D:1A:0B:14:84:CF:B6:35:C5:A3
a=extmap-allow-mixed
a=msid-semantic: WMS *
m=audio 9 UDP/TLS/RTP/SAVPF 111
c=IN IP4 217.61.26.125
a=sendonly
a=mid:a
a=rtcp-mux
a=ice-ufrag:6qSP
a=ice-pwd:qS7jl/dyNVujl+Zs3bkPNX
a=ice-options:trickle
a=setup:actpass
a=rtpmap:111 opus/48000/2
a=rtcp-fb:111 transport-cc
a=extmap:2 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time
a=extmap:4 urn:ietf:params:rtp-hdrext:sdes:mid
a=msid:janus janusa
a=ssrc:1741135762 cname:janus
a=candidate:1 1 udp 2015363327 217.61.26.125 58519 typ host
a=end-of-candidates
m=video 9 UDP/TLS/RTP/SAVPF 100 101
c=IN IP4 217.61.26.125
a=sendonly
a=mid:v
a=rtcp-mux
a=ice-ufrag:6qSP
a=ice-pwd:qS7jl/dyNVujl+Zs3bkPNX
a=ice-options:trickle
a=setup:actpass
a=rtpmap:100 VP8/90000
a=rtcp-fb:100 ccm fir
a=rtcp-fb:100 nack
a=rtcp-fb:100 nack pli
a=rtcp-fb:100 goog-remb
a=rtcp-fb:100 transport-cc
a=extmap:2 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time
a=extmap:4 urn:ietf:params:rtp-hdrext:sdes:mid
a=rtpmap:101 rtx/90000
a=fmtp:101 apt=100
a=ssrc-group:FID 3984012780 438015001
a=msid:janus janusv
a=ssrc:3984012780 cname:janus
a=ssrc:438015001 cname:janus
a=candidate:1 1 udp 2015363327 217.61.26.125 58519 typ host
a=end-of-candidates
", "type": "offer"}
 WARN  Deprecated media object passed, use tracks instead. Automatically translated to: [{"recv": true, "type": "audio"}, {"recv": true, "type": "video"}]
 DEBUG  isTrickleEnabled: undefined
 LOG  Creating PeerConnection
 LOG  rn-webrtc:pc:DEBUG 0 ctor +0ms
 DEBUG  {"_pcId": 0, "_pendingTrackEvents": [], "_remoteStreams": Map {}, "_transceivers": [], "connectionState": "new", "iceConnectionState": "new", "iceGatheringState": "new", "localDescription": null, "remoteDescription": null, "signalingState": "stable"}
 LOG  Preparing local SDP and gathering candidates (trickle=true)
 LOG  rn-webrtc:pc:DEBUG 0 setRemoteDescription +6ms
 ERROR  [Error: PeerConnection not found]
 ERROR  WebRTC error: [Error: PeerConnection not found]

I also get this message on the simulator (sorry to paste text in an image, couldn't find how to copy)
image

Like mentioned above, stream is working fine on Android and Web.

Platform Information

  • React Native Version: 0.72.5
  • WebRTC Module Version: 111.0.3
  • Platform OS + Version: Expo (iOS) (Expo 49.0.13) (iOS Simulator 16)
    To note, I am also using react-native-webrtc-web-shim@1.0.3
@saghul
Copy link
Member

saghul commented Oct 2, 2023

The shim is not update and there are problems with it at this time. That might be it.

@OlliePugh
Copy link
Author

Yeah I saw there was some issues with the shim, but if it's working in web and android i assumed the shim wouldn't override anything that wasn't web, and with android working I assumed the shim was fine?

That said I did try it without the shim and was facing the same error.

@OlliePugh
Copy link
Author

I tried something other than janus.js

https://github.com/smyrgeorge/janus-gateway-tsdx is what I used and it worked a charm, not sure what would have been platform specific in janus.js but hey ho. At least its sorted 🤷

@fukemy
Copy link

fukemy commented Oct 5, 2023

I have exactly asme problem, when debug inside peerConnectionInit, I found peerConnection return nil as image below:

Screenshot 2023-10-05 at 12 47 19 It will cause emtpy value of self.peerConnection inside `peerConnectionAddTrack` method, so the error return: Screenshot 2023-10-05 at 12 45 57

Can someone help?

@saghul
Copy link
Member

saghul commented Oct 5, 2023

It's very unusual for PC creation to fail. Do you see anything in the WebRTC logs?

@fukemy
Copy link

fukemy commented Oct 5, 2023

I found the problem about the iceServers, modified it's then it's working now, But I still do not know why android work

@saghul
Copy link
Member

saghul commented Oct 5, 2023

Can show how you modified them so we can try to reproduce the problem?

@fukemy
Copy link

fukemy commented Oct 5, 2023

Here is before :

I have set this.janus.iceServers = []

createPeer = () => {
        const linkTurnIceServer = this.janus.iceServers.map(i => ({
            urls : [i.Urls, `${i.Urls}?transport=tcp`, `${i.Urls}?transport=udp`],
            username : i.UserName,
            credential : i.Credential,
        }))
        const stunList = this.janus.iceServers.map(i => i.Urls.replace('turn', 'stun'))
        const linkStunIceServer = {
            urls : [...stunList]
        }
        const finalIceServers = [
            ...linkTurnIceServer,
            {...linkStunIceServer},
        ]
        this.pc = new RTCPeerConnection({
            iceTransportPolicy : 'all',
            iceServers: iceServers,
        })
        ....
}

After fix:

export default {
    'iceServers': [
        {
            "urls" : [
                "stun:stun.l.google.com:19302",
                "stun:stun1.l.google.com:19302",
                "stun:stun2.l.google.com:19302",
                "stun:stun3.l.google.com:19302",
                "stun:stun4.l.google.com:19302",
            ]
        },
        {
            'url': 'stun:stun.l.google.com:19302',
        },
        {
            'url': 'stun:stun1.l.google.com:19302',
        },
        {
            'url': 'stun:stun2.l.google.com:19302',
        },
        {
            'url': 'stun:stun3.l.google.com:19302',
        },
        {
            'url': 'stun:stun4.l.google.com:19302',
        },
    ],
};

this.pc = new RTCPeerConnection({
            iceTransportPolicy : 'all',
            iceServers: iceServers,
        })

@saghul
Copy link
Member

saghul commented Oct 5, 2023

Can you please print the iceServers list when it fails?

@fukemy
Copy link

fukemy commented Oct 5, 2023

when it's failed the iceServer = [], I am sure only change iceServer to

[
        {
            "urls" : [
                "stun:stun.l.google.com:19302",
                "stun:stun1.l.google.com:19302",
                "stun:stun2.l.google.com:19302",
                "stun:stun3.l.google.com:19302",
                "stun:stun4.l.google.com:19302",
            ]
        },
        {
            'url': 'stun:stun.l.google.com:19302',
        },
        {
            'url': 'stun:stun1.l.google.com:19302',
        },
        {
            'url': 'stun:stun2.l.google.com:19302',
        },
        {
            'url': 'stun:stun3.l.google.com:19302',
        },
        {
            'url': 'stun:stun4.l.google.com:19302',
        },
    ]

and remove those code

const linkTurnIceServer = this.janus.iceServers.map(i => ({
            urls : [i.Urls, `${i.Urls}?transport=tcp`, `${i.Urls}?transport=udp`],
            username : i.UserName,
            credential : i.Credential,
        }))
        const stunList = this.janus.iceServers.map(i => i.Urls.replace('turn', 'stun'))
        const linkStunIceServer = {
            urls : [...stunList]
        }
        const finalIceServers = [
            ...linkTurnIceServer,
            {...linkStunIceServer},
        ]

that solved my problem

@saghul
Copy link
Member

saghul commented Oct 5, 2023

So an empty array of ICE servers caused it? I'll take a look!

@8BallBomBom
Copy link
Member

Very unusual 🤔
Can't say i've ever experienced that in local testing which mostly doesn't use any ice servers.
But definitely worth looking into.

@saghul
Copy link
Member

saghul commented Oct 5, 2023

I have found something. If converting the ObjC / Java RTCConfiguration to native fails, the returned PC is null.

I'll throw an exception right there and then, since otherwise the error would be masked.

saghul added a commit that referenced this issue Oct 6, 2023
It should usually only trigger for bugs in the library, but things will
break in very weird ways otherwise.

Ref: #1453
@saghul
Copy link
Member

saghul commented Oct 6, 2023

I created #1454 to given an error if we fail to create the PC.

However, I could not reproduce the crash by creating the PC like so:

      const pc = new RTCPeerConnection({ iceServers: [] });
      console.log(pc);
      pc.close();
    }

See:

Screen Shot 2023-10-06 at 11 45 06

What is the minimal repro case for this? A cursory look at how we process ICE servers makes it seem correct to me.

saghul added a commit that referenced this issue Oct 6, 2023
It should usually only trigger for bugs in the library, but things will
break in very weird ways otherwise.

Ref: #1453
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants