summaryrefslogtreecommitdiff
path: root/src/phoenix-test-call.py
blob: 6342eed6e375442b764c6445c6347677e766364e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/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)