Skip to content

haiyangwu/mediasoup-client-android

Repository files navigation

mediasoup-client-android

Codacy Badge

maven

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 'io.github.haiyangwu:mediasoup-client:3.4.0'

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, null)
  • 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, 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

Bugs and Feedback

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

Author

Haiyang Wu(@haiyangwu at Github)

License

MIT