SlideShare uma empresa Scribd logo
1 de 32
WebRTC, STUN and TURN
Amitesh Madhur
Cisco Systems
Agenda
 User Media
 Peer Connection
 STUN and TURN
 Setting up STUN and TURN
Agenda
 User Media
 Peer Connection
 STUN and TURN
 Setting up STUN and TURN
Get User Media
 getUserMedia()
 Collects video audio input
 Synchronization of input
<video id=“me" autoplay></video>
navigator.getUserMedia = navigator.getUserMedia ||
navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia;
if (navigator.getUserMedia) {
navigator.getUserMedia({video: true}, onSuccess, onError);
}
window.URL = window.URL || window.webkitURL;
var me = document.getElementById('me');
function onSuccess(stream) {
me.src = window.URL.createObjectURL(stream);
}
function onError(e) {
// error
}
Vendor Prefixes
Chrome >= 21:
 webkitGetUserMedia()
 window.webkitURL.createObjectURL()
Opera >= 12:
 getUserMedia()
 set video.src
Firefox >= 20:
 mozGetUserMedia()
 window.URL.createObjectURL()
IE: not implemented
Source : http://html5videoguide.net/presentations/WebDirCode2012/#page10
Agenda
 User Media
 Peer Connection
 STUN and TURN
 Setting up STUN and TURN
Peer Connection
 Establish a connection
 Pass the user media stream
 Other side gets the stream
 Add the received stream to <video> tag
Peer Connection
 Compression and de-compression
 P2P connection using STUN or TURN
 Encrypting the data
<video id=“me" autoplay></video>
<video id=“other" autoplay></video>
peer = new RTCPeerConnection(servers);
peer.onaddstream = gotRemoteStream;
peer.addStream(localStream);
if(host) {
peer.createOffer(callGotOffer, null, {mandatory: {
OfferToReceiveAudio: true,
OfferToReceiveVideo: true}});
} else {
peer.createAnswer(peer.remoteDescription, callGotOffer);
}
function callGotOffer(sd) {
peer.setLocalDescription(sd);
}
function gotAnswer(desc) {
peer.setRemoteDescription(new RTCSessionDescription(desc));
}
function gotRemoteStream(e) {
attachMediaStream(remoteVideo, e.stream);
}
chrome://webrtc-internals/
Agenda
 User Media
 Peer Connection
 STUN and TURN
 Setting up STUN and TURN
Need for STUN
NAT NAT
Need for TURN
NAT
Firewall
NAT
Firewall
STUN and TURN
peer = new RTCPeerConnection(servers);
STUN and TURN
var chrome, stun, turn, servers = {}, peer;
chrome = parseInt(navigator.userAgent.match(/Chrom(e|ium)/([0-9]+)./ )[2]);
stun = {url: 'stun:10.0.0.7:9999‘};
turn = {url: 'turn:amitesh@10.0.0.7:333', credential: ‘pass‘};
if (isChrome && chrome >= 28) {
turn = {
url: 'turn:10.0.0.7:3333',
credential: 'madhur',
username: 'amitesh'
};
}
servers.iceServers = [stun, turn];
peer = new RTCPeerConnection(servers);
Public STUN
stun.l.google.com:19302
stun1.l.google.com:19302
stun2.l.google.com:19302
stun3.l.google.com:19302
stun4.l.google.com:19302
Agenda
 User Media
 Peer Connection
 STUN and TURN
 Setting up STUN and TURN
STUN on Linux
 stunprotocol.org
STUN on Linux
 Run “make”
 Provides 3 libraries
(stunserver, stunclient and stuntestcode)
 Run stunserver --help or stunclient --help
 By default runs on port 3478
STUN on Windows
 stunprotocol.org
STUN on Windows
 Unzip
 goto command prompt and run server:
stunserver.exe --mode full --primaryinterface
10.0.0.6 --altinterface 10.0.0.11 --altport 999 --
primaryport 9999 --verbosity 3
TURN on Linux
 Build libevent
$ wget https://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz
$ tar xvfz libevent-2.0.21-stable.tar.gz
$ cd libevent-2.0.21-stable
$ ./configure
$ make
$ make install
TURN on Linux
 Download TURN from
https://code.google.com/p/rfc5766-turn-
server
$ tar xvfz turnserver.tar.gz
$ ./configure
$ make
$ make install
TURN on Linux
 Copy the “turnserver.conf” from
turnserver/examples/etc/turnserver.conf
to
/usr/local/etc/turnserver.conf
 Changes in turnserver.conf
listening-port=<new-port>
listening-ip=<your ip>
user=<user>:<password>
TURN on Linux
 Run turnserver
turnserver -L <ip_address>
IN YOUR JAVASCRIPT
var turn;
turn = { url: 'turn:<user-name>@<IP>:<PORT>',
credential: ‘password‘
};
// for chrome 28 and above
turn = {
url: 'turn:<IP-address>:<PORT>',
username: ‘<user-name>‘,
credential: ‘<password>'
};
TURN on Windows
 Install Cygwin
 Make sure to install devel dependencies
 Build libevent
$ wget https://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz
$ tar xvfz libevent-2.0.21-stable.tar.gz
$ cd libevent-2.0.21-stable
$ ./configure
$ make
$ make install
TURN on Windows
 Download TURN from
https://code.google.com/p/rfc5766-turn-
server
$ tar xvfz turnserver.tar.gz
$ ./configure
$ make
$ make install
TURN on Windows
 Issues during ./configure
 Missing libpq.a, hiredis, postgreSql
(You may Ignore them, since these are optional)
 Issues during make
 error: ‘struct sockaddr_in’ has no member named
‘sin_len’
Edit turnserver.version/src/client/na_turn_ioaddr.c and
comment line #169// addr->s4.sin_len = sizeof(struct
sockaddr_in);
TURN on Windows
 Run fixing “make” and “make install”
 Copy the “turnserver.conf” from
turnserver/examples/etc/turnserver.conf
to
/usr/local/etc/turnserver.conf
 Changes in turnserver.conf
listening-port=<new-port>
listening-ip=<your ip>
user=<user>:<password>
TURN on Windows
 Run turnserver
turnserver.exe -a -r 10.0.0.6
IN YOUR JAVASCRIPT
var turn;
turn = { url: 'turn:<user-name>@<IP>:<PORT>',
credential: ‘password‘
};
// for chrome 28 and above
turn = {
url: 'turn:<IP-address>:<PORT>',
username: ‘<user-name>‘,
credential: ‘<password>'
};
Thank you
Demos : http://webrtc.googlecode.com/svn/trunk/samples/js/demos/
Twitter: @amiteshawa
Facebook: facebook.com/amitesh.madhur
Linkedin: in.linkedin.com/pub/amitesh-madhur/a/932/499

Mais conteúdo relacionado

Mais procurados

Cài đặt web server (linux)-Pham Hoang Phuc-Athena
Cài đặt web server (linux)-Pham Hoang Phuc-AthenaCài đặt web server (linux)-Pham Hoang Phuc-Athena
Cài đặt web server (linux)-Pham Hoang Phuc-Athena
Hoàng Phúc Phạm
 
WSO2 ESB Integration with REST
WSO2 ESB Integration with RESTWSO2 ESB Integration with REST
WSO2 ESB Integration with REST
WSO2
 

Mais procurados (20)

Fools your enemy with MikroTik
Fools your enemy with MikroTikFools your enemy with MikroTik
Fools your enemy with MikroTik
 
Présentation html5
Présentation html5Présentation html5
Présentation html5
 
Tutorial radius client mikrotik
Tutorial radius client mikrotikTutorial radius client mikrotik
Tutorial radius client mikrotik
 
CCNA Lab Guide
CCNA Lab GuideCCNA Lab Guide
CCNA Lab Guide
 
Sip Detailed , Call flows , Architecture descriptions , SIP services , sip se...
Sip Detailed , Call flows , Architecture descriptions , SIP services , sip se...Sip Detailed , Call flows , Architecture descriptions , SIP services , sip se...
Sip Detailed , Call flows , Architecture descriptions , SIP services , sip se...
 
Cara Membangun FTP Server di Windows Server 2008
Cara Membangun FTP Server di Windows Server 2008Cara Membangun FTP Server di Windows Server 2008
Cara Membangun FTP Server di Windows Server 2008
 
Konfigurasi Routing OSPF Di MikroTik
Konfigurasi Routing OSPF Di MikroTikKonfigurasi Routing OSPF Di MikroTik
Konfigurasi Routing OSPF Di MikroTik
 
Engage 2018: IBM Notes and Domino Performance Boost - Reloaded
Engage 2018: IBM Notes and Domino Performance Boost - Reloaded Engage 2018: IBM Notes and Domino Performance Boost - Reloaded
Engage 2018: IBM Notes and Domino Performance Boost - Reloaded
 
Wireshark
WiresharkWireshark
Wireshark
 
summer training report on Computer network and Cisco packet tracer
summer training report on Computer network and Cisco packet tracer summer training report on Computer network and Cisco packet tracer
summer training report on Computer network and Cisco packet tracer
 
WSO2 ESB Introduction to Inbound Endpoints
WSO2 ESB Introduction to Inbound EndpointsWSO2 ESB Introduction to Inbound Endpoints
WSO2 ESB Introduction to Inbound Endpoints
 
Juniper Chassis Cluster Configuration with SRX-1500s
Juniper Chassis Cluster Configuration with SRX-1500sJuniper Chassis Cluster Configuration with SRX-1500s
Juniper Chassis Cluster Configuration with SRX-1500s
 
MikroTik Firewall : Securing your Router with Port Knocking
MikroTik Firewall : Securing your Router with Port KnockingMikroTik Firewall : Securing your Router with Port Knocking
MikroTik Firewall : Securing your Router with Port Knocking
 
Cài đặt web server (linux)-Pham Hoang Phuc-Athena
Cài đặt web server (linux)-Pham Hoang Phuc-AthenaCài đặt web server (linux)-Pham Hoang Phuc-Athena
Cài đặt web server (linux)-Pham Hoang Phuc-Athena
 
Dns
DnsDns
Dns
 
IMS presentation
IMS presentationIMS presentation
IMS presentation
 
Firewall Best Practices for VoIP on pfSense - pfSense Hangout October 2017
Firewall Best Practices for VoIP on pfSense - pfSense Hangout October 2017Firewall Best Practices for VoIP on pfSense - pfSense Hangout October 2017
Firewall Best Practices for VoIP on pfSense - pfSense Hangout October 2017
 
WSO2 ESB Integration with REST
WSO2 ESB Integration with RESTWSO2 ESB Integration with REST
WSO2 ESB Integration with REST
 
Introduction to Diameter Protocol - Part1
Introduction to Diameter Protocol - Part1Introduction to Diameter Protocol - Part1
Introduction to Diameter Protocol - Part1
 
Adaptative streaming : enjeux, panorama, principes et difficultés
Adaptative streaming : enjeux, panorama, principes et difficultésAdaptative streaming : enjeux, panorama, principes et difficultés
Adaptative streaming : enjeux, panorama, principes et difficultés
 

Destaque

OAuth and STUN, TURN in WebRTC context RFC7635
OAuth and STUN, TURN  in WebRTC context RFC7635OAuth and STUN, TURN  in WebRTC context RFC7635
OAuth and STUN, TURN in WebRTC context RFC7635
Mihály Mészáros
 

Destaque (16)

Setup ephemeral password for TURN, Learn RTC in less than 200 Lines of code
Setup ephemeral password for TURN, Learn RTC in less than 200 Lines of codeSetup ephemeral password for TURN, Learn RTC in less than 200 Lines of code
Setup ephemeral password for TURN, Learn RTC in less than 200 Lines of code
 
How I built a WebRTC enabled website in 20 minutes!
How I built a WebRTC enabled website in 20 minutes!How I built a WebRTC enabled website in 20 minutes!
How I built a WebRTC enabled website in 20 minutes!
 
Eyeball Networks AnyFirewall Server V10 Administrator Guide
Eyeball Networks AnyFirewall Server V10 Administrator GuideEyeball Networks AnyFirewall Server V10 Administrator Guide
Eyeball Networks AnyFirewall Server V10 Administrator Guide
 
Server-side WebRTC Infrastructure
Server-side WebRTC InfrastructureServer-side WebRTC Infrastructure
Server-side WebRTC Infrastructure
 
Web rtc 入門
Web rtc 入門Web rtc 入門
Web rtc 入門
 
Eyeball AnyConnect™ Gateway Administration Guide
Eyeball AnyConnect™ Gateway Administration GuideEyeball AnyConnect™ Gateway Administration Guide
Eyeball AnyConnect™ Gateway Administration Guide
 
Amitesh Madhur - Web workers, HTML 5
Amitesh Madhur - Web workers, HTML 5Amitesh Madhur - Web workers, HTML 5
Amitesh Madhur - Web workers, HTML 5
 
Arinjay
ArinjayArinjay
Arinjay
 
AnyConnect Gateway by Eyeball Networks
AnyConnect Gateway by Eyeball NetworksAnyConnect Gateway by Eyeball Networks
AnyConnect Gateway by Eyeball Networks
 
AnyFirewall Engine & Server by Eyeball Networks
AnyFirewall Engine & Server by Eyeball NetworksAnyFirewall Engine & Server by Eyeball Networks
AnyFirewall Engine & Server by Eyeball Networks
 
From NAT to NAT Traversal
From NAT to NAT TraversalFrom NAT to NAT Traversal
From NAT to NAT Traversal
 
Integrate WebRTC Video in an App in Less Than 20 Minutes
Integrate WebRTC Video in an App in Less Than 20 MinutesIntegrate WebRTC Video in an App in Less Than 20 Minutes
Integrate WebRTC Video in an App in Less Than 20 Minutes
 
WebRTC + Socket.io: building a skype-like video chat with native javascript
WebRTC + Socket.io: building a skype-like video chat with native javascriptWebRTC + Socket.io: building a skype-like video chat with native javascript
WebRTC + Socket.io: building a skype-like video chat with native javascript
 
NAT Traversal
NAT TraversalNAT Traversal
NAT Traversal
 
WebRTC for Managers!
WebRTC for Managers!WebRTC for Managers!
WebRTC for Managers!
 
OAuth and STUN, TURN in WebRTC context RFC7635
OAuth and STUN, TURN  in WebRTC context RFC7635OAuth and STUN, TURN  in WebRTC context RFC7635
OAuth and STUN, TURN in WebRTC context RFC7635
 

Semelhante a Web rtc, Media stream, Peer connection, Setting up STUN and TURN on Linux and Windows

Nuxeo5 - Continuous Integration
Nuxeo5 - Continuous IntegrationNuxeo5 - Continuous Integration
Nuxeo5 - Continuous Integration
PASCAL Jean Marie
 
Chris Swan ONUG Academy - Container Networks Tutorial
Chris Swan ONUG Academy - Container Networks TutorialChris Swan ONUG Academy - Container Networks Tutorial
Chris Swan ONUG Academy - Container Networks Tutorial
Cohesive Networks
 
Setting up Notifications, Alerts & Webhooks with Flux v2 by Alison Dowdney
Setting up Notifications, Alerts & Webhooks with Flux v2 by Alison DowdneySetting up Notifications, Alerts & Webhooks with Flux v2 by Alison Dowdney
Setting up Notifications, Alerts & Webhooks with Flux v2 by Alison Dowdney
Weaveworks
 
kubernetes - minikube - getting started
kubernetes - minikube - getting startedkubernetes - minikube - getting started
kubernetes - minikube - getting started
Munish Mehta
 
Domino9on centos6
Domino9on centos6Domino9on centos6
Domino9on centos6
a8us
 
WebRTC & Firefox OS - presentation at Google
WebRTC & Firefox OS - presentation at GoogleWebRTC & Firefox OS - presentation at Google
WebRTC & Firefox OS - presentation at Google
Robert Nyman
 

Semelhante a Web rtc, Media stream, Peer connection, Setting up STUN and TURN on Linux and Windows (20)

WebRTC Standards & Implementation Q&A - All about browser interoperability
WebRTC Standards & Implementation Q&A - All about browser interoperabilityWebRTC Standards & Implementation Q&A - All about browser interoperability
WebRTC Standards & Implementation Q&A - All about browser interoperability
 
Jump into Squeak - Integrate Squeak projects with Docker & Github
Jump into Squeak - Integrate Squeak projects with Docker & GithubJump into Squeak - Integrate Squeak projects with Docker & Github
Jump into Squeak - Integrate Squeak projects with Docker & Github
 
Nuxeo5 - Continuous Integration
Nuxeo5 - Continuous IntegrationNuxeo5 - Continuous Integration
Nuxeo5 - Continuous Integration
 
Quick Start Guide using Virtuozzo 7 (β) on AWS EC2
Quick Start Guide using Virtuozzo 7 (β) on AWS EC2Quick Start Guide using Virtuozzo 7 (β) on AWS EC2
Quick Start Guide using Virtuozzo 7 (β) on AWS EC2
 
How to manage Azure with open source
How to manage Azure with open sourceHow to manage Azure with open source
How to manage Azure with open source
 
How to manage Microsoft Azure with open source
How to manage Microsoft Azure with open sourceHow to manage Microsoft Azure with open source
How to manage Microsoft Azure with open source
 
Installing & Configuring IBM Domino 9 on CentOS
Installing & Configuring IBM Domino 9 on CentOSInstalling & Configuring IBM Domino 9 on CentOS
Installing & Configuring IBM Domino 9 on CentOS
 
Chris Swan ONUG Academy - Container Networks Tutorial
Chris Swan ONUG Academy - Container Networks TutorialChris Swan ONUG Academy - Container Networks Tutorial
Chris Swan ONUG Academy - Container Networks Tutorial
 
Embedded Recipes 2019 - Testing firmware the devops way
Embedded Recipes 2019 - Testing firmware the devops wayEmbedded Recipes 2019 - Testing firmware the devops way
Embedded Recipes 2019 - Testing firmware the devops way
 
Adopt DevOps philosophy on your Symfony projects (Symfony Live 2011)
Adopt DevOps philosophy on your Symfony projects (Symfony Live 2011)Adopt DevOps philosophy on your Symfony projects (Symfony Live 2011)
Adopt DevOps philosophy on your Symfony projects (Symfony Live 2011)
 
OpenStack Murano introduction
OpenStack Murano introductionOpenStack Murano introduction
OpenStack Murano introduction
 
Setting up Notifications, Alerts & Webhooks with Flux v2 by Alison Dowdney
Setting up Notifications, Alerts & Webhooks with Flux v2 by Alison DowdneySetting up Notifications, Alerts & Webhooks with Flux v2 by Alison Dowdney
Setting up Notifications, Alerts & Webhooks with Flux v2 by Alison Dowdney
 
kubernetes - minikube - getting started
kubernetes - minikube - getting startedkubernetes - minikube - getting started
kubernetes - minikube - getting started
 
DeveloperWeek 2015: A Practical Introduction to Docker
DeveloperWeek 2015: A Practical Introduction to DockerDeveloperWeek 2015: A Practical Introduction to Docker
DeveloperWeek 2015: A Practical Introduction to Docker
 
Domino9on centos6
Domino9on centos6Domino9on centos6
Domino9on centos6
 
WebRTC & Firefox OS - presentation at Google
WebRTC & Firefox OS - presentation at GoogleWebRTC & Firefox OS - presentation at Google
WebRTC & Firefox OS - presentation at Google
 
Uyuni Saltboot - automated image deployment and lifecycle with Uyuni
Uyuni Saltboot - automated image deployment and lifecycle with Uyuni Uyuni Saltboot - automated image deployment and lifecycle with Uyuni
Uyuni Saltboot - automated image deployment and lifecycle with Uyuni
 
Azure from scratch part 4
Azure from scratch part 4Azure from scratch part 4
Azure from scratch part 4
 
WebRTC Standards & Implementation Q&A - getDisplayMedia 1.0
WebRTC Standards & Implementation Q&A - getDisplayMedia 1.0WebRTC Standards & Implementation Q&A - getDisplayMedia 1.0
WebRTC Standards & Implementation Q&A - getDisplayMedia 1.0
 
Swift server-side-let swift2016
Swift server-side-let swift2016Swift server-side-let swift2016
Swift server-side-let swift2016
 

Último

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Último (20)

Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 

Web rtc, Media stream, Peer connection, Setting up STUN and TURN on Linux and Windows

  • 1. WebRTC, STUN and TURN Amitesh Madhur Cisco Systems
  • 2. Agenda  User Media  Peer Connection  STUN and TURN  Setting up STUN and TURN
  • 3. Agenda  User Media  Peer Connection  STUN and TURN  Setting up STUN and TURN
  • 4. Get User Media  getUserMedia()  Collects video audio input  Synchronization of input
  • 5. <video id=“me" autoplay></video> navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia; if (navigator.getUserMedia) { navigator.getUserMedia({video: true}, onSuccess, onError); } window.URL = window.URL || window.webkitURL; var me = document.getElementById('me'); function onSuccess(stream) { me.src = window.URL.createObjectURL(stream); } function onError(e) { // error }
  • 6. Vendor Prefixes Chrome >= 21:  webkitGetUserMedia()  window.webkitURL.createObjectURL() Opera >= 12:  getUserMedia()  set video.src Firefox >= 20:  mozGetUserMedia()  window.URL.createObjectURL() IE: not implemented Source : http://html5videoguide.net/presentations/WebDirCode2012/#page10
  • 7. Agenda  User Media  Peer Connection  STUN and TURN  Setting up STUN and TURN
  • 8. Peer Connection  Establish a connection  Pass the user media stream  Other side gets the stream  Add the received stream to <video> tag
  • 9. Peer Connection  Compression and de-compression  P2P connection using STUN or TURN  Encrypting the data
  • 10. <video id=“me" autoplay></video> <video id=“other" autoplay></video> peer = new RTCPeerConnection(servers); peer.onaddstream = gotRemoteStream; peer.addStream(localStream); if(host) { peer.createOffer(callGotOffer, null, {mandatory: { OfferToReceiveAudio: true, OfferToReceiveVideo: true}}); } else { peer.createAnswer(peer.remoteDescription, callGotOffer); } function callGotOffer(sd) { peer.setLocalDescription(sd); } function gotAnswer(desc) { peer.setRemoteDescription(new RTCSessionDescription(desc)); } function gotRemoteStream(e) { attachMediaStream(remoteVideo, e.stream); }
  • 12. Agenda  User Media  Peer Connection  STUN and TURN  Setting up STUN and TURN
  • 15. STUN and TURN peer = new RTCPeerConnection(servers);
  • 16. STUN and TURN var chrome, stun, turn, servers = {}, peer; chrome = parseInt(navigator.userAgent.match(/Chrom(e|ium)/([0-9]+)./ )[2]); stun = {url: 'stun:10.0.0.7:9999‘}; turn = {url: 'turn:amitesh@10.0.0.7:333', credential: ‘pass‘}; if (isChrome && chrome >= 28) { turn = { url: 'turn:10.0.0.7:3333', credential: 'madhur', username: 'amitesh' }; } servers.iceServers = [stun, turn]; peer = new RTCPeerConnection(servers);
  • 18. Agenda  User Media  Peer Connection  STUN and TURN  Setting up STUN and TURN
  • 19. STUN on Linux  stunprotocol.org
  • 20. STUN on Linux  Run “make”  Provides 3 libraries (stunserver, stunclient and stuntestcode)  Run stunserver --help or stunclient --help  By default runs on port 3478
  • 21. STUN on Windows  stunprotocol.org
  • 22. STUN on Windows  Unzip  goto command prompt and run server: stunserver.exe --mode full --primaryinterface 10.0.0.6 --altinterface 10.0.0.11 --altport 999 -- primaryport 9999 --verbosity 3
  • 23. TURN on Linux  Build libevent $ wget https://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz $ tar xvfz libevent-2.0.21-stable.tar.gz $ cd libevent-2.0.21-stable $ ./configure $ make $ make install
  • 24. TURN on Linux  Download TURN from https://code.google.com/p/rfc5766-turn- server $ tar xvfz turnserver.tar.gz $ ./configure $ make $ make install
  • 25. TURN on Linux  Copy the “turnserver.conf” from turnserver/examples/etc/turnserver.conf to /usr/local/etc/turnserver.conf  Changes in turnserver.conf listening-port=<new-port> listening-ip=<your ip> user=<user>:<password>
  • 26. TURN on Linux  Run turnserver turnserver -L <ip_address> IN YOUR JAVASCRIPT var turn; turn = { url: 'turn:<user-name>@<IP>:<PORT>', credential: ‘password‘ }; // for chrome 28 and above turn = { url: 'turn:<IP-address>:<PORT>', username: ‘<user-name>‘, credential: ‘<password>' };
  • 27. TURN on Windows  Install Cygwin  Make sure to install devel dependencies  Build libevent $ wget https://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz $ tar xvfz libevent-2.0.21-stable.tar.gz $ cd libevent-2.0.21-stable $ ./configure $ make $ make install
  • 28. TURN on Windows  Download TURN from https://code.google.com/p/rfc5766-turn- server $ tar xvfz turnserver.tar.gz $ ./configure $ make $ make install
  • 29. TURN on Windows  Issues during ./configure  Missing libpq.a, hiredis, postgreSql (You may Ignore them, since these are optional)  Issues during make  error: ‘struct sockaddr_in’ has no member named ‘sin_len’ Edit turnserver.version/src/client/na_turn_ioaddr.c and comment line #169// addr->s4.sin_len = sizeof(struct sockaddr_in);
  • 30. TURN on Windows  Run fixing “make” and “make install”  Copy the “turnserver.conf” from turnserver/examples/etc/turnserver.conf to /usr/local/etc/turnserver.conf  Changes in turnserver.conf listening-port=<new-port> listening-ip=<your ip> user=<user>:<password>
  • 31. TURN on Windows  Run turnserver turnserver.exe -a -r 10.0.0.6 IN YOUR JAVASCRIPT var turn; turn = { url: 'turn:<user-name>@<IP>:<PORT>', credential: ‘password‘ }; // for chrome 28 and above turn = { url: 'turn:<IP-address>:<PORT>', username: ‘<user-name>‘, credential: ‘<password>' };
  • 32. Thank you Demos : http://webrtc.googlecode.com/svn/trunk/samples/js/demos/ Twitter: @amiteshawa Facebook: facebook.com/amitesh.madhur Linkedin: in.linkedin.com/pub/amitesh-madhur/a/932/499

Notas do Editor

  1. chrome://webrtc-internals/
  2. STUN – session traversal utilities for NAT