{"id":255287,"date":"2015-04-15T15:36:02","date_gmt":"2015-04-15T11:36:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=255287"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=255287","title":{"rendered":"\u041c\u043d\u043e\u0433\u043e\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 \u0447\u0430\u0442 \u0441 \u0438\u0437\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c WebRTC"},"content":{"rendered":"<p> \t\t\t<img decoding=\"async\" src=\"\/\/habrastorage.org\/files\/012\/34e\/5a4\/01234e5a4fb44e168d171390a1ab73ed.png\" alt=\"image\"\/><\/p>\n<p>  WebRTC \u2013 \u044d\u0442\u043e API, \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c\u043e\u0435 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u043e\u043c \u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0435\u0435 \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u043e\u0432\u0430\u0442\u044c P2P \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u043c\u0435\u0436\u0434\u0443 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0430\u043c\u0438. \u0412 \u0418\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0435 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043c\u043d\u043e\u0433\u043e \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432 \u043f\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044e \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u0432\u0438\u0434\u0435\u043e-\u0447\u0430\u0442\u0430 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 WebRTC. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <a href=\"http:\/\/habrahabr.ru\/post\/198632\/\">\u0432\u043e\u0442<\/a> \u0441\u0442\u0430\u0442\u044c\u044f \u043d\u0430 \u0425\u0430\u0431\u0440\u0435. \u041e\u0434\u043d\u0430\u043a\u043e, \u0432\u0441\u0435 \u043e\u043d\u0438 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435\u043c \u0434\u0432\u0443\u0445 \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432. \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u043f\u043e\u0441\u0442\u0430\u0440\u0430\u044e\u0441\u044c \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 WebRTC \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0438 \u043e\u0431\u043c\u0435\u043d \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f\u043c\u0438 \u043c\u0435\u0436\u0434\u0443 \u0442\u0440\u0435\u043c\u044f \u0438 \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c\u0438.<br \/>  <a name=\"habracut\"><\/a><br \/>  \u0418\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 RTCPeerConnection \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 peer-to-peer \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043c\u0435\u0436\u0434\u0443 \u0434\u0432\u0443\u043c\u044f \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0430\u043c\u0438. \u0427\u0442\u043e\u0431\u044b \u0441\u043e\u0435\u0434\u0438\u043d\u0438\u0442\u044c \u0442\u0440\u0435\u0445 \u0438 \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439, \u043d\u0430\u043c \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u043e\u0432\u0430\u0442\u044c mesh-\u0441\u0435\u0442\u044c (\u0441\u0435\u0442\u044c, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043a\u0430\u0436\u0434\u044b\u0439 \u0443\u0437\u0435\u043b \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d \u043a\u043e \u0432\u0441\u0435\u043c \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u043c \u0443\u0437\u043b\u0430\u043c).<br \/>  \u0411\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u0441\u0445\u0435\u043c\u0443:  <\/p>\n<ol>\n<li>\u041f\u0440\u0438 \u043e\u0442\u043a\u0440\u044b\u0442\u0438\u0438 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u043d\u0430\u043b\u0438\u0447\u0438\u0435 ID \u043a\u043e\u043c\u043d\u0430\u0442\u044b \u0432 <b>location.hash<\/b><\/li>\n<li>\u0415\u0441\u043b\u0438 ID \u043a\u043e\u043c\u043d\u0430\u0442\u044b \u043d\u0435 \u0443\u043a\u0430\u0437\u0430\u043d\u043e, \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c \u043d\u043e\u0432\u044b\u0439<\/li>\n<li>\u041e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c signalling server&#8217;\u0443 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043f\u0440\u0438\u0441\u043e\u0435\u0434\u0438\u043d\u0438\u0442\u044c\u0441\u044f \u043a \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0439 \u043a\u043e\u043c\u043d\u0430\u0442\u0435<\/li>\n<li>Signalling server \u0440\u0430\u0437\u0441\u044b\u043b\u0430\u0435\u0442 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u043c \u043a\u043b\u0438\u0435\u043d\u0442\u0430\u043c \u0432 \u044d\u0442\u043e\u0439 \u043a\u043e\u043c\u043d\u0430\u0442\u0435 \u043e\u043f\u043e\u0432\u0435\u0449\u0435\u043d\u0438\u0435 \u043e \u043d\u043e\u0432\u043e\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435<\/li>\n<li>\u041a\u043b\u0438\u0435\u043d\u0442\u044b, \u0443\u0436\u0435 \u043d\u0430\u0445\u043e\u0434\u044f\u0449\u0438\u0435\u0441\u044f \u043a \u043a\u043e\u043c\u043d\u0430\u0442\u0435, \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0442 \u043d\u043e\u0432\u0438\u0447\u043a\u0443 SDP offer<\/li>\n<li>\u041d\u043e\u0432\u0438\u0447\u043e\u043a \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u043d\u0430 offer&#8217;\u044b<\/li>\n<\/ol>\n<p>  <\/p>\n<h4>0. Signalling server<\/h4>\n<p>  \u041a\u0430\u043a \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e, \u0445\u043e\u0442\u044c WebRTC \u0438 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c P2P \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u043c\u0435\u0436\u0434\u0443 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0430\u043c\u0438, \u0434\u043b\u044f \u0435\u0433\u043e \u0440\u0430\u0431\u043e\u0442\u044b \u0432\u0441\u0451 \u0440\u0430\u0432\u043d\u043e \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0442\u0440\u0430\u043d\u0441\u043f\u043e\u0440\u0442 \u0434\u043b\u044f \u043e\u0431\u043c\u0435\u043d\u0430 \u0441\u0435\u0440\u0432\u0438\u0441\u043d\u044b\u043c\u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f\u043c\u0438. \u0412 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0442\u0430\u043a\u043e\u0433\u043e \u0442\u0440\u0430\u043d\u0441\u043f\u043e\u0440\u0442\u0430 \u0432\u044b\u0441\u0442\u0443\u043f\u0430\u0435\u0442 WebSocket \u0441\u0435\u0440\u0432\u0435\u0440, \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 \u043d\u0430 Node.JS \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c socket.io:<\/p>\n<pre><code class=\"javascript\">var socket_io = require(&quot;socket.io&quot;);  module.exports = function (server) { \tvar users = {}; \tvar io = socket_io(server); \tio.on(&quot;connection&quot;, function(socket) {  \t\t\/\/ \u0416\u0435\u043b\u0430\u043d\u0438\u0435 \u043d\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043f\u0440\u0438\u0441\u043e\u0435\u0434\u0438\u043d\u0438\u0442\u044c\u0441\u044f \u043a \u043a\u043e\u043c\u043d\u0430\u0442\u0435 \t\tsocket.on(&quot;room&quot;, function(message) { \t\t\tvar json = JSON.parse(message); \t\t\t\/\/ \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u043e\u043a\u0435\u0442 \u0432 \u0441\u043f\u0438\u0441\u043e\u043a \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \t\t\tusers[json.id] = socket; \t\t\tif (socket.room !== undefined) { \t\t\t\t\/\/ \u0415\u0441\u043b\u0438 \u0441\u043e\u043a\u0435\u0442 \u0443\u0436\u0435 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u043a\u043e\u043c\u043d\u0430\u0442\u0435, \u0432\u044b\u0445\u043e\u0434\u0438\u043c \u0438\u0437 \u043d\u0435\u0435 \t\t\t\tsocket.leave(socket.room); \t\t\t} \t\t\t\/\/ \u0412\u0445\u043e\u0434\u0438\u043c \u0432 \u0437\u0430\u043f\u0440\u043e\u0448\u0435\u043d\u043d\u0443\u044e \u043a\u043e\u043c\u043d\u0430\u0442\u0443 \t\t\tsocket.room = json.room; \t\t\tsocket.join(socket.room); \t\t\tsocket.user_id = json.id; \t\t\t\/\/ \u041e\u0442\u043f\u0440\u0430\u0432\u044f\u043b\u0435\u043c \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u043c \u043a\u043b\u0438\u0435\u043d\u0442\u0430\u043c \u0432 \u044d\u0442\u043e\u0439 \u043a\u043e\u043c\u043d\u0430\u0442\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043e \u043f\u0440\u0438\u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0438 \u043d\u043e\u0432\u043e\u0433\u043e \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u0430 \t\t\tsocket.broadcast.to(socket.room).emit(&quot;new&quot;, json.id); \t\t});  \t\t\/\/ \u0421\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u043e\u0435 \u0441 WebRTC (SDP offer, SDP answer \u0438\u043b\u0438 ICE candidate) \t\tsocket.on(&quot;webrtc&quot;, function(message) { \t\t\tvar json = JSON.parse(message); \t\t\tif (json.to !== undefined && users[json.to] !== undefined) { \t\t\t\t\/\/ \u0415\u0441\u043b\u0438 \u0432 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0438 \u0443\u043a\u0430\u0437\u0430\u043d \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u0435\u043b\u044c \u0438 \u044d\u0442\u043e\u0442 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u0435\u043b\u044c \u0438\u0437\u0432\u0435\u0441\u0442\u0435\u043d \u0441\u0435\u0440\u0432\u0435\u0440\u0443, \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0435\u043c\u0443... \t\t\t\tusers[json.to].emit(&quot;webrtc&quot;, message); \t\t\t} else { \t\t\t\t\/\/ ...\u0438\u043d\u0430\u0447\u0435 \u0441\u0447\u0438\u0442\u0430\u0435\u043c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0448\u0438\u0440\u043e\u043a\u043e\u0432\u0435\u0449\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c \t\t\t\tsocket.broadcast.to(socket.room).emit(&quot;webrtc&quot;, message); \t\t\t} \t\t});  \t\t\/\/ \u041a\u0442\u043e-\u0442\u043e \u043e\u0442\u0441\u043e\u0435\u0434\u0438\u043d\u0438\u043b\u0441\u044f \t\tsocket.on(&quot;disconnect&quot;, function() { \t\t\t\/\/ \u041f\u0440\u0438 \u043e\u0442\u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0438 \u043a\u043b\u0438\u0435\u043d\u0442\u0430, \u043e\u043f\u043e\u0432\u0435\u0449\u0430\u0435\u043c \u043e\u0431 \u044d\u0442\u043e\u043c \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445 \t\t\tsocket.broadcast.to(socket.room).emit(&quot;leave&quot;, socket.user_id); \t\t\tdelete users[socket.user_id]; \t\t}); \t}); }; <\/code><\/pre>\n<p>  <\/p>\n<h4>1. index.html<\/h4>\n<p>  \u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434 \u0441\u0430\u043c\u043e\u0439 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0439. \u042f \u0441\u043e\u0437\u043d\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0435 \u0441\u0442\u0430\u043b \u0443\u0434\u0435\u043b\u044f\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0432\u0435\u0440\u0441\u0442\u043a\u0435 \u0438 \u043f\u0440\u043e\u0447\u0438\u043c \u043a\u0440\u0430\u0441\u0438\u0432\u043e\u0441\u0442\u044f\u043c, \u0442\u0430\u043a \u043a\u0430\u043a \u044d\u0442\u043e \u0441\u0442\u0430\u0442\u044c\u044f \u043d\u0435 \u043e\u0431 \u044d\u0442\u043e\u043c. \u0415\u0441\u043b\u0438 \u043a\u043e\u043c\u0443-\u0442\u043e \u0437\u0430\u0445\u043e\u0447\u0435\u0442\u0441\u044f, \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0435\u0435 \u043a\u0440\u0430\u0441\u0438\u0432\u043e\u0439, \u043e\u0441\u043e\u0431\u043e\u0433\u043e \u0442\u0440\u0443\u0434\u0430 \u043d\u0435 \u0441\u043e\u0441\u0442\u0430\u0432\u0438\u0442.<\/p>\n<pre><code class=\"html\">&lt;html&gt; &lt;head&gt; \t&lt;title&gt;WebRTC Chat Demo&lt;\/title&gt; \t&lt;script src=&quot;\/socket.io\/socket.io.js&quot;&gt;&lt;\/script&gt; &lt;\/head&gt; &lt;body&gt; \t&lt;div&gt;Connected to &lt;span id=&quot;connection_num&quot;&gt;0&lt;\/span&gt; peers&lt;\/div&gt; \t&lt;div&gt;&lt;textarea id=&quot;message&quot;&gt;&lt;\/textarea&gt;&lt;br\/&gt;&lt;button onclick=&quot;sendMessage();&quot;&gt;Send&lt;\/button&gt;&lt;\/div&gt; \t&lt;div id=&quot;room_link&quot;&gt;&lt;\/div&gt; \t&lt;div id=&quot;chatlog&quot;&gt;&lt;\/div&gt; \t&lt;script type=&quot;text\/javascript&quot; src=&quot;\/javascripts\/main.js&quot;&gt;&lt;\/script&gt; &lt;\/body&gt; &lt;\/html&gt; <\/code><\/pre>\n<p>  <\/p>\n<h4>2. main.js<\/h4>\n<p>  <\/p>\n<h5>2.0. \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0441\u0441\u044b\u043b\u043e\u043a \u043d\u0430 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u0438 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b WebRTC<\/h5>\n<p>  <\/p>\n<pre><code class=\"javascript\">var chatlog = document.getElementById(&quot;chatlog&quot;); var message = document.getElementById(&quot;message&quot;); var connection_num = document.getElementById(&quot;connection_num&quot;); var room_link = document.getElementById(&quot;room_link&quot;); <\/code><\/pre>\n<p>  \u041d\u0430\u043c \u043f\u043e \u043f\u0440\u0435\u0436\u043d\u0435\u043c\u0443 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u043d\u044b\u0435 \u043f\u0440\u0435\u0444\u0438\u043a\u0441\u044b \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043a \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430\u043c WebRTC.<\/p>\n<pre><code class=\"javascript\">var PeerConnection = window.mozRTCPeerConnection || window.webkitRTCPeerConnection; var SessionDescription = window.mozRTCSessionDescription || window.RTCSessionDescription; var IceCandidate = window.mozRTCIceCandidate || window.RTCIceCandidate; <\/code><\/pre>\n<p>  <\/p>\n<h5>2.1. \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 ID \u043a\u043e\u043c\u043d\u0430\u0442\u044b<\/h5>\n<p>  \u0422\u0443\u0442 \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0430 \u043a\u043e\u043c\u043d\u0430\u0442\u044b \u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f. \u0411\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u044d\u0442\u0438\u0445 \u0446\u0435\u043b\u0435\u0439 UUID.<\/p>\n<pre><code class=\"javascript\">function uuid () { \tvar s4 = function() { \t\treturn Math.floor(Math.random() * 0x10000).toString(16); \t}; \treturn s4() + s4() + &quot;-&quot; + s4() + &quot;-&quot; + s4() + &quot;-&quot; + s4() + &quot;-&quot; + s4() + s4() + s4(); } <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0432\u044b\u0442\u0430\u0449\u0438\u0442\u044c \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u043a\u043e\u043c\u043d\u0430\u0442\u044b \u0438\u0437 \u0430\u0434\u0440\u0435\u0441\u0430. \u0415\u0441\u043b\u0438 \u0442\u0430\u043a\u043e\u0432\u043e\u0433\u043e \u043d\u0435 \u0437\u0430\u0434\u0430\u043d\u043e, \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c \u043d\u043e\u0432\u044b\u0439. \u0412\u044b\u0432\u0435\u0434\u0435\u043c \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443 \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u0442\u0435\u043a\u0443\u0449\u0443\u044e \u043a\u043e\u043c\u043d\u0430\u0442\u0443, \u0438, \u0437\u0430 \u043e\u0434\u043d\u043e, \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.<\/p>\n<pre><code class=\"javascript\">var ROOM = location.hash.substr(1);  if (!ROOM) { \tROOM = uuid(); } room_link.innerHTML = &quot;&lt;a href='#&quot;+ROOM+&quot;'&gt;Link to the room&lt;\/a&gt;&quot;;  var ME = uuid(); <\/code><\/pre>\n<p>  <\/p>\n<h5>2.2. WebSocket<\/h5>\n<p>  \u0421\u0440\u0430\u0437\u0443 \u043f\u0440\u0438 \u043e\u0442\u043a\u0440\u044b\u0442\u0438\u0438 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u043c\u0441\u044f \u043a \u043d\u0430\u0448\u0435\u043c\u0443 signalling server&#8217;\u0443, \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u043c \u0437\u0430\u043f\u0440\u043e\u0441 \u043d\u0430 \u0432\u0445\u043e\u0434 \u0432 \u043a\u043e\u043c\u043d\u0430\u0442\u0443 \u0438 \u0443\u043a\u0430\u0436\u0435\u043c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439.<\/p>\n<pre><code class=\"javascript\">\/\/ \u0423\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c, \u0447\u0442\u043e \u043f\u0440\u0438 \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043d\u0443\u0436\u043d\u043e \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0441\u0435\u0440\u0432\u0435\u0440\u0443 \u043e\u043f\u043e\u0432\u0435\u0449\u0435\u043d\u0438\u0435 \u043e\u0431 \u044d\u0442\u043e\u043c var socket = io.connect(&quot;&quot;, {&quot;sync disconnect on unload&quot;: true}); socket.on(&quot;webrtc&quot;, socketReceived); socket.on(&quot;new&quot;, socketNewPeer); \/\/ \u0421\u0440\u0430\u0437\u0443 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u0437\u0430\u043f\u0440\u043e\u0441 \u043d\u0430 \u0432\u0445\u043e\u0434 \u0432 \u043a\u043e\u043c\u043d\u0430\u0442\u0443 socket.emit(&quot;room&quot;, JSON.stringify({id: ME, room: ROOM}));  \/\/ \u0412\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0430\u0434\u0440\u0435\u0441\u043d\u044b\u0445 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u0441 WebRTC function sendViaSocket(type, message, to) { \tsocket.emit(&quot;webrtc&quot;, JSON.stringify({id: ME, to: to, type: type, data: message})); } <\/code><\/pre>\n<p>  <\/p>\n<h5>2.3. \u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 PeerConnection<\/h5>\n<p>  \u0411\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440\u043e\u0432 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043a \u0418\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0443 \u0447\u0435\u0440\u0435\u0437 NAT. \u0418\u0437-\u0437\u0430 \u044d\u0442\u043e\u0433\u043e \u043f\u0440\u044f\u043c\u043e\u0435 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043d\u0435 \u0442\u0430\u043a\u0438\u043c \u0443\u0436 \u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u044b\u043c \u0434\u0435\u043b\u043e\u043c. \u041f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0441\u043f\u0438\u0441\u043e\u043a STUN \u0438 TURN \u0441\u0435\u0440\u0432\u0435\u0440\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0440\u0430\u0443\u0437\u0435\u0440 \u0431\u0443\u0434\u0435\u0442 \u043f\u044b\u0442\u0430\u0442\u044c\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u043e\u0431\u0445\u043e\u0434\u0430 NAT. \u0422\u0430\u043a \u0436\u0435 \u0443\u043a\u0430\u0436\u0435\u043c \u043f\u0430\u0440\u0443 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043e\u043f\u0446\u0438\u0439 \u0434\u043b\u044f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f.<\/p>\n<pre><code class=\"javascript\">var server = { \ticeServers: [ \t\t{url: &quot;stun:23.21.150.121&quot;}, \t\t{url: &quot;stun:stun.l.google.com:19302&quot;}, \t\t{url: &quot;turn:numb.viagenie.ca&quot;, credential: &quot;your password goes here&quot;, username: &quot;example@example.com&quot;} \t] }; var options = { \toptional: [ \t\t{DtlsSrtpKeyAgreement: true}, \/\/ \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u043c\u0435\u0436\u0434\u0443 Chrome \u0438 Firefox \t\t{RtpDataChannels: true} \/\/ \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0432 Firefox \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f DataChannels API \t] } <\/code><\/pre>\n<p>  <\/p>\n<h5>2.4. \u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043d\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f<\/h5>\n<p>  \u041a\u043e\u0433\u0434\u0430 \u0432 \u043a\u043e\u043c\u043d\u0430\u0442\u0443 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u043e\u0432\u044b\u0439 \u043f\u0438\u0440, \u0441\u0435\u0440\u0432\u0435\u0440 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u043d\u0430\u043c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 <b>new<\/b>. \u0421\u043e\u0433\u043b\u0430\u0441\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430\u043c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439, \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u043c \u0432\u044b\u0448\u0435, \u0432\u044b\u0437\u043e\u0432\u0435\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f <b>socketNewPeer<\/b>.<\/p>\n<pre><code class=\"javascript\">var peers = {};  function socketNewPeer(data) { \tpeers[data] = { \t\tcandidateCache: [] \t};  \t\/\/ \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043d\u043e\u0432\u043e\u0435 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \tvar pc = new PeerConnection(server, options); \t\/\/ \u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0443\u0435\u043c \u0435\u0433\u043e \tinitConnection(pc, data, &quot;offer&quot;);  \t\/\/ \u0421\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u043f\u0438\u0440\u0430 \u0432 \u0441\u043f\u0438\u0441\u043a\u0435 \u043f\u0438\u0440\u043e\u0432 \tpeers[data].connection = pc;  \t\/\/ \u0421\u043e\u0437\u0434\u0430\u0435\u043c DataChannel \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u0438 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442\u044c \u043e\u0431\u043c\u0435\u043d \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f\u043c\u0438 \tvar channel = pc.createDataChannel(&quot;mychannel&quot;, {}); \tchannel.owner = data; \tpeers[data].channel = channel;  \t\/\/ \u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u043a\u0430\u043d\u0430\u043b\u0430 \tbindEvents(channel);  \t\/\/ \u0421\u043e\u0437\u0434\u0430\u0435\u043c SDP offer \tpc.createOffer(function(offer) { \t\tpc.setLocalDescription(offer); \t}); }  function initConnection(pc, id, sdpType) { \tpc.onicecandidate = function (event) { \t\tif (event.candidate) { \t\t\t\/\/ \u041f\u0440\u0438 \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0435\u043d\u0438\u0438 \u043d\u043e\u0432\u043e\u0433\u043e ICE \u043a\u0430\u043d\u0434\u0438\u0434\u0430\u0442\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0435\u0433\u043e \u0432 \u0441\u043f\u0438\u0441\u043e\u043a \u0434\u043b\u044f \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0439 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \t\t\tpeers[id].candidateCache.push(event.candidate); \t\t} else { \t\t\t\/\/ \u041a\u043e\u0433\u0434\u0430 \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0435\u043d\u0438\u0435 \u043a\u0430\u043d\u0434\u0438\u0434\u0430\u0442\u043e\u0432 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u043e, \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u0432\u0430\u043d \u0435\u0449\u0435 \u0440\u0430\u0437, \u043d\u043e \u0431\u0435\u0437 \u043a\u0430\u043d\u0434\u0438\u0434\u0430\u0442\u0430 \t\t\t\/\/ \u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u044b \u043e\u0442\u043f\u0440\u0430\u0432\u044f\u043b\u0435\u043c \u043f\u0438\u0440\u0443 \u0441\u043d\u0430\u0447\u0430\u043b\u0430 SDP offer \u0438\u043b\u0438 SDP answer (\u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438)... \t\t\tsendViaSocket(sdpType, pc.localDescription, id); \t\t\t\/\/ ...\u0430 \u0437\u0430\u0442\u0435\u043c \u0432\u0441\u0435 \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u044b\u0435 \u0440\u0430\u043d\u0435\u0435 ICE \u043a\u0430\u043d\u0434\u0438\u0434\u0430\u0442\u044b \t\t\tfor (var i = 0; i &lt; peers[id].candidateCache.length; i++) { \t\t\t\tsendViaSocket(&quot;candidate&quot;, peers[id].candidateCache[i], id); \t\t\t} \t\t} \t} \tpc.oniceconnectionstatechange = function (event) { \t\tif (pc.iceConnectionState == &quot;disconnected&quot;) { \t\t\tconnection_num.innerText = parseInt(connection_num.innerText) - 1; \t\t\tdelete peers[id]; \t\t} \t} }  function bindEvents (channel) { \tchannel.onopen = function () { \t\tconnection_num.innerText = parseInt(connection_num.innerText) + 1; \t}; \tchannel.onmessage = function (e) { \t\tchatlog.innerHTML += &quot;&lt;div&gt;Peer says: &quot; + e.data + &quot;&lt;\/div&gt;&quot;; \t}; } <\/code><\/pre>\n<p>  <\/p>\n<h5>2.5. SDP offer, SDP answer, ICE candidate<\/h5>\n<p>  \u041f\u0440\u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0438 \u043e\u0434\u043d\u043e\u0433\u043e \u0438\u0437 \u044d\u0442\u0438\u0445 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f.  <\/p>\n<pre><code class=\"javascript\">function socketReceived(data) { \tvar json = JSON.parse(data); \tswitch (json.type) { \t\tcase &quot;candidate&quot;:  \t\t\tremoteCandidateReceived(json.id, json.data); \t\t\tbreak; \t\tcase &quot;offer&quot;: \t\t\tremoteOfferReceived(json.id, json.data); \t\t\tbreak; \t\tcase &quot;answer&quot;: \t\t\tremoteAnswerReceived(json.id, json.data); \t\t\tbreak; \t} } <\/code><\/pre>\n<p>  <\/p>\n<h6>2.5.0 SDP offer<\/h6>\n<p>  <\/p>\n<pre><code class=\"javascript\">function remoteOfferReceived(id, data) { \tcreateConnection(id); \tvar pc = peers[id].connection;  \tpc.setRemoteDescription(new SessionDescription(data)); \tpc.createAnswer(function(answer) { \t\tpc.setLocalDescription(answer); \t}); } function createConnection(id) { \tif (peers[id] === undefined) { \t\tpeers[id] = { \t\t\tcandidateCache: [] \t\t}; \t\tvar pc = new PeerConnection(server, options); \t\tinitConnection(pc, id, &quot;answer&quot;);  \t\tpeers[id].connection = pc; \t\tpc.ondatachannel = function(e) { \t\t\tpeers[id].channel = e.channel; \t\t\tpeers[id].channel.owner = id; \t\t\tbindEvents(peers[id].channel); \t\t} \t} } <\/code><\/pre>\n<p>  <\/p>\n<h6>2.5.1 SDP answer<\/h6>\n<p>  <\/p>\n<pre><code class=\"javascript\">function remoteAnswerReceived(id, data) { \tvar pc = peers[id].connection; \tpc.setRemoteDescription(new SessionDescription(data)); } <\/code><\/pre>\n<p>  <\/p>\n<h6>2.5.2 ICE candidate<\/h6>\n<p>  <\/p>\n<pre><code class=\"javascript\">function remoteCandidateReceived(id, data) { \tcreateConnection(id); \tvar pc = peers[id].connection; \tpc.addIceCandidate(new IceCandidate(data)); } <\/code><\/pre>\n<p>  <\/p>\n<h5>2.6. \u041e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f<\/h5>\n<p>  \u041f\u0440\u0438 \u043d\u0430\u0436\u0430\u0442\u0438\u0438 \u043d\u0430 \u043a\u043d\u043e\u043f\u043a\u0443 <b>Send<\/b> \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f <b>sendMessage<\/b>. \u0412\u0441\u0451, \u0447\u0442\u043e \u043e\u043d\u0430 \u0434\u0435\u043b\u0430\u0435\u0442, \u044d\u0442\u043e \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u043e \u0441\u043f\u0438\u0441\u043a\u0443 \u043f\u0438\u0440\u043e\u0432, \u0438 \u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0432\u0441\u0435\u043c \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435.<\/p>\n<pre><code class=\"javascript\">function sendMessage () { \tvar msg = message.value; \tfor (var peer in peers) { \t\tif (peers.hasOwnProperty(peer)) { \t\t\tif (peers[peer].channel !== undefined) { \t\t\t\ttry { \t\t\t\t\tpeers[peer].channel.send(msg); \t\t\t\t} catch (e) {} \t\t\t} \t\t} \t} \tchatlog.innerHTML += &quot;&lt;div&gt;Peer says: &quot; + msg + &quot;&lt;\/div&gt;&quot;; \tmessage.value = &quot;&quot;; } <\/code><\/pre>\n<p>  <\/p>\n<h5>2.7. \u041e\u0442\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h5>\n<p>  \u041d\u0443 \u0438 \u0432 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0438, \u043f\u0440\u0438 \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u0438 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b, \u0445\u043e\u0440\u043e\u0448\u043e \u0431\u044b \u0437\u0430\u043a\u0440\u044b\u0442\u044c \u0432\u0441\u0435 \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u0435 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f.<\/p>\n<pre><code class=\"javascript\">window.addEventListener(&quot;beforeunload&quot;, onBeforeUnload);  function onBeforeUnload(e) { \tfor (var peer in peers) { \t\tif (peers.hasOwnProperty(peer)) { \t\t\tif (peers[peer].channel !== undefined) { \t\t\t\ttry { \t\t\t\t\tpeers[peer].channel.close(); \t\t\t\t} catch (e) {} \t\t\t} \t\t} \t} } <\/code><\/pre>\n<p>  <\/p>\n<h4>3. \u0421\u043f\u0438\u0441\u043e\u043a \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u043e\u0432<\/h4>\n<p>  <\/p>\n<ol>\n<li><a href=\"http:\/\/www.html5rocks.com\/en\/tutorials\/webrtc\/basics\/\">http:\/\/www.html5rocks.com\/en\/tutorials\/webrtc\/basics\/<\/a><\/li>\n<li><a href=\"https:\/\/www.webrtc-experiment.com\/docs\/WebRTC-PeerConnection.html\">https:\/\/www.webrtc-experiment.com\/docs\/WebRTC-PeerConnection.html<\/a><\/li>\n<li><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/Guide\/API\/WebRTC\/WebRTC_basics\">https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/Guide\/API\/WebRTC\/WebRTC_basics<\/a><\/li>\n<\/ol>\n<div class=\"clear\"><\/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\/255833\/\"> http:\/\/habrahabr.ru\/post\/255833\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p> \t\t\t<img decoding=\"async\" src=\"\/\/habrastorage.org\/files\/012\/34e\/5a4\/01234e5a4fb44e168d171390a1ab73ed.png\" alt=\"image\"\/><\/p>\n<p>  WebRTC \u2013 \u044d\u0442\u043e API, \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c\u043e\u0435 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u043e\u043c \u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0435\u0435 \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u043e\u0432\u0430\u0442\u044c P2P \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u043c\u0435\u0436\u0434\u0443 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0430\u043c\u0438. \u0412 \u0418\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0435 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043c\u043d\u043e\u0433\u043e \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432 \u043f\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044e \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u0432\u0438\u0434\u0435\u043e-\u0447\u0430\u0442\u0430 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 WebRTC. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <a href=\"http:\/\/habrahabr.ru\/post\/198632\/\">\u0432\u043e\u0442<\/a> \u0441\u0442\u0430\u0442\u044c\u044f \u043d\u0430 \u0425\u0430\u0431\u0440\u0435. \u041e\u0434\u043d\u0430\u043a\u043e, \u0432\u0441\u0435 \u043e\u043d\u0438 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435\u043c \u0434\u0432\u0443\u0445 \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432. \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u043f\u043e\u0441\u0442\u0430\u0440\u0430\u044e\u0441\u044c \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 WebRTC \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0438 \u043e\u0431\u043c\u0435\u043d \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f\u043c\u0438 \u043c\u0435\u0436\u0434\u0443 \u0442\u0440\u0435\u043c\u044f \u0438 \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c\u0438.  <\/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-255287","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/255287","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=255287"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/255287\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=255287"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=255287"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=255287"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}