@@ -25,10 +25,13 @@ public class WebRtcClient {
2525 private MediaConstraints pcConstraints = new MediaConstraints ();
2626 private MediaStream localMS ;
2727 private VideoSource videoSource ;
28- private RTCListener mListener ;
28+ private RtcListener mListener ;
2929 private Socket client ;
3030
31- public interface RTCListener {
31+ /**
32+ * Implement this interface to be notified of events.
33+ */
34+ public interface RtcListener {
3235 void onCallReady (String callId );
3336
3437 void onStatusChanged (String newStatus );
@@ -92,6 +95,14 @@ public void execute(String peerId, JSONObject payload) throws JSONException {
9295 }
9396 }
9497
98+ /**
99+ * Send a message through the signaling server
100+ *
101+ * @param to id of recipient
102+ * @param type type of message
103+ * @param payload payload of message
104+ * @throws JSONException
105+ */
95106 public void sendMessage (String to , String type , JSONObject payload ) throws JSONException {
96107 JSONObject message = new JSONObject ();
97108 message .put ("to" , to );
@@ -111,7 +122,7 @@ private MessageHandler() {
111122 commandMap .put ("candidate" , new AddIceCandidateCommand ());
112123 }
113124
114- public Emitter .Listener onMessage = new Emitter .Listener () {
125+ private Emitter .Listener onMessage = new Emitter .Listener () {
115126 @ Override
116127 public void call (Object ... args ) {
117128 JSONObject data = (JSONObject ) args [0 ];
@@ -140,7 +151,7 @@ public void call(Object... args) {
140151 }
141152 };
142153
143- public Emitter .Listener onId = new Emitter .Listener () {
154+ private Emitter .Listener onId = new Emitter .Listener () {
144155 @ Override
145156 public void call (Object ... args ) {
146157 String id = (String ) args [0 ];
@@ -156,6 +167,7 @@ private class Peer implements SdpObserver, PeerConnection.Observer{
156167
157168 @ Override
158169 public void onCreateSuccess (final SessionDescription sdp ) {
170+ // TODO: modify sdp to use pcParams prefered codecs
159171 try {
160172 JSONObject payload = new JSONObject ();
161173 payload .put ("type" , sdp .type .canonicalForm ());
@@ -252,7 +264,7 @@ private void removePeer(String id) {
252264 endPoints [peer .endPoint ] = false ;
253265 }
254266
255- public WebRtcClient (RTCListener listener , String host , PeerConnectionParameters params , EGLContext mEGLcontext ) {
267+ public WebRtcClient (RtcListener listener , String host , PeerConnectionParameters params , EGLContext mEGLcontext ) {
256268 mListener = listener ;
257269 pcParams = params ;
258270 PeerConnectionFactory .initializeAndroidGlobals (listener , true , true ,
@@ -277,14 +289,23 @@ public WebRtcClient(RTCListener listener, String host, PeerConnectionParameters
277289 pcConstraints .optional .add (new MediaConstraints .KeyValuePair ("DtlsSrtpKeyAgreement" , "true" ));
278290 }
279291
292+ /**
293+ * Call this method in Activity.onPause()
294+ */
280295 public void onPause () {
281296 if (videoSource != null ) videoSource .stop ();
282297 }
283298
299+ /**
300+ * Call this method in Activity.onResume()
301+ */
284302 public void onResume () {
285303 if (videoSource != null ) videoSource .restart ();
286304 }
287305
306+ /**
307+ * Call this method in Activity.onDestroy()
308+ */
288309 public void onDestroy () {
289310 for (Peer peer : peers .values ()) {
290311 peer .pc .dispose ();
@@ -300,6 +321,14 @@ private int findEndPoint() {
300321 return MAX_PEER ;
301322 }
302323
324+ /**
325+ * Start the client.
326+ *
327+ * Set up the local stream and notify the signaling server.
328+ * Call this method after onCallReady.
329+ *
330+ * @param name client name
331+ */
303332 public void start (String name ){
304333 setCamera ();
305334 try {
0 commit comments