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

Unable to connect to a peer in Safari on macOS #478

Closed
maxpavlov opened this issue Jan 23, 2019 · 11 comments
Closed

Unable to connect to a peer in Safari on macOS #478

maxpavlov opened this issue Jan 23, 2019 · 11 comments

Comments

@maxpavlov
Copy link

Whenever I am trying to connect to a peer in Safari with specifying an option of { reliable: true } I get an error:
TypeError: Object is not a constructor (evaluating 'new Reliable(this._dc, util.debug)')
image

Is there a way I can still use reliable data channel in Safari?

@kidandcat
Copy link
Member

Sorry, I'm not updated about Safari, I don't even have access to it. But there are some people here that uses PeerJS with Safari, let's wait them.

@tombertrand
Copy link

tombertrand commented Feb 19, 2019

The error seems to come from the way Reliable is exported.

source -> import { Reliable } from "reliable";
babel -> var Reliable = require('reliable');

Changing the compiled code to the following works...
this._reliable = new Reliable.Reliable(this._dc, util.debug);

and then negotiator.js is missing an import for Reliable https://github.com/peers/peerjs/blob/master/lib/negotiator.ts#L226 & 280

[Error] Unhandled Promise Rejection: ReferenceError: Can't find variable: Reliable

EDIT:
seems like a PR to fix it was opened but never merged michelle/reliable@a797057

An alternative for fixing this any not relying on this lib is to remove reliable: true from your init config

@kidandcat
Copy link
Member

Wow, I haven't access to that repo. @tombertrand what do you recommend? the fix to the import or just remove reliable: true?

If it's better to have it, I'll clone the repo and do the update.

@pReya
Copy link
Contributor

pReya commented Feb 21, 2019

Tried tweeting and mailing to @michelle if she can merge this PR. Just hope she'll respond.

@tombertrand
Copy link

tombertrand commented Feb 21, 2019

I've experimented with Safari, fixing JS errors caused by Reliable lib and negotiator.ts. There was no more errors but a message (ex: connection.send('hello');) wouldn't reach the connections while on Chrome/FF there was no problem. I ended up doing reliable connections for the browsers that supports it, unreliable for unsupported browsers.

import Peer from 'peerjs';
import Util from 'peerjs/lib/util';

// Host
const peer = new Peer(HOST_PEER_ID, { secure: true, debug: 3 });

// Guests
const guestPeer = new Peer(null, { secure: true, debug: 3 });
const guestConnection = guestPeer.connect(HOST_PEER_ID, {
  reliable: Util.supports.reliable, // true / false depending if the browser supports reliable connection
});

@pReya
Copy link
Contributor

pReya commented Feb 21, 2019

I've reached @michelle and she merged the PR in the reliable repo. Also a good workaround @tombertrand. But it's still sad to see reliable connections not working on Safari :(

@kidandcat
Copy link
Member

It should just work then, because the package.json uses the latest master version from the repo.

@maxpavlov
Copy link
Author

maxpavlov commented Mar 20, 2019

Ok, so as 'reliable' part got fixed, I am still seeing this when I attempt to connect to peer from Safari 12:
image

Can anyone suggest what is wrong here? Thanks.

P.S. I noticed peerjs uses an outdated version of webrtc-adapter package. Maybe this is the reason why we often are getting out of sync integration wise. Just an assumption.
P.P.S. I've forked peerjs, changed it to utilize the latest webrtc-adapter library and I still get the same error in Safari when trying to make a connection.

@maxpavlov
Copy link
Author

I was able to trace the problem down to this point. Once new t.RTCPeerConnection is called with an array of iceServers, it fails internally in the native code.
Screen Shot 2019-03-21 at 8 30 46 AM

@maxpavlov
Copy link
Author

The problem turned out to be exactly as the error implies. I was passing in the array of url instead of urls and the array of actual strings containing the urls for stun servers. My mistake after all.

@ninest
Copy link

ninest commented Sep 5, 2019

Is this related to #574 in any way? I tried using safari. If Safari is the host, it fail silently. If I try to connect another browser (ex, Chrome) to Safari, I get the error

Unhandled Promise Rejection: TypeError: Argument 1 ('options') to RTCPeerConnection.createOffer must be a dictionary

It seems to be a problem with i.createOffer(function(e) { in peer.min.js

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

5 participants