Liblinphone 5.5.0
Receiving Real-Time Text

This program is able to receive chat message in real time on port 5060.

Use realtimetext_sender to generate chat message usage: ./realtimetext_receiver

/*
* Copyright (c) 2010-2022 Belledonne Communications SARL.
*
* This file is part of Liblinphone
* (see https://gitlab.linphone.org/BC/public/liblinphone).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "linphone/core.h"
#include <signal.h>
static bool_t running = TRUE;
static void stop(int signum) {
running = FALSE;
}
/*
* Call state notification callback
*/
static void call_state_changed(LinphoneCore *lc, LinphoneCall *call, LinphoneCallState cstate, const char *msg) {
switch (cstate) {
case LinphoneCallIncomingReceived:
printf("It is now ringing remotely !\n");
break;
case LinphoneCallReleased:
printf("call terminated, exit...\n");
running = FALSE;
break;
default:
printf("Unhandled notification %i\n", cstate);
}
}
/*
* Completed message received
*/
static void message_received(LinphoneCore *lc, LinphoneChatRoom *room, LinphoneChatMessage *message) {
printf(" Message [%s] received from [%s] \n", linphone_chat_message_get_text(message), from);
ms_free(from);
}
/*
*
* Remote is typing
*/
static void is_composing_received(LinphoneCore *lc, LinphoneChatRoom *room) {
LinphoneCall *call = linphone_chat_room_get_call(room); /*get corresponding call*/
linphone_call_get_current_params(call))) /*check if realtime text enabled for this call*/
printf("%c", linphone_chat_room_get_char(room));
/*else ignored*/
}
int main(int argc, char *argv[]) {
LinphoneCoreVTable vtable = {0};
signal(SIGINT, stop);
#ifdef DEBUG_LOGS
linphone_core_enable_logs(NULL); /*enable liblinphone logs.*/
#endif
/*
Fill the LinphoneCoreVTable with application callbacks.
All are optional. Here we only use the call_state_changed callbacks
in order to get notifications about the progress of the call.
*/
vtable.call_state_changed = call_state_changed; /*to receive incoming call*/
vtable.message_received = message_received; /*to receive committed messages*/
vtable.is_composing_received = is_composing_received; /*to receive char in real time*/
/*
Instanciate a LinphoneCore object given the LinphoneCoreVTable
*/
lc = linphone_core_new(&vtable, NULL, NULL, NULL);
/* main loop for receiving notifications and doing background linphonecore work: */
while (running) {
ms_usleep(50000);
}
printf("Shutting down...\n");
printf("Exited\n");
return 0;
}
const LinphoneCallParams * linphone_call_get_current_params(const LinphoneCall *call)
Returns current parameters associated to the call.
MS2_DEPRECATED LinphoneStatus linphone_core_accept_call(LinphoneCore *core, LinphoneCall *call)
Accept an incoming call.
struct _LinphoneCall LinphoneCall
This object represents a call issued or received by the LinphoneCore.
Definition c-types.h:299
enum _LinphoneCallState LinphoneCallState
LinphoneCallState enum represents the different states a call can reach into.
LinphoneCall * linphone_chat_room_get_call(const LinphoneChatRoom *chat_room)
Gets the current call associated to this chatroom if any To commit a message, use linphone_chat_messa...
const LinphoneAddress * linphone_chat_room_get_peer_address(LinphoneChatRoom *chat_room)
Get the peer address associated to this chat room.
struct _LinphoneChatRoom LinphoneChatRoom
A chat room is the place where LinphoneChatMessage are exchanged.
Definition c-types.h:468
uint32_t linphone_chat_room_get_char(LinphoneChatRoom *chat_room)
When realtime text is enabled in a LinphoneCall (see linphone_call_params_realtime_text_enabled()),...
MS2_DEPRECATED const char * linphone_chat_message_get_text(const LinphoneChatMessage *message)
Get text part of this message.
struct _LinphoneChatMessage LinphoneChatMessage
A LinphoneChatMessage represents an instant message that can be send or received through a LinphoneCh...
Definition c-types.h:429
void linphone_core_iterate(LinphoneCore *core)
Main loop integration.
MS2_DEPRECATED LinphoneCore * linphone_core_new(const LinphoneCoreVTable *vtable, const char *config_path, const char *factory_config_path, void *userdata)
Instanciates a LinphoneCore object.
struct _LinphoneCore LinphoneCore
Main object to instantiate and on which to keep a reference.
Definition types.h:487
MS2_DEPRECATED void linphone_core_destroy(LinphoneCore *core)
Destroys a LinphoneCore.
char * linphone_address_as_string(const LinphoneAddress *address)
Returns the address as a string.
bool_t linphone_call_params_realtime_text_enabled(const LinphoneCallParams *params)
Use to get real time text following rfc4103.
This structure holds all callbacks that the application should implement.
Definition core.h:197
LinphoneCoreCbsMessageReceivedCb message_received
Notifies when a message is received (can be text or external body)
Definition core.h:217
LinphoneCoreCallStateChangedCb call_state_changed
Notifies when call state changes.
Definition core.h:200
LinphoneCoreIsComposingReceivedCb is_composing_received
Notifies when an is-composing notification is received.
Definition core.h:224