我立即通过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));