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?
2 Answers
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)

- 91
- 2
- 2
-
Thank you @Liana! Your answer is really helpful! – Mina Djuric Nov 14 '19 at 14:48
-
Thank you Liana! This is much better than philnash's answer as this sets the name pre-publishing the track. Allowing to store the track in various places pre-publishing, and manipulating it in other ways. – danefondo Oct 07 '20 at 13:27
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 LocalTrack
s 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);
});

- 70,667
- 10
- 60
- 88
-
This is not helpful at all. I need to place user's camera feed at one location and screen feed at a different one. There should be a way to tell which is which and who's camera and screen it is. – Nishant Sep 05 '18 at 17:25
-
@Nishant you made me question myself, thank you. Turns out you can tell, by setting a name for the tracks. See the edit to my answer. – philnash Sep 06 '18 at 01:52
-
ha ha, I got it figured, came here to add to the answer. Glad to see you've done it better. Thanks +1. – Nishant Sep 06 '18 at 03:17