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

No WebRTC support: Specify `opts.wrtc` option in this environment #1639

Closed
KingZee opened this issue Jun 11, 2019 · 3 comments
Closed

No WebRTC support: Specify `opts.wrtc` option in this environment #1639

KingZee opened this issue Jun 11, 2019 · 3 comments
Labels

Comments

@KingZee
Copy link

@KingZee KingZee commented Jun 11, 2019

What version of WebTorrent?
0.103.1
What operating system and Node.js version?
Windows 7, v11.6.0

I'm having this issue again : feross/simple-peer#110

I don't understand what I'm doing wrong.
Here is my code for adding a torrent :

var TorClient = new WebTorrent({ tracker: { wrtc: false }});
TorClient.on('error', function(err){
    console.log('Fatal client error. Restart server.');
});

function addTorrent(tor,path){
    return new Promise(function(resolve,reject){
	    try {
		    TorClient.add(tor, {path: path},function ontorrent (torrent) {
			    resolve(torrent);	//called when torrent is ready to be downloaded
		    });
	    } catch (e) {
		    reject(e);
	    }
    });
}

(As I pasted this snippet I just remember I added a try-catch block for this reason around a month ago, I just forgot about this problem.)

Once the torrent is added through the code above, it's downloaded for a few seconds, and then an error is thrown.
The error thrown is similar to the linked issue :

  throw makeError('No WebRTC support: Specify `opts.wrtc` option in this environment', 'ERR_WEBRTC_SUPPORT')
  ^

Error: No WebRTC support: Specify `opts.wrtc` option in this environment
at makeError (...\node_modules\simple-peer\index.js:1017:13)

This is weird because I tried to go through simple-peer to disable wrtc, but it seems ironic, here's the relevant code for the error above :

  self._wrtc = (opts.wrtc && typeof opts.wrtc === 'object')
    ? opts.wrtc
    : getBrowserRTC() //returns null if it doesn't find window

  if (!self._wrtc) {
    if (typeof window === 'undefined') {
      throw makeError('No WebRTC support: Specify `opts.wrtc` option in this environment', 'ERR_WEBRTC_SUPPORT')
    } else {
      throw makeError('No WebRTC support: Not a supported browser', 'ERR_WEBRTC_SUPPORT')
    }
  }

Setting wrtc to either a falsey value, or a truthy one, will always trigger the error. Any help on how to work around this error? Thanks.

@KingZee

This comment has been minimized.

Copy link
Author

@KingZee KingZee commented Jun 23, 2019

const wrtc = require('wrtc');
var TorClient = new WebTorrent({ tracker: { wrtc: wrtc }});

Even including wrtc still triggers this error, anyone to help out please on how to fix this? Thanks.

@feross

This comment has been minimized.

Copy link
Member

@feross feross commented Aug 6, 2019

Are you running this code in a Node.js environment, Electron environment, or the browser? If so, which browser?

In Node.js, you shouldn't need to even set the option to { tracker: { wrtc: { false } }. I'll repeat what I said in the issue you linked:

The only way the error you're getting could possibly happen (as far as I can tell), is if you're setting the wrtc option in WebTorrent like this:

new WebTorrent({ tracker: { wrtc: true }})

Or you're setting global.WRTC to a truthy value, or using a shim for RTCPeerConnection that is confusing the get-browser-rtc module's detection code.

@KingZee

This comment has been minimized.

Copy link
Author

@KingZee KingZee commented Aug 7, 2019

The behavior of this was so inconsistent I couldn't accurately reproduce it because of the multiple packages involved (wrtc, simple-peer, and webtorrent).

I have tried with the options you mentioned and other different workarounds, but in any case I made my own fork of simple-peer so the error is no longer thrown, so I will close this unless I can accurately reproduce it.

@KingZee KingZee closed this Aug 7, 2019
@no-response no-response bot removed the need more info label Aug 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.