WebRTC Voice Chat Using Firebase

2019-02-21 07:16发布

问题:

I have never tried webrtc before. I have an application made using Firebase. Now I'm trying to add voice call feature in it.

So tried searching for some tutorials, Most are using PubNub or most tutorials are based on web app.

I saw this stackoverflow thread and knew that it's possible to use webrtc using Firebase.

Voice calls over a Chat app using Firebase

After trying some tutorials, I wrote this code,

    PeerConnectionFactory.initializeAndroidGlobals(this,false,true,true);
    PeerConnectionFactory peerConnectionFactory = new PeerConnectionFactory();
    AudioSource audioSource = peerConnectionFactory.createAudioSource(new MediaConstraints());
    AudioTrack audioTrack = peerConnectionFactory.createAudioTrack("4444",audioSource);
    audioTrack.setEnabled(true);
    MediaStream mediaStream = peerConnectionFactory.createLocalMediaStream("4444");
    mediaStream.addTrack(audioTrack);

But then I'm confused how to share the stream with other devices using Firebase. Need Help :(

回答1:

AFAIK I don't think Firebase has any support for voice calls for now .

On other hand WebRTC((Web Real-Time Communication) is a free, open-source project that provides web browsers and mobile applications with real-time communication (RTC) via simple application programming interfaces (APIs).

Basically what you need is a Socket for signalling with SignallingServer and PeerConnection for establishing the connection between two clients. Below are some links to start with.

  1. Get started
  2. Step wise Sample for android

SignallingServer implementation also provided in the sample. You will going to need NODE.JS to run it . WebRTC is pretty amazing.

If you want to use Firebase as SignallingServer you can use it. But i think it will an overhead Whereas a simple Socket can work .