peers / peerjs

Simple peer-to-peer with WebRTC.
https://peerjs.com
MIT License
12.48k stars 1.43k forks source link

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

Closed maxpavlov closed 5 years ago

maxpavlov commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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 https://github.com/michelle/reliable/pull/18/commits/a797057fe25174cee33f1eb7331b5808bd8a0ff5

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

kidandcat commented 5 years ago

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 commented 5 years ago

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

tombertrand commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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

maxpavlov commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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