仅在收到授权事件后,如何调用由其他事件触发的功能?

时间:2018-06-25 21:28:43

标签: javascript node.js socket.io

我有一个实现jwt授权的Socket.io连接。我已经设法发出auth令牌并获得响应,但是我只想在授权连接后才发出“ onClick()”内部的内容。有什么办法可以做到这一点?

const socket = io('http://localhost:8000',{transports: ['websocket']});

socket.on('connect', function () {
  console.log('Connected?');

  socket
    .on('authenticated', function () {
      console.log('Authenticated');
      socket.emit('message', 'hello');
    })
    .emit('authenticate', {token: jwt}) //send the jwt

});


onClick = () => {

    socket.emit('message','button clicked');
}

0 个答案:

没有答案