#!/usr/bin/env python # -*- coding: utf-8 -*- import sys from gi.repository import GObject, Gio, GLib from gi.repository import TelepathyGLib as Tp from test import main, TestConnection class CallConnection(TestConnection): def __init__(self, t, connection): TestConnection.__init__(self, t, connection) self.call_success = False def hangup(self): self.channel.hangup_async(Tp.CallStateChangeReason.USER_REQUESTED, '', '', None, None) def check_call_status(self, *args): (state, flags, details, reason) = self.channel.get_state() got_audio = self.proxy.get_cached_property('ReceivingAudio') got_video = self.proxy.get_cached_property('ReceivingVideo') if state == Tp.CallState.ACTIVE and got_audio and got_video: self.t.write('Successful call, letting it run for 5 seconds') self.call_success = True GLib.timeout_add_seconds(5, self.hangup) if state == Tp.CallState.ENDED: self.t.assertEqual(True, self.call_success) self.t.assertEqual(Tp.CallStateChangeReason.USER_REQUESTED, reason.reason) self.t.assertEqual(self.connection.get_self_handle(), reason.actor) self.t.done() def create_channel_finished(self, req, r, u): TestConnection.create_channel_finished(self, req, r, u) d = Gio.bus_get_sync(Gio.BusType.SESSION, None) self.proxy = proxy = Gio.DBusProxy.new_sync(d, 0, None, 'org.freedesktop.Telepathy.Phoenix.Calls', '/org/freedesktop/Telepathy/Phoenix/Calls' + self.channel.get_object_path(), 'org.freedesktop.Telepathy.Phoenix.CallInfo', None) proxy.connect('g-properties-changed', self.check_call_status, None) self.channel.connect('notify::state', self.check_call_status, None) def handle_capabilities(self): account = self.contact.get_account() req = Tp.AccountChannelRequest.new_audio_call(account, 0) req.set_hint('call-mode', GLib.Variant('s', 'test-inputs')) req.set_target_contact(self.contact) req.create_and_observe_channel_async('', None, self.create_channel_finished, None) if __name__ == '__main__': main(sys.argv, 'VOIP', CallConnection)