LinphoneFriend *lf, const char *url);
static void linphonec_text_received(LinphoneCore *lc, LinphoneChatRoom *cr,
- const char *from, const char *msg);
+ const LinphoneAddress *from, const char *msg);
static void linphonec_display_status (LinphoneCore * lc, const char *something);
static void linphonec_dtmf_received(LinphoneCore *lc, LinphoneCall *call, int dtmf);
static void print_prompt(LinphoneCore *opm);
*/
static void
linphonec_text_received(LinphoneCore *lc, LinphoneChatRoom *cr,
- const char *from, const char *msg)
+ const LinphoneAddress *from, const char *msg)
{
- printf("%s: %s\n", from, msg);
+ printf("%s: %s\n", linphone_address_as_string(from), msg);
// TODO: provide mechanism for answering.. ('say' command?)
}
return FALSE;
}
-void linphone_chat_room_text_received(LinphoneChatRoom *cr, LinphoneCore *lc, const char *from, const char *msg){
+void linphone_chat_room_text_received(LinphoneChatRoom *cr, LinphoneCore *lc, const LinphoneAddress *from, const char *msg){
if (lc->vtable.text_received!=NULL) lc->vtable.text_received(lc, cr, from, msg);
}
/* create a new chat room */
cr=linphone_core_create_chat_room(lc,cleanfrom);
}
+
linphone_address_destroy(addr);
- linphone_chat_room_text_received(cr,lc,cleanfrom,msg);
+ linphone_chat_room_text_received(cr,lc,cr->peer_url,msg);
ms_free(cleanfrom);
}
void * linphone_chat_room_get_user_data(LinphoneChatRoom *cr){
return cr->user_data;
}
+const LinphoneAddress* linphone_chat_room_get_peer_address(LinphoneChatRoom *cr) {
+ return cr->peer_url;
+}
clean-local:
rm -rf doc
-noinst_PROGRAMS=helloworld registration buddy_status
+noinst_PROGRAMS=helloworld registration buddy_status chatroom
helloworld_SOURCES=helloworld.c
registration_SOURCES=registration.c
-registration_LDADD=$(top_builddir)/coreapi/liblinphone.la \
- $(MEDIASTREAMER_LIBS) \
- $(ORTP_LIBS)
+registration_LDADD=$(helloworld_LDADD)
buddy_status_SOURCES=buddy_status.c
-buddy_status_LDADD=$(top_builddir)/coreapi/liblinphone.la \
- $(MEDIASTREAMER_LIBS) \
- $(ORTP_LIBS)
+buddy_status_LDADD=$(helloworld_LDADD)
+
+chatroom_SOURCES=chatroom.c
+
+chatroom_LDADD=$(helloworld_LDADD)
+
INCLUDES=-I$(top_srcdir)/coreapi \
/*
-linphone
+buddy_status
Copyright (C) 2010 Belledonne Communications SARL
This program is free software; you can redistribute it and/or
* @defgroup buddy_tutorials Basic buddy status notification
* @ingroup tutorials
*This program is a _very_ simple usage example of liblinphone,
- *desmonstrating how to initiate SIP subscriptions and receive notifications from a sip uri identity passed from the command line.
+ *demonstrating how to initiate SIP subscriptions and receive notifications from a sip uri identity passed from the command line.
*<br>Argument must be like sip:jehan@sip.linphone.org .
*<br>
*ex budy_list sip:jehan@sip.linphone.org
#endif
/*
Fill the LinphoneCoreVTable with application callbacks.
- All are optional. Here we only use the registration_state_changed callbacks
- in order to get notifications about the progress of the registration.
+ All are optional. Here we only use the both notify_presence_recv and new_subscription_request callbacks
+ in order to get notifications about friend status.
*/
vtable.notify_presence_recv=notify_presence_recv_updated;
vtable.new_subscription_request=new_subscription_request;
/*
- Instanciate a LinphoneCore object given the LinphoneCoreVTable
+ Instantiate a LinphoneCore object given the LinphoneCoreVTable
*/
lc=linphone_core_new(&vtable,NULL,NULL,NULL);
LinphoneFriend* my_friend=NULL;
--- /dev/null
+
+/*
+linphone
+Copyright (C) 2010 Belledonne Communications SARL
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program 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 General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+
+/**
+ * @defgroup chatroom_tuto Chat room and messaging
+ * @ingroup tutorials
+ *This program is a _very_ simple usage example of liblinphone,
+ *desmonstrating how to send/receive SIP MESSAGE from a sip uri identity passed from the command line.
+ *<br>Argument must be like sip:jehan@sip.linphone.org .
+ *<br>
+ *ex chatroom sip:jehan@sip.linphone.org
+ *<br>
+ *@include chatroom.c
+
+ *
+ */
+
+#include "linphonecore.h"
+
+#include <signal.h>
+
+static bool_t running=TRUE;
+
+static void stop(int signum){
+ running=FALSE;
+}
+void text_received(LinphoneCore *lc, LinphoneChatRoom *room, const LinphoneAddress *from, const char *message) {
+ printf(" Message [%s] received from [%s] \n",message,linphone_address_as_string (from));
+}
+
+
+LinphoneCore *lc;
+int main(int argc, char *argv[]){
+ LinphoneCoreVTable vtable={0};
+
+ char* dest_friend=NULL;
+
+
+ /* takes sip uri identity from the command line arguments */
+ if (argc>1){
+ dest_friend=argv[1];
+ }
+
+ signal(SIGINT,stop);
+//#define DEBUG
+#ifdef DEBUG
+ linphone_core_enable_logs(NULL); /*enable liblinphone logs.*/
+#endif
+ /*
+ Fill the LinphoneCoreVTable with application callbacks.
+ All are optional. Here we only use the text_received callback
+ in order to get notifications about incoming message.
+ */
+ vtable.text_received=text_received;
+
+ /*
+ Instantiate a LinphoneCore object given the LinphoneCoreVTable
+ */
+ lc=linphone_core_new(&vtable,NULL,NULL,NULL);
+
+
+ /*Next step is to create a chat root*/
+ LinphoneChatRoom* chat_room = linphone_core_create_chat_room(lc,dest_friend);
+
+ linphone_chat_room_send_message(chat_room,"Hello world"); /*sending message*/
+
+ /* main loop for receiving incoming messages and doing background linphone core work: */
+ while(running){
+ linphone_core_iterate(lc);
+ ms_usleep(50000);
+ }
+
+ printf("Shutting down...\n");
+ linphone_chat_room_destroy(chat_room);
+ linphone_core_destroy(lc);
+ printf("Exited\n");
+ return 0;
+}
+
<br> A complete tutorial can be found at : \ref buddy_tutorials "Registration tutorial"
-*/
+**/
+
+/**
+* @defgroup chatroom Chat room and Messaging
+<b> Exchanging text messages</b>
+<br> Messages are sent using #LinphoneChatRoom object. First step is to create a \link linphone_core_create_chat_room() chat room \endlink
+from a peer sip uri.
+\code
+LinphoneChatRoom* chat_room = linphone_core_create_chat_room(lc,"sip:joe@sip.linphone.org");
+\endcode
+<br>Once created, messages are sent using function linphone_chat_room_send_message() .
+\code
+linphone_chat_room_send_message(chat_room,"Hello world"); /*sending message*/
+\endcode
+<br>Incoming message are received from call back LinphoneCoreVTable.text_received
+\code
+void text_received(LinphoneCore *lc, LinphoneChatRoom *room, const LinphoneAddress *from, const char *message) {
+ printf(" Message [%s] received from [%s] \n",message,linphone_address_as_string (from));
+}
+\endcode
+<br> A complete tutorial can be found at : \ref chatroom_tuto "Chat room tutorial"
+**/
/**
* @defgroup call_logs Managing call logs
struct _LinphoneChatRoom;
+/**
+ * @addtogroup chatroom
+ * @{
+ */
+/**
+ * A chat room is the place where text messages are exchanged.
+ * <br> Can be created by linphone_core_create_chat_room().
+ */
typedef struct _LinphoneChatRoom LinphoneChatRoom;
+/**
+ * Create a new chat room for messaging from a sip uri like sip:joe@sip.linphone.org
+ * @param lc #LinphoneCore object
+ * @param to destination address for messages
+ * @return #LinphoneChatRoom where messaging can take place.
+ */
+LinphoneChatRoom * linphone_core_create_chat_room(LinphoneCore *lc, const char *to);
+/**
+ * Destructor
+ * @param cr #LinphoneChatRoom object
+ */
+void linphone_chat_room_destroy(LinphoneChatRoom *cr);
+
-LinphoneChatRoom * linphone_core_create_chat_room(struct _LinphoneCore *lc, const char *to);
+/**
+ * get peer address \link linphone_core_create_chat_room() associated to \endlink this #LinphoneChatRoom
+ * @param cr #LinphoneChatRoom object
+ * @return #LinphoneAddress peer address
+ */
+const LinphoneAddress* linphone_chat_room_get_peer_address(LinphoneChatRoom *cr);
+/**
+ * send a message to peer member of this chat room.
+ * @param cr #LinphoneChatRoom object
+ * @param msg message to be sent
+ */
void linphone_chat_room_send_message(LinphoneChatRoom *cr, const char *msg);
-void linphone_chat_room_destroy(LinphoneChatRoom *cr);
+
void linphone_chat_room_set_user_data(LinphoneChatRoom *cr, void * ud);
void * linphone_chat_room_get_user_data(LinphoneChatRoom *cr);
+/**
+ * @}
+ */
typedef enum _LinphoneGlobalState{
LinphoneGlobalOff,
LinphoneGlobalStartup,
typedef void (*AuthInfoRequested)(struct _LinphoneCore *lc, const char *realm, const char *username);
/** Callback prototype */
typedef void (*CallLogUpdated)(struct _LinphoneCore *lc, struct _LinphoneCallLog *newcl);
-/** Callback prototype */
-typedef void (*TextMessageReceived)(struct _LinphoneCore *lc, LinphoneChatRoom *room, const char *from, const char *message);
+/**
+ * Callback prototype
+ *
+ * @param lc #LinphoneCore object
+ * @param room #LinphoneChatRoom involved in this conversation. Can be be created by the framework in case \link #LinphoneAddress the from \endlink is not present in any chat room.
+ * @param from #LinphoneAddress from
+ * @param message incoming message
+ * */
+typedef void (*TextMessageReceived)(LinphoneCore *lc, LinphoneChatRoom *room, const LinphoneAddress *from, const char *message);
/** Callback prototype */
typedef void (*DtmfReceived)(struct _LinphoneCore* lc, LinphoneCall *call, int dtmf);
/** Callback prototype */
}
}
-void linphone_gtk_text_received(LinphoneCore *lc, LinphoneChatRoom *room, const char *from, const char *message){
+void linphone_gtk_text_received(LinphoneCore *lc, LinphoneChatRoom *room, const LinphoneAddress *from, const char *message){
GtkWidget *w=(GtkWidget*)linphone_chat_room_get_user_data(room);
if (w==NULL){
- w=linphone_gtk_init_chatroom(room,from);
+ w=linphone_gtk_init_chatroom(room,linphone_address_as_string_uri_only(from));
}
linphone_gtk_push_text(GTK_TEXT_VIEW(linphone_gtk_get_widget(w,"textlog")),
- from,
+ linphone_address_as_string_uri_only(from),
message,FALSE);
gtk_window_present(GTK_WINDOW(w));
/*gtk_window_set_urgency_hint(GTK_WINDOW(w),TRUE);*/
void linphone_gtk_show_parameters(void);
void linphone_gtk_load_identities(void);
void linphone_gtk_create_chatroom(const char *with);
-void linphone_gtk_text_received(LinphoneCore *lc, LinphoneChatRoom *room, const char *from, const char *message);
+void linphone_gtk_text_received(LinphoneCore *lc, LinphoneChatRoom *room, const LinphoneAddress *from, const char *message);
void linphone_gtk_call_log_update(GtkWidget *w);
void linphone_gtk_create_log_window(void);
void linphone_gtk_log_show(void);