简体   繁体   English

为什么我的 socket.io 视频聊天无法在 heroku 上运行?

[英]Why my socket.io video chat won't work on heroku?

I'm new to WS and Heroku and all that... so i have this code我是 WS 和 Heroku 的新手……所以我有这个代码

//this sets up client-side sockets i guess //这设置了客户端 sockets 我猜

    import {io} from 'socket.io-client';
    
    const options = {
      "force new connection": true,
      reconnectionAttempts: "Infinity", 
      timeout : 10000, 
      transports : ["websocket"]
    }
    
const socket = io('/', options)

export default socket;

and for the server side对于服务器端

    const path = require('path');
    const express = require('express');
    const app = express();
    const server = require('http').createServer(app);
    const io = require('socket.io')(server);
    const {version, validate} = require('uuid');
    
    const ACTIONS = require('./src/socket/actions');
    const PORT = process.env.PORT || 3001;
///more code

When deployed to heroku this results in this app https://lit-atoll-99067.herokuapp.com/ and the chrome console says:当部署到 heroku 时,这会导致此应用程序https://lit-atoll-99067.herokuapp.com/和 chrome 控制台显示:

WebSocket connection to 'wss://lit-atoll-99067.herokuapp.com/socket.io/?EIO=4&transport=websocket' failed: WebSocket is closed before the connection is established. WebSocket 连接到 'wss://lit-atoll-99067.herokuapp.com/socket.io/?EIO=4&transport=websocket' 失败:WebSocket 在连接建立之前关闭。

So i ran out of ideas.所以我没有主意了。 but i guess this has to be about port or something... dunno really.但我想这一定是关于港口什么的……真的不知道。 Any ideas are welcome!欢迎任何想法!

I think you need to pass the full URL at the client-side but you only passed the "/" only example:-我认为您需要在客户端传递完整的 URL 但您仅传递了“/”示例:-

import {io} from 'socket.io-client';
    
const options = {
  "force new connection": true,
   reconnectionAttempts: "Infinity", 
   timeout : 10000, 
   transports : ["websocket"]
}
// here need to pass the full url
const socket = io('https://example.com/', options)

export default socket;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM