【问题标题】:TypeError: Cannot read property 'forEach' of undefined in twilio with angularTypeError:无法读取带有角度的 twilio 中未定义的属性“forEach”
【发布时间】:2019-10-31 12:51:10
【问题描述】:

private async getAuthToken(name: string, room: string) {
    const auth = await this.http
    .post('http://localhost:8000/token', {name, room}).toPromise();
    return auth;
  }

  async onRoom(){
    const token = await this.getAuthToken(this.user, this.room);
    try {
      await connect(
          token, {
              name,
          }).then(room =>
            {
              this.activeRoom = room;
              console.log(this.activeRoom);
              
              console.log(`Successfully joined a Room: ${room}`);
              // Log new Participants as they connect to the Room
              room.once('participantConnected', participant => {
                console.log(`El participante "${participant.identity}" se está conectando`);
              });

              // Log Participants as they disconnect from the Room
              room.once('participantDisconnected', participant => {
                console.log(`El participante "${participant.identity}"se está desconectando`);
              });
              room.on('participantConnected', participant => {
                console.log(`El participante ${participant.identity} se conecto`);
                console.log(participant.track)
                participant.track.forEach(track => {
                  console.log('foreach participant');
                  const localMediaContainer = document.getElementById('remote-media');
                  localMediaContainer.appendChild(track.attach());
                });
                participant.on('trackAdded', track => {
                  console.log('track added');
                  const localMediaContainer = document.getElementById('remote-media');
                  localMediaContainer.appendChild(track.attach());
                })
              });
              room.on('participantDisconnected', participant => {
                console.log(`El participante ${participant.identity} se desconecto` );
              });
              room.on('disconnected', room => {
                room.localParticipant.tracks.forEach(track => {
                  const attachedElements = track.detach();
                  attachedElements.forEach(element => element.remove());
                  console.log(`La sala ${room} se ha desconectado con éxito`)
                });
              });
            });
    } catch (error) {
        return console.error(`Unable to connect to Room: ${error.message}`);
    }
  }

我设法连接房间,但是当另一个用户进入房间时,我抛出以下错误

错误类型错误:无法读取未定义的属性“forEach”

当我想离开房间时,我会抛出以下错误

ERROR TypeError: track.detach 不是函数

【问题讨论】:

  • 您使用的是哪个版本的 Twilio Video JS?

标签: twilio


【解决方案1】:

第一个调用是参与者.track,第二个是参与者.tracks。哪一个是正确的? forEach 错误意味着参与者.track 不存在。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-02-18
    • 1970-01-01
    • 2018-10-28
    • 2018-09-19
    • 2021-07-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多