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._delayedCancel = gobject_utils.Async(self._on_cancel)
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
49 self._implement_property_get(
50 telepathy.interfaces.CHANNEL_INTERFACE,
52 'InitiatorHandle': lambda: dbus.UInt32(self._initiator.id),
53 'InitiatorID': lambda: self._initiator.name,
56 self._add_immutables({
57 'InitiatorHandle': telepathy.interfaces.CHANNEL_INTERFACE,
58 'InitiatorID': telepathy.interfaces.CHANNEL_INTERFACE,
60 self._implement_property_get(
61 telepathy.interfaces.CHANNEL_INTERFACE_GROUP,
63 'LocalPendingMembers': lambda: self.GetLocalPendingMembersWithInfo()
66 self._implement_property_get(
67 telepathy.interfaces.CHANNEL_TYPE_STREAMED_MEDIA,
69 "InitialAudio": self.initial_audio,
70 "InitialVideo": self.initial_video,
73 self._add_immutables({
74 'InitialAudio': telepathy.interfaces.CHANNEL_TYPE_STREAMED_MEDIA,
75 'InitialVideo': telepathy.interfaces.CHANNEL_TYPE_STREAMED_MEDIA,
78 self.GroupFlagsChanged(0, 0)
80 '', [self._conn.GetSelfHandle()], [], [], [contactHandle],
81 0, telepathy.CHANNEL_GROUP_CHANGE_REASON_NONE
84 def initial_audio(self):
87 def initial_video(self):
90 @misc_utils.log_exception(_moduleLogger)
95 _moduleLogger.debug("Closing call")
96 tp.ChannelTypeStreamedMedia.Close(self)
97 self.remove_from_connection()
98 self._delayedCancel.cancel()
100 @misc_utils.log_exception(_moduleLogger)
101 def GetLocalPendingMembersWithInfo(self):
102 info = dbus.Array([], signature="(uuus)")
103 for member in self._local_pending:
104 info.append((member, self._handle, 0, ''))
107 @misc_utils.log_exception(_moduleLogger)
108 def AddMembers(self, handles, message):
109 _moduleLogger.info("Add members %r: %s" % (handles, message))
110 for handle in handles:
111 if handle == int(self.GetSelfHandle()) and self.GetSelfHandle() in self._local_pending:
112 _moduleLogger.info("Technically the user just accepted the call")
114 @misc_utils.log_exception(_moduleLogger)
115 def RemoveMembers(self, handles, message):
116 _moduleLogger.info("Remove members (no-op) %r: %s" % (handles, message))
118 @misc_utils.log_exception(_moduleLogger)
119 def RemoveMembersWithReason(self, handles, message, reason):
120 _moduleLogger.info("Remove members (no-op) %r: %s (%i)" % (handles, message, reason))
122 @misc_utils.log_exception(_moduleLogger)
123 def ListStreams(self):
125 For org.freedesktop.Telepathy.Channel.Type.StreamedMedia
129 @misc_utils.log_exception(_moduleLogger)
130 def RemoveStreams(self, streams):
132 For org.freedesktop.Telepathy.Channel.Type.StreamedMedia
134 raise telepathy.errors.NotImplemented("Cannot remove a stream")
136 @misc_utils.log_exception(_moduleLogger)
137 def RequestStreamDirection(self, stream, streamDirection):
139 For org.freedesktop.Telepathy.Channel.Type.StreamedMedia
141 @note Since streams are short lived, not bothering to implement this
143 _moduleLogger.info("A request was made to change the stream direction")
144 raise telepathy.errors.NotImplemented("Cannot change directions")
146 @misc_utils.log_exception(_moduleLogger)
147 def RequestStreams(self, contactId, streamTypes):
149 For org.freedesktop.Telepathy.Channel.Type.StreamedMedia
151 @returns [(Stream ID, contact, stream type, stream state, stream direction, pending send flags)]
153 contact = self._conn.get_handle_by_id(telepathy.constants.HANDLE_TYPE_CONTACT, contactId)
154 assert self.__contactHandle == contact, "%r != %r" % (self.__contactHandle, contact)
155 contactNumber = contact.phoneNumber
157 self.CallStateChanged(self.__contactHandle, telepathy.constants.CHANNEL_CALL_STATE_RINGING)
158 self._delayedCancel.start()
159 self._conn.session.backend.call(contactNumber)
162 streamState = telepathy.constants.MEDIA_STREAM_STATE_CONNECTED
163 streamDirection = telepathy.constants.MEDIA_STREAM_DIRECTION_BIDIRECTIONAL
164 pendingSendFlags = telepathy.constants.MEDIA_STREAM_PENDING_REMOTE_SEND
165 return [(streamId, contact, streamTypes[0], streamState, streamDirection, pendingSendFlags)]
167 @misc_utils.log_exception(_moduleLogger)
168 def GetCallStates(self):
170 For org.freedesktop.Telepathy.Channel.Interface.CallState
172 Get the current call states for all contacts involved in this call.
173 @returns {Contact: telepathy.constants.CHANNEL_CALL_STATE_*}
175 return {self.__contactHandle: telepathy.constants.CHANNEL_CALL_STATE_FORWARDED}
177 @misc_utils.log_exception(_moduleLogger)
178 def _on_cancel(self, *args):
179 self.CallStateChanged(self.__contactHandle, telepathy.constants.CHANNEL_CALL_STATE_FORWARDED)