<commit_before>/*
 *  Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree.
 */
var getMediaButton = document.getElementById('getMedia');
var createPeerConnectionButton = document.getElementById('createPeerConnection');
var createOfferButton = document.getElementById('createOffer');
var setOfferButton = document.getElementById('setOffer');
var createAnswerButton = document.getElementById('createAnswer');
var setAnswerButton = document.getElementById('setAnswer');
var hangupButton = document.getElementById('hangup');

getMediaButton.onclick = getMedia;
createPeerConnectionButton.onclick = createPeerConnection;
createOfferButton.onclick = createOffer;
setOfferButton.onclick = setOffer;
createAnswerButton.onclick = createAnswer;
setAnswerButton.onclick = setAnswer;
hangupButton.onclick = hangup;

var offerSdpTextarea = document.getElementById('localSDP');
var answerSdpTextarea = document.getElementById('remoteSDP');

var audioSelect = document.getElementById('audioSrc');
var videoSelect = document.getElementById('videoSrc');

// audioSelect.onchange = videoSelect.onchange = getMedia;

var localVideo = document.getElementById('localVideo');
var remoteVideo = document.getElementById('remoteVideo');

var selectSourceDiv = document.getElementById('selectSource');

var localPeerConnection, remotePeerConnection;
var localStream;
var sdpConstraints = {
  'mandatory': {
    'OfferToReceiveAudio': true,
    'OfferToReceiveVideo': true
  }
};

function getSources() {
  if (typeof MediaStreamTrack === 'undefined'){
    alert('This browser does not support MediaStreamTrack.\n\nTry Chrome Canary.');
  } else {
    MediaStreamTrack.getSources(gotSources);
    // selectSourceDiv.classList.remove('hidden');
  }
}

var AdapterJS = AdapterJS || {};
AdapterJS.onwebrtcready = function(isUsingPlugin) {
  getSources();
}

function gotSources(sourceInfos) {
  var audioCount = 0;
  var videoCount = 0;
  for (var i = 0; i < sourceInfos.length; i++) {
    var option = document.createElement('option');
    option.value = sourceInfos[i].id;
    option.text = sourceInfos[i].label;
    if (sourceInfos[i].kind === 'audio') {
      audioCount++;
      if (option.text === '') {
        option.text = 'Audio ' + audioCount;
      }
      audioSelect.appendChild(option);
    } else {
      videoCount++;
      if (option.text === '') {
        option.text = 'Video ' + videoCount;
      }
      videoSelect.appendChild(option);
    }<commit_msg>TWP-151: add screensharing option from JS when available<commit_after>/*
 *  Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree.
 */
var getMediaButton = document.getElementById('getMedia');
var createPeerConnectionButton = document.getElementById('createPeerConnection');
var createOfferButton = document.getElementById('createOffer');
var setOfferButton = document.getElementById('setOffer');
var createAnswerButton = document.getElementById('createAnswer');
var setAnswerButton = document.getElementById('setAnswer');
var hangupButton = document.getElementById('hangup');

getMediaButton.onclick = getMedia;
createPeerConnectionButton.onclick = createPeerConnection;
createOfferButton.onclick = createOffer;
setOfferButton.onclick = setOffer;
createAnswerButton.onclick = createAnswer;
setAnswerButton.onclick = setAnswer;
hangupButton.onclick = hangup;

var offerSdpTextarea = document.getElementById('localSDP');
var answerSdpTextarea = document.getElementById('remoteSDP');

var audioSelect = document.getElementById('audioSrc');
var videoSelect = document.getElementById('videoSrc');

// audioSelect.onchange = videoSelect.onchange = getMedia;

var localVideo = document.getElementById('localVideo');
var remoteVideo = document.getElementById('remoteVideo');

var selectSourceDiv = document.getElementById('selectSource');

var localPeerConnection, remotePeerConnection;
var localStream;
var sdpConstraints = {
  'mandatory': {
    'OfferToReceiveAudio': true,
    'OfferToReceiveVideo': true
  }
};

function getSources() {
  if (typeof MediaStreamTrack === 'undefined'){
    alert('This browser does not support MediaStreamTrack.\n\nTry Chrome Canary.');
  } else {
    MediaStreamTrack.getSources(gotSources);
    // selectSourceDiv.classList.remove('hidden');
  }
}

var AdapterJS = AdapterJS || {};
AdapterJS.onwebrtcready = function(isUsingPlugin) {
  getSources();
}

function gotSources(sourceInfos) {
  var audioCount = 0;
  var videoCount = 0;
  for (var i = 0; i < sourceInfos.length; i++) {
    var option = document.createElement('option');
    option.value = sourceInfos[i].id;
    option.text = sourceInfos[i].label;
    if (sourceInfos[i].kind === 'audio') {
      audioCount++;
      if (option.text === '') {
        option.text = 'Audio ' + audioCount;
      }
      audioSelect.appendChild(option);
    } else {
      videoCount++;
      if (option.text === '') {
        option.text = 'Video ' + videoCount;
      }
      videoSelect.appendChild(option);
    }
  }

  if (AdapterJS.WebRTCPlugin.plugin.HasScreensharingFeature
    && AdapterJS.WebRTCPlugin.plugin.isScreensharingAvailable) {
    var option = document.createElement('option');
    option.value = AdapterJS.WebRTCPlugin.plugin.screensharingKey;
    option.text = "Screensharing";
    videoSelect.appendChild(option);
{'fraction_non_alphanumeric': 0.1180692625157007, 'fraction_numerical': 0.003050421675937556, 'mean_word_length': 4.830543933054393, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4503565', 'n_tokens_mistral': 1602, 'n_tokens_neox': 1561, 'n_words': 360}