最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

socket.io - Peer + Socket - Failed: Invalid frame header (node, heroku) - Stack Overflow

programmeradmin1浏览0评论

I searched and found that some people had the same problem, but the way they solved didn't work for me, so I think my problem might be a little different.

In localhost worked fine (peerjs and socketio together), but when I run on heroku, things get a little more complicated. So I started changing and analysing to see if I could find the problem but nothing worked.

For the time being, my code:

peerInstance = new Peer(user.uid, { //Usa userUid como identificador no peerjs     

host: process.env.REACT_APP_PORTVIDEOCHAT ? "yomglee": 'localhost', 
        port: "",
        path: "/peerjs",
        secure: process.env.REACT_APP_PORTVIDEOCHAT ? true : false,
        config: {
          iceServers: [
            { urls: 'stun:stun.l.google:19302' }, // STUN
            { urls: 'stun:stun1.l.google:19302' }, // Outro STUN do Google
            { urls: 'stun:stun2.l.google:19302' }, // Mais um STUN do Google
            {
              urls: "stun:stun.relay.metered.ca:80",
            },
            {
              urls: "turn:global.relay.metered.ca:80",
              username: "xxxxx",
              credential: "xxxxx",
            },
            {
              urls: "turn:global.relay.metered.ca:80?transport=tcp",
              username: "xxxxx",
              credential: "xxxxx",
            },
            {
              urls: "turn:global.relay.metered.ca:443",
              username: "xxxxx",
              credential: "xxxxx",
            },
            {
              urls: "turns:global.relay.metered.ca:443?transport=tcp",
              username: "xxxxx",
              credential: "xxxxx",
            },
          ],
          iceTransportPolicy: 'all'
        }
      });

And the server, I'm using:

var ExpressPeerServer = require("peer").ExpressPeerServer;    
var options = {
  debug: true,
  allow_discovery: true,
  secure: true,
};
let peerServer = ExpressPeerServer(server, options);
app.use("/peerjs", peerServer);

Important informations: 1 - Although the problem is in the socketio, it works fine without the peer. The peer is causing the error:

WebSocket connection to 'wss://yomglee/socket.io/?EIO=4&transport=websocket' failed: Invalid frame header

2 - The socketio also uses the server: const ioSocket = require('socket.io')(server);

By the way, I use REACT_APP_PORTVIDEOCHAT just to check if it's in heroku

I have tried: port 443 in frontnend Creating my own port (like 9000) front and backend (just wanted to try) Using location.port in frontnend Using '/' for host in frontend (I know it is probably the same as putting the url anyway) I'm really at a loss and would really appreciate a solution. It means a lot to me <3

What I expect is to work the connection between two users, and for that to happen I have to fix the error regarding the door

EDIT
I saw that many solved their problem by just putting another door, like I've tried (door 9000) but surely didn't work since heroku doesn't allow that

EDIT2
Someone wrote that you can't create socketio and peerjs in the same server, cuz it doesn't work (probably cuz they both kind of use socket, so it conflicts)
That is why worked in localhost, I was creating a different way.
However, heroku doesn't allow me to create a new door like 9000, so apparently I have no way around.
Have someone gone trough that?

"it's not possible to run socket.io and a PeerJS server on the same Express(/http(s) server) instance."

发布评论

评论列表(0)

  1. 暂无评论