在我的app.js中,

io.sockets.on("connection", connectSocket);


然后在另一个文件中,我有:

const connectSocket = (socket, bitlyAppURL) => {
  socket.once(AUTHENTICATED_CONNECTION_REQUEST, params => {
    connectAuthenticatedSocket(socket, params, bitlyAppURL);
  });

  socket.once("disconnect", disconnectSocket);

  socket.emit(AUTHENTICATE_YOURSELF);
};


但是我不确定如何将此bitlyAppURL传递给app.js中的函数。

最佳答案

使用socket.on的回调:

io.sockets.on("connection", socket => connectSocket(socket, bitlyAppURL));

08-07 20:17