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.ChannelInterfaceGroup,
17 tp.ChannelInterfaceCallState,
18 tp.ChannelInterfaceHold,
21 def __init__(self, connection, manager, props, contactHandle):
22 self.__manager = manager
24 self._delayedClose = gobject_utils.Timeout(self._on_close_requested)
26 if telepathy.interfaces.CHANNEL_INTERFACE + '.InitiatorHandle' in props:
27 self._initiator = connection.get_handle_by_id(
28 telepathy.HANDLE_TYPE_CONTACT,
29 props[telepathy.interfaces.CHANNEL_INTERFACE + '.InitiatorHandle'],
31 elif telepathy.interfaces.CHANNEL_INTERFACE + '.InitiatorID' in props:
32 self._initiator = connection.get_handle_by_name(
33 telepathy.HANDLE_TYPE_CONTACT,
34 props[telepathy.interfaces.CHANNEL_INTERFACE + '.InitiatorHandle'],
37 # Maemo 5 seems to require InitiatorHandle/InitiatorID to be set
38 # even though I can't find them in the dbus spec. I think its
39 # generally safe to assume that its locally initiated if not
40 # specified. Specially for The One Ring, its always locally
42 _moduleLogger.warning('InitiatorID or InitiatorHandle not set on new channel, assuming locally initiated')
43 self._initiator = connection.GetSelfHandle()
45 tp.ChannelTypeStreamedMedia.__init__(self, connection, manager, props)
46 tp.ChannelInterfaceGroup.__init__(self)
47 tp.ChannelInterfaceCallState.__init__(self)
48 tp.ChannelInterfaceHold.__init__(self)
49 self.__contactHandle = contactHandle
50 self.__calledNumer = None
52 self._implement_property_get(
53 telepathy.interfaces.CHANNEL_INTERFACE,
55 'InitiatorHandle': lambda: dbus.UInt32(self._initiator.id),
56 'InitiatorID': lambda: self._initiator.name,
59 self._add_immutables({
60 'InitiatorHandle': telepathy.interfaces.CHANNEL_INTERFACE,
61 'InitiatorID': telepathy.interfaces.CHANNEL_INTERFACE,
63 self._implement_property_get(
64 telepathy.interfaces.CHANNEL_INTERFACE_GROUP,
66 'LocalPendingMembers': lambda: self.GetLocalPendingMembersWithInfo()
69 self._implement_property_get(
70 telepathy.interfaces.CHANNEL_TYPE_STREAMED_MEDIA,
72 "InitialAudio": self.initial_audio,
73 "InitialVideo": self.initial_video,
76 self._add_immutables({
77 'InitialAudio': telepathy.interfaces.CHANNEL_TYPE_STREAMED_MEDIA,
78 'InitialVideo': telepathy.interfaces.CHANNEL_TYPE_STREAMED_MEDIA,
81 self.GroupFlagsChanged(0, 0)
83 '', [self._conn.GetSelfHandle()], [], [], [contactHandle],
84 0, telepathy.CHANNEL_GROUP_CHANGE_REASON_NONE
87 def initial_audio(self):
90 def initial_video(self):
93 @misc_utils.log_exception(_moduleLogger)
98 _moduleLogger.debug("Closing call")
99 tp.ChannelTypeStreamedMedia.Close(self)
100 self.remove_from_connection()
101 if self.__calledNumer is not None:
102 self._conn.session.backend.cancel(self.__calledNumer)
103 self._delayedClose.cancel()
105 @misc_utils.log_exception(_moduleLogger)
106 def GetLocalPendingMembersWithInfo(self):
107 info = dbus.Array([], signature="(uuus)")
108 for member in self._local_pending:
109 info.append((member, self._handle, 0, ''))
112 @misc_utils.log_exception(_moduleLogger)
113 def AddMembers(self, handles, message):
114 _moduleLogger.info("Add members %r: %s" % (handles, message))
115 for handle in handles:
116 if handle == int(self.GetSelfHandle()) and self.GetSelfHandle() in self._local_pending:
117 _moduleLogger.info("Technically the user just accepted the call")
119 @misc_utils.log_exception(_moduleLogger)
120 def RemoveMembers(self, handles, message):
121 _moduleLogger.info("Remove members (no-op) %r: %s" % (handles, message))
123 @misc_utils.log_exception(_moduleLogger)
124 def RemoveMembersWithReason(self, handles, message, reason):
125 _moduleLogger.info("Remove members (no-op) %r: %s (%i)" % (handles, message, reason))
127 @misc_utils.log_exception(_moduleLogger)
128 def ListStreams(self):
130 For org.freedesktop.Telepathy.Channel.Type.StreamedMedia
134 @misc_utils.log_exception(_moduleLogger)
135 def RemoveStreams(self, streams):
137 For org.freedesktop.Telepathy.Channel.Type.StreamedMedia
139 raise telepathy.errors.NotImplemented("Cannot remove a stream")
141 @misc_utils.log_exception(_moduleLogger)
142 def RequestStreamDirection(self, stream, streamDirection):
144 For org.freedesktop.Telepathy.Channel.Type.StreamedMedia
146 @note Since streams are short lived, not bothering to implement this
148 _moduleLogger.info("A request was made to change the stream direction")
149 raise telepathy.errors.NotImplemented("Cannot change directions")
151 @misc_utils.log_exception(_moduleLogger)
152 def RequestStreams(self, contactId, streamTypes):
154 For org.freedesktop.Telepathy.Channel.Type.StreamedMedia
156 @returns [(Stream ID, contact, stream type, stream state, stream direction, pending send flags)]
158 contact = self._conn.get_handle_by_id(telepathy.constants.HANDLE_TYPE_CONTACT, contactId)
159 assert self.__contactHandle == contact, "%r != %r" % (self.__contactHandle, contact)
160 contactNumber = contact.phoneNumber
162 self.__calledNumer = contactNumber
163 self.CallStateChanged(self.__contactHandle, telepathy.constants.CHANNEL_CALL_STATE_RINGING)
164 self._conn.session.backend.call(contactNumber)
165 self._delayedClose.start(seconds=2)
166 self.CallStateChanged(self.__contactHandle, telepathy.constants.CHANNEL_CALL_STATE_FORWARDED)
169 streamState = telepathy.constants.MEDIA_STREAM_STATE_CONNECTED
170 streamDirection = telepathy.constants.MEDIA_STREAM_DIRECTION_BIDIRECTIONAL
171 pendingSendFlags = telepathy.constants.MEDIA_STREAM_PENDING_REMOTE_SEND
172 return [(streamId, contact, streamTypes[0], streamState, streamDirection, pendingSendFlags)]
174 @misc_utils.log_exception(_moduleLogger)
175 def GetCallStates(self):
177 For org.freedesktop.Telepathy.Channel.Interface.CallState
179 Get the current call states for all contacts involved in this call.
180 @returns {Contact: telepathy.constants.CHANNEL_CALL_STATE_*}
182 return {self.__contactHandle: telepathy.constants.CHANNEL_CALL_STATE_FORWARDED}
184 @misc_utils.log_exception(_moduleLogger)
185 def GetHoldState(self):
187 For org.freedesktop.Telepathy.Channel.Interface.Hold
189 Get the current hold state
190 @returns (HoldState, Reason)
193 telepathy.constants.LOCAL_HOLD_STATE_UNHELD,
194 telepathy.constants.LOCAL_HOLD_STATE_REASON_NONE,
197 @misc_utils.log_exception(_moduleLogger)
198 def RequestHold(self, Hold):
200 For org.freedesktop.Telepathy.Channel.Interface.Hold
204 _moduleLogger.debug("Closing without cancel to get out of users way")
205 self.__calledNumer = None
208 @misc_utils.log_exception(_moduleLogger)
209 def _on_close_requested(self, *args):
210 _moduleLogger.debug("Cancel now disallowed")
211 self.__calledNumer = None