Skip to content

Instantly share code, notes, and snippets.

@samiy-xx
Created March 21, 2013 12:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samiy-xx/5212544 to your computer and use it in GitHub Desktop.
Save samiy-xx/5212544 to your computer and use it in GitHub Desktop.
WebRTC Fail
import 'dart:html';
void main() {
RtcPeerConnection pc1 = new RtcPeerConnection(null);
RtcPeerConnection pc2 = new RtcPeerConnection(null);
pc1.onAddStream.listen((MediaStreamEvent e) {
print("pc1 got stream");
});
pc2.onAddStream.listen((MediaStreamEvent e) {
print("pc2 got stream");
});
pc1.onIceCandidate.listen((RtcIceCandidateEvent e) {
if (e.candidate != null)
pc2.addIceCandidate(e.candidate);
});
pc2.onIceCandidate.listen((RtcIceCandidateEvent e) {
if (e.candidate != null)
pc1.addIceCandidate(e.candidate);
});
pc1.onNegotiationNeeded.listen((Event e) {
pc1.createOffer({}).then((RtcSessionDescription sdp) {
pc1.setLocalDescription(sdp);
pc2.setRemoteDescription(sdp);
pc2.createAnswer({}).then((RtcSessionDescription sdp2) {
pc2.setLocalDescription(sdp2);
pc1.setRemoteDescription(sdp2);
});
});
});
if (MediaStream.supported) {
window.navigator.getUserMedia(audio: true, video: true).then((LocalMediaStream stream) {
pc1.addStream(stream);
pc2.addStream(stream);
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment