twilio / twilio-video.js

Twilio’s Programmable Video JavaScript SDK
https://www.twilio.com/docs/video/javascript
Other
571 stars 217 forks source link

track.stop() is not a function #1067

Closed TravBradfield closed 4 years ago

TravBradfield commented 4 years ago

Code to reproduce the issue:

room.on('disconnected', room => {
        console.log('You disconnected: ', room);
        room.participants.forEach(element => {
          this.participantDisconnected(element)
        });
      })

  participantDisconnected = (participant) => {
    console.log('Participant "%s" disconnected', participant.identity);
    document.getElementById(participant.sid).remove();
    const track = [...participant.videoTracks.values()][0].track;
    track.stop();
    track.detach(this.localVideoTrack.current);
    participant.unpublishTrack(track);
    this.disconnectCall();
  }

Expected behavior:

I expect the local video to be stopped by "track.stop()".

Actual behavior:

I'm getting an error saying track.stop() is not a function.

TODO

Software versions:

manjeshbhargav commented 4 years ago

Hi @TravBradfield ,

Thanks for writing in with your issue. In your snippet, you are attempting to stop RemoteParticipants' Tracks, which is not possible. You can only stop your own Tracks, which can be done as follows:

  room.on('disconnected', room => {
    console.log('You disconnected: ', room);
    room.participants.forEach(participant => this.participantDisconnected(participant));
    this.participantDisconnected(room.localParticipant);
  });

  participantDisconnected = participant => {
    console.log('Participant "%s" disconnected', participant.identity);
    document.getElementById(participant.sid).remove();
    const track = [...participant.videoTracks.values()][0].track;
    if (track.stop) {
      track.stop();
      track.detach(this.localVideoTrack.current);
    }
    this.disconnectCall();
  }

Hope this helps. I'll close this issue since I've answered your question, but we can continue the conversation here if you need any more clarification.

Thanks,

Manjesh Malavalli JSDK Team

TravBradfield commented 4 years ago

@manjeshbhargav Thanks for your response. I've tried your code snippet but it hasn't made any difference.. Here is a screen shot of my console.

Screenshot 2020-06-23 at 20 47 57
TravBradfield commented 4 years ago

Hi @TravBradfield ,

Thanks for writing in with your issue. In your snippet, you are attempting to stop RemoteParticipants' Tracks, which is not possible. You can only stop your own Tracks, which can be done as follows:

  room.on('disconnected', room => {
    console.log('You disconnected: ', room);
    room.participants.forEach(participant => this.participantDisconnected(participant));
    this.participantDisconnected(room.localParticipant);
  });

  participantDisconnected = participant => {
    console.log('Participant "%s" disconnected', participant.identity);
    document.getElementById(participant.sid).remove();
    const track = [...participant.videoTracks.values()][0].track;
    if (track.stop) {
      track.stop();
      track.detach(this.localVideoTrack.current);
    }
    this.disconnectCall();
  }

Hope this helps. I'll close this issue since I've answered your question, but we can continue the conversation here if you need any more clarification.

Thanks,

Manjesh Malavalli JSDK Team

const track = [...participant.videoTracks.values()][0].track;

this track is always undefined!! I'm really battling to understand why. There is no participant being passed in which is why it always fails.. But why!?!?!

(Tearing my hair out)