y_arl
y_arl

Reputation: 351

Twilio-video: how to tell if a track is a screenshare?

Right now in "room.on('trackAdded')", I can't tell if the track which was added is a screenshare or not. Is there a way to tell?

Upvotes: 5

Views: 1621

Answers (2)

Liana Gukasyan
Liana Gukasyan

Reputation: 91

Thank you, @philnash, I was using suggested behaviour.

But with Twilio 2.x it seems to be broken. And according to documentation it's required to specify options (add a name) during local track creation:

const newScreenLocalTrack = new Twilio.Video.LocalVideoTrack(newScreenTrack, {name: 'screen'})

and then just publish created track without any options:

localParticipant.publishTrack(newScreenLocalTrack)

Upvotes: 9

philnash
philnash

Reputation: 73065

Twilio developer evangelist here.

As far as I am aware each track is either a VideoTrack or an AudioTrack. A screenshare will be a VideoTrack, but other than that there is nothing to tell it apart from another VideoTrack from a camera source.

Edit

After some further research I've found the following:

You can set a name for LocalTracks which shows up on the remote side. For example, if you create a new MediaStreamTrack which is the screen, and publish that track to your local participant, then you can set a name for it.

localParticipant.publishTrack(screenVideoTrack, { name: 'screen' })

Then, when you receive the trackAdded event you can inspect the track's name property:

room.on('trackAdded', (track, participant) => {
  console.log(track.name);
});

Upvotes: 8

Related Questions