cpw.malu.xmpp.google_ft: ea80a29a: Send local candidates to the other clien...

malu at pidgin.im malu at pidgin.im
Sun Sep 12 17:30:54 EDT 2010


----------------------------------------------------------------------
Revision: ea80a29a5a149750a33e39367ba205e73ff9b06d
Parent:   a2b4d45631c0eea4d0d0b5e3f6eca3d953ae7f54
Author:   malu at pidgin.im
Date:     09/12/10 17:26:19
Branch:   im.pidgin.cpw.malu.xmpp.google_ft
URL: http://d.pidgin.im/viewmtn/revision/info/ea80a29a5a149750a33e39367ba205e73ff9b06d

Changelog: 

Send local candidates to the other client

Changes against parent a2b4d45631c0eea4d0d0b5e3f6eca3d953ae7f54

  patched  libpurple/protocols/jabber/google/google_share.c

-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/google/google_share.c	f4386b8a2d1c99e2b2d56bb7bc4c58bf802c1412
+++ libpurple/protocols/jabber/google/google_share.c	5ec92fb74eb96c30c11b0aa295867121003f7e4f
@@ -44,6 +44,72 @@ static void
 }
 
 static void
+google_share_writable_cb(NiceAgent *agent, guint stream_id, guint compont_id,
+	gpointer user_data)
+{
+	purple_debug_info("google-share", "tranport writable!\n");
+}
+
+static xmlnode *
+google_share_nice_candidate_to_xml(const NiceCandidate *cand)
+{
+	xmlnode *candidate = xmlnode_new("candidate");
+	gchar address[NICE_ADDRESS_STRING_LEN];
+	gchar pref[16];
+	
+	nice_address_to_string(&cand->addr, address);
+	xmlnode_set_attrib(candidate, "address", address);
+	xmlnode_set_attrib(candidate, "port",
+		g_strdup_printf("%d", nice_address_get_port(&cand->addr)));
+	xmlnode_set_attrib(candidate, "name", "rtp");
+	xmlnode_set_attrib(candidate, "username", cand->username);
+	xmlnode_set_attrib(candidate, "password",
+		cand->password != NULL ? cand->password : "");
+	g_ascii_dtostr(pref, 16, cand->priority / 1000.0);
+	xmlnode_set_attrib(candidate, "preference", pref);
+	xmlnode_set_attrib(candidate, "protocol",
+		cand->transport == NICE_CANDIDATE_TRANSPORT_UDP ? "udp" : "tcp");
+	xmlnode_set_attrib(candidate, "type",
+	    cand->type == NICE_CANDIDATE_TYPE_HOST ? "host" :
+		cand->type == NICE_CANDIDATE_TYPE_SERVER_REFLEXIVE ? "stun" :
+		cand->type == NICE_CANDIDATE_TYPE_RELAYED ? "relay" : "host");
+	xmlnode_set_attrib(candidate, "generation", "0");
+	xmlnode_set_attrib(candidate, "network", "0");
+
+	return candidate;
+}
+
+static void
+google_share_candidate_gathering_done_cb(NiceAgent *agent,
+    guint stream_id, gpointer user_data)
+{
+	GoogleSession *session = (GoogleSession *) user_data;
+	GoogleShareSessionData *session_data =
+		(GoogleShareSessionData *) session->session_data;
+	GSList *candidates = nice_agent_get_local_candidates(agent,
+		session_data->stream_id, NICE_COMPONENT_TYPE_RTP);
+
+	purple_debug_info("google-share", "candidate gathering done!\n");
+
+	while (candidates) {
+		NiceCandidate *candidate = (NiceCandidate *) candidates->data;
+		JabberIq *iq = jabber_iq_new(session->js, JABBER_IQ_SET);
+		xmlnode *sess =
+			google_session_create_xmlnode(session, "candidates");
+
+		xmlnode_insert_child(iq->node, sess);
+		xmlnode_set_attrib(iq->node, "to", session->remote_jid);
+		xmlnode_insert_child(sess,
+			google_share_nice_candidate_to_xml(candidate));
+
+		jabber_iq_send(iq);
+
+		nice_candidate_free(candidate);
+		candidates = g_slist_delete_link(candidates, candidates);
+	}
+}
+
+static void
 google_share_data_received_cb(NiceAgent *agent, guint stream_id,
 	guint component_id, guint len, gchar *buf, gpointer user_data)
 {
@@ -77,6 +143,12 @@ google_share_init(PurpleXfer *xfer)
 	nice_agent_attach_recv(session_data->agent, session_data->stream_id,
 	    NICE_COMPONENT_TYPE_RTP, g_main_context_default(),
 	    google_share_data_received_cb, session);
+	g_signal_connect(G_OBJECT(session_data->agent),
+		"candidate-gathering-done",
+	    G_CALLBACK(google_share_candidate_gathering_done_cb), session);
+	g_signal_connect(G_OBJECT(session_data->agent),
+	    "reliable-transport-writable",
+	    G_CALLBACK(google_share_writable_cb), session);
 }
 
 static void
@@ -87,7 +159,7 @@ google_share_init_agent(GoogleSession *s
 	GoogleShareSessionData *session_data =
 		(GoogleShareSessionData *) session->session_data;
 	NiceAgent *agent = nice_agent_new_reliable(g_main_context_default(),
-			                                           NICE_COMPATIBILITY_GOOGLE);
+		NICE_COMPATIBILITY_GOOGLE);
 	guint stream_id = nice_agent_add_stream(agent, 1);
 	const gchar *stun_ip = purple_network_get_stun_ip() ?
 		purple_network_get_stun_ip() : session->js->stun_ip;


More information about the Commits mailing list