SkyWay公式ドキュメント
を元に、チュートリアルを作成したのですが、相互画面(相手側)が表示されません。
ブラウザ:Google Chorme
テスト方法:複数タブで、相手側のIDを入力して通信開始
確認したこと:開発ツールで、ピア通信が確率されている。
CSS
↑文字制限で入らなかったため。ここのCSSをコピペです。
解決方法をどなたかご教示下さい。
HTML
1<!DOCTYPE html> 2<html> 3<head lang="ja"> 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> 5 <title>SkyWay JS SDK Tutorial</title> 6 <link rel="stylesheet" href="css/style.css"> 7</head> 8<div class="pure-g"> 9 10 <!-- Video area --> 11 <div class="pure-u-2-3" id="video-container"> 12 <video id="their-video" autoplay></video> 13 <video id="my-video" muted="true" autoplay></video> 14 </div> 15 16 <!-- Steps --> 17 <div class="pure-u-1-3"> 18 <h2>SkyWay Video Chat</h2> 19 20 <p>Your id: <span id="my-id">...</span></p> 21 <p>Share this id with others so they can call you.</p> 22 <h3>Make a call</h3> 23 <form id="make-call" class="pure-form"> 24 <input type="text" placeholder="Call user id..." id="callto-id"> 25 <button href="#" class="pure-button pure-button-success" type="submit">Call</button> 26 </form> 27 <form id="end-call" class="pure-form"> 28 <p>Currently in call with <span id="their-id">...</span></p> 29 <button href="#" class="pure-button pure-button-success" type="submit">End Call</button 30 </form> 31 </div> 32</div> 33<script type="text/javascript" src="https://code.jquery.com/jquery-3.2.1.min.js"></script> 34<script type="text/javascript" src="https://cdn.webrtc.ecl.ntt.com/skyway-latest.js"></script> 35<script type="text/javascript" src="js/script.js"></script> 36</html> 37
js
1 2'use strict'; 3 4let localStream = null; 5let peer = null; 6let existingCall = null; 7 8navigator.mediaDevices.getUserMedia({video: true, audio: true}) 9.then(function (stream) { 10 // Success 11 $('#my-video').get(0).srcObject = stream; 12 localStream = stream; 13}).catch(function (error) { 14 // Error 15 console.error('mediaDevice.getUserMedia() error:', error); 16 return; 17}); 18 19peer = new Peer({ 20 key: 'ee326e13-d617-4058-ba8b-010c3ae81a3c', 21 debug: 3 22}); 23 24peer.on('open', function(){ 25 $('#my-id').text(peer.id); 26}); 27 28peer.on('error', function(err){ 29 alert(err.message); 30}); 31 32peer.on('close', function(){ 33}); 34 35peer.on('disconnected', function(){ 36}); 37 38$('#make-call').submit(function(e){ 39 e.preventDefault(); 40 const call = peer.call($('#callto-id').val(), localStream); 41 setupCallEventHandlers(call); 42}); 43 44$('#end-call').click(function(){ 45 existingCall.close(); 46}); 47 48peer.on('call', function(call){ 49 call.answer(localStream); 50 setupCallEventHandlers(call); 51}); 52 53function setupCallEventHandlers(call){ 54 if (existingCall) { 55 existingCall.close(); 56 }; 57 58 existingCall = call; 59 call.on('stream', function(stream){ 60 addVideo(call,stream); 61 setupEndCallUI(); 62 $('#their-id').text(call.remoteId); 63 }); 64 // 省略 65} 66 67function setupCallEventHandlers(call){ 68 // 省略 69 call.on('close', function(){ 70 removeVideo(call.remoteId); 71 setupMakeCallUI(); 72 }); 73} 74 75function addVideo(call,stream){ 76 $('#their-video').get(0).srcObject = stream; 77} 78 79function removeVideo(peerId){ 80 $('#' + peerId).remove(); 81} 82 83function setupMakeCallUI(){ 84 $('#make-call').show(); 85 $('#end-call').hide(); 86} 87 88function setupEndCallUI() { 89 $('#make-call').hide(); 90 $('#end-call').show(); 91} 92
あなたの回答
tips
プレビュー