This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apply plugin: 'com.android.application' | |
android { | |
compileSdkVersion 29 | |
buildToolsVersion "29.0.2" | |
defaultConfig { | |
applicationId "com.matr..." | |
minSdkVersion 21 | |
targetSdkVersion 29 | |
versionCode 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.m...; | |
import org.webrtc.DataChannel; | |
public class CustomDataChannelObserver implements DataChannel.Observer { | |
public CustomDataChannelObserver(){ | |
} | |
@Override |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.m...; | |
import com.mat...; | |
import org.webrtc.DataChannel; | |
import org.webrtc.IceCandidate; | |
import org.webrtc.MediaStream; | |
import org.webrtc.PeerConnection; | |
import org.webrtc.RtpReceiver; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.matrixf...n; | |
import org.webrtc.SdpObserver; | |
import org.webrtc.SessionDescription; | |
public class CustomSdpObserver implements SdpObserver { | |
public CustomSdpObserver(){ | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
peerConnection = peerConnectionFactory.createPeerConnection(rtcConfig, new CustomPeerConnectionObserver() { | |
@Override | |
public void onIceCandidate(IceCandidate iceCandidate) { | |
super.onIceCandidate(iceCandidate); | |
// | |
} | |
@Override | |
public void onDataChannel(DataChannel dataChannel) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void setIceCandidate(String candidate, String sdpmid, int sdpmlineIndex){ | |
peerConnection.addIceCandidate(new IceCandidate(sdpmid, sdpmlineIndex, candidate)); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DataChannel.Init dcInit = new DataChannel.Init(); | |
dataChannel = peerConnection.createDataChannel("1", dcInit); | |
dataChannel.registerObserver(new CustomDataChannelObserver(){ | |
@Override | |
public void onMessage(DataChannel.Buffer buffer) { | |
super.onMessage(buffer); | |
// will be called when message is received from another peer | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void initialize(){ | |
PeerConnectionFactory.InitializationOptions initializationOptions = | |
PeerConnectionFactory.InitializationOptions.builder(context) | |
.createInitializationOptions(); | |
PeerConnectionFactory.initialize(initializationOptions); | |
PeerConnectionFactory.Options options = new PeerConnectionFactory.Options(); | |
peerConnectionFactory = PeerConnectionFactory.builder().setOptions(options) | |
.createPeerConnectionFactory(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void createOffer(){ | |
peerConnection.createOffer(new CustomSdpObserver(){ | |
@Override | |
public void onCreateSuccess(SessionDescription sessionDescription) { | |
super.onCreateSuccess(sessionDescription); | |
peerConnection.setLocalDescription(new CustomSdpObserver(), sessionDescription); | |
// sessionDescription.description is string which needs to the shared across network |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void createAnswer(){ | |
peerConnection.createAnswer(new CustomSdpObserver(){ | |
@Override | |
public void onCreateSuccess(SessionDescription sessionDescription) { | |
super.onCreateSuccess(sessionDescription); | |
peerConnection.setLocalDescription(new CustomSdpObserver(), sessionDescription); | |
// sessionDescription.description is string which needs to the shared across network |
OlderNewer