首页 > 解决方案 > 发出套接字时出错:内部/引导程序/pre_execution.js:308

问题描述

internal/bootstrap/pre_execution.js:308
    get() {
       ^

RangeError: Maximum call stack size exceeded
    at get (internal/bootstrap/pre_execution.js:308:8)
    at hasBinary (/home/spirit/Documents/ProjectsJS/ProjectBack/node_modules/has-binary2/index.js:44:3)

您好,我正在尝试发出我的套接字,但出现此错误,并且我无法在我使用的所有代码下方的后端接收我的套接字

io.on('connection', function (socket) {
  setInterval(() => Queue.searching() , 1000);
  sessionMap.set(socket.id,socket);
  //ADD PLAYER TO QUEUE
  socket.on('addPlayer-Queue', (result) => {
      const player = {
        id:result.id,
        socketid: socket.id,
        name: result.name,
        mmr: result.mmr,
        socket: socket
      }
      const nPlayer = new Player(player);
      Queue.addPlayer(nPlayer);  
      /*
      console.log(queue);
      console.log(sessionMap.all());*/
  //socket.emit('match', matches) 
  });


});

//

 searching = () =>  {
    const firstPlayer = this.getRandomPlayer();
    const secondPlayer = this.players.find(
      playerTwo =>
        playerTwo.mmr < this.calculateLessThanPercentage(firstPlayer) &&
        playerTwo.mmr > this.calculateGreaterThanPercentage(firstPlayer) &&
        playerTwo.id != firstPlayer.id
    );
    if(secondPlayer){
    const matchedPlayers = [firstPlayer, secondPlayer];
    this.removePlayers(matchedPlayers);
    Matches.configurePlayersForNewMatch(matchedPlayers);
    }
  }

//

  getMatchConfigurationFor = players => {
    console.log(sessionMap.all())
    if(players){
      const match = new Match(players);
      const result = {
        idMatch: match.id,
        playerOne: match.players[0],
        playerTwo:match.players[1]
      }
      return result;
    }
  }
  configurePlayersForNewMatch = (matchedPlayers) => {
    matchedPlayers.forEach(player =>
      sessionMap.get(player.socketId)
        .broadcast.to(player.socketId)
        .emit('match',
          this.getMatchConfigurationFor(matchedPlayers)));
  }

所以我承认问题出在这段代码片段中:

matchedPlayers.forEach(player =>
  sessionMap.get(player.socketId)
    .broadcast.to(player.socketId)
    .emit('match',
      this.getMatchConfigurationFor(matchedPlayers)));

会话映射是我的套接字保存密钥(套接字 ID)和稍后通过发射发送的套接字的映射。关于我的 session.map 的控制台日志,这是控制台。登录我的套接字播放器https://pastebin.com/XHDXH9ih

标签: node.jssocket.io

解决方案


推荐阅读