Javascript NextJS,Socket.io:在服务器端,我的第三个参数是确认';s回调返回给我:回调不是函数

Javascript NextJS,Socket.io:在服务器端,我的第三个参数是确认';s回调返回给我:回调不是函数,javascript,reactjs,websocket,socket.io,next.js,Javascript,Reactjs,Websocket,Socket.io,Next.js,我正在将NextJS与Socket.IO一起使用。所有的基础工作都很好,现在,我正在尝试使用emit的函数进行确认回调。在我看来,我已经遵守了所有的规则,但它不起作用。我不明白为什么 下面是我的server.js代码段: // listen for socket's connection io.sockets.on("connection", (socket)=>{ // socket.join('some room'); // on connection, listen an

我正在将NextJS与Socket.IO一起使用。所有的基础工作都很好,现在,我正在尝试使用emit的函数进行确认回调。在我看来,我已经遵守了所有的规则,但它不起作用。我不明白为什么

下面是我的server.js代码段:

// listen for socket's connection
io.sockets.on("connection", (socket)=>{ 
  // socket.join('some room');

  // on connection, listen any event on join's channel 
  socket.on('join',(param, callback) => {
    console.log("callback: ", callback) 

    // some logs to appreciate if my URL's params follow the rules 
    console.log("!isRealString(param.name): ", !isRealString(param.name) )
    console.log(" !isRealString(param.room): ",  !isRealString(param.room))

    // if they fails to follow the rules, return an error 
    if(!isRealString(param.name) || !isRealString(param.room)){ 
      callback("Name and room are required") // not a function
    } 

      // if no error, returns a succeed's log -set in client side- 
    callback()      

});
我的客户端代码片段:

// set socket.io variable 
this.socket=io(); 

   // on connect, trigger a function
   this.socket.on("connect", () => {

      // get the window's URL  
      // and pass an helper which translate URL's queries in javascript's object
      var param =deparam(window.location.search);

      // then emit an event on joint channel
      // three parameters: channel, param, acknowledgement callback
      this.socket.emit("join", param, function(err){ 

      // if there is an error, alert the user then redirect
      if(err){ 
         alert(err);
         Router.replace("/");
      } 
      // errorFree? display a succeed's message
      else{ 
         console.log("No error");
      }
   });
});
在我看来,如果我相信我所做的谷歌搜索,一切都是好的。也许是NextJS有一些古怪的行为, 任何暗示都很好,
感谢您,window对象并不总是在下一个js中定义,但您可以使用

  process.browser

在调用window.location以避免错误之前

window对象并不总是在下一个js中定义,但您可以使用

  process.browser
在调用window.location以避免错误之前