2017-09-12 7 views
0

私は望むなら、ビデオトラックを無効にする機能をユーザーに提供したいと思います。これにLocalVideoTrack.disable()を使用できますか?はいの場合は、私に例を示すことができますか?ユーザーの好みに応じて、ビデオトラックを停止してtwilioビデオを使用してビデオトラックを再送信する方法を教えてください。

は、ここに私のコードです:ユーザーは、私はすでに送信ミリアンペア場合は、ビデオの送信を停止するかI私はないですビデオの送信を開始するトグル・ビデオボタンをclciks

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 to Twilio: ' + error.message); 
     }); 


    // Bind button to leave Room. 
    document.getElementById('button-leave').onclick = function() { 
     log('Leaving room...'); 
     leaveRoomIfJoined(); 
    }; 
}); 

// Successfully connected! 
function roomJoined(room) { 
    //To collect the timing data for 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 already attached. 
    // var previewContainer = document.getElementById('local-media'); 
    // if (!previewContainer.querySelector('video')) { 
    //  attachParticipantTracks(room.localParticipant, previewContainer); 
    // } 

    // Attach the Tracks of the Room's Participants. 
    room.participants.forEach(function (participant) { 
     log("Already in Room: '" + participant.identity + "'"); 
     var previewContainer = document.getElementById('remote-media'); 
     attachParticipantTracks(participant, previewContainer); 
    }); 

    // When a Participant joins the Room, log the event. 
    room.on('participantConnected', function (participant) { 
     console.log(participant); 
     log("Joining: '" + participant.identity + "'"); 
    }); 

    // When a Participant adds a Track, attach it to the 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 a Participant removes a Track, detach it from the DOM. 
    room.on('trackRemoved', function (track, participant) { 
     log(participant.identity + " removed track: " + track.kind); 
     detachTracks([track]); 
    }); 

    // When a Participant leaves the Room, detach its Tracks. 
    room.on('participantDisconnected', function (participant) { 
     log("Participant '" + participant.identity + "' left the room"); 
     log(new Date().getMinutes()); 
     detachParticipantTracks(participant); 
    }); 
    $('#toggle-video').click(function(e){ 
     console.log(room.localParticipant.videoTracks); 
     // room.localParticipant.videoTracks.disable(); 
    }); 
    // Once the LocalParticipant leaves the room, detach the Tracks 
    // of all Participants, including that of the 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'; 
    }); 
} 

だから、基本的にはとき。このためにLocalVideoTrackを取得するにはどうすればよいですか?

答えて

1

ここではTwilioの開発者エバンジェリストです。

この場合、確かにLocalTrack.disable()を使用できます。または、トラックを一時停止または一時停止解除するブール値の引数をLocalTrack.enable([enabled])に渡すことができます。あなたがそれを達成する方法は次のとおりです。

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); 
    }); 
    }) 
} 

それがまったく役に立ったら教えてください。

+0

ボタンをクリックしたときに共有したコードを使用しましたが、このエラーがスローされています:Uncaught TypeError:localParticipant.videoTracks.values(...)forEachは関数ではありません – lightbringer

+0

ここでコードは '$ 'toggle-video'))をクリックします(video_rack)。.enable(false); }); }); ' – lightbringer

+0

申し訳ありませんが、私はこれを修正して再現しようとします。 – philnash

関連する問題