ãã¿ãã¬ïŒããããªãã 圌ãã®ããã«ãéçºè ã¯ãããè¡ããŸãã
Flashãäœå¹Žãåã«æ®ºããå§ãããšãããã©ãŠã¶ã²ãŒã ã ãã§ãªã被害ãåããŸããã Flashã¯åŸæ¥ãé³å£°é話ããããªé話ã§åŒ·åã§ããããã€ã¯ãã«ã¡ã©ãã¹ããŒã«ãŒãžã®çŽæ¥ã¢ã¯ã»ã¹ãUDPãã±ãããåŠçããæ©èœã HTML5ã§ã¯ãWebRTCãã¯ãããžãŒã代ããã«ãªããŸããã æ°ã¶æåã«ã€ãã«SafariãšEdgeã«äžéžãããã®ã ããã§ãiPhoneã§éããŠããWebããŒãžããå¥ã®WebããŒãžãããšãã°ãLinuxäžã®Firefox Quantumã§éããŠããWebããŒãžã«é»è©±ããããããšãã§ããŸãã
Flashã«ãªãWebRTCã®æ©èœã®1ã€ã¯ããã©ãŠã¶ãŒéã®P2Pæ¥ç¶ã®å¯èœæ§ã§ãã ãããããã¢ããŒãã¢ãæ©èœããã«ã¯ãããã°ã©ããŒãèŠããå¿ èŠããããŸãã ãã©ãŠã¶ãUDPãã±ãããéä¿¡ããå Žæã«ã€ããŠã©ã®ããã«åæããããããã³éçºè ãããã§äœããã¹ããã«ã€ããŠ-ã«ããã®äžã§ã
ãã¢ã©ãŒã ã-圌ãã話ããªãããã«ããããš
ã»ãšãã©ã®WebRTCãã¥ãŒããªã¢ã«ã«ã¯ãåãWiFiã«æ¥ç¶ãããŠããå Žåã«ãiPhoneããWindowsã©ããããããžã®ãããªé話ãè¡ãéã®ãFlashã®ã¯ãŒã«ãªäº€æããã©ãŠã¶ãŒããã®é³å£°é話ãšãããªé話ããã¢ããŒãã¢ãš10ã¡ã¬ãã€ãã®ãããªã¹ããªãŒã ã«é¢ããé 延ã®ãªã話ããããŸãã ã³ãŒããšããŠã圌ãã¯éåžžããããããã«åçŽãã説åŸåããã£ãŠå®èšŒããJavaScriptã®æ°è¡ã瀺ããŸãã
ç§Theã¯ãWebRTCã®ã©ãããŒãéåžžå®èšŒãããããšã§ãã ãã®ãããªã©ãããŒã¯ã RTCPeerConnectionãšMediaDevices.getUserMediaãè žã®éçºè ããé ãããšã«å ããŠãPubNubãTwilioããŸãã¯Voximplantãªã©ãç¬èªã®ã¯ã©ãŠããšãã¯ãããžãŒã¹ã¿ãã¯ã䜿çšãã2ã€ã®ãã©ãŠã¶ãŒéã®ãã¹ãŠã®éä¿¡ãéçºè ããé ããŸãã éçºè ã®ããã«ä»äºãããã®ã¯è¯ãããšã§ãã ããããæè¡ã¹ã¿ãã¯ãåçŽåããŠãããã³ãããå ãã§çºçããããã»ã¹ã®èª€è§£ãæéãç Žãã解決çããæè¡çåé¡ãã解決ãããšãã«æéç匟ãæ€ããããšããããããŸãã
ãã®ã¹ããŒãªãŒã¯ãWebRTCã§ã®ã·ã°ããªã³ã°ãç§ãã¡ãä»ã®äŒæ¥ãè¡ãæ¹æ³ãæ¢æã®ãµãŒãã¹ã䜿çšããã«ãŒããããœãªã¥ãŒã·ã§ã³ãäœæããå Žåã®æ¹æ³ã«ã€ããŠèª¬æããŠããŸãã
P2Pã³ãŒã«ã«ãµãŒããŒãå¿ èŠãªçç±
ããã¢ããŒãã¢ããšãããã¬ãŒãºãèããŠãç§ãã¡ã¯éåžžãã¬ã³ããæãåºããŸãã äžå€®ãµãŒããŒããªãããã§ãã WebRTCã®ãã·ã°ããªã³ã°ããšã¯äœã§ããããŸãããµãŒããŒã¯ã©ãã«ãããŸããïŒ
WebRTCãšJavaScriptã³ãŒãã䜿çšããŠWebããŒãžãäœæãããšããŸãã WiFiã«æ¥ç¶ããã3å°ã®ã©ãããããã§éããæåã®ã©ããããããã3çªç®ã®ã©ããããããžã®ãããªé話ãè¡ããŸãã æåã®ã©ãããããã®WebRTCã¯ã3çªç®ã«æ¥ç¶ããå¿ èŠãããããšãã©ã®ããã«èªèããŸããïŒ WebRTCéçºè ã®ä»£ããã«äœãããŸããïŒ
æåã«æãã€ããæ¹æ³ã¯ãæåã®ã©ãããããã®WebRTCã3çªç®ã®ã©ãããããã®IPã¢ãã¬ã¹ã«éä¿¡ããUDPãã±ãããéä¿¡ãããããšã§ããã ãã ãããã®æ¹æ³ã¯ãäž¡æ¹ã®ããã€ã¹ãåããããã¯ãŒã¯ã«æ¥ç¶ãããŠããããã®ãããã¯ãŒã¯ã§çžäºããã®ãã±ããã®åä¿¡ãèš±å¯ãããŠããå Žåã«ã®ã¿æ©èœããŸãïŒãµãã©ã€ãº-ããã«ãäŒè°å Žã§ã®ãããªãã¯WiFiã¯ã»ãšãã©ã®å Žåèš±å¯ãããŸããïŒã ãããã1ã€ã§ã¯ãªã3ã€ã®WiFiã¢ã¯ã»ã¹ãã€ã³ããããå Žåã¯ã©ãã§ããããã ãŸãã3å°ã®ã©ãããããã¯ãã¹ãŠç°ãªãã¢ã¯ã»ã¹ãã€ã³ãã«æ¥ç¶ãããåãä»®æ³IPã¢ãã¬ã¹ïŒã192.168.0.5ããªã©ïŒãæã£ãŠããŸãã æåã®ã©ãããããã§å®è¡ãããŠãããã©ãŠã¶ã¯ã©ãã«ãã±ãããéä¿¡ããå¿ èŠããããŸããïŒ
ãã®ç¶æ³ã§ã¯åŒã³åºãã¯è¡ãããªããšæ³å®ã§ããŸããããããã®å Žåããäž¡æ¹ã®ã©ãããããã®ãã©ãŠã¶ãŒãçžäºã«éä¿¡ã§ãããå®éã®ãIPã¢ãã¬ã¹ãæã€å€éšãµãŒããŒãå¿ èŠã§ãã ããããWebRTCã®äœæè ã¯ãé³å£°ãšãããªã¯ãã©ãã£ãã¯éçŽåã®éä¿¡ã§ãããäœçŸäžäººãã®Skype for WebãŸãã¯Googleãã³ã°ã¢ãŠããŠãŒã¶ãŒããããªãã¯ãµãŒããŒãä»ããŠé»è©±ãããããšããããã®ãµãŒããŒãããŒã¹ãããããšãæããŸããã WebRTCã®äœæè ã¯ãäž¡æ¹ã®ããã€ã¹ã«ä»®æ³IPã¢ãã¬ã¹ããããçŽæ¥ãã±ããã亀æã§ããªãå Žåã§ããNATãããã³ããããŠP2Pæ¥ç¶ã確ç«ããæ©èœããã¯ãããžã«ä»äžããŸããã ååã¯åããã¢ã©ãŒã ãã§ããã éçºè ã¯ã2çªç®ã®ããã€ã¹ãŸãã¯å€éšãµãŒããŒã®WebRTC IPã¢ãã¬ã¹ãåã«éä¿¡ããããšã¯ã§ããŸããã 圌ã¯ãäž¡æ¹ã®ãã©ãŠã¶ããããã¯ãŒã¯ãæ éã«æ€æ»ããäºãã«åæããã®ãæäŒãå¿ èŠããããŸãã ãã®ããã«ã圌ã¯åœŒã®Signaling Serverãå¿ èŠãšããŸãã
ãªãã¡ãŒãã¢ã³ãµãŒãICEåè£ããã®ä»ã®æãããèšè
ããã§ã¯ã2ã€ã®ãã©ãŠã¶éã®ãããªã³ãŒã«ã¯éçºè ã®èŠ³ç¹ããã©ã®ããã«èŠããŸããïŒ
- æåã®ãã©ãŠã¶ãŒã§å¿ èŠãªJavaScriptãªããžã§ã¯ãã®æºåãšäœæããã¹ãŠå®äºããåŸãWebRTCã¡ãœããcreateOfferïŒïŒãåŒã³åºãããSDP圢åŒã®ããã¹ãããã±ãŒãžïŒãŸãã¯ãå°æ¥ãAPIã®oRTCããŒãžã§ã³ããã¯ã©ã·ãã¯ããªããžã§ã¯ããååŸããå Žåã¯JSONã·ãªã¢ã©ã€ãºå¯èœãªããžã§ã¯ãïŒãè¿ããŸãã ãã®ããã±ãŒãžã«ã¯ãéçºè ãå¿ èŠãšããã³ãã¥ãã±ãŒã·ã§ã³ã®çš®é¡ã«é¢ããæ å ±ãå«ãŸããŠããŸããé³å£°ããããªããŸãã¯ããŒã¿ã®éä¿¡ãã©ã®ã³ãŒããã¯ãååšããã-ãã®ã¹ããŒãªãŒå šäœ
- ãããŠä»-ã¢ã©ãŒã ã éçºè ã¯ã©ãããããã ïŒæ¬åœã«ãä»æ§ã«æžãããŠããŸãïŒïŒãã®ããã¹ãããã±ãŒãžã®æäŸã2çªç®ã®ãã©ãŠã¶ãŒã«æž¡ãå¿ èŠããããŸãã ããšãã°ãã€ã³ã¿ãŒãããäžã§ç¬èªã®ãµãŒããŒã䜿çšããäž¡æ¹ã®ãã©ãŠã¶ãŒããWebSocketæ¥ç¶ãã
- 2çªç®ã®ãã©ãŠã¶ãŒã§ãªãã¡ãŒãåãåã£ãåŸãéçºè ã¯setRemoteDescriptionïŒïŒã¡ãœããã䜿çšããŠWebRTCã«ãªãã¡ãŒãæž¡ããŸãã 次ã«ãcreateAnswerïŒïŒã¡ãœãããåŒã³åºããŸãããã®ã¡ãœããã¯ãåãããã¹ããã±ãããSDP圢åŒã§è¿ããŸããã2çªç®ã®ãã©ãŠã¶ãŒã«å¯ŸããŠãæåã®åä¿¡ãã±ãããèæ ®ã«å ¥ããŸã
- ã·ã°ããªã³ã°ã®ç¶ç¶ïŒéçºè ã¯å¿çããã¹ããã±ãããæåã®ãã©ãŠã¶ãŒã«è¿ããŸã
- éçºè ã¯ãæåã®ãã©ãŠã¶ãŒã§åçãåãåã£ãåŸããã§ã«è¿°ã¹ãsetRemoteDescriptionïŒïŒã¡ãœããã䜿çšããŠWebRTCã«æž¡ããŸãããã®åŸãäž¡æ¹ã®ãã©ãŠã¶ãŒã®WebRTCã¯æå°éã®çžäºèªèãè¡ããŸãã æ¥ç¶ã§ããŸããïŒ ãããããã å®éããã¹ãŠãå§ãŸã£ãã°ããã§ã
- äž¡æ¹ã®ãã©ãŠã¶ãŒã®WebRTCã¯ããããã¯ãŒã¯æ¥ç¶ã®ç¶æ ã®èª¿æ»ãéå§ããŸãïŒå®éãæšæºã§ã¯ãããè¡ãã¿ã€ãã³ã°ã瀺ãããŠããããå€ãã®ãã©ãŠã¶ãŒã§ã¯ãWebRTCã¯å¯Ÿå¿ãããªããžã§ã¯ããäœæããçŽåŸã«ãããã¯ãŒã¯ã®èª¿æ»ãéå§ããæ¥ç¶æã«äžèŠãªé 延ãçºçããªãããã«ããŸãïŒã éçºè ãæåã®æé ã§WebRTCãªããžã§ã¯ããäœæãããšããå°ãªããšãSTUNãµãŒããŒã®ã¢ãã¬ã¹ãæž¡ãå¿ èŠããããŸãã ããã¯ããç§ã®IPãšã¯äœãããšããUDPãã±ããã«å¿çããŠããã®ãã±ãããåä¿¡ããIPã¢ãã¬ã¹ãéä¿¡ãããµãŒããŒã§ãã WebRTCã¯STUNãµãŒããŒã䜿çšããŠãå€éšãIPã¢ãã¬ã¹ãååŸããããããå éšãIPã¢ãã¬ã¹ãšæ¯èŒããŠãNATããããã©ããã確èªããŸãã ãããããªããã©ã®NATãªããŒã¹ããŒããUDPãã±ããã®ã«ãŒãã£ã³ã°ã«äœ¿çšããŸããïŒ
- æã ãäž¡æ¹ã®ãã©ãŠã¶ã®WebRTCã¯ãonicecandidateã³ãŒã«ããã¯ãåŒã³åºãããã§ã«éŠŽæã¿ã®ããSIPãã±ããã«2çªç®ã®æ¥ç¶åå è ã®æ å ±ãéä¿¡ããŸãã ãã®ããã±ãŒãžã«ã¯ãå éšããã³å€éšIPã¢ãã¬ã¹ãæ¥ç¶è©Šè¡ãNATã䜿çšããããŒããªã©ã«é¢ããæ å ±ãå«ãŸããŠããŸãã éçºè ã¯ãã·ã°ããªã³ã°ã䜿çšããŠãããã®ãã±ããããã©ãŠã¶éã§è»¢éããŸãã éä¿¡ããããã±ããã¯ã addIceCandidateïŒïŒã¡ãœããã䜿çšããŠWebRTCã«éä¿¡ãããŸã
- ãã°ãããããšãWebRTCã¯ãã¢ããŒãã¢æ¥ç¶ã確ç«ããŸãã ãŸãã¯ãNATãå¹²æžããå Žåã¯äœ¿çšã§ããŸããã ãã®ãããªå Žåãéçºè ã¯TURNãµãŒããŒã®ã¢ãã¬ã¹ãéä¿¡ã§ããŸããããã¯å€éšæ¥ç¶èŠçŽ ãšããŠäœ¿çšãããŸããäž¡æ¹ã®ãã©ãŠã¶ãŒã¯ãé³å£°ãŸãã¯ãããªãå«ãUDPãã±ãããéä¿¡ããŸãã STUNãµãŒããŒãç¡æã§èŠã€ããå ŽåïŒããšãã°ãGoogleã«ããå ŽåïŒãèªåã§TURNãµãŒããŒãäžããå¿ èŠããããŸãã ãã®ããã«ãã©ãã€ãã®ãããªãã©ãã£ãã¯ãèªåèªèº«ã«æž¡ãããšã«èª°ãèå³ããªã
å®æãããã©ãããã©ãŒã ã䜿çšãããšãããããã¹ãŠã®ãã¥ã¢ã³ã¹ãé ãããšãã§ããŸãã Web SDKã¯ãWebRTCãæ£ããæ§æããSDPãã±ããã«ããããé©çšããVoximplantã¯ã©ãŠããžã®WebSocketæ¥ç¶ããµããŒãããããã«å€ãã®è©³çŽ°ãåŠçããŸãã ãããŠãã¡ãããç¬èªã®STUNãµãŒããŒãšTURNãµãŒããŒããããã©ã®ãããªå Žåã§ãæ¥ç¶ãè¡ãããŸãã ãããããã¥ã¢ã³ã¹ãé ããŠèªåã§ããããšã¯ã§ããŸããïŒ ãã©ãŠã¶ã§å©çšå¯èœãªAPIã«ããã以äžã®ããã«ãããŸããŸãªæ¹æ³ã§ã¢ã©ãŒã ãäœæã§ããããã«ãªããŸããã
åäœããªãåçŽãªHTTPãªã¯ãšã¹ãã·ã°ããªã³ã°
æåã«æãæµ®ãã¶ã®ã¯ãæãåçŽãªHTTPãµãŒããŒãšããã©ãŠã¶ãŒåŽããã®xmlHttpRequest / fetchã§ãã æ²ããããªãããã¯æç§æžã®ãããã«ã¡ã¯äžçãã«å¯ŸããŠã®ã¿æ©èœããŸãã å®éã«ã¯ããµãŒããŒã¯éåžžã«å€ãã®ãªã¯ãšã¹ãããèœã¡ãŸãã ããã¯éåžžã«é »ç¹ã«å®è¡ããå¿ èŠãããããããæ¥ç¶ããã¯ãªãã¯ããããšã§ããŠãŒã¶ãŒã¯ãæ¥ç¶ã確ç«ãããããã«æ°åéåŸ ããªãããã«ããŸãã ãŸããWebRTCã¯ãªã¢ã«ã¿ã€ã ã®ã¹ããŒãªãŒã§ããããªãã¡ãŒ/ã¢ã³ãµãŒ/ã¢ã€ã¹ãéåžžã«è¿ éã«éä¿¡ããå¿ èŠããããããé »ç¹ã«è¡ãå¿ èŠããããŸãã æ°ç§ã®é 延ã§ããããäœãèµ·ãããªãããšããWebRTCã®ã·ã°ãã«ãšããŠæ©èœãããã®åŸããšã³ãžã³ã¯æ¥ç¶ã®ç¢ºç«ãè©Šè¡ããªããªããŸãã ãŸãã¯ãããã³ã°ããŒãªã³ã°ãææ³ãè©Šãããšãã§ããŸãããå®éã«ã¯ããŸãæ©èœãããäžéã®ã€ã³ã¿ãŒãããã€ã³ãã©ã¹ãã©ã¯ãã£ã¯ãã®ãããªãé ããHTTPãªã¯ãšã¹ããäžæããããšã奜ã¿ãŸãã
WebSockets SignalingïŒ æãå¹æç 㪠æŠç¥ãæçš
WebRTCã䜿çšããã»ãšãã©ã®ãœãªã¥ãŒã·ã§ã³ã¯ãã·ã°ããªã³ã°ã«WebSocketã䜿çšããŸãã ãã®ãããã³ã«ã¯ããã§ã«äœ¿çšãããŠããWebãã©ãŠã¶ãŒãšãããã¯ãŒã¯æ©åšã®å€§éšåã§ãµããŒãã§ããã»ã©ãå€ãããã®ã§ãã ãŸããsocket.ioãSocketJSã®ãããªã©ãããŒã䜿çšããå ŽåãWebSocketãæ©èœããªããŸããªã±ãŒã¹ã§ã¯ãHTTPãã³ã°ããŒãªã³ã°ã«äœäžãããããšãã§ããŸããããã¯ãå°ãªããšãäœããã®åœ¢ã§ãæ©èœããŸãã ãµãŒããŒåŽã§ã¯ãããŒã¿ãéä¿¡ãããªãWebSocketæ¥ç¶ã¯ã»ãšãã©ãªãœãŒã¹ãæ¶è²»ããããµãŒããŒã¯åŒã³åºããåŸ ã£ãŠããäœäžãã®WebããŒãžãç°¡åã«åŠçã§ããŸãã
WebSocketã«ã¯ã©ã®ãããªåé¡ããããŸããïŒ ãŸããæ¥ç¶ãæã å£ããŸã-ããã¯åŠçããå¿ èŠããããŸãã ãŸããããŒãã¢ã©ã€ãã¿ã€ã ã¢ãŠããé«ããªã£ãŠããŸããæ¥ç¶ã¯çããŠããããã«èŠããŸãããå®éã«ã¯äžéæ©åšã®ã©ããã§æ¢ã«åæãããŠããŸãã ãããŠã次ã®ããŒãã¢ã©ã€ããã±ãããæ¥ãªãå Žåã«ã®ã¿ãããã«ã€ããŠç¥ãããšãã§ããŸããããã¯10åã«ãªãããšããããŸãã ãã®éã圌ãã¯ç§ãã¡ã«å°éããããšããŸãããå°éã§ããŸããã ãã®ã¡ã«ããºã ã¯ãã©ãŠã¶ãŒãšãµãŒããŒã®å®è£ ã«äŸåããŠããããããµãŒããŒåŽã®ãã³ãã³ãã¬ãŒã ã¯ãå¿ èŠã«å¿ããŠç¢ºèªããã³åŒ·åããã®ã«åœ¹ç«ã¡ãŸãã
WebSocketã®ææ°ã®ã¢ããã°ãšããŠã®HTTP / 2ã·ã°ããªã³ã°
HTTPã®ããŒãžã§ã³2ã®äººæ°ãé«ãŸããšãWebSocketãšãµãŒããŒãµã€ãã€ãã³ãã¯éå»ã®ãã®ã«ãªãå¯èœæ§ããããŸãã ãµãŒããŒãšåæ¹åã®éä¿¡ã®ãã€ããªãã£ãã«ã§ãããããã䜿çšããŠHTMLããŒãžãšç»åã®äž¡æ¹ãååŸããWebRTCã·ã°ããªã³ã°ãæŽçã§ããŸãã æ®å¿µãªããšã«ã人æ°ã®ãããã©ãŠã¶ãŒã®ææ°ããŒãžã§ã³ã®ãµããŒãã«ãããããããHTTP / 2ã¯ãå€ãã®ãŠãŒã¶ãŒããããããžã§ã¯ãã§äœ¿çšããã®ã«äŸç¶ãšããŠå±éºã§ãã ãã®çç±ã¯ãã€ã³ã¿ãŒãããã®ãã¹ã±ã«ãã³ããæ§æããäžéæ©åšã«ãããŸãã ããããã¹ãŠã®ã«ãŒã¿ãŒãã²ãŒããŠã§ã€ãããªã±ãŒããããã³20æ³ã®ç«ã¯ãå€ãã®å ŽåHTTP / 2æ¥ç¶ãå®äºãããããäœã§ããããç解ããã誰ãããäœãããä¿è·ãããããšããŸãã
ååž°ã®äŸãšããŠã®WebRTCã·ã°ããªã³ã°
å¥ã®WebRTCæ¥ç¶ã䜿çšããŠãWebRTCã«ä¿¡å·ãéãããšãã§ããŸãïŒ å¥åŠã«èãããŸããããã®æ¹æ³ã«ã¯å©ç¹ããããŸãã ä»ã®ã·ã°ããªã³ã°ã䜿çšããŠããã©ãŠã¶ãšã¯ã©ãŠãã®éã«æåã®WebRTCæ¥ç¶ã確ç«ãããšïŒéP2Pã³ãŒã«ã®å Žåãšåæ§ïŒããã®ãããªæ¥ç¶ã§ã¯ããŒã¿ãã£ãã«APIã䜿çšã§ããŸãã ããã¯ããTCPã®ããã«ãã ãã§ãªããUDPã®ããã«ãæ©èœããé ä¿¡ãä¿èšŒããã«éåžžã«è¿ éã«ãã±ãããéä¿¡ã§ãããšããç¹ã§ãWebSocketsãšæ¯èŒããŠæå©ã§ãã ãã®æ¹æ³ã«ãããWebSocketsãHTTP / 2ãããé«éã«æ¥ç¶ãã·ã°ãã«ããããšãã§ããŸãã å Žåã«ãã£ãŠã¯ããã®ã¡ãœãããå¿ èŠã§ãã ããšãã°ãã²ãŒã ã§ã
TL; DL
説æãããŠãããã¹ãŠãèŠçŽããŸãïŒWebRTCããã¢ããŒãã¢æ¥ç¶ã確ç«ããåã«ãéçºè ã¯2ã€ã®ãã©ãŠã¶ãŒïŒãŸãã¯ä»ã®ããã€ã¹; Googleã®libwebrtcã©ã€ãã©ãªã«ãããC ++ã³ã³ãã€ã«ã
ãµã€ãwww.elasticrtc.comããã«ã¿ãžã®ã€ã©ã¹ã
www.sococo.com/blog/webrtc-signaling-here-be-dragonsã®ãã©ãŽã³ã€ã©ã¹ã