/soc/2013/ashmew2/filetransferX: 34932967acb7: Setting up NiceAgent

Ashish Gupta ashmew2 at gmail.com
Wed Aug 14 15:00:42 EDT 2013


Changeset: 34932967acb73b0d1da4dda95e11373be6bea4fa
Author:	 Ashish Gupta <ashmew2 at gmail.com>
Date:	 2013-08-14 00:05 +0530
Branch:	 filetransferX
URL: https://hg.pidgin.im/soc/2013/ashmew2/filetransferX/rev/34932967acb7

Description:

Setting up NiceAgent

diffstat:

 libpurple/protocols/jabber/google/google_session.c |  120 +++++++++++++-------
 1 files changed, 79 insertions(+), 41 deletions(-)

diffs (161 lines):

diff --git a/libpurple/protocols/jabber/google/google_session.c b/libpurple/protocols/jabber/google/google_session.c
--- a/libpurple/protocols/jabber/google/google_session.c
+++ b/libpurple/protocols/jabber/google/google_session.c
@@ -41,6 +41,11 @@ typedef struct {
 } GoogleXferSessionData; 
 
 typedef struct {
+	NiceAgent *agent;
+	guint stream_id;
+} TempStruct;
+
+typedef struct {
 	PurpleMedia *media;
 	gboolean video;
 	gboolean share;
@@ -51,7 +56,7 @@ typedef struct {
 	 							   to media (ie. after getting relay credentials */
 } GoogleAVSessionData;
 
-/*TODO: When cleaning uptypedef struct {
+/*TODO: When cleaning up typedef struct {
 
   } GoogleShareManifest;
 */
@@ -1027,63 +1032,96 @@ gtalk_port_cb(int listenfd, gpointer dat
 }
 
 void
-cb_candidate_gathering_done(void)
+cb_candidate_gathering_done(TempStruct *temp)
 {
+  guint  stream_id = temp->stream_id;
+  NiceAgent *agent = temp->agent;
+  GList *lcands = nice_agent_get_local_candidates(agent, stream_id, 1);
+
   purple_debug_info("google_session", "CANDIDATES GATHERED??\n");
+
+  if(lcands)
+	  purple_debug_info("google_session", "lcands is nOT null..\n");
+  else
+	  purple_debug_info("google_session", "lcands is NULL\n");	  
 }
 
 void
 gtalk_xfer_send_candidates(GoogleSession *session)
 {	
 
-  guint stream_id;
-  gchar buffer[] = "hello world!";
-  GSList *lcands = NULL, *rcands = NULL;
+	guint stream_id;
+	gchar buffer[] = "hello world!";
+	GSList *lcands = NULL, *rcands = NULL;
+	TempStruct *temp_struct = g_new0(TempStruct, 1);
+  
+	// Create a nice agent
+	NiceAgent *agent = nice_agent_new (NULL, NICE_COMPATIBILITY_GOOGLE);
+	JabberStream *js = session->js;
 
-  // Create a nice agent
-    NiceAgent *agent = nice_agent_new (NULL, NICE_COMPATIBILITY_GOOGLE);
+	agent->stun_server = js->stun_ip;
+	agent->stun_server_port = js->stun_port;
+	if(!g_object_get_data(G_OBJECT (agent), "stun->server")) {
+		purple_debug_info("google_session", "Agent's STUN is NULL..");
+		g_object_set_property (G_OBJECT (agent), "stun-server", js->stun_ip);
+		g_object_set_property (G_OBJECT (agent), "stun-server-port", &(js->stun_port));	    
+	}
+	else
+		purple_debug_info("google_session", "Agent's stun was not NULL.");
 
-  // Connect the signals
-    /*    g_signal_connect (G_OBJECT (agent), "candidate-gathering-done",
-      G_CALLBACK (cb_candidate_gathering_done), NULL);*/
+	purple_debug_info("google_session", "Inside send candids\n");
+	temp_struct->agent = agent;
+	// Connect the signals
+	g_signal_connect (G_OBJECT (agent), "candidate-gathering-done",
+			  G_CALLBACK (cb_candidate_gathering_done),  G_OBJECT (temp_struct));
 
-  /*  g_signal_connect (G_OBJECT (agent), "component-state-changed",
-		    G_CALLBACK (cb_component_state_changed), NULL);
-  g_signal_connect (G_OBJECT (agent), "new-selected-pair",
-		    G_CALLBACK (cb_new_selected_pair), NULL);
-  */
-  // Create a new stream with one component and start gathering candidates
+	/*  g_signal_connect (G_OBJECT (agent), "component-state-changed",
+	    G_CALLBACK (cb_component_state_changed), NULL);
+	    g_signal_connect (G_OBJECT (agent), "new-seXlected-pair",
+	    G_CALLBACK (cb_new_selected_pair), NULL);
+	*/
+	// Create a new stream with one component and start gathering candidates
   
-  stream_id = nice_agent_add_stream (agent, 1);
-  nice_agent_gather_candidates (agent, stream_id);
+	stream_id = nice_agent_add_stream (agent, 1);
+	temp_struct->stream_id = stream_id;
 
-  // Attach to the component to receive the data
-  /*  nice_agent_attach_recv (agent, stream_id, 1, NULL
-			  cb_nice_recv, NULL);
-  */
-  // ... Wait until the signal candidate-gathering-done is fired ...
-  lcands = nice_agent_get_local_candidates(agent, stream_id, 1);
+
+	if(!nice_agent_gather_candidates (agent, stream_id))
+		purple_debug_info("google_session", "Gather candidates returned FALSE\n");
+	else
+		purple_debug_info("google_session", "Gather Candidates returned TRUE\n");
+
+	return;
+	// Attach to the component to receive the data
+	/*  nice_agent_attach_recv (agent, stream_id, 1, NULL
+	    cb_nice_recv, NULL);
+
+	    /*TODO: need to add $(NICE_LIBS) and look it up with configure.ac*/
   
-  for(; lcands ; lcands=lcands->next) {
-    NiceCandidate *x = (NiceCandidate *)(lcands->data);
-    NiceAddress *address;
-    address = &(x->addr);
-    char *ip;
-    nice_address_to_string(address, ip);
-    purple_debug_info("google_session", "IP is : %s\n",ip);
-  }
-  return;
-  // ... Send local candidates to the peer and set the peer's remote candidates
-  //nice_agent_set_remote_candidates (agent, stream_id, 1, rcands);
+	// ... Wait until the signal candidate-gathering-done is fired ...
+	lcands = nice_agent_get_local_candidates(agent, stream_id, 1);
+	return;
 
-  // ... Wait until the signal new-selected-pair is fired ...
-  // Send our message!
-  //nice_agent_send (agent, stream_id, 1, sizeof(buffer), buffer);
+	for(; lcands ; lcands=lcands->next) {
+		NiceCandidate *x = (NiceCandidate *)(lcands->data);
+		NiceAddress *address;
+		address = &(x->addr);
+		char *ip;
+		nice_address_to_string(address, ip);
+		purple_debug_info("google_session", "IP is : %s\n",ip);
+	}
+	return;
+	// ... Send local candidates to the peer and set the peer's remote candidates
+	//nice_agent_set_remote_candidates (agent, stream_id, 1, rcands);
 
-  // Anything received will be received through the cb_nice_recv callback
+	// ... Wait until the signal new-selected-pair is fired ...
+	// Send our message!
+	//nice_agent_send (agent, stream_id, 1, sizeof(buffer), buffer);
 
-  // Destroy the object
-  g_object_unref(agent);
+	// Anything received will be received through the cb_nice_recv callback
+
+	// Destroy the object
+	g_object_unref(agent);
 }
 
 void



More information about the Commits mailing list