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

parseIceServers returns undefined turnServer and stunServer #385

Open
nandito opened this issue May 27, 2024 · 2 comments
Open

parseIceServers returns undefined turnServer and stunServer #385

nandito opened this issue May 27, 2024 · 2 comments

Comments

@nandito
Copy link
Contributor

nandito commented May 27, 2024

The RTCIceGatherer's ice server config has undefined value for each key:

https://github.com/shinyoshiaki/werift-webrtc/blob/develop/packages/webrtc/src/peerConnection.ts#L485

{
  stunServer: undefined,
  turnServer: undefined,
  turnUsername: undefined,
  turnPassword: undefined
}

I think this happens as the parseIceServers util (https://github.com/shinyoshiaki/werift-webrtc/blob/develop/packages/webrtc/src/peerConnection.ts#L485) tries to use the .includes("turn:") and .includes("stun:") on arrays.

So we have this function call in the utils.ts:

const turnServer = url2Address(
  iceServers.find(({ urls }) => urls.includes("turn:"))?.urls.slice(5),
);

where the iceServers looks like this:

 [
  {
    url: 'turn:turn-myturnserver.com:443',
    urls: ['turn:turn-myturnserver.com:443'],
    username: 'username',
    credential: 'creds='
  }
]

If we inspect the url2Address parameter:

iceServers.find(({urls}) => urls.includes("turn:"))

We can see that it runs the includes() fn on an array, not on a string.

['turn:turn-myturnserver.com:443'].includes("turn:")

This is always false, therefore the find() won't find any turn: in this case.

I assume a nested find() function would fix this issue.

@nandito
Copy link
Contributor Author

nandito commented May 30, 2024

As I see urls can be a string or an array of strings:

urls
This required property is either a single string or an array of strings, each specifying a URL which can be used to connect to the server.

So the current implementation is also correct, but not 100% complete as it does not handle the array of strings.

@shinyoshiaki
Copy link
Owner

I will eventually fix it, but PullRequests are also welcome

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

2 participants