peers / peerjs

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

CORS issue persistently coming in firefox with peerjs and handshake issue with peerjs server. #257

Closed uditk2 closed 5 years ago

uditk2 commented 9 years ago

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://0.peerjs.com:9000/yu809arn510v0a4i/id?ts=14186500467940.28066380713229955. This can be fixed by moving the resource to the same domain or enabling CORS.

I have enabled Cors in my project using the cors module available and also tried through express. IT is still showing the same issue. On using peerjs server, I am facing another issue. WebSocket connection to 'ws://192.168.1.8:8124/peerjs/peerjs?key=yu809arn510v0a4i&id=7o77ca9v31fqd7vi&token=3xmerqa9pzmsfw29' failed: Connection closed before receiving a handshake response

Can you provide me pointers as to where I should be looking to solve any of the issue. Whichever way would be just awesome. I am assuming, I am missing some configuration code.

fyyyyy commented 9 years ago

see #220 and peers/peerjs-server#49

chynonm commented 9 years ago

Having the same issue as well, firefox straight up refuses to connect and gives a CORS warning.

Chrome can connect with XHR, but connect drops when the WB timesout waiting for the handshake.

uditk2 commented 9 years ago

Hey, Did this happen even after mentioning the cross origin policy in the server. Did you go over this link to understand the issue and

http://stackoverflow.com/questions/10636611/how-does-access-control-allow-origin-header-work and also tried this code in the header of the other site.

// enabling access control origin app.use(function (req, res, next) { res.header("Access-Control-Allow-Origin", "*"); res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept"); next(); });

Let me know if this helps.

Regards

Udit

On Fri, Jul 3, 2015 at 10:20 PM, chynonm notifications@github.com wrote:

Having the same issue as well, firefox straight up refuses to connect and gives a CORS warning.

Chrome can connect with XHR, but connect drops when the WB timesout waiting for the handshake.

— Reply to this email directly or view it on GitHub https://github.com/peers/peerjs/issues/257#issuecomment-118391598.

chynonm commented 9 years ago

Truth be told this issue should be on the peerjs-server since it's an issue with the server they provide, my app runs fine when I use their cloud-hosted servers.

On my own server, the code I use is :

var fs = require('fs'); var PeerServer = require('peer').PeerServer; var server = PeerServer({port: 8081, ssl: { key: fs.readFileSync('/path.key'), cert: fs.readFileSync('/path.pem')},
path: '/immersive'});

server.use(function(req, res, next) { res.header("Access-Control-Allow-Origin", "*"); res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept"); next(); });

the code you provided didn't solve the issue (not to mention peerserver should already be handling the CORS). Issue happens when it tries to upgrade to websockets.

uditk2 commented 9 years ago

Hi, Just one more confirmation. The order in which you mention does matter. Also check if the header has the right params set. The content type and others. After several attempts, I have been able to use the peer server code successfully in a sample application. I am currently not in office. Once I reach home, I will mail you the code. See if that works for you. Do checkout your client side peer object initialization as well.

Regards ~Udit On Jul 6, 2015 4:12 PM, "chynonm" notifications@github.com wrote:

Truth be told this issue should be on the peerjs-server since it's an issue with the server they provide, my app runs fine when I use their cloud-hosted servers.

On my own server, the code I use is :

var PeerServer = require('peer').PeerServer; var server = PeerServer({port: 8081, path: '/immersive'});

/ server.use(function(req, res, next) { res.header("Access-Control-Allow-Origin", ""); res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept"); next(); }); */

the code you provided didn't solve the issue (not to mention peerserver should already be handling the CORS). Issue happens when it tries to upgrade to websockets.

Starting to get a bit frustrated about their servers, the few documentation it has doesn't even work, can't get SSL to work on the server either

— Reply to this email directly or view it on GitHub https://github.com/peers/peerjs/issues/257#issuecomment-118805989.

uditk2 commented 9 years ago

Hey, Forgot to post the code. Here you go, in case you are still working on it. You can omit the ejs inclusion.

var express = require('express');var app = express();var ExpressPeerServer = require('peer').ExpressPeerServer; // ejs inclusion.var ejs = require('ejs'); app.engine('html', require('ejs').renderFile); app.set('views', __dirname + '/views'); app.set('view engine', 'ejs');

app.get('/', function (req, res) { res.render('index');});

app.get('/peerconnector.js', function (req, res) { res.sendFile('peerconnector.js', {root: __dirname+'/views/'});});

app.get('/peer.js', function (req, res) { res.sendFile('peer.js', {root: __dirname+'/views/'});});

//app.listen(8878,"192.168.1.8"); var options = { debug: true} var server = require('http').createServer(app);

app.use('/peerjs', ExpressPeerServer(server, options));

server.listen(8878, "192.168.1.14");

Code in peerconnector

var peer = new Peer({ host: '192.168.1.14', port: 8878, path: '/peerjs', config: { 'iceServers': [ { url: 'stun:stun01.sipphone.com' }, { url: 'stun:stun.ekiga.net' }, { url: 'stun:stun.fwdnet.net' }, { url: 'stun:stun.ideasip.com' }, { url: 'stun:stun.iptel.org' }, { url: 'stun:stun.rixtelecom.se' }, { url: 'stun:stun.schlund.de' }, { 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' }, { url: 'stun:stunserver.org' }, { url: 'stun:stun.softjoys.com' }, { url: 'stun:stun.voiparound.com' }, { url: 'stun:stun.voipbuster.com' }, { url: 'stun:stun.voipstunt.com' }, { url: 'stun:stun.voxgratia.org' }, { url: 'stun:stun.xten.com' }, { url: 'turn:192.158.29.39:3478?transport=udp', credential: 'JZEOEt2V3Qb0y27GRntt2u2PAYA=', username: '28224511:1379330808' }, { url: 'turn:192.158.29.39:3478?transport=tcp', credential: 'JZEOEt2V3Qb0y27GRntt2u2PAYA=', username: '28224511:1379330808' } ] },

debug: 3});

Let me know if it solves the issue.

Regards

Udit

On Mon, Jul 6, 2015 at 5:58 PM, Udit Khandelwal uditk2@gmail.com wrote:

Hi, Just one more confirmation. The order in which you mention does matter. Also check if the header has the right params set. The content type and others. After several attempts, I have been able to use the peer server code successfully in a sample application. I am currently not in office. Once I reach home, I will mail you the code. See if that works for you. Do checkout your client side peer object initialization as well.

Regards ~Udit On Jul 6, 2015 4:12 PM, "chynonm" notifications@github.com wrote:

Truth be told this issue should be on the peerjs-server since it's an issue with the server they provide, my app runs fine when I use their cloud-hosted servers.

On my own server, the code I use is :

var PeerServer = require('peer').PeerServer; var server = PeerServer({port: 8081, path: '/immersive'});

/ server.use(function(req, res, next) { res.header("Access-Control-Allow-Origin", ""); res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept"); next(); }); */

the code you provided didn't solve the issue (not to mention peerserver should already be handling the CORS). Issue happens when it tries to upgrade to websockets.

Starting to get a bit frustrated about their servers, the few documentation it has doesn't even work, can't get SSL to work on the server either

— Reply to this email directly or view it on GitHub https://github.com/peers/peerjs/issues/257#issuecomment-118805989.

chynonm commented 9 years ago

I ended up just using the base code for launching the server. For now the problem seems to have inexplicably solved itself, I didn't notice since I was developing with cors disabled on my browser, but now it's working without that option.

However it's still only working on chrome, on firefox cors is still failing spectacularly.