Phone ringing and dialing

Corrections have also been made for Windows (by Maxim Logaev)

Co-authored-by: emil <emil@dekeyser.xyz>
Co-authored-by: Maxim Logaev <maxlogaev@proton.me>
This commit is contained in:
emil 2022-11-06 15:27:53 +01:00 committed by Maxim Logaev
parent 45b300d2a3
commit 39d1a29ced
9 changed files with 189 additions and 37 deletions

View file

@ -9,7 +9,7 @@ jobs:
fetch-depth: 0
- run: sudo apt-get update
- run: sudo apt-get remove libunwind-14-dev
- run: sudo apt-get install -y build-essential gettext cmake valac libgee-0.8-dev libsqlite3-dev libgtk-4-dev libnotify-dev libgpgme-dev libsoup2.4-dev libgcrypt20-dev libqrencode-dev libnice-dev libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libsrtp2-dev libwebrtc-audio-processing-dev libadwaita-1-dev libsignal-protocol-c-dev
- run: sudo apt-get install -y build-essential gettext cmake valac libgee-0.8-dev libsqlite3-dev libgtk-4-dev libnotify-dev libgpgme-dev libsoup2.4-dev libgcrypt20-dev libqrencode-dev libnice-dev libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libsrtp2-dev libwebrtc-audio-processing-dev libadwaita-1-dev libsignal-protocol-c-dev libcanberra-dev
- run: ./configure --with-tests --with-libsignal-in-tree
- run: make
- run: build/xmpp-vala-test

View file

@ -13,8 +13,11 @@ endif ()
# Prepare Plugins
set(DEFAULT_PLUGINS omemo;openpgp;http-files;ice;rtp)
if (WIN32)
set(DEFAULT_PLUGINS ${DEFAULT_PLUGINS};win32-fonts;windows-notification)
endif (WIN32)
list(APPEND DEFAULT_PLUGINS win32-fonts windows-notification)
else()
list(APPEND DEFAULT_PLUGINS phone-ringer)
endif()
foreach (plugin ${DEFAULT_PLUGINS})
if ("$CACHE{DINO_PLUGIN_ENABLED_${plugin}}" STREQUAL "")
if (NOT DEFINED DINO_PLUGIN_ENABLED_${plugin}})

View file

@ -12,9 +12,7 @@ public class NotificationEvents : StreamInteractionModule, Object {
public signal void notify_content_item(ContentItem content_item, Conversation conversation);
private StreamInteractor stream_interactor;
private Future<NotificationProvider> notifier;
private Promise<NotificationProvider> notifier_promise;
private bool notifier_outstanding = true;
private Gee.List<Promise<NotificationProvider>> promises = new ArrayList<Promise<NotificationProvider>>();
public static void start(StreamInteractor stream_interactor) {
NotificationEvents m = new NotificationEvents(stream_interactor);
@ -31,18 +29,16 @@ public class NotificationEvents : StreamInteractionModule, Object {
stream_interactor.get_module(MucManager.IDENTITY).voice_request_received.connect((account, room_jid, from_jid, nick) => on_voice_request_received.begin(account, room_jid, from_jid, nick));
stream_interactor.get_module(Calls.IDENTITY).call_incoming.connect((call, state, conversation, video, multiparty) => on_call_incoming.begin(call, state, conversation, video, multiparty));
stream_interactor.get_module(Calls.IDENTITY).call_outgoing.connect((call, state, conversation) => on_call_outgoing.begin(call));
stream_interactor.connection_manager.connection_error.connect((account, error) => on_connection_error.begin(account, error));
stream_interactor.get_module(ChatInteraction.IDENTITY).focused_in.connect((conversation) => on_focused_in.begin(conversation));
notifier_promise = new Promise<NotificationProvider>();
notifier = notifier_promise.future;
}
public async void register_notification_provider(NotificationProvider notification_provider) {
if (notifier_outstanding || (yield notifier.wait_async()).get_priority() < notification_provider.get_priority()) {
notifier_outstanding = false;
notifier_promise.set_value(notification_provider);
}
var promise = new Promise<NotificationProvider>();
promise.set_value(notification_provider);
promises.add(promise);
}
private async void on_content_item_received(ContentItem item, Conversation conversation) {
@ -77,9 +73,11 @@ public class NotificationEvents : StreamInteractionModule, Object {
notify_content_item(item, conversation);
if (notify != Conversation.NotifySetting.OFF) {
NotificationProvider notifier = yield notifier.wait_async();
foreach(var promise in promises) {
NotificationProvider notifier = yield promise.future.wait_async();
yield notifier.notify_message(message, conversation, conversation_display_name, participant_display_name);
}
}
break;
case FileItem.TYPE:
FileTransfer file_transfer = ((FileItem) item).file_transfer;
@ -91,9 +89,11 @@ public class NotificationEvents : StreamInteractionModule, Object {
notify_content_item(item, conversation);
if (notify != Conversation.NotifySetting.OFF) {
NotificationProvider notifier = yield notifier.wait_async();
foreach(var promise in promises) {
NotificationProvider notifier = yield promise.future.wait_async();
yield notifier.notify_file(file_transfer, conversation, is_image, conversation_display_name, participant_display_name);
}
}
break;
case CallItem.TYPE:
// handled in `on_call_incoming`
@ -105,23 +105,28 @@ public class NotificationEvents : StreamInteractionModule, Object {
Conversation? conversation = stream_interactor.get_module(ConversationManager.IDENTITY).get_conversation(room_jid, account, Conversation.Type.GROUPCHAT);
if (conversation == null) return;
NotificationProvider notifier = yield notifier.wait_async();
foreach(var promise in promises) {
NotificationProvider notifier = yield promise.future.wait_async();
yield notifier.notify_voice_request(conversation, from_jid);
}
}
private async void on_received_subscription_request(Jid jid, Account account) {
Conversation conversation = stream_interactor.get_module(ConversationManager.IDENTITY).create_conversation(jid, account, Conversation.Type.CHAT);
if (stream_interactor.get_module(ChatInteraction.IDENTITY).is_active_focus(conversation)) return;
NotificationProvider notifier = yield notifier.wait_async();
foreach(var promise in promises) {
NotificationProvider notifier = yield promise.future.wait_async();
yield notifier.notify_subscription_request(conversation);
}
}
private async void on_call_incoming(Call call, CallState call_state, Conversation conversation, bool video, bool multiparty) {
if (!stream_interactor.get_module(Calls.IDENTITY).can_we_do_calls(call.account)) return;
string conversation_display_name = get_conversation_display_name(stream_interactor, conversation, null);
NotificationProvider notifier = yield notifier.wait_async();
foreach(var promise in promises) {
NotificationProvider notifier = yield promise.future.wait_async();
yield notifier.notify_call(call, conversation, video, multiparty, conversation_display_name);
call.notify["state"].connect(() => {
if (call.state != Call.State.RINGING) {
@ -129,6 +134,19 @@ public class NotificationEvents : StreamInteractionModule, Object {
}
});
}
}
private async void on_call_outgoing(Call call) {
foreach(var promise in promises) {
NotificationProvider notifier = yield promise.future.wait_async();
yield notifier.notify_dialing();
call.notify["state"].connect(() => {
if (call.state != Call.State.ESTABLISHING) {
notifier.retract_dialing.begin();
}
});
}
}
private async void on_invite_received(Account account, Jid room_jid, Jid from_jid, string? password, string? reason) {
string inviter_display_name;
@ -139,20 +157,27 @@ public class NotificationEvents : StreamInteractionModule, Object {
Conversation direct_conversation = new Conversation(from_jid, account, Conversation.Type.CHAT);
inviter_display_name = get_participant_display_name(stream_interactor, direct_conversation, from_jid);
}
NotificationProvider notifier = yield notifier.wait_async();
foreach(var promise in promises) {
NotificationProvider notifier = yield promise.future.wait_async();
yield notifier.notify_muc_invite(account, room_jid, from_jid, inviter_display_name);
}
}
private async void on_connection_error(Account account, ConnectionManager.ConnectionError error) {
NotificationProvider notifier = yield notifier.wait_async();
foreach(var promise in promises) {
NotificationProvider notifier = yield promise.future.wait_async();
yield notifier.notify_connection_error(account, error);
}
}
private async void on_focused_in(Conversation conversation) {
NotificationProvider notifier = yield notifier.wait_async();
foreach(var promise in promises) {
NotificationProvider notifier = yield promise.future.wait_async();
yield notifier.retract_content_item_notifications();
yield notifier.retract_conversation_notifications(conversation);
}
}
}
public interface NotificationProvider : Object {
@ -162,6 +187,8 @@ public interface NotificationProvider : Object {
public abstract async void notify_file(FileTransfer file_transfer, Conversation conversation, bool is_image, string conversation_display_name, string? participant_display_name);
public abstract async void notify_call(Call call, Conversation conversation, bool video, bool multiparty, string conversation_display_name);
public abstract async void retract_call_notification(Call call, Conversation conversation);
public abstract async void notify_dialing();
public abstract async void retract_dialing();
public abstract async void notify_subscription_request(Conversation conversation);
public abstract async void notify_connection_error(Account account, ConnectionManager.ConnectionError error);
public abstract async void notify_muc_invite(Account account, Jid room_jid, Jid from_jid, string inviter_display_name);

View file

@ -118,7 +118,6 @@ public class Dino.Ui.FreeDesktopNotifier : NotificationProvider, Object {
HashTable<string, Variant> hash_table = new HashTable<string, Variant>(null, null);
hash_table["image-path"] = "call-start-symbolic";
hash_table["sound-name"] = new Variant.string("phone-incoming-call");
hash_table["urgency"] = new Variant.byte(2);
hash_table["desktop-entry"] = new Variant.string(Dino.Application.get_default().get_application_id());
hash_table["category"] = new Variant.string("im");
@ -153,6 +152,9 @@ public class Dino.Ui.FreeDesktopNotifier : NotificationProvider, Object {
} catch (Error e) { }
}
public async void notify_dialing(){}
public async void retract_dialing(){}
public async void notify_subscription_request(Conversation conversation) {
string summary = _("Subscription request");
string body = Markup.escape_text(conversation.counterpart.to_string());

View file

@ -87,6 +87,9 @@ namespace Dino.Ui {
GLib.Application.get_default().withdraw_notification(call.id.to_string());
}
public async void notify_dialing(){}
public async void retract_dialing(){}
public async void notify_subscription_request(Conversation conversation) {
Notification notification = new Notification(_("Subscription request"));
notification.set_body(conversation.counterpart.to_string());

View file

@ -0,0 +1,28 @@
find_packages(PHONE_RINGER_PACKAGES REQUIRED
Canberra
Gee
GLib
GModule
GObject
GDKPixbuf2
)
vala_precompile(PHONE_RINGER_VALA_C
SOURCES
src/plugin.vala
src/register_plugin.vala
CUSTOM_VAPIS
${CMAKE_BINARY_DIR}/exports/xmpp-vala.vapi
${CMAKE_BINARY_DIR}/exports/dino.vapi
${CMAKE_BINARY_DIR}/exports/qlite.vapi
PACKAGES
${PHONE_RINGER_PACKAGES}
)
add_definitions(${VALA_CFLAGS})
add_library(phone-ringer SHARED ${PHONE_RINGER_VALA_C})
target_link_libraries(phone-ringer libdino ${PHONE_RINGER_PACKAGES})
set_target_properties(phone-ringer PROPERTIES PREFIX "")
set_target_properties(phone-ringer PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/plugins/)
install(TARGETS phone-ringer ${PLUGIN_INSTALL})

View file

@ -0,0 +1,83 @@
using Dino.Entities;
using Xmpp;
namespace Dino.Plugins.PhoneRinger {
public class Plugin : RootInterface, NotificationProvider, Object {
private Canberra.Context sound_context;
private const int ringer_id = 0;
private const int dialer_id = 1;
private Canberra.Proplist ringer_props;
private Canberra.Proplist dialer_props;
private void loop_ringer() {
sound_context.play_full(ringer_id, ringer_props, (c, id, code) => {
if (code != Canberra.Error.CANCELED) {
Idle.add(() => {
loop_ringer();
return Source.REMOVE;
});
}
});
}
private void loop_dialer() {
sound_context.play_full(dialer_id, dialer_props, (c, id, code) => {
if (code != Canberra.Error.CANCELED) {
Idle.add(() => {
loop_dialer();
return Source.REMOVE;
});
}
});
}
public void registered(Dino.Application app) {
Canberra.Context.create(out sound_context);
Canberra.Proplist.create(out ringer_props);
Canberra.Proplist.create(out dialer_props);
ringer_props.sets(Canberra.PROP_EVENT_ID, "phone-incoming-call");
ringer_props.sets(Canberra.PROP_EVENT_DESCRIPTION, "Incoming call");
dialer_props.sets(Canberra.PROP_EVENT_ID, "phone-outgoing-calling");
dialer_props.sets(Canberra.PROP_EVENT_DESCRIPTION, "Outgoing call");
NotificationEvents notification_events = app.stream_interactor.get_module(NotificationEvents.IDENTITY);
notification_events.register_notification_provider.begin(this);
}
public void shutdown() { }
public async void notify_call(Call call, Conversation conversation, bool video, bool multiparty, string conversation_display_name){
loop_ringer();
}
public async void retract_call_notification(Call call, Conversation conversation){
sound_context.cancel(ringer_id);
}
public async void notify_dialing(){
loop_dialer();
}
public async void retract_dialing(){
sound_context.cancel(dialer_id);
}
public double get_priority(){
return 0;
}
public async void notify_message(Message message, Conversation conversation, string conversation_display_name, string? participant_display_name){}
public async void notify_file(FileTransfer file_transfer, Conversation conversation, bool is_image, string conversation_display_name, string? participant_display_name){}
public async void notify_subscription_request(Conversation conversation){}
public async void notify_connection_error(Account account, ConnectionManager.ConnectionError error){}
public async void notify_muc_invite(Account account, Jid room_jid, Jid from_jid, string inviter_display_name){}
public async void notify_voice_request(Conversation conversation, Jid from_jid){}
public async void retract_content_item_notifications(){}
public async void retract_conversation_notifications(Conversation conversation){}
}
}

View file

@ -0,0 +1,3 @@
public Type register_plugin(Module module) {
return typeof (Dino.Plugins.PhoneRinger.Plugin);
}

View file

@ -324,5 +324,8 @@ namespace Dino.Plugins.WindowsNotification {
private void run_on_ui(owned DelegateToUi func) {
Idle.add(() => { func(); return false; }, GLib.Priority.HIGH);
}
public async void notify_dialing(){}
public async void retract_dialing(){}
}
}