Skip to content

Dekalabs/mediasoup-client-android

 
 

Repository files navigation

mediasoup-client-android

Bintray Codacy Badge

mediasoup android client side library https://mediasoup.org

Getting Started

Setting up the dependency

Include mediasoup-client-android into your project, for example, as a Gradle compile dependency:

implementation 'org.mediasoup.droid:mediasoup-client:3.0.8-beta-3'

Example

  • Initialize MediasoupClient
MediasoupClient.initialize(getApplicationContext());
  • Create Device and load routerRtpCapabilities
Device mMediasoupDevice = new Device();
// ...
// routerRtpCapabilities, the response of request `getRouterRtpCapabilities` from mediasoup-demo server
mMediasoupDevice.load(routerRtpCapabilities)
  • Create SendTransport and produce MediaStreamTrack
// ...
// res, the response of request `createWebRtcTransport` from mediasoup-demo server
JSONObject info = new JSONObject(res);
String id = info.optString("id");
String iceParameters = info.optString("iceParameters");
String iceCandidates = info.optString("iceCandidates");
String dtlsParameters = info.optString("dtlsParameters");
String sctpParameters = info.optString("sctpParameters");

SendTransport mSendTransport =
  mMediasoupDevice.createSendTransport(
  sendTransportListener, id, iceParameters, iceCandidates, dtlsParameters);
// ...
// mLocalVideoTrack, created by `org.webrtc.PeerConnectionFactory`
Producer mCamProducer =
  mSendTransport.produce(
  producer -> {
    Logger.e(TAG, "onTransportClose(), camProducer");
  },
  mLocalVideoTrack, null, null);
  • Create RecvTransport and consume MediaStreamTrack
// ...
// res, the response of request `createWebRtcTransport` from mediasoup-demo server
JSONObject info = new JSONObject(res);
String id = info.optString("id");
String iceParameters = info.optString("iceParameters");
String iceCandidates = info.optString("iceCandidates");
String dtlsParameters = info.optString("dtlsParameters");
String sctpParameters = info.optString("sctpParameters");

RecvTransport mRecvTransport =
  mMediasoupDevice.createRecvTransport(
  recvTransportListener, id, iceParameters, iceCandidates, dtlsParameters);

// ...
// request, the request `newConsumer` from mediasoup-demo server
JSONObject data = request.getData();
String peerId = data.optString("peerId");
String producerId = data.optString("producerId");
String id = data.optString("id");
String kind = data.optString("kind");
String rtpParameters = data.optString("rtpParameters");
String type = data.optString("type");
String appData = data.optString("appData");
Consumer consumer =
  mRecvTransport.consume(
  c -> {
    Logger.w(TAG, "onTransportClose for consume");
  },
  id, producerId, kind, rtpParameters, appData);

Dependencies

  • libmediasoupclient mediasoup client side C++ library which supported by mediasoup team
  • webrtc-android-build my personal webrtc android prebuilt static library which may be compiled with some patch

Demo Project

mediasoup-demo-android

TODO

  • sync to the latest version of libmediasoupclient and adapter to webrtc m79
  • support DataProducer etc
  • add convenient Gradle Tasks for sync, compile and so on
  • add script to use generate-jni to automatic generate `xxx-jni.h
  • add java MediaSoupClientException mapping to `MediaSoupClientErrors.hpp
  • document

Bugs and Feedback

For bugs, feature requests, and discussion please use GitHub Issues.

Author

Haiyang Wu(@haiyangwu at Github)

License

MIT

Packages

No packages published

Languages

  • C++ 80.0%
  • C 5.7%
  • Python 5.4%
  • Java 5.0%
  • Objective-C++ 1.9%
  • Objective-C 1.2%
  • Other 0.8%