2014-11-11 6 views
1

영어가 좋지 않지만 문제를 설명하려고합니다. PeerJS를 사용하여 사용자들에게 전화 오디오를 보내고 있습니다. 그리고이 예제를 사용합니다 : http://cdn.peerjs.com/demo/videochat 그리고 그것의 작품. 하지만이 스크립트에서는 사용자에게 대답을 추가하거나 응답하지 않기를 원합니다. 내가 어떻게 할 수 있니? 이것은 내 스크립트입니다.peerJS 스크립트에 답변 추가

<html> 
<head> 
    <title>PeerJS - Video chat example</title> 
    <link rel="stylesheet" href="style.css"> 
    <link href="http://netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap.min.css" rel="stylesheet"> 
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script> 
    <script type="text/javascript" src="./jquery.confirm.js"></script> 

    <script src="./peer.min.js"></script> 
    <script> 

    // Compatibility shim 
    navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia; 

    // PeerJS object 
    var peer = new Peer({ key: 'lwjd5qra8257b9', debug: 3}); 

    peer.on('open', function(){ 
     $('#my-id').text(peer.id); 
    }); 

    // Receiving a call 
    peer.on('call', function(call){ 
     // Answer the call automatically (instead of prompting user) for demo purposes 

     //here is Ansswer 

     call.answer(window.localStream); 
     step3(call); 

    }); 
    peer.on('error', function(err){ 
     alert(err.message); 
     // Return to step 2 if error occurs 
     step2(); 
    }); 

    // Click handlers setup 
    $(function(){ 
     $('#make-call').click(function(){ 
     // Initiate a call! 
     var call = peer.call($('#callto-id').val(), window.localStream); 

     step3(call); 
     }); 

     $('#end-call').click(function(){ 
     window.existingCall.close(); 
     step2(); 
     }); 

     // Retry if getUserMedia fails 
     $('#step1-retry').click(function(){ 
     $('#step1-error').hide(); 
     step1(); 
     }); 

     // Get things started 
     step1(); 
    }); 

    function step1() { 
     // Get audio/video stream 
     navigator.getUserMedia({audio: true, video: false}, function(stream){ 
     // Set your video displays 
     $('#my-video').prop('src', URL.createObjectURL(stream)); 

     window.localStream = stream; 
     step2(); 
     }, function(){ $('#step1-error').show(); }); 
    } 

    function step2() { 
     $('#step1, #step3').hide(); 
     $('#step2').show(); 
    } 

    function step3 (call) { 
     // Hang up on an existing call if present 
     if (window.existingCall) { 
     window.existingCall.close(); 
     } 

     // Wait for stream on the call, then set peer video display 
     call.on('stream', function(stream){ 
     $('#their-video').prop('src', URL.createObjectURL(stream)); 
     }); 

     // UI stuff 
     window.existingCall = call; 
     $('#their-id').text(call.peer); 
     call.on('close', step2); 
     $('#step1, #step2').hide(); 
     $('#step3').show(); 
    } 

    </script> 

    <style> 
    .pure-g { 
     width: 350px; 
     margin: auto; 
    } 
    .pure-u-1-3{ 
     width: 100%; 
    } 
    </style> 

</head> 

<body> 

    <div class="pure-g"> 
     <!-- Video area --> 
     <div class="pure-u-2-3" id="video-container" style='display: none'> 
     <video id="their-video" autoplay></video> 
     </div> 

     <!-- Steps --> 
     <div class="pure-u-1-3"> 
     <h2>SMA Voice Chat</h2> 

     <!-- Get local audio/video stream --> 
     <div id="step1"> 
      <p>Please click `allow` on the top of the screen so we can access your webcam and microphone for calls.</p> 
      <div id="step1-error"> 
      <p>Failed to access the webcam and microphone. Make sure to run this demo on an http server and click allow when asked for permission by the browser.</p> 
      <a href="#" class="pure-button pure-button-error" id="step1-retry">Try again</a> 
      </div> 
     </div> 

     <!-- Make calls to others --> 
     <div id="step2"> 
      <p>Your id: <span id="my-id">...</span></p> 
      <p>Share this id with others so they can call you.</p> 
      <h3>Make a call</h3> 
      <div class="pure-form"> 
      <input type="text" placeholder="Call user id..." id="callto-id"> 
      <a href="#" class="pure-button pure-button-success" id="make-call">Call</a> 
      </div> 
     </div> 

     <!-- Call in progress --> 
     <div id="step3"> 
      <p>Currently in call with <span id="their-id">...</span></p> 
      <p><a href="#" class="pure-button pure-button-error" id="end-call">End call</a></p> 
     </div> 
     </div> 
    </div> 

<script src="http://netdna.bootstrapcdn.com/bootstrap/3.0.2/js/bootstrap.min.js"></script> 
<script src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js"></script> 

</body> 
</html> 

아이디어가 있으십니까?

+0

도움이 나를하시기 바랍니다. – user3231235

+0

아래의 답은 오류없이 u에서 효과가 있었습니까 ?? 왜냐하면 내가 그걸 시도했을 때 나에게 어떤 알림도 표시하지 않았기 때문이다. – Zammuuz

+0

네, 나와 함께 작동합니다. – user3231235

답변

0

내가 PeerJS에 익숙하지 않은,하지만 난이 다음과 같이 당신이 당신의 peer.on('call',...) 부분을 다시 시도 할 수 있습니다 생각 :

peer.on('call', function(call){ 
    $.confirm({ 
    text: "Receive a call?", 
    confirm: function(button) { 
     //user clicked "ok" 
     call.answer(window.localStream); 
     step3(call); 
    }, 
    cancel: function(button) { 
     //user clicked "cancel" 
    } 
    }); 
}); 
+0

매우 다발 – user3231235