Why does the WebRTC stream to peer sample have two RTCPeerConnection objects - webrtc

I am studying this sample and working to modify it so that video can be streamed from one browser instance and then appear on the second instance.
I have a few questions:
Is the reason that the ICEServers array is empty because of localhost? Would this still be okay running on two browser instances?
I also don't understand why there are two RTCPeerConnection objects? Shouldn't there only be a single object since the RTCPeerConnection class contains methods for both local and remote?

Related

Second RTCPeerConnection stuck in "connecting" state, while first connection successfully connects

So I'm trying to set up a 3-way video call with WebRTC.
The first two connections connect fine. I have it set up so that the third person to join the room sends an offer to the first 2 sockets in the room (I'm using Node.js socket.io as a signalling server). The offer successfully sends to both sockets, and both sockets send back their answers. Both answers contain 1 audio track and 1 video track, however, for some reason, the connection only works with one of them.
The result is that with 3 users, the first user (usually) ends up seeing both peers, and then the second and third people only see one other person. When I look at the connectionState for each peer connection, one of them is stuck in "connecting", while everything else looks fine.
Any ideas?
Are you creating a new PeerConnection for the first two people in the room? When you say first 2 sockets it sounds like you are trying to use the same PeerConnection for multiple connections.
Each PeerConnection is only for a 1:1 connection. What you are trying to create is a Mesh Topology I believe.

webRTC to setup signaling server

how to setup a signaling server for webRTC when the system are connected in Local Area Network? Its mandatory that we must use STUN and TURN server for signaling?
To make WebRTC run on LAN, you will require to have a signaling server in that LAN. A signaling server is any web server that will allow your web clients to exchange the SDP offer/answer and ICE candidates that are generated by the WebRTC PeerConnection. This can be done using AJAX or WebSockets.
I have listed some top sources for information about WebRTC. Please go through some of the links on that page to better understand how the WebRTC signaling works.
You will not require a STUN/TURN server as your WebRTC clients (i.e. Web Browser) will be in the LAN and accessible to each other. FYI... STUN/TURN servers are not part of the signaling but part of the media leg and usually required for NAT traversals of media.
Webrtc needs some kind of signalling system for initial negotiation.. like transferring SDP, ICE-candidates, sending and receiving offers etc... rest is done by peer-peer connection. For initial signalling you can use any technique like sending AJAX calls, using socket.io etc.
STUN and TURN servers are required for NAT traversal, NAT traversal is important because it is needed for determining the path between peers. You can use google provided STUN/TURN server address stun:stun.l.google.com:19302 etc , or you can configure your own turn server by using rfc-5766 turn server
Making signalling server for WebRTC is quite easy.
I used PHP, MYSQL and AJAX to maintain signalling data.
Suppose A wants to call B.
Then A creates offer using createOffer method. This method returns an offer object.
You have to transfer this offer object to user B, This is a part of signalling process.
Now create MYSQL database, having columns :
caller, callee, offer, answer, callerICE and calleeICE
Now offer created by A is stored in offer attribute with the help of AJAX call .
(Remember to use JSON.stringify the JS object before "POSTing" object to server.)
Now user B scans this offer attribute created by caller A , again with the help of AJAX call.
In this way , offer object created at user A can arrive at user B.
Now, user B responds to the offer by calling createAnswer method. This method returns answer object. This can again be stored in "answer" attribute of database.
Then the caller A scans this "answer" attribute created by callee B.
In this way, answer object created by B can arrive at A.
To store iceCandidate object representing caller A, use "callerIce" attribute of MYSQL table. Note that, callee B is scanning "callerIce" to know the details of caller A.
In this way we can transfer the iceCandidate objects representing future peer.
After you complete transferring of iceCandidate object, the connectionState property holds "connected" indicating two peers are connected.
If any questions, let me know!
Cheers ! You can now share local media stream to the remote peer.

Is it possible to use webRTC to send a stream to a peer without him sending his local stream to you?

I am trying to create an application which requires a user to send his local video stream to multiple peers using webRTC. As far as I've seen I am responsible for managing several PeerConnection objects because a PeerConnection can only connect to a single peer at a time. What I want to know is if it is possible to create a connection and send my local stream to a peer without him sendig his local stream to me using webRTC.
Simply don't call peer.addStream for broadcast-viewers to make it oneway streaming!
You can disable audio/video media lines in the session description by setting OfferToReceiveAudio and OfferToReceiveVideo to false.
3-Way handshake isn't drafted by RTCWebb IETF WG, yet.
Because browser needs to take care of a lot stuff simultaneously like multi-tracks and multi-media lines; where each m-line should point out a unique peer.

Sending a local stream to multiple remote peers

How do I send my local video stream to multiple remote peers? Do I need to instantiate one PeerConnection per remote peer? Or can the same PeerConnection be used for all remote peers at the same time?
According to user dom on #webrtc on irc.w3.org, each PeerConnection is associated with a single remote peer. The developer is responsible for sharing the same stream instance with multiple PeerConnections:
<Cow_woC> Can a single PeerConnection connect to multiple remote peers, or only a single one at a time? If I want to stream the same video to multiple remote peers, what am I supposed to do?
<dom> Cow_woC, you need to manage several PeerConnection objects
<dom> and plug your video stream to each of them
<Cow_woC> dom: How do I share the camera feed with multiple PeerConnections? Is getUserMedia() allowed to return the same resource (and share it) multiple times?
<Cow_woC> dom: Or am I responsible for keeping the reference around and passing it to multiple PeerConnections?
<dom> the latter

How to add a socket as QTCaptureOutputs for a QTCaptureSession

I'm reading Apple's documentation on using QTKit to capture streaming audio and video from input sources. I read that the central class QTCaptureSession handles the input and sends it to every possible output (QTCaptureOutput). The documentation lists six subclasses of QTCaptureOutput (e.g., QTCaptureMovieFileOutput).
I would like to create a subclass of QTCaptureOutput to write to an NSSocket so I could send the video stream over to another machine.
Any ideas would be appreciated.
QTCaptureOutput does not strike me as a class designed to be subclassed outside of QTKit. Instead, you can try dumping the data to a local domain socket in the file system using a QTCaptureFileOutput object, and simultaneously pulling the data from that local domain socket and sending it over to the remote machine.