Created
April 11, 2020 09:03
-
-
Save Abhi1code/df7efc3ab426c8cb8a53cfbe5cf8fd29 to your computer and use it in GitHub Desktop.
This file contains hidden or 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(); | |
List<PeerConnection.IceServer> iceServers = new ArrayList<>(); | |
iceServers.add(PeerConnection.IceServer.builder("stun:stun2.1.google.com:19302").createIceServer()); | |
iceServers.add(PeerConnection.IceServer.builder("turn:numb.viagenie.ca") | |
.setUsername("[email protected]") | |
.setPassword("muazkh") | |
.createIceServer()); | |
PeerConnection.RTCConfiguration rtcConfig = | |
new PeerConnection.RTCConfiguration(iceServers); | |
peerConnection = peerConnectionFactory.createPeerConnection(rtcConfig, new CustomPeerConnectionObserver() { | |
@Override | |
public void onIceCandidate(IceCandidate iceCandidate) { | |
super.onIceCandidate(iceCandidate); | |
} | |
@Override | |
public void onDataChannel(DataChannel dataChannel) { | |
super.onDataChannel(dataChannel); | |
} | |
@Override | |
public void onIceConnectionChange(PeerConnection.IceConnectionState iceConnectionState) { | |
super.onIceConnectionChange(iceConnectionState); | |
if(iceConnectionState != null){ | |
if(iceConnectionState == PeerConnection.IceConnectionState.CONNECTED){ | |
} | |
if(iceConnectionState == PeerConnection.IceConnectionState.CLOSED){ | |
} | |
if(iceConnectionState == PeerConnection.IceConnectionState.FAILED){ | |
} | |
} | |
} | |
}); | |
if(peerConnection == null){ | |
return; | |
} | |
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); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment