changeset 26113:7bbac147f276

Convert the GTalk code to completely use the new ready signal.
author Mike Ruprecht <maiku@soc.pidgin.im>
date Tue, 13 Jan 2009 06:48:30 +0000
parents 027ce238eb40
children 2809a63dbadf 62b41bb71a60
files libpurple/protocols/jabber/google.c
diffstat 1 files changed, 34 insertions(+), 62 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/jabber/google.c	Tue Jan 13 06:30:29 2009 +0000
+++ b/libpurple/protocols/jabber/google.c	Tue Jan 13 06:48:30 2009 +0000
@@ -98,34 +98,6 @@
 }
 
 static void
-google_session_send_accept(GoogleSession *session)
-{
-	xmlnode *sess, *desc, *payload;
-	GList *codecs = purple_media_get_codecs(session->media, "google-voice");
-	JabberIq *iq = jabber_iq_new(session->js, JABBER_IQ_SET);
-
-	xmlnode_set_attrib(iq->node, "to", session->remote_jid);
-	sess = google_session_create_xmlnode(session, "accept");
-	xmlnode_insert_child(iq->node, sess);
-	desc = xmlnode_new_child(sess, "description");
-	xmlnode_set_namespace(desc, "http://www.google.com/session/phone");
-
-	for (;codecs; codecs = codecs->next) {
-		PurpleMediaCodec *codec = (PurpleMediaCodec*)codecs->data;
-		char id[8], clockrate[10];
-		payload = xmlnode_new_child(desc, "payload-type");
-		g_snprintf(id, sizeof(id), "%d", codec->id);
-		g_snprintf(clockrate, sizeof(clockrate), "%d", codec->clock_rate);
-		xmlnode_set_attrib(payload, "name", codec->encoding_name);
-		xmlnode_set_attrib(payload, "id", id);
-		xmlnode_set_attrib(payload, "clockrate", clockrate);
-	}
-
-	purple_media_codec_list_free(codecs);
-	jabber_iq_send(iq);
-}
-
-static void
 google_session_send_terminate(GoogleSession *session)
 {
 	xmlnode *sess;
@@ -140,7 +112,7 @@
 }
 
 static void 
-google_session_candidates_prepared (PurpleMedia *media, gchar *session_id,
+google_session_send_candidates(PurpleMedia *media, gchar *session_id,
 		gchar *participant, GoogleSession *session)
 {
 	JabberIq *iq = jabber_iq_new(session->js, JABBER_IQ_SET);
@@ -204,38 +176,42 @@
 				session->js->user->node,
 				session->js->user->domain,
 				session->js->user->resource);
+		JabberIq *iq = jabber_iq_new(session->js, JABBER_IQ_SET);
+		xmlnode *sess, *desc, *payload;
+		GList *codecs, *iter;
+
 		if (!strcmp(session->id.initiator, me)) {
-			JabberIq *iq = jabber_iq_new(session->js, JABBER_IQ_SET);
-			xmlnode *sess, *desc, *payload;
-			GList *codecs, *iter;
-
-			sess = google_session_create_xmlnode(session, "initiate");
-			xmlnode_insert_child(iq->node, sess);
 			xmlnode_set_attrib(iq->node, "to", session->remote_jid);
 			xmlnode_set_attrib(iq->node, "from", session->id.initiator);
-			desc = xmlnode_new_child(sess, "description");
-			xmlnode_set_namespace(desc, "http://www.google.com/session/phone");
+			sess = google_session_create_xmlnode(session, "initiate");
+		} else {
+			xmlnode_set_attrib(iq->node, "to", session->remote_jid);
+			xmlnode_set_attrib(iq->node, "from", me);
+			sess = google_session_create_xmlnode(session, "accept");
+		}
+		xmlnode_insert_child(iq->node, sess);
+		desc = xmlnode_new_child(sess, "description");
+		xmlnode_set_namespace(desc, "http://www.google.com/session/phone");
+
+		codecs = purple_media_get_codecs(media, "google-voice");
 
-			codecs = purple_media_get_codecs(media, "google-voice");
-	
-			for (iter = codecs; iter; iter = g_list_next(iter)) {
-				PurpleMediaCodec *codec = (PurpleMediaCodec*)iter->data;
-				gchar *id = g_strdup_printf("%d", codec->id);
-				gchar *clock_rate = g_strdup_printf("%d", codec->clock_rate);
-				payload = xmlnode_new_child(desc, "payload-type");
-				xmlnode_set_attrib(payload, "id", id);
-				xmlnode_set_attrib(payload, "name", codec->encoding_name);
-				xmlnode_set_attrib(payload, "clockrate", clock_rate);
-				g_free(clock_rate);
-				g_free(id);
-			}
-			purple_media_codec_list_free(codecs);
+		for (iter = codecs; iter; iter = g_list_next(iter)) {
+			PurpleMediaCodec *codec = (PurpleMediaCodec*)iter->data;
+			gchar *id = g_strdup_printf("%d", codec->id);
+			gchar *clock_rate = g_strdup_printf("%d", codec->clock_rate);
+			payload = xmlnode_new_child(desc, "payload-type");
+			xmlnode_set_attrib(payload, "id", id);
+			xmlnode_set_attrib(payload, "name", codec->encoding_name);
+			xmlnode_set_attrib(payload, "clockrate", clock_rate);
+			g_free(clock_rate);
+			g_free(id);
+		}
+		purple_media_codec_list_free(codecs);
 
-			jabber_iq_send(iq);
-	
-			google_session_candidates_prepared(session->media,
-					"google-voice", session->remote_jid, session);
-		}
+		jabber_iq_send(iq);
+
+		google_session_send_candidates(session->media,
+				"google-voice", session->remote_jid, session);
 	}
 }
 
@@ -327,8 +303,6 @@
 
 	g_signal_connect(G_OBJECT(session->media), "ready-new",
 			G_CALLBACK(google_session_ready), session);
-	g_signal_connect_swapped(G_OBJECT(session->media), "accepted",
-			G_CALLBACK(google_session_send_accept), session);
 	g_signal_connect(G_OBJECT(session->media), "state-changed",
 			G_CALLBACK(google_session_state_changed_cb), session);
 	purple_media_ready(session->media);
@@ -389,10 +363,8 @@
 
 	purple_media_set_remote_codecs(session->media, "google-voice", session->remote_jid, codecs);
 
-	g_signal_connect_swapped(G_OBJECT(session->media), "accepted",
-				 G_CALLBACK(google_session_send_accept), session);
-	g_signal_connect(G_OBJECT(session->media), "candidates-prepared", 
-			 G_CALLBACK(google_session_candidates_prepared), session);
+	g_signal_connect(G_OBJECT(session->media), "ready-new",
+			G_CALLBACK(google_session_ready), session);
 	g_signal_connect(G_OBJECT(session->media), "state-changed",
 			G_CALLBACK(google_session_state_changed_cb), session);
 	purple_media_ready(session->media);