Socket.io-client在React js上使用调用数据设置自定义时间

时间:2018-09-11 14:48:59

标签: javascript reactjs websocket socket.io

我立即通过socket.io获取数据,但是我需要通过socket.io-client使用自定义时间间隔的数据,但是无法获得解决方案,我也尝试过setInterval和其他自定义计时器方法,请帮助我进行排序

import socketIOClient from "socket.io-client";


this.host = process.env.REACT_APP_HOST;

const test_key = process.env.REACT_APP_TEST_KEY;
if (test_key) {
  this.host = `${this.host}?test_key=${test_key}`;
}
this.connectionOptions = {
  forceNew: true,
  reconnectionAttempts: "Infinity",
  timeout: 10000,
  transports: ["websocket"],
  path: process.env.REACT_APP_SOCKET_ROUTE
};


this.socket = socketIOClient(this.host,this.connectionOptions);
this.socket.on("shotTaken", shot => this.handleShot(shot));
this.socket.on("invalidOrigin", msg => this.handleOrigin(msg));

0 个答案:

没有答案