{"id":198632,"date":"2013-10-23T04:39:02","date_gmt":"2013-10-23T00:39:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=198632"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=198632","title":{"rendered":"<span class=\"post_title\">\u0414\u0435\u043b\u0430\u0435\u043c \u0441\u0432\u043e\u0439 \u043f\u0435\u0440\u0441\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0439 Skype, \u043f\u043e\u0448\u0430\u0433\u043e\u0432\u0430\u044f \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f WebRTC \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f<\/span>"},"content":{"rendered":"<div class=\"content html_format\">   \t<img decoding=\"async\" src=\"http:\/\/habr.habrastorage.org\/post_images\/727\/ba4\/ce7\/727ba4ce74e9b4a610a9ace27e03c14c.png\" alt=\"WebRTC\"\/><\/p>\n<p>  WebRTC \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c real-time \u0430\u0443\u0434\u0438\u043e\/\u0432\u0438\u0434\u0435\u043e \u0441\u0432\u044f\u0437\u044c \u0447\u0435\u0440\u0435\u0437 \u0431\u0440\u0430\u0443\u0437\u0435\u0440 (<img decoding=\"async\" src=\"http:\/\/habr.habrastorage.org\/post_images\/f7d\/a2c\/eb0\/f7da2ceb020805bb54081c8cbf346b3e.png\" alt=\"firefox\"\/> \u0438 <img decoding=\"async\" src=\"http:\/\/habr.habrastorage.org\/post_images\/3bb\/c82\/7bd\/3bbc827bd8ddd527661949013075dab0.png\" alt=\"chrome\"\/>).<\/p>\n<p>  \u0412 \u044d\u0442\u043e\u043c \u0442\u043e\u043f\u0438\u043a\u0435 \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u043a\u0430\u043a \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0435\u0435 WebRTC \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435.<\/p>\n<p>  <a name=\"habracut\"><\/a>  <\/p>\n<h4>1. getUserMedia \u2014 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u043c\u0435\u0434\u0438\u0430 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430\u043c (\u043c\u0438\u043a\u0440\u043e\u0444\u043e\u043d\/\u0432\u0435\u0431\u043a\u0430\u043c\u0435\u0440\u0430)<\/h4>\n<p>  \u041d\u0438\u0447\u0435\u0433\u043e \u0441\u043b\u043e\u0436\u043d\u043e\u0433\u043e, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e 10 \u0441\u0442\u0440\u043e\u043a javascript-\u043a\u043e\u0434\u0430 \u0432\u044b \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0438 \u0443\u0441\u043b\u044b\u0448\u0430\u0442\u044c \u0441\u0435\u0431\u044f \u0432 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0435(<a href=\"http:\/\/jsfiddle.net\/HRJP8\/\">\u0434\u0435\u043c\u043e<\/a>).<\/p>\n<p>  C\u043e\u0437\u0434\u0430\u0439\u0442\u0435 index.html:<\/p>\n<pre><code class=\"javascript\">&lt;video autoplay&gt;&lt;\/video&gt;  &lt;script&gt; navigator.getUserMedia = navigator.getUserMedia || navigator.mozGetUserMedia || navigator.webkitGetUserMedia; navigator.getUserMedia({ audio: true, video: true }, gotStream, streamError);  function gotStream(stream) {    document.querySelector('video').src = URL.createObjectURL(stream); }  function streamError(error) {    console.log(error); } &lt;\/script&gt; <\/code><\/pre>\n<p>  \u041a \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0443 video \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c <a href=\"http:\/\/html5-demos.appspot.com\/static\/css\/filters\/index.html\">css3-\u0444\u0438\u043b\u044c\u0442\u0440\u044b<\/a>.<\/p>\n<p>  \u041e\u0433\u043e\u0440\u0447\u0430\u0435\u0442 \u0437\u0434\u0435\u0441\u044c \u0442\u043e, \u0447\u0442\u043e \u043d\u0430 \u0434\u0430\u043d\u043d\u043e\u043c \u044d\u0442\u0430\u043f\u0435 \u0440\u0430\u0437\u0432\u0438\u0442\u0438\u044f WebRTC \u044f \u043d\u0435 \u043c\u043e\u0433\u0443 \u0441\u043a\u0430\u0437\u0430\u0442\u044c \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0443 \u00ab\u044d\u0442\u043e\u043c\u0443 \u0441\u0430\u0439\u0442\u0443 \u044f \u0434\u043e\u0432\u0435\u0440\u044f\u044e, \u0432\u0441\u0435\u0433\u0434\u0430 \u0434\u0430\u0432\u0430\u0439 \u0435\u043c\u0443 \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043c\u043e\u0435\u0439 \u043a\u0430\u043c\u0435\u0440\u0435 \u0438 \u043c\u0438\u043a\u0440\u043e\u0444\u043e\u043d\u0443\u00bb \u0438 \u043d\u0443\u0436\u043d\u043e \u043d\u0430\u0436\u0438\u043c\u0430\u0442\u044c Allow \u043f\u043e\u0441\u043b\u0435 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043e\u0442\u043a\u0440\u044b\u0442\u0438\u044f\/\u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b. <\/p>\n<p>  \u041d\u0443 \u0438 \u043d\u0435 \u043b\u0438\u0448\u043d\u0438\u043c \u0431\u0443\u0434\u0435\u0442 \u043d\u0430\u043f\u043e\u043c\u043d\u0438\u0442\u044c, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u0432\u044b \u0434\u0430\u043b\u0438 \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043a\u0430\u043c\u0435\u0440\u0435 \u0432 \u043e\u0434\u043d\u043e\u043c \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0435, \u0434\u0440\u0443\u0433\u043e\u0439 \u043f\u0440\u0438 \u043f\u043e\u043f\u044b\u0442\u043a\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043f\u043e\u043b\u0443\u0447\u0438\u0442 PERMISSION_DENIED.<\/p>\n<h4>2. Signaling server (\u0441\u0438\u0433\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u0441\u0435\u0440\u0432\u0435\u0440)<\/h4>\n<p>  \u0417\u0434\u0435\u0441\u044c \u044f \u043d\u0430\u0440\u0443\u0448\u0430\u044e \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0430 \u00abwebrtc getting started\u00bb \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0439 \u043f\u043e\u0442\u043e\u043c\u0443 \u043a\u0430\u043a \u043e\u043d\u0438 \u0432\u0442\u043e\u0440\u044b\u043c \u0448\u0430\u0433\u043e\u043c \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0443\u0440\u0443\u044e\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 webRTC \u043d\u0430 \u043e\u0434\u043d\u043e\u043c \u043a\u043b\u0438\u0435\u043d\u0442\u0435, \u0447\u0442\u043e \u043b\u0438\u0447\u043d\u043e \u043c\u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u043e \u043f\u0443\u0442\u0430\u043d\u0438\u0446\u044b \u0432 \u043e\u0431\u044a\u044f\u0441\u043d\u0435\u043d\u0438\u0435.<\/p>\n<p>  \u0421\u0438\u0433\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u0441\u0435\u0440\u0432\u0435\u0440 \u2014 \u044d\u0442\u043e \u043a\u043e\u043e\u0440\u0438\u043d\u0438\u0440\u0443\u044e\u0449\u0438\u0439 \u0446\u0435\u043d\u0442\u0440 WebRTC, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442 \u043a\u043e\u043c\u043c\u0443\u043d\u0438\u043a\u0430\u0446\u0438\u044e \u043c\u0435\u0436\u0434\u0443 \u043a\u043b\u0438\u0435\u043d\u0442\u0430\u043c\u0438, \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0438 \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u0435 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f, \u043e\u0442\u0447\u0435\u0442\u044b \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0430\u0445.<\/p>\n<p>  \u0421\u0438\u0433\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u0441\u0435\u0440\u0432\u0435\u0440 \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e Node.js + socket.io + node-static, \u043e\u043d \u0431\u0443\u0434\u0435\u0442 \u0441\u043b\u0443\u0448\u0430\u0442\u044c \u043f\u043e\u0440\u0442 1234. <br \/>  \u041f\u043b\u044e\u0441 \u043a\u043e \u0432\u0441\u0435\u043c\u0443 node-static \u043c\u043e\u0436\u0435\u0442 \u043e\u0442\u0434\u0430\u0442\u044c index.html, \u0447\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0435\u0442 \u043d\u0430\u0448\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u044b\u043c.<\/p>\n<p>  \u0412 \u043f\u0430\u043f\u043a\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0435:<\/p>\n<pre><code class=\"bash\">npm install socket.io npm install node-static <\/code><\/pre>\n<p>  \u0421\u043a\u0430\u0447\u0430\u0439\u0442\u0435 server.js \u0432 \u043f\u0430\u043f\u043a\u0443 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u0421\u0435\u0440\u0432\u0435\u0440\u043d\u0443\u044e \u0447\u0430\u0441\u0442\u044c \u044f \u043d\u0435 \u0431\u0443\u0434\u0443 \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0442\u044c, \u043e\u043d\u0430 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u0430 \u043f\u0440\u043e\u0441\u0442\u0430 \u0434\u043b\u044f \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f, \u043a \u0442\u043e\u043c\u0443 \u0436\u0435 \u043e\u043d\u0430 \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0439 \u0447\u0430\u0441\u0442\u044c\u044e WebRTC, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u043e\u0441\u0442\u043e \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u0435 \u0441\u0435\u0440\u0432\u0435\u0440:<\/p>\n<pre><code class=\"bash\">node server.js <\/code><\/pre>\n<h4>3. WebRTC<\/h4>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0443 \u043d\u0430\u0441 \u0432\u0441\u0435 \u0433\u043e\u0442\u043e\u0432\u043e \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0441 WebRTC. \u0421\u043a\u0430\u0447\u0430\u0439\u0442\u0435 \u0440\u0430\u0431\u043e\u0447\u0438\u0439 <a href=\"http:\/\/pastebin.com\/raw.php?i=e3RArdtq\">index.html<\/a> \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e, \u0434\u0430\u043b\u044c\u0448\u0435 \u044f \u0431\u0443\u0434\u0443 \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0442\u044c \u0435\u0433\u043e \u043f\u043e \u043a\u0443\u0441\u043a\u0430\u043c.<\/p>\n<h5>3.0. \u0421\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u044b \u043f\u043e\u043a\u0430 \u043d\u0435 \u043f\u0440\u0438\u043d\u044f\u0442\u044b, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u043e\u043a\u0430 \u0447\u0442\u043e \u043c\u044b \u0432\u044b\u043d\u0443\u0436\u0434\u0435\u043d\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0435\u0444\u0438\u043a\u0441\u044b \u0434\u043b\u044f \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u043e\u0432:<\/h5>\n<p>  <\/p>\n<pre><code class=\"javascript\">var PeerConnection = window.mozRTCPeerConnection || window.webkitRTCPeerConnection; var IceCandidate = window.mozRTCIceCandidate || window.RTCIceCandidate; var SessionDescription = window.mozRTCSessionDescription || window.RTCSessionDescription; navigator.getUserMedia = navigator.getUserMedia || navigator.mozGetUserMedia || navigator.webkitGetUserMedia; <\/code><\/pre>\n<h5>3.1. getUserMedia<\/h5>\n<p>  <\/p>\n<pre><code class=\"javascript\">navigator.getUserMedia(   { audio: true, video: true },    gotStream,    function(error) { console.log(error) } );  function gotStream(stream) {   document.getElementById(&quot;callButton&quot;).style.display = 'inline-block';   document.getElementById(&quot;localVideo&quot;).src = URL.createObjectURL(stream);    pc = new PeerConnection(null);   pc.addStream(stream);   pc.onicecandidate = gotIceCandidate;   pc.onaddstream = gotRemoteStream; }  <\/code><\/pre>\n<p>  \u042d\u0442\u0443 \u0447\u0430\u0441\u0442\u044c \u043c\u044b \u0443\u0436\u0435 \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u043b\u0438 \u0432 \u0441\u0430\u043c\u043e\u043c \u043d\u0430\u0447\u0430\u043b\u0435 \u043f\u043e\u0441\u0442\u0430, \u0437\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 gotStream \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0435\u043c PeerConnection \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0434\u0432\u0430 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430 \u0441\u043e\u0431\u044b\u0442\u0438\u0439:   <\/p>\n<ul>\n<li><code>onicecandidate<\/code> \u043e\u0442\u0434\u0430\u0435\u0442 \u043d\u0430\u043c \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 ICE Candidate, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0434\u0438\u043c \u0441\u0438\u0433\u043d\u0430\u043b\u044c\u043d\u043e\u043c\u0443 \u0441\u0435\u0440\u0432\u0435\u0440\u0443, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043f\u0435\u0440\u0435\u0434\u0430\u0441\u0442 \u0438\u0445 \u0441\u043e\u0431\u0435\u0441\u0435\u0434\u043d\u0438\u043a\u0443<\/li>\n<li><code>onaddstream<\/code> \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u0432\u0430\u043d \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u043c\u0435\u0434\u0438\u0430\u043f\u043e\u0442\u043e\u043a \u0441\u043e\u0431\u0435\u0441\u0435\u0434\u043d\u0438\u043a\u0430<\/li>\n<\/ul>\n<h5>3.2. Call Offer<\/h5>\n<p>  Call Offer \u2014 \u044d\u0442\u043e \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0441\u0435\u0441\u0441\u0438\u0438 WebRTC. Call Offer \u0438 Call Answer(\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0448\u0430\u0433) \u0438\u043c\u0435\u044e\u0442 \u0444\u043e\u0440\u043c\u0430\u0442 <a href=\"http:\/\/en.wikipedia.org\/wiki\/Session_Description_Protocol\">SDP<\/a> (Session Description Protocol) \u0438 \u0441\u043b\u0443\u0436\u0430\u0442 \u0434\u043b\u044f \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432(\u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u0435, \u043a\u043e\u0434\u0435\u043a \u0438 \u0442.\u0434.) \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043c\u0435\u0434\u0438\u0430\u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432.<\/p>\n<p>  \u0412\u0410\u0416\u041d\u041e: \u043a\u043b\u0438\u0435\u043d\u0442\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0434\u0430\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043c\u0435\u0434\u0438\u0430\u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430\u043c \u0414\u041e \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 Call Offer.<\/p>\n<pre><code class=\"javascript\">function createOffer() {   pc.createOffer(     gotLocalDescription,      function(error) { console.log(error) },      { 'mandatory': { 'OfferToReceiveAudio': true, 'OfferToReceiveVideo': true } }   ); } <\/code><\/pre>\n<h5>3.3. Call Answer<\/h5>\n<p>  Call Answer \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u0435\u0441\u0435\u0434\u043d\u0438\u043a \u0441\u0440\u0430\u0437\u0443 \u043f\u043e\u0441\u043b\u0435 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f Call Offer. \u041e\u0442\u043c\u0435\u0447\u0443 \u0447\u0442\u043e callback-\u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0443 <code>createOffer()<\/code> \u0438 <code>createAnswer()<\/code> \u043e\u0434\u043d\u0430 \u0438 \u0442\u0430 \u0436\u0435 \u2014 gotLocalDescription, \u0442.\u0435. localDescription \u0434\u043b\u044f \u043e\u0434\u043d\u043e\u0433\u043e \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u0441\u043e\u0437\u0434\u0430\u043d \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 <code>createOffer()<\/code>, \u0434\u043b\u044f \u0434\u0440\u0443\u0433\u043e\u0433\u043e \u2014 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 <code>createAnswer()<\/code>.<\/p>\n<pre><code class=\"javascript\">function createAnswer() {   pc.createAnswer(     gotLocalDescription,     function(error) { console.log(error) },      { 'mandatory': { 'OfferToReceiveAudio': true, 'OfferToReceiveVideo': true } }   ); }  <\/code><\/pre>\n<h5>3.4. ICE Candidate<\/h5>\n<p>  <a href=\"http:\/\/en.wikipedia.org\/wiki\/Interactive_Connectivity_Establishment\">ICE<\/a> (Interactive Connectivity Establishment) Candidate \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432, \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u044f \u043f\u0443\u0442\u044c \u043c\u0435\u0436\u0434\u0443 \u043a\u043b\u0438\u0435\u043d\u0442\u0430\u043c\u0438, \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u0431\u0443\u0434\u0443\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c\u0441\u044f \u043c\u0435\u0434\u0438\u0430\u043f\u043e\u0442\u043e\u043a\u0438. \u0421\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 ICE Candidate \u043c\u044b \u0442\u0430\u043a\u0436\u0435 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u0438\u0433\u043d\u0430\u043b\u044c\u043d\u043e\u043c\u0443 \u0441\u0435\u0440\u0432\u0435\u0440\u0443, \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u043e\u0442 \u0441\u0438\u0433\u043d\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u043d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u0448\u0430\u0433\u0435.<\/p>\n<pre><code class=\"javascript\">function gotIceCandidate(event){   if (event.candidate) {     sendMessage({       type: 'candidate',       label: event.candidate.sdpMLineIndex,       id: event.candidate.sdpMid,       candidate: event.candidate.candidate     });   } }  <\/code><\/pre>\n<h5>3.5. \u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u043e\u0442 \u0441\u0438\u0433\u043d\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0441\u0435\u0440\u0432\u0435\u0440\u0430<\/h5>\n<p>  <\/p>\n<pre><code class=\"javascript\">var socket = io.connect('', {port: 1234});  socket.on('message', function (message){   if (message.type === 'offer') {     pc.setRemoteDescription(new SessionDescription(message));     createAnswer();   }    else if (message.type === 'answer') {     pc.setRemoteDescription(new SessionDescription(message));   }    else if (message.type === 'candidate') {     var candidate = new IceCandidate({sdpMLineIndex: message.label, candidate: message.candidate});     pc.addIceCandidate(candidate);   } }); <\/code><\/pre>\n<p>  \u041a\u043e\u0434 \u043f\u0440\u043e\u0441\u0442\u043e\u0439, \u043d\u043e \u043f\u043e\u044f\u0441\u043d\u044e:  <\/p>\n<ul>\n<li>\u043a\u0430\u043a \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 Call Offer, \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c createAnswer<\/li>\n<li>\u043f\u0440\u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0438 \u043a\u0430\u043a Call Offer \u0442\u0430\u043a \u0438 Call Answer \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c <code>setRemoteDescription<\/code> \u0441 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u043c SDP<\/li>\n<li>\u043f\u0440\u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0438 ICE Candidate \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c addIceCandidate<\/li>\n<\/ul>\n<h5>3.6. gotRemoteStream<\/h5>\n<p>  \u0415\u0441\u043b\u0438 \u0432\u0441\u0435 \u043f\u0440\u043e\u0448\u043b\u043e \u0443\u0441\u043f\u0435\u0448\u043d\u043e, \u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u0432\u0430\u043d \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a <code>onaddstream<\/code> \u0438\u0437 \u0448\u0430\u0433\u0430 3.1, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u043c\u0435\u0434\u0438\u0430\u043f\u043e\u0442\u043e\u043a \u043e\u0442 \u0441\u043e\u0431\u0435\u0441\u0435\u0434\u043d\u0438\u043a\u0430.  <\/p>\n<pre><code class=\"javascript\">function gotRemoteStream(event){   document.getElementById(&quot;remoteVideo&quot;).src = URL.createObjectURL(event.stream); } <\/code><\/pre>\n<p>  \u041d\u0430\u043f\u043e\u043c\u043d\u044e, \u0447\u0442\u043e \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0446\u0435\u043b\u0438\u043a\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u0432\u0437\u044f\u0442\u044c <a href=\"http:\/\/pastebin.com\/raw.php?i=e3RArdtq\">\u0437\u0434\u0435\u0441\u044c<\/a>.<\/p>\n<h4>\u041b\u0438\u0442\u0435\u0440\u0430\u0442\u0443\u0440\u0430:<\/h4>\n<p>  <\/p>\n<ul>\n<li><a href=\"http:\/\/www.webrtc-experiment.com\/docs\/webrtc-for-beginners.html\">www.webrtc-experiment.com\/docs\/webrtc-for-beginners.html<\/a><\/li>\n<li><a href=\"http:\/\/bitbucket.org\/webrtc\/codelab\">bitbucket.org\/webrtc\/codelab<\/a><\/li>\n<li><a href=\"http:\/\/html5videoguide.net\/presentations\/LCA_2013_webrtc\/\">html5videoguide.net\/presentations\/LCA_2013_webrtc\/<\/a><\/li>\n<li><a href=\"http:\/\/hacks.mozilla.org\/category\/webrtc\/as\/complete\/\">hacks.mozilla.org\/category\/webrtc\/as\/complete\/<\/a><\/li>\n<li><a href=\"http:\/\/www.html5rocks.com\/en\/tutorials\/webrtc\/basics\/\">www.html5rocks.com\/en\/tutorials\/webrtc\/basics\/<\/a><\/li>\n<\/ul>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/198632\/\"> http:\/\/habrahabr.ru\/post\/198632\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">   \t<img decoding=\"async\" src=\"http:\/\/habr.habrastorage.org\/post_images\/727\/ba4\/ce7\/727ba4ce74e9b4a610a9ace27e03c14c.png\" alt=\"WebRTC\"\/><\/p>\n<p>  WebRTC \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c real-time \u0430\u0443\u0434\u0438\u043e\/\u0432\u0438\u0434\u0435\u043e \u0441\u0432\u044f\u0437\u044c \u0447\u0435\u0440\u0435\u0437 \u0431\u0440\u0430\u0443\u0437\u0435\u0440 (<img decoding=\"async\" src=\"http:\/\/habr.habrastorage.org\/post_images\/f7d\/a2c\/eb0\/f7da2ceb020805bb54081c8cbf346b3e.png\" alt=\"firefox\"\/> \u0438 <img decoding=\"async\" src=\"http:\/\/habr.habrastorage.org\/post_images\/3bb\/c82\/7bd\/3bbc827bd8ddd527661949013075dab0.png\" alt=\"chrome\"\/>).<\/p>\n<p>  \u0412 \u044d\u0442\u043e\u043c \u0442\u043e\u043f\u0438\u043a\u0435 \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u043a\u0430\u043a \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0435\u0435 WebRTC \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-198632","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/198632","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=198632"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/198632\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=198632"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=198632"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=198632"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}