In the next is WEBRTC development novice, at present encountered a problem, turned over to have not understood. Maybe English is not good, look at the document to see blindfolded, so has not found a solution.
Development environment:
node. JS Server built
I'm using Socket.io to do communications now.
Development Purpose:
A classmate to B students to initiate a request, B received after the two sides live video.
If there is a clear classmate trouble tell me ha, really trouble everyone O (∩_∩) o~~
Problem Description:
Currently in the two-person video demo, but on both sides of the signal exchange information problems. The console prints it out like this:
The code is as follows:
1 varServers =NULL;2 3 functionTrace (text) {4Console.log ((Performance.now ()/+). ToFixed (3) + ":" +text);5 }6 7 //Creating an Peerconnection instance8Localpeerconnection =Newrtcpeerconnection (servers);9Trace ("Created local Peer Connection object Localpeerconnection");Ten ALocalpeerconnection.onicecandidate =function(evt) { - -Socket.send (json.stringify ({"Candidate": Evt.candidate}); the -Trace ("Local ICE candidate: \ n" +evt.candidate.candidate); - - } + -Localpeerconnection.onaddstream =function(evt) { +REMOTEVIDEO.SRC =Url.createobjecturl (evt.stream); ATrace ("Add remote stream to other peer") at }; - - Localpeerconnection.addstream (localstream); -Trace ("Added Localstream to Localpeerconnection"); - - if(iscaller) { in Localpeerconnection.createoffer (gotdescription, handleError); - to } + Else{ - Localpeerconnection.createanswer (localpeerconnection.remotedescription, gotdescription); the } * $ }Panax Notoginseng - functiongotdescription (evt) { the + localpeerconnection.setlocaldescription (evt); ASocket.send (json.stringify ({"SDP": evt}); the } + -Socket.on (' Pushmessagedone ',function(evt) { $ $ if(!localpeerconnection) { -Console.log (1); -Callfalse); the } - Wuyi varSignal =Json.parse (evt); the - if(SIGNAL.SDP) { Wu -Localpeerconnection.setremotedescription (Newrtcsessiondescription (SIGNAL.SDP)); About}Else { $ -Localpeerconnection.addicecandidate (Newrtcicecandidate (signal.candidate)); - } - }); A + the functionHandleError () {}
Ask a question: about WEBRTC communication