<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Security_temp.aspx.cs" Inherits="NECPATEL.Security" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    
    <form id="form1" runat="server" >
    <div>
    <device type="media" onchange="update(this.data)"></device>
        
<video autoplay></video>
<script>
    var errorCallback = function (e) {
        console.log('Reeeejected!', e);
    };
    navigator.getUserMedia = navigator.getUserMedia ||
                              navigator.webkitGetUserMedia ||
                              navigator.mozGetUserMedia ||
                              navigator.msGetUserMedia;

    var video = document.querySelector('video');

    if (navigator.getUserMedia) {
        navigator.getUserMedia({ audio: true, video: true }, function (stream) {
            video.src = window.URL.createObjectURL(stream);
        }, errorCallback);
    } else {
        video.src = 'somevideo.webm'; // fallback.
    }

    MediaStreamTrack.getSources(function (sourceInfos) {
        var audioSource = null;
        var videoSource = null;

        for (var i = 0; i != sourceInfos.length; ++i) {
            var sourceInfo = sourceInfos[i];
            if (sourceInfo.kind === 'audio') {
                console.log(sourceInfo.id, sourceInfo.label || 'microphone');

                audioSource = sourceInfo.id;
            } else if (sourceInfo.kind === 'video') {
                console.log(sourceInfo.id, sourceInfo.label || 'camera');

                videoSource = sourceInfo.id;
            } else {
                console.log('Some other kind of source: ', sourceInfo);
            }
        }

        sourceSelected(audioSource, videoSource);
    });

    function sourceSelected(audioSource, videoSource) {
        var constraints = {
            audio: {
                optional: [{ sourceId: audioSource }]
            },
            video: {
                optional: [{ sourceId: videoSource }]
            }
        };

        navigator.getUserMedia(constraints, successCallback, errorCallback);
    }
    
    function update(stream) {
        document.querySelector('video').src = stream.url;
    }
</script> 
    
    </div>
    </form>
</body>
</html>
