Peerjs Configuration and Server

36 views Asked by At

When I initialize PeerJS with the following configuration, the program runs normally:

let localPeer = new Peer({
    host: 'localhost',
    port: 9000,
})

However, when I change 'localhost' in the configuration options to a domain name, the browser throws the following errors:

GET http://****/peerjs/id?ts=17107492759630.8115906905384951&version=1.4.7 net::ERR_FAILED 301 (Moved Permanently)

localPeer error, the error information is: {"type":"server-error"}

socket.ts:42 WebSocket connection to 'ws://*****/peerjs?key=peerjs&id=null&token=dog3czx15b&version=1.4.7' failed:

I tried adding the secure option in the configuration and set it to true, but then the browser allows requests without restrictions and throws the following error:

WebSocket connection to 'wss://******/peerjs?key=peerjs&id=59f82535-3d41-4004-89da-40c118333dd2&token=9zzvvakquzk&version=1.4.7' failed:

index.js:80 localPeer error, the error information is: {"type":"network"}

I have set up a reverse proxy on Nginx with the following configuration:


location /peerjs {
    proxy_pass http://127.0.0.1:3000;
}

location /peerjs/id {
    proxy_pass http://127.0.0.1:3001;
}

Where 3000 is the port of my Spring Boot project and 3001 is the port of the PeerJS server. I started the PeerJS server using the following command:

peerjs --port 3001 --key peerjs

Additional Information: When starting the PeerJS service locally, the current ID is printed in the command prompt every time I access it. However, this does not happen on the cloud server. Although accessing https://******/peerjs/id through the address bar returns an ID, it still does not print anything on the cloud server.

0

There are 0 answers