Add a stub VV implementation to demo protocol

Thu, 11 Aug 2022 21:26:10 -0500

author
Elliott Sales de Andrade <quantum.analyst@gmail.com>
date
Thu, 11 Aug 2022 21:26:10 -0500
changeset 41487
86b6cbbee778
parent 41486
92f498b16ea5
child 41488
95f59c2bc50d

Add a stub VV implementation to demo protocol

This doesn't really do anything, because libpurple without a backend doesn't do
any further signalling. But at least we'll get a contact with the option to
start a media session.

Testing Done:
Compiled and pressed the Audio/Video Call menu item.

Reviewed at https://reviews.imfreedom.org/r/1580/

libpurple/protocols/demo/meson.build file | annotate | diff | comparison | revisions
libpurple/protocols/demo/purpledemocontacts.c file | annotate | diff | comparison | revisions
libpurple/protocols/demo/purpledemoprotocol.c file | annotate | diff | comparison | revisions
libpurple/protocols/demo/purpledemoprotocolmedia.c file | annotate | diff | comparison | revisions
libpurple/protocols/demo/purpledemoprotocolmedia.h file | annotate | diff | comparison | revisions
--- a/libpurple/protocols/demo/meson.build	Thu Aug 11 21:23:28 2022 -0500
+++ b/libpurple/protocols/demo/meson.build	Thu Aug 11 21:26:10 2022 -0500
@@ -11,6 +11,8 @@
 	'purpledemoprotocolclient.h',
 	'purpledemoprotocolim.c',
 	'purpledemoprotocolim.h',
+	'purpledemoprotocolmedia.c',
+	'purpledemoprotocolmedia.h',
 ]
 
 if DYNAMIC_DEMO
--- a/libpurple/protocols/demo/purpledemocontacts.c	Thu Aug 11 21:23:28 2022 -0500
+++ b/libpurple/protocols/demo/purpledemocontacts.c	Thu Aug 11 21:26:10 2022 -0500
@@ -128,6 +128,9 @@
 			purple_demo_protocol_load_icon(account, name);
 			purple_demo_protocol_load_status(account, group, contact, buddy,
 			                                 buddy_object);
+			if (purple_strequal(name, "Echo")) {
+				purple_protocol_got_media_caps(account, name);
+			}
 		}
 
 		buddies = g_list_delete_link(buddies, buddies);
--- a/libpurple/protocols/demo/purpledemoprotocol.c	Thu Aug 11 21:23:28 2022 -0500
+++ b/libpurple/protocols/demo/purpledemoprotocol.c	Thu Aug 11 21:26:10 2022 -0500
@@ -24,6 +24,7 @@
 #include "purpledemoprotocolactions.h"
 #include "purpledemoprotocolclient.h"
 #include "purpledemoprotocolim.h"
+#include "purpledemoprotocolmedia.h"
 
 #include "purpledemocontacts.h"
 
@@ -85,6 +86,8 @@
 	                              purple_demo_protocol_client_init)
 	G_IMPLEMENT_INTERFACE_DYNAMIC(PURPLE_TYPE_PROTOCOL_IM,
 	                              purple_demo_protocol_im_init)
+	G_IMPLEMENT_INTERFACE_DYNAMIC(PURPLE_TYPE_PROTOCOL_MEDIA,
+	                              purple_demo_protocol_media_init)
 )
 
 static void
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libpurple/protocols/demo/purpledemoprotocolmedia.c	Thu Aug 11 21:26:10 2022 -0500
@@ -0,0 +1,104 @@
+/*
+ * Purple - Internet Messaging Library
+ * Copyright (C) Pidgin Developers <devel@pidgin.im>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <https://www.gnu.org/licenses/>.
+ */
+
+#include <time.h>
+
+#include <glib/gi18n-lib.h>
+
+#include "purpledemoprotocol.h"
+#include "purpledemoprotocolmedia.h"
+
+/******************************************************************************
+ * PurpleProtocolMedia Implementation
+ *****************************************************************************/
+static PurpleMediaCaps
+purple_demo_protocol_media_get_caps(G_GNUC_UNUSED PurpleProtocolMedia *media,
+                                    G_GNUC_UNUSED PurpleAccount *account,
+                                    const gchar *who)
+{
+	if(purple_strequal(who, "Echo")) {
+		return PURPLE_MEDIA_CAPS_AUDIO | PURPLE_MEDIA_CAPS_VIDEO |
+		       PURPLE_MEDIA_CAPS_AUDIO_VIDEO;
+	}
+
+	return PURPLE_MEDIA_CAPS_NONE;
+}
+
+static gboolean
+purple_demo_protocol_media_initiate_session(PurpleProtocolMedia *media,
+                                            PurpleAccount *account,
+                                            const gchar *who,
+                                            PurpleMediaSessionType type)
+{
+	PurpleConnection *connection = NULL;
+	gchar *session_name = NULL;
+	gchar *message = NULL;
+	GDateTime *timestamp = NULL;
+
+	connection = purple_account_get_connection(account);
+
+	session_name = g_flags_to_string(PURPLE_MEDIA_TYPE_SESSION_TYPE, type);
+	message = g_strdup_printf(_("Initiated demo %s session with %s"),
+	                          session_name, who);
+	timestamp = g_date_time_new_now_utc();
+
+	purple_serv_got_im(connection, "Echo",
+	                   message, PURPLE_MESSAGE_RECV,
+	                   g_date_time_to_unix(timestamp));
+
+	g_date_time_unref(timestamp);
+	g_free(message);
+	g_free(session_name);
+
+	/* TODO: When libpurple gets a backend, we can implement more of this. */
+	return FALSE;
+}
+
+static gboolean
+purple_demo_protocol_media_send_dtmf(G_GNUC_UNUSED PurpleProtocolMedia *protocol_media,
+                                     PurpleMedia *media, gchar dtmf,
+                                     guint8 volume, guint8 duration)
+{
+	PurpleAccount *account = NULL;
+	PurpleConnection *connection = NULL;
+	gchar *message = NULL;
+	GDateTime *timestamp = NULL;
+
+	account = purple_media_get_account(media);
+	connection = purple_account_get_connection(account);
+
+	message = g_strdup_printf(_("Received DTMF %c at volume %d for %d seconds"),
+	                          dtmf, volume, duration);
+	timestamp = g_date_time_new_now_utc();
+
+	purple_serv_got_im(connection, "Echo",
+	                   message, PURPLE_MESSAGE_RECV,
+	                   g_date_time_to_unix(timestamp));
+
+	g_date_time_unref(timestamp);
+	g_free(message);
+
+	return TRUE;
+}
+
+void
+purple_demo_protocol_media_init(PurpleProtocolMediaInterface *iface) {
+	iface->get_caps = purple_demo_protocol_media_get_caps;
+	iface->initiate_session = purple_demo_protocol_media_initiate_session;
+	iface->send_dtmf = purple_demo_protocol_media_send_dtmf;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libpurple/protocols/demo/purpledemoprotocolmedia.h	Thu Aug 11 21:26:10 2022 -0500
@@ -0,0 +1,28 @@
+/*
+ * Purple - Internet Messaging Library
+ * Copyright (C) Pidgin Developers <devel@pidgin.im>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <https://www.gnu.org/licenses/>.
+ */
+
+#ifndef PURPLE_DEMO_PROTOCOL_MEDIA_H
+#define PURPLE_DEMO_PROTOCOL_MEDIA_H
+
+#include <glib.h>
+
+#include <purple.h>
+
+G_GNUC_INTERNAL void purple_demo_protocol_media_init(PurpleProtocolMediaInterface *iface);
+
+#endif /* PURPLE_DEMO_PROTOCOL_MEDIA_H */

mercurial