7 import util.go_utils as gobject_utils
8 import util.misc as misc_utils
11 _moduleLogger = logging.getLogger(__name__)
15 tp.ChannelTypeStreamedMedia,
16 tp.ChannelInterfaceCallState,
17 tp.ChannelInterfaceGroup,
20 def __init__(self, connection, manager, props, contactHandle):
21 self.__manager = manager
23 self._delayedClose = gobject_utils.Timeout(self._on_close_requested)
25 if telepathy.interfaces.CHANNEL_INTERFACE + '.InitiatorHandle' in props:
26 self._initiator = connection.get_handle_by_id(
27 telepathy.HANDLE_TYPE_CONTACT,
28 props[telepathy.interfaces.CHANNEL_INTERFACE + '.InitiatorHandle'],
30 elif telepathy.interfaces.CHANNEL_INTERFACE + '.InitiatorID' in props:
31 self._initiator = connection.get_handle_by_name(
32 telepathy.HANDLE_TYPE_CONTACT,
33 props[telepathy.interfaces.CHANNEL_INTERFACE + '.InitiatorHandle'],
36 # Maemo 5 seems to require InitiatorHandle/InitiatorID to be set
37 # even though I can't find them in the dbus spec. I think its
38 # generally safe to assume that its locally initiated if not
39 # specified. Specially for The One Ring, its always locally
41 _moduleLogger.warning('InitiatorID or InitiatorHandle not set on new channel, assuming locally initiated')
42 self._initiator = connection.GetSelfHandle()
44 tp.ChannelTypeStreamedMedia.__init__(self, connection, manager, props)
45 tp.ChannelInterfaceCallState.__init__(self)
46 tp.ChannelInterfaceGroup.__init__(self)
47 self.__contactHandle = contactHandle
48 self.__calledNumer = None
50 self._implement_property_get(
51 telepathy.interfaces.CHANNEL_INTERFACE,
53 'InitiatorHandle': lambda: dbus.UInt32(self._initiator.id),
54 'InitiatorID': lambda: self._initiator.name,
57 self._add_immutables({
58 'InitiatorHandle': telepathy.interfaces.CHANNEL_INTERFACE,
59 'InitiatorID': telepathy.interfaces.CHANNEL_INTERFACE,
61 self._implement_property_get(
62 telepathy.interfaces.CHANNEL_INTERFACE_GROUP,
64 'LocalPendingMembers': lambda: self.GetLocalPendingMembersWithInfo()
67 self._implement_property_get(
68 telepathy.interfaces.CHANNEL_TYPE_STREAMED_MEDIA,
70 "InitialAudio": self.initial_audio,
71 "InitialVideo": self.initial_video,
74 self._add_immutables({
75 'InitialAudio': telepathy.interfaces.CHANNEL_TYPE_STREAMED_MEDIA,
76 'InitialVideo': telepathy.interfaces.CHANNEL_TYPE_STREAMED_MEDIA,
79 self.GroupFlagsChanged(0, 0)
81 '', [self._conn.GetSelfHandle()], [], [], [contactHandle],
82 0, telepathy.CHANNEL_GROUP_CHANGE_REASON_NONE
85 def initial_audio(self):
88 def initial_video(self):
91 @misc_utils.log_exception(_moduleLogger)
96 _moduleLogger.debug("Closing call")
97 tp.ChannelTypeStreamedMedia.Close(self)
98 self.remove_from_connection()
99 if self.__calledNumer is not None:
100 self._conn.session.backend.cancel(self.__calledNumer)
101 self._delayedClose.cancel()
103 @misc_utils.log_exception(_moduleLogger)
104 def GetLocalPendingMembersWithInfo(self):
105 info = dbus.Array([], signature="(uuus)")
106 for member in self._local_pending:
107 info.append((member, self._handle, 0, ''))
110 @misc_utils.log_exception(_moduleLogger)
111 def AddMembers(self, handles, message):
112 _moduleLogger.info("Add members %r: %s" % (handles, message))
113 for handle in handles:
114 if handle == int(self.GetSelfHandle()) and self.GetSelfHandle() in self._local_pending:
115 _moduleLogger.info("Technically the user just accepted the call")
117 @misc_utils.log_exception(_moduleLogger)
118 def RemoveMembers(self, handles, message):
119 _moduleLogger.info("Remove members (no-op) %r: %s" % (handles, message))
121 @misc_utils.log_exception(_moduleLogger)
122 def RemoveMembersWithReason(self, handles, message, reason):
123 _moduleLogger.info("Remove members (no-op) %r: %s (%i)" % (handles, message, reason))
125 @misc_utils.log_exception(_moduleLogger)
126 def ListStreams(self):
128 For org.freedesktop.Telepathy.Channel.Type.StreamedMedia
132 @misc_utils.log_exception(_moduleLogger)
133 def RemoveStreams(self, streams):
135 For org.freedesktop.Telepathy.Channel.Type.StreamedMedia
137 raise telepathy.errors.NotImplemented("Cannot remove a stream")
139 @misc_utils.log_exception(_moduleLogger)
140 def RequestStreamDirection(self, stream, streamDirection):
142 For org.freedesktop.Telepathy.Channel.Type.StreamedMedia
144 @note Since streams are short lived, not bothering to implement this
146 _moduleLogger.info("A request was made to change the stream direction")
147 raise telepathy.errors.NotImplemented("Cannot change directions")
149 @misc_utils.log_exception(_moduleLogger)
150 def RequestStreams(self, contactId, streamTypes):
152 For org.freedesktop.Telepathy.Channel.Type.StreamedMedia
154 @returns [(Stream ID, contact, stream type, stream state, stream direction, pending send flags)]
156 contact = self._conn.get_handle_by_id(telepathy.constants.HANDLE_TYPE_CONTACT, contactId)
157 assert self.__contactHandle == contact, "%r != %r" % (self.__contactHandle, contact)
158 contactNumber = contact.phoneNumber
160 self.__calledNumer = contactNumber
161 self.CallStateChanged(self.__contactHandle, telepathy.constants.CHANNEL_CALL_STATE_RINGING)
162 self._conn.session.backend.call(contactNumber)
163 self._delayedClose.start(seconds=5)
164 self.CallStateChanged(self.__contactHandle, telepathy.constants.CHANNEL_CALL_STATE_FORWARDED)
167 streamState = telepathy.constants.MEDIA_STREAM_STATE_CONNECTED
168 streamDirection = telepathy.constants.MEDIA_STREAM_DIRECTION_BIDIRECTIONAL
169 pendingSendFlags = telepathy.constants.MEDIA_STREAM_PENDING_REMOTE_SEND
170 return [(streamId, contact, streamTypes[0], streamState, streamDirection, pendingSendFlags)]
172 @misc_utils.log_exception(_moduleLogger)
173 def GetCallStates(self):
175 For org.freedesktop.Telepathy.Channel.Interface.CallState
177 Get the current call states for all contacts involved in this call.
178 @returns {Contact: telepathy.constants.CHANNEL_CALL_STATE_*}
180 return {self.__contactHandle: telepathy.constants.CHANNEL_CALL_STATE_FORWARDED}
182 @misc_utils.log_exception(_moduleLogger)
183 def _on_close_requested(self, *args):
184 _moduleLogger.debug("Cancel now disallowed")
185 self.__calledNumer = None