Node.js 如何设置node socket.io

Node.js 如何设置node socket.io,node.js,socket.io,Node.js,Socket.io,我正在尝试完成,在浏览器控制台中出现此错误 index.js:16 Uncaught TypeError: this.io.on is not a function at index.js:16 这是我的index.js的全部内容 navigator.getUserMedia( { video: true, audio: true }, stream => { const localVideo = document.getElementById("lo

我正在尝试完成,在浏览器控制台中出现此错误

index.js:16 Uncaught TypeError: this.io.on is not a function
    at index.js:16
这是我的index.js的全部内容

navigator.getUserMedia(
    { video: true, audio: true },
    stream => {
      const localVideo = document.getElementById("local-video");
      if (localVideo) {
        localVideo.srcObject = stream;
      }
    },
    error => {
      console.warn(error.message);
    }
   );

   this.io.on("connection", socket => {
    const existingSocket = this.activeSockets.find(
      existingSocket => existingSocket === socket.id
    );

    if (!existingSocket) {
      this.activeSockets.push(socket.id);

      socket.emit("update-user-list", {
        users: this.activeSockets.filter(
          existingSocket => existingSocket !== socket.id
        )
      });

      socket.broadcast.emit("update-user-list", {
        users: [socket.id]
      });
    }
  })
我错过了什么?我知道“this”应该是指一些封闭的对象,但是什么呢?

结帐教程

您要引用的部分位于socket-connection.ts文件中,而不是作者所指的index.js

或者它可能是一个打字脚本abrakadabra:)

另外,您还应该记住,“this”构造总是在函数中(但不是在arrow函数中)