Skip to content

Commit

Permalink
extended functionality of ToxSession
Browse files Browse the repository at this point in the history
  • Loading branch information
naxuroqa committed Jun 13, 2014
1 parent 1082381 commit f224f9f
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 36 deletions.
10 changes: 6 additions & 4 deletions src/core/Contact.vala
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@


namespace Venom {

public enum AudioCallState {
RINGING,
STARTING,
ENDING
STARTED,
ENDED
}


public interface IContact : GLib.Object {
public abstract string get_name_string();
public abstract string get_name_string_with_hyperlinks();
Expand Down Expand Up @@ -56,7 +56,9 @@ namespace Venom {
public Gdk.Pixbuf? image { get; set; default = null; }
public int unread_messages { get; set; default = 0; }
public bool is_typing { get; set; default = false; }
public AudioCallState audio_call_state { get; set; default = AudioCallState.ENDING; }
// ToxAV stuff
public int call_index { get; set; default = -1; }
public AudioCallState audio_call_state { get; set; default = AudioCallState.ENDED; }

private GLib.HashTable<uint8, FileTransfer> _file_transfers = new GLib.HashTable<uint8, FileTransfer>(null, null);

Expand Down
99 changes: 69 additions & 30 deletions src/core/ToxSession.vala
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ namespace Venom {
}
}


// Wrapper class for accessing tox functions threadsafe
public class ToxSession : Object {

Expand Down Expand Up @@ -865,80 +866,118 @@ namespace Venom {
}

// TOXAV functions
public void start_audio_call(Contact c) {
// start audio thread, ...
int call_index = 0;
toxav_handle.call(ref call_index, c.friend_id, ToxAV.CallType.AUDIO, 10);
}

public void hangup_call(Contact c) {
toxav_handle.hangup(c.call_index);
}

public void cancel_call(Contact c) {
toxav_handle.cancel(c.call_index, c.friend_id, "do not want");
}

// TOXAV callbacks
private void on_av_invite_callback(int32 call_index) {
int friend_id = toxav_handle.get_peer_id(call_index, 0);
Idle.add(() => {
on_av_invite(_contacts.get(friend_id));
Contact c = _contacts.get(friend_id);
c.call_index = call_index;
on_av_invite(c);
return false;
});
}
private void on_av_start_callback(int32 call_index) {
int friend_id = toxav_handle.get_peer_id(call_index, 0);
Idle.add(() => {
on_av_start(_contacts.get(friend_id));
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;
on_av_start(c);
return false;
});
}
private void on_av_cancel_callback(int32 call_index) {
int friend_id = toxav_handle.get_peer_id(call_index, 0);
Idle.add(() => {
on_av_cancel(_contacts.get(friend_id));
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;
on_av_cancel(c);
return false;
});
}
private void on_av_reject_callback(int32 call_index) {
int friend_id = toxav_handle.get_peer_id(call_index, 0);
Idle.add(() => {
on_av_reject(_contacts.get(friend_id));
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;
on_av_reject(c);
return false;
});
}
private void on_av_end_callback(int32 call_index) {
int friend_id = toxav_handle.get_peer_id(call_index, 0);
Idle.add(() => {
on_av_end(_contacts.get(friend_id));
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;
on_av_end(c);
return false;
});
}
private void on_av_ringing_callback(int32 call_index) {
int friend_id = toxav_handle.get_peer_id(call_index, 0);
Idle.add(() => {
on_av_ringing(_contacts.get(friend_id));
int friend_id = toxav_handle.get_peer_id(call_index, 0);
Idle.add(() => {
Contact c = _contacts.get(friend_id);
c.call_index = call_index;
c.audio_call_state = AudioCallState.RINGING;
on_av_ringing(c);
return false;
});
}
private void on_av_starting_callback(int32 call_index) {
int friend_id = toxav_handle.get_peer_id(call_index, 0);
Idle.add(() => {
on_av_starting(_contacts.get(friend_id));
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;
on_av_starting(c);
return false;
});
}
private void on_av_ending_callback(int32 call_index) {
int friend_id = toxav_handle.get_peer_id(call_index, 0);
Idle.add(() => {
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;
on_av_ending(_contacts.get(friend_id));
return false;
});
}
private void on_av_error_callback(int32 call_index) {
int friend_id = toxav_handle.get_peer_id(call_index, 0);
Idle.add(() => {
on_av_error(_contacts.get(friend_id));
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;
on_av_error(c);
return false;
});
}
private void on_av_request_timeout_callback(int32 call_index) {
int friend_id = toxav_handle.get_peer_id(call_index, 0);
Idle.add(() => {
on_av_request_timeout(_contacts.get(friend_id));
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;
on_av_request_timeout(c);
return false;
});
}
private void on_av_peer_timeout_callback(int32 call_index) {
int friend_id = toxav_handle.get_peer_id(call_index, 0);
Idle.add(() => {
on_av_peer_timeout(_contacts.get(friend_id));
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;
on_av_peer_timeout(c);
return false;
});
}
Expand Down
15 changes: 13 additions & 2 deletions src/ui/ContactListWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -845,11 +845,22 @@ namespace Venom {
}

private void on_start_audio_call(Contact c) {
AudioManager.instance.set_pipeline_playing();
session.start_audio_call(c);
}

private void on_stop_audio_call(Contact c) {
AudioManager.instance.set_pipeline_paused();
switch(c.audio_call_state) {
case AudioCallState.RINGING:
session.cancel_call(c);
break;
case AudioCallState.STARTED:
session.hangup_call(c);
break;
case AudioCallState.ENDED:
break;
default:
assert_not_reached();
}
}

private void on_file_sendrequest(int friendnumber, uint8 filenumber, uint64 filesize,string filename) {
Expand Down

0 comments on commit f224f9f

Please sign in to comment.