HTML5   发布时间:2022-04-25  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了websocket – 使用HTML5或Javascript进行P2P视频配置大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试使用 html5javascript构建视频会议,直到现在我能够流式传输相机并将其显示在画布上

这是代码

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"  dir="ltr">
<head>  
<style>

    nav .search {
        display: none;
    }

    .demoFrame header,.demoFrame .footer,.demoFrame h1,.demoFrame .p {
        display: none !important;
    }

    h1 {
        font-size: 2.6em;
    }

    h2,h3 {
        font-size: 1.7em;
    }

    .left {
        width: 920px !important;
        padding-bottom: 40px;
        min-height: auto !important;
        padding-right: 0;
        float: left;
    }

    div.p {
        font-size: .8em;
        font-family: arial;
        margin-top: -20px;
        font-style: italic;
        padding: 10px 0;
    }

    .footer {
        padding: 20px;
        margin: 20px 0 0 0;
        BACkground: #f8f8f8;
        font-weight: bold;
        font-family: arial;
        border-top: 1px solid #ccc;
    }

    .left > p:first-of-type { 
        BACkground: #ffd987; 
        font-style: italic; 
        padding: 5px 10px; 
        margin-bottom: 40px;
    }

    .demoAds {
        position: absolute;
        top: 0;
        right: 0;
        width: 270px;
        padding: 10px 0 0 10px;
        BACkground: #f8f8f8;
    }
    .demoAds a {
        margin: 0 10px 10px 0 !important;
        display: inline-block !important;
    }

    #promoNode { 
        margin: 20px 0; 
    }

    @media only screen and (max-width : 1024pX) {
        .left {
            float: none;
        }

        body .one .bsa_it_ad {
            position: relative !important;
        }
    }
</style>    <style>
        video { border: 1px solid #ccc; display: block; margin: 0 0 20px 0; }
        #canvas { margin-top: 20px; border: 1px solid #ccc; display: block; }
    </style>
</head>
<body>



<!-- Add the HTML header -->
<div id="page">




<!-- holds content,will be frequently changed -->
<div id="contentHolder">

    <!-- start the left section if not the homepage -->
    <section class="left">

    <!--
        Ideally these elements aren't created until it's confirmed that the 
        client supports video/camera,but for the sake of illustrating the 
        elements involved,they are created with markup (not JavaScript)
    -->
    <video id="video" width="640" height="480" autoplay></video>
    <button id="snap" class="sexyButton">Snap Photo</button>
    <canvas id="canvas" width="640" height="480"></canvas>

    <script>

        // Put event listeners into place
        window.addEventListener("DOMContentLoaded",function() {
            // Grab elements,create setTings,etc.
            var canvas = document.getElementById("canvas"),context = canvas.getContext("2d"),video = document.getElementById("video"),videoObj = { "video": true,"audio" : true },errBACk = function(error) {
                    console.log("Video capture error: ",error.codE); 
                };

            // Put video listeners into place
            if(navigator.getUserMedia) { // Standard
                navigator.getUserMedia(videoObj,function(stream) {
                    video.src = stream;
                    video.play();
                },errBACk);
            } else if(navigator.webkitGetUserMedia) { // WebKit-prefixed
                navigator.webkitGetUserMedia(videoObj,function(stream){
                    video.src = window.webkitURl.createObjectURL(stream);
                    video.play();
                },errBACk);
            }

            // trigger photo take
            document.getElementById("snap").addEventListener("click",function() {
                context.drawImage(video,640,480);
            });
        },falsE);

    </script>

</section>

<style>
body .one .bsa_it_ad { BACkground: #f8f8f8; border: none; font-family: inherit; width: 200px; position: absolute; top: 0; right: 0; text-align: center; border-radius: 8px; }
body .one .bsa_it_ad .bsa_it_i { display: block; padding: 0; float: none; margin: 0 0 5px; }
body .one .bsa_it_ad .bsa_it_i img { padding: 10px; border: none; margin: 0 auto; }
body .one .bsa_it_ad .bsa_it_t { padding: 6px 0; }
body .one .bsa_it_ad .bsa_it_d { padding: 0; font-size: 12px; color: #333; }
body .one .bsa_it_p { display: none; }
body #bsap_aplink,body #bsap_aplink:hover { display: block; font-size: 10px; margin: 12px 15px 0; text-align: right; }
</style>

</div>

</body>
</html>

现在我只想流视频以在两个人之间召开会议,我知道我必须使用webRTC或websocket,但我不知道如何开始为此编写代码.
任何帮助或建议都会非常有帮助.

解决方法@H_419_20@
HTML5rocks有很好的教程.

WebRTC tutorial

总结如下所涉及的步骤: –

>获取流式音频,视频或其他数据.>获取IP地址和端口等网络信息,并与其他WebRTC客户端(称为对等端)进行交换,以实现连接,甚至通过NAT和防火墙.协调“信令”通信以报告错误并启动或关闭会话.>交换有关媒体和客户端功能的信息,例如分辨率和编解码器.>传输流式音频,视频或数据.要获取和传递流数据,WebRTC实现以下API.     MediaStream:可以访问数据流,例如来自用户的摄像头和麦克风. RTCPeerConnection:音频或视频呼叫,具有加密和带宽管理功能. RTCDataChAnnel:通用数据的对等通信.

大佬总结

以上是大佬教程为你收集整理的websocket – 使用HTML5或Javascript进行P2P视频配置全部内容,希望文章能够帮你解决websocket – 使用HTML5或Javascript进行P2P视频配置所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。