@Override
public synchronized void onContentRequest(
WebRtcContentSession contentSession) throws Exception {
String contentId = contentSession.getContentId();
if (firstWebRtcEndpoint == null) {
MediaPipeline mp = contentSession.getMediaPipelineFactory()
.create();
contentSession.releaseOnTerminate(mp);
firstWebRtcEndpoint = mp.newWebRtcEndpoint().build();
sessionId = contentSession.getSessionId();
contentSession.releaseOnTerminate(firstWebRtcEndpoint);
firstWebRtcEndpoint.connect(firstWebRtcEndpoint);
if (contentId != null && contentId.equalsIgnoreCase("record")) {
RecorderEndpoint recorderEndPoint = mp.newRecorderEndpoint(
"file:///tmp/master").build();
contentSession.setAttribute("recorder", recorderEndPoint);
firstWebRtcEndpoint.connect(recorderEndPoint);
}
contentSession.start(firstWebRtcEndpoint);
} else {
MediaPipeline mp = firstWebRtcEndpoint.getMediaPipeline();
WebRtcEndpoint newWebRtcEndpoint = mp.newWebRtcEndpoint().build();
contentSession.releaseOnTerminate(newWebRtcEndpoint);
newWebRtcEndpoint.connect(firstWebRtcEndpoint);
firstWebRtcEndpoint.connect(newWebRtcEndpoint);
if (contentId != null && contentId.equalsIgnoreCase("record")) {
RecorderEndpoint recorderEndPoint = mp.newRecorderEndpoint(
"file:///tmp/peer").build();
contentSession.setAttribute("recorder", recorderEndPoint);
newWebRtcEndpoint.connect(recorderEndPoint);
}