Liblinphone  3.12.0
Real Time Text Sender

This program just send chat message in real time to dest uri. Use realtimetext_receiver to receive message. usage: ./realtimetext_sender sip:localhost:5060

/*
linphone
Copyright (C) 2015 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "linphone/core.h"
#include <signal.h>
static bool_t running=TRUE;
static void stop(int signum){
running=FALSE;
}
int main(int argc, char *argv[]){
LinphoneCoreVTable vtable={0};
LinphoneCall *call=NULL;
LinphoneChatRoom *chat_room;
LinphoneChatMessage *chat_message=NULL;
const char *dest=NULL;
LCSipTransports tp;
/* take the destination sip uri from the command line arguments */
if (argc>1){
dest=argv[1];
}
signal(SIGINT,stop);
#ifdef DEBUG
linphone_core_enable_logs(NULL); /*enable liblinphone logs.*/
#endif
/*
Instanciate a LinphoneCore object given the LinphoneCoreVTable
*/
lc=linphone_core_new(&vtable,NULL,NULL,NULL);
linphone_core_set_sip_transports(lc,&tp); /*to avoid port colliding with receiver*/
if (dest){
/*
Place an outgoing call with rtt enabled
*/
linphone_call_params_enable_realtime_text(cp,TRUE); /*enable real time text*/
if (call==NULL){
printf("Could not place call to %s\n",dest);
goto end;
}else printf("Call to %s is in progress...",dest);
}
/*wait for call to be established*/
ms_usleep(50000);
}
/*check if call is established*/
switch (linphone_call_get_state(call)) {
printf("Could not place call to %s\n",dest);
goto end;
break;
default:
break;
/*continue*/
}
chat_room=linphone_call_get_chat_room(call); /*create a chat room associated to this call*/
/* main loop for sending message and doing background linphonecore work: */
while(running){
int character;
/*to disable terminal buffering*/
if (system ("/bin/stty raw") == -1){
ms_error("/bin/stty error");
}
character = getchar();
if (system("/bin/stty cooked") == -1){
ms_error("/bin/stty error");
}
if (character==0x03) {/*CTRL C*/
running=0;
break;
}
if (character != EOF) {
/* user has typed something*/
if (chat_message == NULL) {
/*create a new message*/
chat_message = linphone_chat_room_create_message(chat_room,""); /*create an empty message*/
}
if (character == '\r') {
/*new line, committing message*/
linphone_chat_room_send_chat_message(chat_room,chat_message);
chat_message = NULL; /*reset message*/
} else {
linphone_chat_message_put_char(chat_message,character); /*send char in realtime*/
}
}
ms_usleep(50000);
}
/* terminate the call */
printf("Terminating the call...\n");
/*at this stage we don't need the call object */
}
end:
printf("Shutting down...\n");
printf("Exited\n");
return 0;
}
LinphoneCallOutgoingInit
An outgoing call is started.
Definition: types.h:305
LinphoneCallError
The call encountered an error.
Definition: types.h:315
LinphoneCore
struct _LinphoneCore LinphoneCore
Linphone core main object created by function linphone_core_new() .
Definition: types.h:472
linphone_call_get_chat_room
LinphoneChatRoom * linphone_call_get_chat_room(LinphoneCall *call)
Create a new chat room for messaging from a call if not already existing, else return existing one.
linphone_core_set_sip_transports
LinphoneStatus linphone_core_set_sip_transports(LinphoneCore *lc, const LinphoneSipTransports *transports)
Sets the ports to be used for each of transport (UDP or TCP) A zero value port for a given transport ...
linphone_chat_room_create_message
LinphoneChatMessage * linphone_chat_room_create_message(LinphoneChatRoom *cr, const char *message)
Create a message attached to a dedicated chat room;.
LinphoneCallParams
struct _LinphoneCallParams LinphoneCallParams
The LinphoneCallParams is an object containing various call related parameters.
Definition: types.h:295
linphone_call_ref
LinphoneCall * linphone_call_ref(LinphoneCall *call)
Acquire a reference to the call.
linphone_core_enable_logs
LINPHONE_DEPRECATED void linphone_core_enable_logs(FILE *file)
Enable logs in supplied FILE*.
LinphoneCallReleased
The call object is no more retained by the core.
Definition: types.h:321
LinphoneCallEnd
The call ended normally.
Definition: types.h:316
linphone_call_params_enable_realtime_text
LinphoneStatus linphone_call_params_enable_realtime_text(LinphoneCallParams *params, bool_t yesno)
Use to enable real time text following rfc4103.
linphone_core_iterate
void linphone_core_iterate(LinphoneCore *lc)
Main loop function.
LC_SIP_TRANSPORT_RANDOM
#define LC_SIP_TRANSPORT_RANDOM
Randomly chose a sip port for this transport Use with #LinphoneSipTransports.
Definition: misc.h:50
LinphoneChatMessage
struct _LinphoneChatMessage LinphoneChatMessage
A chat room message to hold content to be sent.
Definition: types.h:354
linphone_chat_message_put_char
LinphoneStatus linphone_chat_message_put_char(LinphoneChatMessage *msg, uint32_t character)
Fulfill a chat message char by char.
linphone_core_create_call_params
LinphoneCallParams * linphone_core_create_call_params(LinphoneCore *lc, LinphoneCall *call)
Create a LinphoneCallParams suitable for linphone_core_invite_with_params(), linphone_core_accept_cal...
linphone_core_new
LINPHONE_DEPRECATED LinphoneCore * linphone_core_new(const LinphoneCoreVTable *vtable, const char *config_path, const char *factory_config_path, void *userdata)
Instanciates a LinphoneCore object.
LinphoneCall
struct _LinphoneCall LinphoneCall
The LinphoneCall object represents a call issued or received by the LinphoneCore.
Definition: types.h:262
linphone_chat_room_send_chat_message
void linphone_chat_room_send_chat_message(LinphoneChatRoom *cr, LinphoneChatMessage *msg)
Send a message to peer member of this chat room.
linphone_call_get_state
LinphoneCallState linphone_call_get_state(const LinphoneCall *call)
Retrieves the call's current state.
linphone_call_unref
void linphone_call_unref(LinphoneCall *call)
Release reference to the call.
linphone_call_params_unref
void linphone_call_params_unref(LinphoneCallParams *cp)
Release a reference to the call params.
LinphoneChatRoom
struct _LinphoneChatRoom LinphoneChatRoom
A chat room is the place where text messages are exchanged.
Definition: types.h:382
linphone_core_invite_with_params
LinphoneCall * linphone_core_invite_with_params(LinphoneCore *lc, const char *url, const LinphoneCallParams *params)
Initiates an outgoing call according to supplied call parameters The application doesn't own a refere...
LinphoneCallOutgoingProgress
An outgoing call is in progress.
Definition: types.h:306
linphone_core_terminate_call
LINPHONE_DEPRECATED LinphoneStatus linphone_core_terminate_call(LinphoneCore *lc, LinphoneCall *call)
Terminates a call.
_LinphoneCoreVTable
This structure holds all callbacks that the application should implement.
Definition: core.h:180
linphone_core_destroy
LINPHONE_DEPRECATED void linphone_core_destroy(LinphoneCore *lc)
Destroys a LinphoneCore.