# HG changeset patch
# Node ID 2528b48c8ca2
# Parent  74a04628357f
diff --git a/libpurple/protocols/demo/meson.build b/libpurple/protocols/demo/meson.build
--- a/libpurple/protocols/demo/meson.build
+++ b/libpurple/protocols/demo/meson.build
@@ -11,6 +11,8 @@ DEMO_SOURCES = [
 	'purpledemoprotocolclient.h',
 	'purpledemoprotocolim.c',
 	'purpledemoprotocolim.h',
+	'purpledemoprotocolmedia.c',
+	'purpledemoprotocolmedia.h',
 ]
 
 if DYNAMIC_DEMO
diff --git a/libpurple/protocols/demo/purpledemocontacts.c b/libpurple/protocols/demo/purpledemocontacts.c
--- a/libpurple/protocols/demo/purpledemocontacts.c
+++ b/libpurple/protocols/demo/purpledemocontacts.c
@@ -128,6 +128,9 @@ purple_demo_protocol_load_buddies(Purple
 			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);
diff --git a/libpurple/protocols/demo/purpledemoprotocol.c b/libpurple/protocols/demo/purpledemoprotocol.c
--- a/libpurple/protocols/demo/purpledemoprotocol.c
+++ b/libpurple/protocols/demo/purpledemoprotocol.c
@@ -24,6 +24,7 @@
 #include "purpledemoprotocolactions.h"
 #include "purpledemoprotocolclient.h"
 #include "purpledemoprotocolim.h"
+#include "purpledemoprotocolmedia.h"
 
 #include "purpledemocontacts.h"
 
@@ -85,6 +86,8 @@ G_DEFINE_DYNAMIC_TYPE_EXTENDED(
 	                              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
diff --git a/libpurple/protocols/demo/purpledemoprotocolmedia.h b/libpurple/protocols/demo/purpledemoprotocolmedia.h
new file mode 100644
--- /dev/null
+++ b/libpurple/protocols/demo/purpledemoprotocolmedia.h
@@ -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 */
diff --git a/libpurple/protocols/demo/purpledemoprotocolmedia.c b/libpurple/protocols/demo/purpledemoprotocolmedia.c
new file mode 100644
--- /dev/null
+++ b/libpurple/protocols/demo/purpledemoprotocolmedia.c
@@ -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;
+}
