]> git.0d.be Git - empathy.git/blob - libempathy-gtk/empathy-call-utils.c
Don't require EmpathyContacts to start a call
[empathy.git] / libempathy-gtk / empathy-call-utils.c
1 /*
2  * Copyright (C) 2011 Collabora Ltd.
3  *
4  * The code contained in this file is free software; you can redistribute
5  * it and/or modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either version
7  * 2.1 of the License, or (at your option) any later version.
8  *
9  * This file is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this code; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17  *
18  * Authors: Emilio Pozuelo Monfort <emilio.pozuelo@collabora.co.uk>
19  */
20
21 #include "config.h"
22
23 #include <telepathy-glib/telepathy-glib.h>
24
25 #if HAVE_CALL
26  #include <telepathy-yell/telepathy-yell.h>
27 #endif
28
29 #include "empathy-call-utils.h"
30
31 #include <libempathy/empathy-request-util.h>
32
33 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
34 #include <libempathy/empathy-debug.h>
35
36 #if HAVE_CALL
37 GHashTable *
38 empathy_call_create_call_request (const gchar *contact,
39     gboolean initial_audio,
40     gboolean initial_video)
41 {
42   return tp_asv_new (
43     TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING,
44       TPY_IFACE_CHANNEL_TYPE_CALL,
45     TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT,
46       TP_HANDLE_TYPE_CONTACT,
47     TP_PROP_CHANNEL_TARGET_ID, G_TYPE_STRING,
48       contact,
49     TPY_PROP_CHANNEL_TYPE_CALL_INITIAL_AUDIO, G_TYPE_BOOLEAN,
50       initial_audio,
51     TPY_PROP_CHANNEL_TYPE_CALL_INITIAL_VIDEO, G_TYPE_BOOLEAN,
52       initial_video,
53     NULL);
54 }
55 #endif
56
57 GHashTable *
58 empathy_call_create_streamed_media_request (const gchar *contact,
59     gboolean initial_audio,
60     gboolean initial_video)
61 {
62   return tp_asv_new (
63     TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING,
64       TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA,
65     TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT,
66       TP_HANDLE_TYPE_CONTACT,
67     TP_PROP_CHANNEL_TARGET_ID, G_TYPE_STRING,
68       contact,
69     TP_PROP_CHANNEL_TYPE_STREAMED_MEDIA_INITIAL_AUDIO, G_TYPE_BOOLEAN,
70       initial_audio,
71     TP_PROP_CHANNEL_TYPE_STREAMED_MEDIA_INITIAL_VIDEO, G_TYPE_BOOLEAN,
72       initial_video,
73     NULL);
74 }
75
76 static void
77 create_streamed_media_channel_cb (GObject *source,
78     GAsyncResult *result,
79     gpointer user_data)
80 {
81   GError *error = NULL;
82
83   if (!tp_account_channel_request_create_channel_finish (
84            TP_ACCOUNT_CHANNEL_REQUEST (source),
85            result,
86            &error))
87     {
88       DEBUG ("Failed to create StreamedMedia channel: %s", error->message);
89       g_error_free (error);
90     }
91 }
92
93 #if HAVE_CALL
94 static void
95 create_call_channel_cb (GObject *source,
96     GAsyncResult *result,
97     gpointer user_data)
98 {
99   TpAccountChannelRequest *streamed_media_req = user_data;
100   GError *error = NULL;
101
102   if (tp_account_channel_request_create_channel_finish (
103       TP_ACCOUNT_CHANNEL_REQUEST (source), result, &error))
104     {
105       g_object_unref (streamed_media_req);
106       return;
107     }
108
109   DEBUG ("Failed to create Call channel: %s", error->message);
110
111   if (error->code != TP_ERROR_NOT_IMPLEMENTED)
112     return;
113
114   DEBUG ("Let's try with an StreamedMedia channel");
115   g_error_free (error);
116   tp_account_channel_request_create_channel_async (streamed_media_req,
117       EMPATHY_AV_BUS_NAME, NULL,
118       create_streamed_media_channel_cb,
119       NULL);
120 }
121 #endif
122
123 void
124 empathy_call_new_with_streams (const gchar *contact,
125     TpAccount *account,
126     gboolean initial_audio,
127     gboolean initial_video,
128     gint64 timestamp)
129 {
130 #if HAVE_CALL
131   GHashTable *call_request, *streamed_media_request;
132   TpAccountChannelRequest *call_req, *streamed_media_req;
133
134   call_request = empathy_call_create_call_request (contact,
135       initial_audio,
136       initial_video);
137
138   streamed_media_request = empathy_call_create_streamed_media_request (
139       contact, initial_audio, initial_video);
140
141   call_req = tp_account_channel_request_new (account, call_request, timestamp);
142   streamed_media_req = tp_account_channel_request_new (account,
143       streamed_media_request,
144       timestamp);
145
146   tp_account_channel_request_create_channel_async (call_req,
147       EMPATHY_CALL_BUS_NAME, NULL,
148       create_call_channel_cb,
149       streamed_media_req);
150
151   g_hash_table_unref (call_request);
152   g_hash_table_unref (streamed_media_request);
153   g_object_unref (call_req);
154 #else
155   GHashTable *request;
156   TpAccountChannelRequest *req;
157
158   request = empathy_call_create_streamed_media_request (contact,
159       initial_audio,
160       initial_video);
161
162   req = tp_account_channel_request_new (account, request, timestamp);
163
164   tp_account_channel_request_create_channel_async (req,
165       EMPATHY_AV_BUS_NAME, NULL,
166       create_streamed_media_channel_cb,
167       NULL);
168
169   g_hash_table_unref (request);
170   g_object_unref (req);
171 #endif
172 }