Skip to content

Commit

Permalink
doc
Browse files Browse the repository at this point in the history
  • Loading branch information
pchab committed Apr 2, 2015
1 parent 50287f9 commit b6cd373
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/src/main/java/fr/pchab/androidrtc/RtcActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import java.util.List;

public class RtcActivity extends Activity implements WebRtcClient.RTCListener {
public class RtcActivity extends Activity implements WebRtcClient.RtcListener {
private final static int VIDEO_CALL_SENT = 666;
private static final String VIDEO_CODEC_VP9 = "VP9";
private static final String AUDIO_CODEC_OPUS = "opus";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@ public class WebRtcClient {
private MediaConstraints pcConstraints = new MediaConstraints();
private MediaStream localMS;
private VideoSource videoSource;
private RTCListener mListener;
private RtcListener mListener;
private Socket client;

public interface RTCListener{
/**
* Implement this interface to be notified of events.
*/
public interface RtcListener{
void onCallReady(String callId);

void onStatusChanged(String newStatus);
Expand Down Expand Up @@ -92,6 +95,14 @@ public void execute(String peerId, JSONObject payload) throws JSONException {
}
}

/**
* Send a message through the signaling server
*
* @param to id of recipient
* @param type type of message
* @param payload payload of message
* @throws JSONException
*/
public void sendMessage(String to, String type, JSONObject payload) throws JSONException {
JSONObject message = new JSONObject();
message.put("to", to);
Expand All @@ -111,7 +122,7 @@ private MessageHandler() {
commandMap.put("candidate", new AddIceCandidateCommand());
}

public Emitter.Listener onMessage = new Emitter.Listener() {
private Emitter.Listener onMessage = new Emitter.Listener() {
@Override
public void call(Object... args) {
JSONObject data = (JSONObject) args[0];
Expand Down Expand Up @@ -140,7 +151,7 @@ public void call(Object... args) {
}
};

public Emitter.Listener onId = new Emitter.Listener() {
private Emitter.Listener onId = new Emitter.Listener() {
@Override
public void call(Object... args) {
String id = (String) args[0];
Expand All @@ -156,6 +167,7 @@ private class Peer implements SdpObserver, PeerConnection.Observer{

@Override
public void onCreateSuccess(final SessionDescription sdp) {
// TODO: modify sdp to use pcParams prefered codecs
try {
JSONObject payload = new JSONObject();
payload.put("type", sdp.type.canonicalForm());
Expand Down Expand Up @@ -252,7 +264,7 @@ private void removePeer(String id) {
endPoints[peer.endPoint] = false;
}

public WebRtcClient(RTCListener listener, String host, PeerConnectionParameters params, EGLContext mEGLcontext) {
public WebRtcClient(RtcListener listener, String host, PeerConnectionParameters params, EGLContext mEGLcontext) {
mListener = listener;
pcParams = params;
PeerConnectionFactory.initializeAndroidGlobals(listener, true, true,
Expand All @@ -277,14 +289,23 @@ public WebRtcClient(RTCListener listener, String host, PeerConnectionParameters
pcConstraints.optional.add(new MediaConstraints.KeyValuePair("DtlsSrtpKeyAgreement", "true"));
}

/**
* Call this method in Activity.onPause()
*/
public void onPause() {
if(videoSource != null) videoSource.stop();
}

/**
* Call this method in Activity.onResume()
*/
public void onResume() {
if(videoSource != null) videoSource.restart();
}

/**
* Call this method in Activity.onDestroy()
*/
public void onDestroy() {
for (Peer peer : peers.values()) {
peer.pc.dispose();
Expand All @@ -300,6 +321,14 @@ private int findEndPoint() {
return MAX_PEER;
}

/**
* Start the client.
*
* Set up the local stream and notify the signaling server.
* Call this method after onCallReady.
*
* @param name client name
*/
public void start(String name){
setCamera();
try {
Expand Down

0 comments on commit b6cd373

Please sign in to comment.