Comments (11)
Hey Majid,
I can't replicate this, can you post the specific code you're running?
On Tue, May 28, 2013 at 11:33 PM, Majid Fouladpour <[email protected]
wrote:
Trying the code in Getting started guide, I get this error in Google
Chrome console:Failed to load resource: the server responded with a status of 401
(Unauthorized)Opening the link in a new tab, this is the json sent with header 401:
{"code":"MethodNotAllowedError","message":"GET is not allowed"}
Am I missing a required step?
—
Reply to this email directly or view it on GitHubhttps://github.com//issues/52
.
510-691-3951
http://ericzhang.com
from peerjs.
Here's an example:
<!DOCTYPE html>
<html>
<head>
<script src="http://cdn.peerjs.com/0/peer.min.js"></script>
</head>
<body>
</body>
<script>
var local = new Peer('localID', {key: '...'});
local.on('connection', function(conn) {
console.log("LOCAL connection open", conn)
conn.on('data', function(data){
console.log("LOCAL got message", data);
});
});
</script>
<script>
var remote = new Peer('remoteID', {key: '...', debug:true});
var conn = remote.connect('localID');
console.log("REMOTE connecting to LOCAL", conn)
conn.on('open', function(){
console.log("connect to REMOTE opened", conn);
conn.send('hi!');
});
</script>
</html>
Above works fine in FF, but fails in Chrome: 401 unathorized. Haven't tracked it down yet.. but I'm 99% sure it has something to do with CORS and Chrome not being happy about it. Netlog:
t=1373081418783 [st= 6] +HTTP_TRANSACTION_SEND_REQUEST [dt=0]
t=1373081418783 [st= 6] HTTP_TRANSACTION_SEND_REQUEST_HEADERS
--> POST /.../remoteID/.../candidate HTTP/1.1
Host: 0.peerjs.com:9000
Connection: keep-alive
Content-Length: 196
Cache-Control: no-cache
Pragma: no-cache
Origin: http://localhost:8000
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1558.0 Safari/537.36
Content-Type: application/json
Accept: */*
Referer: http://localhost:8000/peerjs.html
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
t=1373081418783 [st= 6] HTTP_TRANSACTION_SEND_REQUEST_BODY
--> did_merge = true
--> is_chunked = false
--> length = 196
t=1373081418783 [st= 6] -HTTP_TRANSACTION_SEND_REQUEST
t=1373081418783 [st= 6] +HTTP_TRANSACTION_READ_HEADERS [dt=100]
t=1373081418783 [st= 6] HTTP_STREAM_PARSER_READ_HEADERS [dt=100]
t=1373081418883 [st=106] HTTP_TRANSACTION_READ_RESPONSE_HEADERS
--> HTTP/1.1 401 Unauthorized
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET,PUT,POST,DELETE
Access-Control-Allow-Headers: Content-Type
Date: Sat, 06 Jul 2013 03:30:18 GMT
Connection: keep-alive
Transfer-Encoding: chunked
t=1373081418883 [st=106] -HTTP_TRANSACTION_READ_HEADERS
t=1373081418883 [st=106] -URL_REQUEST_START_JOB
t=1373081418884 [st=107] HTTP_TRANSACTION_READ_BODY [dt=0]
from peerjs.
Hrm. Are you sure the API key you're using is valid?
I tried this code with our demo API key and got the following logs:
PeerJS: Data channel connection success peer.min.js:1
connect to REMOTE opened
l {_events: Object, open: true, label: "peerjs", metadata: undefined, serialization: "binary"…}
test.html:27
PeerJS: Data channel connection success peer.min.js:1
LOCAL got message hi!
from peerjs.
Ah, I think it's an issue with the connection to the server. This may be the same issue as #55.
I will investigate, but the best way to get it to work for now is by not calling connect
until the connection to the server opens.
See fixed code below.
<!DOCTYPE html>
<html>
<head>
<script src="http://cdn.peerjs.com/0/peer.min.js"></script>
</head>
<body>
</body>
<script>
var local = new Peer('localID', {key: '...'});
local.on('connection', function(conn) {
console.log("LOCAL connection open", conn)
conn.on('data', function(data){
console.log("LOCAL got message", data);
});
});
var remote = new Peer('remoteID', {key: '...', debug:true});
// ADDED THIS:
remote.on('open', function() {
var conn = remote.connect('localID');
console.log("REMOTE connecting to LOCAL", conn)
conn.on('open', function(){
console.log("connect to REMOTE opened", conn);
conn.send('hi!');
});
});
</script>
</html>
from peerjs.
Won't close for now though, since I'm not quite sure your 401 issue is the same as @majid4466's
Also, very weird: I can't get it to repro again for that original block of code.
from peerjs.
Nevermind my "99%" comment earlier - it's not Chrome. It may be a race with WS vs XHR here...
from peerjs.
Ah, that could be the case. When WS connects the remaining XHR requests are 401ed.
from peerjs.
Right, that's the bug.. WS overrides the hash with proper IP, whereas XHR's are setting "undefined" for IP. Just sent a pull which should (hopefully) fix this.
from peerjs.
Should be fixed. Feel free to reopen if this happens again.
from peerjs.
I'm currently testing the connection with the peer.js server and simulating bad connections, reconnecting multiple times per minute to see what happens. Sometimes I get the same error.
from peerjs.
I did get this error earlier this morning, however, the issue was to do with http(s) request.
from peerjs.
Related Issues (20)
- Peerjs reconnecting not working fine sometime one of the device is not connected
- Having problem with Blob in v 1.5.1 peerjs.min.js HOT 6
- Insufficient postMessage Validation HOT 2
- ReferenceError: navigator is not defined when using nestjs HOT 4
- Call answer for a stream coming from screen share on peer which does not have a webcam shows nothing HOT 2
- New maintainer(s) wanted!
- connection problem HOT 3
- Play() was interrupted by new load request
- Peer TURN servers seems to be down HOT 2
- peer.connect not open on some users
- Remote video stream shows black screen. HOT 2
- Works only for same network HOT 6
- Remote video transmission not working again
- 'close' event on DataConnection is not emitted on Firefox HOT 1
- New feature: add 'allow_override_connect' startup option
- [electron] Can't establish connection between two local clients HOT 2
- Slow initial connection speed HOT 3
- Working on LAN Perfectly but also working in WAN, but in WAN if there is network latency the connection was interrupting. HOT 2
- peerjs needs Content-Security-Policy `script-src: unsafe-eval` HOT 3
- Can't send Blob object HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from peerjs.