Skip to content

Commit

Permalink
added video call button functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
naxuroqa committed Jul 23, 2014
1 parent 5c93827 commit 3b5cdc2
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 48 deletions.
5 changes: 3 additions & 2 deletions src/core/Contact.vala
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

namespace Venom {

public enum AudioCallState {
public enum CallState {
RINGING, // outgoing call
CALLING, // incoming call
STARTED, // call commencing
Expand Down Expand Up @@ -73,7 +73,8 @@ namespace Venom {
public bool is_typing { get; set; default = false; }
// ToxAV stuff
public int call_index { get; set; default = -1; }
public AudioCallState audio_call_state { get; set; default = AudioCallState.ENDED; }
public CallState call_state { get; set; default = CallState.ENDED; }
public bool video { get; set; default = false; }
public double volume { get; set; default = 1.0; }

private GLib.HashTable<uint8, FileTransfer> _file_transfers = new GLib.HashTable<uint8, FileTransfer>(null, null);
Expand Down
44 changes: 28 additions & 16 deletions src/core/ToxSession.vala
Original file line number Diff line number Diff line change
Expand Up @@ -885,23 +885,33 @@ namespace Venom {

// TOXAV functions
public void start_audio_call(Contact c) {
// start audio thread, ...
Logger.log(LogLevel.DEBUG, "starting audio call");
int call_index = 0;
c.video = false;
ToxAV.AV_Error ret = _toxav_handle.call(ref call_index, c.friend_id, ToxAV.CallType.AUDIO, 10);

if(ret != ToxAV.AV_Error.NONE) {
Logger.log(LogLevel.ERROR, "toxav_call returned an error: %s".printf(ret.to_string()));
} else {
c.call_index = (int)call_index;
c.call_index = call_index;
}
}

public void start_video_call(Contact c) {
//TODO
Logger.log(LogLevel.DEBUG, "starting video call");
int call_index = 0;
c.video = true;
ToxAV.AV_Error ret = _toxav_handle.call(ref call_index, c.friend_id, ToxAV.CallType.VIDEO, 10);

if(ret != ToxAV.AV_Error.NONE) {
Logger.log(LogLevel.ERROR, "toxav_call returned an error: %s".printf(ret.to_string()));
} else {
c.call_index = call_index;
}
}

public void answer_audio_call(Contact c) {
ToxAV.AV_Error ret = _toxav_handle.answer(c.call_index, ToxAV.CallType.AUDIO);
public void answer_call(Contact c) {
ToxAV.AV_Error ret = _toxav_handle.answer(c.call_index, c.video ? ToxAV.CallType.VIDEO : ToxAV.CallType.AUDIO);

if(ret != ToxAV.AV_Error.NONE) {
Logger.log(LogLevel.ERROR, "toxav_answer returned an error: %s".printf(ret.to_string()));
Expand All @@ -926,7 +936,7 @@ namespace Venom {

public void cancel_call(Contact c) {
ToxAV.AV_Error ret = _toxav_handle.cancel(c.call_index, ToxAV.CallType.AUDIO, "do not want");
c.audio_call_state = AudioCallState.ENDED;
c.call_state = CallState.ENDED;

if(ret != ToxAV.AV_Error.NONE) {
Logger.log(LogLevel.ERROR, "toxav_cancel returned an error: %s".printf(ret.to_string()));
Expand All @@ -937,10 +947,12 @@ namespace Venom {
private void on_av_invite_callback(ToxAV.ToxAV av, int32 call_index) {
Logger.log(LogLevel.DEBUG, "on_av_invite_callback %i".printf(call_index));
int friend_id = _toxav_handle.get_peer_id(call_index, 0);
bool video = ((ToxAV.CallType)_toxav_handle.get_peer_transmission_type(call_index, 0) == ToxAV.CallType.VIDEO);
Idle.add(() => {
Contact c = _contacts.get(friend_id);
c.call_index = call_index;
c.audio_call_state = AudioCallState.CALLING;
c.call_state = CallState.CALLING;
c.video = video;
on_av_invite(c);
return false;
});
Expand All @@ -950,7 +962,7 @@ namespace Venom {
int friend_id = _toxav_handle.get_peer_id(call_index, 0);
Idle.add(() => {
Contact c = _contacts.get(friend_id);
c.audio_call_state = AudioCallState.STARTED;
c.call_state = CallState.STARTED;
on_av_start(c);
return false;
});
Expand All @@ -960,7 +972,7 @@ namespace Venom {
int friend_id = _toxav_handle.get_peer_id(call_index, 0);
Idle.add(() => {
Contact c = _contacts.get(friend_id);
c.audio_call_state = AudioCallState.ENDED;
c.call_state = CallState.ENDED;
on_av_cancel(c);
return false;
});
Expand All @@ -970,7 +982,7 @@ namespace Venom {
int friend_id = _toxav_handle.get_peer_id(call_index, 0);
Idle.add(() => {
Contact c = _contacts.get(friend_id);
c.audio_call_state = AudioCallState.ENDED;
c.call_state = CallState.ENDED;
on_av_reject(c);
return false;
});
Expand All @@ -980,7 +992,7 @@ namespace Venom {
int friend_id = _toxav_handle.get_peer_id(call_index, 0);
Idle.add(() => {
Contact c = _contacts.get(friend_id);
c.audio_call_state = AudioCallState.ENDED;
c.call_state = CallState.ENDED;
on_av_end(c);
return false;
});
Expand All @@ -991,7 +1003,7 @@ namespace Venom {
Idle.add(() => {
Contact c = _contacts.get(friend_id);
c.call_index = call_index;
c.audio_call_state = AudioCallState.RINGING;
c.call_state = CallState.RINGING;
on_av_ringing(c);
return false;
});
Expand All @@ -1001,7 +1013,7 @@ namespace Venom {
int friend_id = _toxav_handle.get_peer_id(call_index, 0);
Idle.add(() => {
Contact c = _contacts.get(friend_id);
c.audio_call_state = AudioCallState.STARTED;
c.call_state = CallState.STARTED;
on_av_starting(c);
return false;
});
Expand All @@ -1011,7 +1023,7 @@ namespace Venom {
int friend_id = _toxav_handle.get_peer_id(call_index, 0);
Idle.add(() => {
Contact c = _contacts.get(friend_id);
c.audio_call_state = AudioCallState.ENDED;
c.call_state = CallState.ENDED;
on_av_ending(c);
return false;
});
Expand All @@ -1021,7 +1033,7 @@ namespace Venom {
int friend_id = _toxav_handle.get_peer_id(call_index, 0);
Idle.add(() => {
Contact c = _contacts.get(friend_id);
c.audio_call_state = AudioCallState.ENDED;
c.call_state = CallState.ENDED;
on_av_request_timeout(c);
return false;
});
Expand All @@ -1031,7 +1043,7 @@ namespace Venom {
int friend_id = _toxav_handle.get_peer_id(call_index, 0);
Idle.add(() => {
Contact c = _contacts.get(friend_id);
c.audio_call_state = AudioCallState.ENDED;
c.call_state = CallState.ENDED;
on_av_peer_timeout(c);
return false;
});
Expand Down
28 changes: 19 additions & 9 deletions src/ui/ContactListWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -856,24 +856,24 @@ namespace Venom {
Gtk.MessageType.QUESTION,
Gtk.ButtonsType.NONE,
"");
message_dialog.set_markup("'%s' is calling ...".printf(c.get_name_string()));
message_dialog.set_markup("'%s' is calling (%s) ...".printf(c.get_name_string(), c.video ? "Video call" : "Audio only"));
message_dialog.add_buttons("_Cancel", Gtk.ResponseType.CANCEL, "_Accept", Gtk.ResponseType.ACCEPT, null);
//close message dialog when callstate changes (timeout, cancel, ...)
c.notify["audio-call-state"].connect(() => {
c.notify["call-state"].connect(() => {
message_dialog.destroy();
});

int response = message_dialog.run();
message_dialog.destroy();

if(c.audio_call_state != AudioCallState.CALLING) {
if(c.call_state != CallState.CALLING) {
//when remote cancels the request
Logger.log(LogLevel.DEBUG, "call with %s already canceled".printf(c.name));
return;
}

if(response == Gtk.ResponseType.ACCEPT) {
session.answer_audio_call(c);
session.answer_call(c);
} else {
session.reject_call(c);
}
Expand All @@ -883,29 +883,37 @@ namespace Venom {
session.start_audio_call(c);
}

private void on_start_video_call(Contact c) {
session.start_video_call(c);
}

private void on_stop_audio_call(Contact c) {
Logger.log(LogLevel.DEBUG, "on_stop_audio_call");
switch(c.audio_call_state) {
case AudioCallState.RINGING:
switch(c.call_state) {
case CallState.RINGING:
Logger.log(LogLevel.DEBUG, "cancelling call with %s".printf(c.name));
session.cancel_call(c);
break;
case AudioCallState.CALLING:
case CallState.CALLING:
Logger.log(LogLevel.DEBUG, "rejecting call from %s".printf(c.name));
session.reject_call(c);
break;
case AudioCallState.STARTED:
case CallState.STARTED:
Logger.log(LogLevel.DEBUG, "hanging up on %s".printf(c.name));
session.hangup_call(c);
break;
case AudioCallState.ENDED:
case CallState.ENDED:
Logger.log(LogLevel.DEBUG, "call with %s already ended".printf(c.name));
break;
default:
assert_not_reached();
}
}

private void on_stop_video_call(Contact c) {
//TODO
}

private void on_file_sendrequest(int friendnumber, uint8 filenumber, uint64 filesize,string filename) {
Logger.log(LogLevel.INFO, "received file send request friend: %i filenumber: %i filename: %s ".printf(friendnumber, filenumber, filename));
Contact contact = session.get_contact_list()[friendnumber];
Expand Down Expand Up @@ -1094,6 +1102,8 @@ namespace Venom {
w.new_outgoing_file.connect(on_outgoing_file);
w.start_audio_call.connect(on_start_audio_call);
w.stop_audio_call.connect(on_stop_audio_call);
w.start_video_call.connect(on_start_video_call);
w.stop_video_call.connect(on_stop_video_call);
w.typing_status.connect( (is_typing) => {
if(Settings.instance.send_typing_status) {
session.set_user_is_typing(c.friend_id, is_typing);
Expand Down
69 changes: 48 additions & 21 deletions src/ui/ConversationWidget.vala
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ namespace Venom {
public signal void contact_changed(Contact c);
public signal void start_audio_call(Contact c);
public signal void stop_audio_call(Contact c);
public signal void start_video_call(Contact c);
public signal void stop_video_call(Contact c);

public ConversationWidget( Contact contact ) {
this.contact = contact;
Expand All @@ -68,7 +70,10 @@ namespace Venom {
button_send_file.sensitive = contact.online;
button_send.sensitive = contact.online;
button_call.sensitive = contact.online;
//button_call_video.sensitive = contact.online;

#if DEBUG
button_call_video.sensitive = contact.online;
#endif

// remove is_typing notification for offline contacts
if(!contact.online){
Expand Down Expand Up @@ -120,29 +125,46 @@ namespace Venom {
button_call.clicked.connect(button_call_clicked);
button_call_video.clicked.connect(button_call_video_clicked);
button_call_video.sensitive = false;
contact.notify["audio-call-state"].connect(() => {
Logger.log(LogLevel.DEBUG, "Changing call state to " + contact.audio_call_state.to_string());
box_volume.visible = contact.audio_call_state == AudioCallState.STARTED;
unowned Gtk.StyleContext ctx = button_call.get_style_context();
switch(contact.audio_call_state) {
case AudioCallState.RINGING:
case AudioCallState.CALLING:
ctx.remove_class("callbutton");
ctx.remove_class("callbutton-started");
ctx.add_class("callbutton-ringing");
contact.notify["call-state"].connect(() => {
Logger.log(LogLevel.DEBUG, "Changing call state to " + contact.call_state.to_string());
box_volume.visible = contact.call_state == CallState.STARTED;
unowned Gtk.StyleContext ctx_ca = button_call.get_style_context();
unowned Gtk.StyleContext ctx_cv = button_call_video.get_style_context();
switch(contact.call_state) {
case CallState.RINGING:
case CallState.CALLING:
ctx_ca.remove_class("callbutton");
ctx_ca.remove_class("callbutton-started");
ctx_ca.add_class("callbutton-ringing");
if(contact.video) {
ctx_cv.remove_class("callbutton");
ctx_cv.remove_class("callbutton-started");
ctx_cv.add_class("callbutton-ringing");
}
break;
case AudioCallState.STARTED:
ctx.remove_class("callbutton");
ctx.remove_class("callbutton-ringing");
ctx.add_class("callbutton-started");
case CallState.STARTED:
ctx_ca.remove_class("callbutton");
ctx_ca.remove_class("callbutton-ringing");
ctx_ca.add_class("callbutton-started");
if(contact.video) {
ctx_cv.remove_class("callbutton");
ctx_cv.remove_class("callbutton-ringing");
ctx_cv.add_class("callbutton-started");
}
break;
default:
ctx.add_class("callbutton");
ctx.remove_class("callbutton-ringing");
ctx.remove_class("callbutton-started");
ctx_ca.add_class("callbutton");
ctx_ca.remove_class("callbutton-ringing");
ctx_ca.remove_class("callbutton-started");
if(contact.video) {
ctx_cv.add_class("callbutton");
ctx_cv.remove_class("callbutton-ringing");
ctx_cv.remove_class("callbutton-started");
}
break;
}
ctx.invalidate();
ctx_ca.invalidate();
ctx_cv.invalidate();
});
//FIXME currently commented out as it introduces sigsev on gtk 3.4
/*
Expand Down Expand Up @@ -357,15 +379,20 @@ namespace Venom {
}

public void button_call_clicked(Gtk.Button source) {
if(contact.audio_call_state != AudioCallState.ENDED) {
if(contact.call_state != CallState.ENDED) {
stop_audio_call(contact);
} else {
start_audio_call(contact);
}
}

public void button_call_video_clicked(Gtk.Button source) {
//TODO
if(contact.call_state == CallState.ENDED) {
start_video_call(contact);
} else {
//FIXME enable video when call already running
stop_audio_call(contact);
}
}

private void on_drag_data_received(Gtk.Widget sender, Gdk.DragContext drag_context, int x, int y, Gtk.SelectionData data, uint info, uint time) {
Expand Down

0 comments on commit 3b5cdc2

Please sign in to comment.