webrtc - How can I allow stop the video track and resend the video track using twilio video depending on the user preference? -
i give users functionality disable videotrack if wish. can use localvideotrack.disable() this? if yes, can show me example?
here code:
navigator.mediadevices.getusermedia({ audio: true, video: {width: 320} }) .then(function (mediastream) { var connectoptions = { name: roomname, loglevel: 'off', tracks: mediastream.gettracks() }; return video.connect(data.token, connectoptions); }) .then(roomjoined, function (error) { log('could not connect twilio: ' + error.message); }); // bind button leave room. document.getelementbyid('button-leave').onclick = function () { log('leaving room...'); leaveroomifjoined(); }; }); // connected! function roomjoined(room) { //to collect timing data billing purposes $.post('/classrooms/logs/joinedroom/' + lessonid + '/' + identity, function (data) { console.log(data); }); activeroom = room; log("joined" + room); log(new date().getminutes()); // attach localparticipant's tracks, if not attached. // var previewcontainer = document.getelementbyid('local-media'); // if (!previewcontainer.queryselector('video')) { // attachparticipanttracks(room.localparticipant, previewcontainer); // } // attach tracks of room's participants. room.participants.foreach(function (participant) { log("already in room: '" + participant.identity + "'"); var previewcontainer = document.getelementbyid('remote-media'); attachparticipanttracks(participant, previewcontainer); }); // when participant joins room, log event. room.on('participantconnected', function (participant) { console.log(participant); log("joining: '" + participant.identity + "'"); }); // when participant adds track, attach dom. room.on('trackadded', function (track, participant) { log(participant.identity + " added track: " + track.kind); var previewcontainer = document.getelementbyid('remote-media'); var h = previewcontainer.offsetwidth * 0.75 + "px"; if (participant.identity === classroom.teacher._id) { attachtracks([track], previewcontainer); previewcontainer.style.height = h; // } else { // if(track.kind == 'audio') { // console.log(typeof(track.kind)); // attachtracks([track], previewcontainer); // } } }); // when participant removes track, detach dom. room.on('trackremoved', function (track, participant) { log(participant.identity + " removed track: " + track.kind); detachtracks([track]); }); // when participant leaves room, detach tracks. room.on('participantdisconnected', function (participant) { log("participant '" + participant.identity + "' left room"); log(new date().getminutes()); detachparticipanttracks(participant); }); $('#toggle-video').click(function(e){ console.log(room.localparticipant.videotracks); // room.localparticipant.videotracks.disable(); }); // once localparticipant leaves room, detach tracks // of participants, including of localparticipant. room.on('disconnected', function () { $.post('/classrooms/logs/leftroom/' + lessonid + '/' + identity, function (data) { detachparticipanttracks(room.localparticipant); room.participants.foreach(detachparticipanttracks); activeroom = null; // document.getelementbyid('button-join').style.display = 'inline'; document.getelementbyid('button-leave').style.display = 'none'; }); log('left'); log(new date().getminutes()); detachparticipanttracks(room.localparticipant); room.participants.foreach(detachparticipanttracks); activeroom = null; // document.getelementbyid('button-join').style.display = 'inline'; document.getelementbyid('button-leave').style.display = 'none'; }); }
so when user clciks toggle-video button want stop sending video if ma sending or start sending video i not. how can hold of localvideotrack this?
twilio developer evangelist here.
you can indeed use localtrack.disable()
in case. or, make easier, can pass boolean argument localtrack.enable([enabled])
pauses or unpauses track. here's how achieve that:
function roomjoined(room) { const localparticipant = room.localparticipant; let videoenabled = true; $('#toggle-video').click(function(e) { videoenabled = !videoenabled; localparticipant.videotracks.foreach(function(videotrack) { videotrack.enable(videoenabled); }); }) }
let me know if helps @ all.
Comments
Post a Comment