mediasoup android client side library https://mediasoup.org
Include mediasoup-client-android
into your project, for example, as a Gradle compile dependency:
implementation 'io.github.haiyangwu:mediasoup-client:3.4.0'
- Initialize
MediasoupClient
MediasoupClient.initialize(getApplicationContext());
- Create
Device
and loadrouterRtpCapabilities
Device mMediasoupDevice = new Device();
// ...
// routerRtpCapabilities, the response of request `getRouterRtpCapabilities` from mediasoup-demo server
mMediasoupDevice.load(routerRtpCapabilities, null)
- Create
SendTransport
and produceMediaStreamTrack
// ...
// 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 consumeMediaStreamTrack
// ...
// 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);
- 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
For bugs, feature requests, and discussion please use GitHub Issues.
Haiyang Wu(@haiyangwu at Github)