Adding hack for change in python-telepathy __init__ params
[theonering] / src / channel / call.py
1 import logging
2
3 import telepathy
4
5 import gtk_toolbox
6 import handle
7
8
9 _moduleLogger = logging.getLogger("channel.call")
10
11
12 class CallChannel(
13                 telepathy.server.ChannelTypeStreamedMedia,
14                 telepathy.server.ChannelInterfaceCallState,
15                 telepathy.server.ChannelInterfaceGroup,
16         ):
17
18         def __init__(self, connection, manager, props, contactHandle):
19                 self._manager = manager
20                 self._props = props
21
22                 try:
23                         # Older python-telepathy way
24                         telepathy.server.ChannelTypeStreamedMedia.__init__(self, connection, None)
25                 except TypeError:
26                         # Newer python-telepathy way
27                         telepathy.server.ChannelTypeStreamedMedia.__init__(self, connection, manager, props)
28                 telepathy.server.ChannelInterfaceCallState.__init__(self)
29                 telepathy.server.ChannelInterfaceGroup.__init__(self)
30                 self._contactHandle = contactHandle
31                 self._implement_property_get(
32                         telepathy.interfaces.CHANNEL_TYPE_STREAMED_MEDIA,
33                         {
34                                 "InitialAudio": self.initial_audio,
35                                 "InitialVideo": self.initial_video,
36                         },
37                 )
38
39         def initial_audio(self):
40                 return False
41
42         def initial_video(self):
43                 return False
44
45         @gtk_toolbox.log_exception(_moduleLogger)
46         def Close(self):
47                 self.close()
48
49         def close(self):
50                 telepathy.server.ChannelTypeStreamedMedia.Close(self)
51                 if self._manager.channel_exists(self._props):
52                         # Older python-telepathy requires doing this manually
53                         self._manager.remove_channel(self)
54                 self.remove_from_connection()
55
56         @gtk_toolbox.log_exception(_moduleLogger)
57         def ListStreams(self):
58                 """
59                 For org.freedesktop.Telepathy.Channel.Type.StreamedMedia
60                 """
61                 return ()
62
63         @gtk_toolbox.log_exception(_moduleLogger)
64         def RemoveStreams(self, streams):
65                 """
66                 For org.freedesktop.Telepathy.Channel.Type.StreamedMedia
67                 """
68                 raise telepathy.errors.NotImplemented("Cannot remove a stream")
69
70         @gtk_toolbox.log_exception(_moduleLogger)
71         def RequestStreamDirection(self, stream, streamDirection):
72                 """
73                 For org.freedesktop.Telepathy.Channel.Type.StreamedMedia
74
75                 @note Since streams are short lived, not bothering to implement this
76                 """
77                 _moduleLogger.info("A request was made to change the stream direction")
78                 raise telepathy.errors.NotImplemented("Cannot change directions")
79
80         @gtk_toolbox.log_exception(_moduleLogger)
81         def RequestStreams(self, contactId, streamTypes):
82                 """
83                 For org.freedesktop.Telepathy.Channel.Type.StreamedMedia
84
85                 @returns [(Stream ID, contact, stream type, stream state, stream direction, pending send flags)]
86                 """
87                 contact = self._conn.handle(telepathy.constants.HANDLE_TYPE_CONTACT, contactId)
88                 assert self._contactHandle == contact, "%r != %r" % (self._contactHandle, contact)
89                 contactId, contactNumber = handle.ContactHandle.from_handle_name(contact.name)
90
91                 self.CallStateChanged(self._contactHandle, telepathy.constants.CHANNEL_CALL_STATE_RINGING)
92                 self._conn.session.backend.call(contactNumber)
93                 self.CallStateChanged(self._contactHandle, telepathy.constants.CHANNEL_CALL_STATE_FORWARDED)
94
95                 streamId = 0
96                 streamState = telepathy.constants.MEDIA_STREAM_STATE_DISCONNECTED
97                 streamDirection = telepathy.constants.MEDIA_STREAM_DIRECTION_BIDIRECTIONAL
98                 pendingSendFlags = telepathy.constants.MEDIA_STREAM_PENDING_REMOTE_SEND
99                 return [(streamId, contact, streamTypes[0], streamState, streamDirection, pendingSendFlags)]
100
101         @gtk_toolbox.log_exception(_moduleLogger)
102         def GetCallStates(self):
103                 """
104                 For org.freedesktop.Telepathy.Channel.Interface.CallState
105
106                 Get the current call states for all contacts involved in this call. 
107                 @returns {Contact: telepathy.constants.CHANNEL_CALL_STATE_*}
108                 """
109                 return {self._contactHandle: telepathy.constants.CHANNEL_CALL_STATE_FORWARDED}