Switching over to a copy-paste version of python-telepathy's channel manager
[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                 telepathy.server.ChannelTypeStreamedMedia.__init__(self, connection, None)
23                 telepathy.server.ChannelInterfaceCallState.__init__(self)
24                 telepathy.server.ChannelInterfaceGroup.__init__(self)
25                 self._contactHandle = contactHandle
26                 self._implement_property_get(
27                         telepathy.interfaces.CHANNEL_TYPE_STREAMED_MEDIA,
28                         {
29                                 "InitialAudio": self.initial_audio,
30                                 "InitialVideo": self.initial_video,
31                         },
32                 )
33
34         def initial_audio(self):
35                 return False
36
37         def initial_video(self):
38                 return False
39
40         @gtk_toolbox.log_exception(_moduleLogger)
41         def Close(self):
42                 self.close()
43
44         def close(self):
45                 telepathy.server.ChannelTypeStreamedMedia.Close(self)
46                 if self._manager.channel_exists(self._props):
47                         # Older python-telepathy requires doing this manually
48                         self._manager.remove_channel(self)
49                 self.remove_from_connection()
50
51         @gtk_toolbox.log_exception(_moduleLogger)
52         def ListStreams(self):
53                 """
54                 For org.freedesktop.Telepathy.Channel.Type.StreamedMedia
55                 """
56                 return ()
57
58         @gtk_toolbox.log_exception(_moduleLogger)
59         def RemoveStreams(self, streams):
60                 """
61                 For org.freedesktop.Telepathy.Channel.Type.StreamedMedia
62                 """
63                 raise telepathy.errors.NotImplemented("Cannot remove a stream")
64
65         @gtk_toolbox.log_exception(_moduleLogger)
66         def RequestStreamDirection(self, stream, streamDirection):
67                 """
68                 For org.freedesktop.Telepathy.Channel.Type.StreamedMedia
69
70                 @note Since streams are short lived, not bothering to implement this
71                 """
72                 _moduleLogger.info("A request was made to change the stream direction")
73                 raise telepathy.errors.NotImplemented("Cannot change directions")
74
75         @gtk_toolbox.log_exception(_moduleLogger)
76         def RequestStreams(self, contactId, streamTypes):
77                 """
78                 For org.freedesktop.Telepathy.Channel.Type.StreamedMedia
79
80                 @returns [(Stream ID, contact, stream type, stream state, stream direction, pending send flags)]
81                 """
82                 contact = self._conn.handle(telepathy.constants.HANDLE_TYPE_CONTACT, contactId)
83                 assert self._contactHandle == contact, "%r != %r" % (self._contactHandle, contact)
84                 contactId, contactNumber = handle.ContactHandle.from_handle_name(contact.name)
85
86                 self.CallStateChanged(self._contactHandle, telepathy.constants.CHANNEL_CALL_STATE_RINGING)
87                 self._conn.session.backend.call(contactNumber)
88                 self.CallStateChanged(self._contactHandle, telepathy.constants.CHANNEL_CALL_STATE_FORWARDED)
89
90                 streamId = 0
91                 streamState = telepathy.constants.MEDIA_STREAM_STATE_DISCONNECTED
92                 streamDirection = telepathy.constants.MEDIA_STREAM_DIRECTION_BIDIRECTIONAL
93                 pendingSendFlags = telepathy.constants.MEDIA_STREAM_PENDING_REMOTE_SEND
94                 return [(streamId, contact, streamTypes[0], streamState, streamDirection, pendingSendFlags)]
95
96         @gtk_toolbox.log_exception(_moduleLogger)
97         def GetCallStates(self):
98                 """
99                 For org.freedesktop.Telepathy.Channel.Interface.CallState
100
101                 Get the current call states for all contacts involved in this call. 
102                 @returns {Contact: telepathy.constants.CHANNEL_CALL_STATE_*}
103                 """
104                 return {self._contactHandle: telepathy.constants.CHANNEL_CALL_STATE_FORWARDED}