11 _moduleLogger = logging.getLogger("channel.call")
15 tp.ChannelTypeStreamedMedia,
16 tp.ChannelInterfaceCallState,
17 tp.ChannelInterfaceGroup,
20 def __init__(self, connection, manager, props, contactHandle):
21 self.__manager = manager
23 self.__cancelId = None
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 @gtk_toolbox.log_exception(_moduleLogger)
95 _moduleLogger.debug("Closing call")
96 tp.ChannelTypeStreamedMedia.Close(self)
97 self.remove_from_connection()
98 if self.__cancelId is not None:
99 gobject.source_remove(self.__cancelId)
100 self.__cancelId = None
102 @gtk_toolbox.log_exception(_moduleLogger)
103 def GetLocalPendingMembersWithInfo(self):
104 info = dbus.Array([], signature="(uuus)")
105 for member in self._local_pending:
106 info.append((member, self._handle, 0, ''))
109 @gtk_toolbox.log_exception(_moduleLogger)
110 def AddMembers(self, handles, message):
111 _moduleLogger.info("Add members %r: %s" % (handles, message))
112 for handle in handles:
113 if handle == int(self.GetSelfHandle()) and self.GetSelfHandle() in self._local_pending:
114 _moduleLogger.info("Technically the user just accepted the call")
116 @gtk_toolbox.log_exception(_moduleLogger)
117 def RemoveMembers(self, handles, message):
118 _moduleLogger.info("Remove members (no-op) %r: %s" % (handles, message))
120 @gtk_toolbox.log_exception(_moduleLogger)
121 def RemoveMembersWithReason(self, handles, message, reason):
122 _moduleLogger.info("Remove members (no-op) %r: %s (%i)" % (handles, message, reason))
124 @gtk_toolbox.log_exception(_moduleLogger)
125 def ListStreams(self):
127 For org.freedesktop.Telepathy.Channel.Type.StreamedMedia
131 @gtk_toolbox.log_exception(_moduleLogger)
132 def RemoveStreams(self, streams):
134 For org.freedesktop.Telepathy.Channel.Type.StreamedMedia
136 raise telepathy.errors.NotImplemented("Cannot remove a stream")
138 @gtk_toolbox.log_exception(_moduleLogger)
139 def RequestStreamDirection(self, stream, streamDirection):
141 For org.freedesktop.Telepathy.Channel.Type.StreamedMedia
143 @note Since streams are short lived, not bothering to implement this
145 _moduleLogger.info("A request was made to change the stream direction")
146 raise telepathy.errors.NotImplemented("Cannot change directions")
148 @gtk_toolbox.log_exception(_moduleLogger)
149 def RequestStreams(self, contactId, streamTypes):
151 For org.freedesktop.Telepathy.Channel.Type.StreamedMedia
153 @returns [(Stream ID, contact, stream type, stream state, stream direction, pending send flags)]
155 contact = self._conn.get_handle_by_id(telepathy.constants.HANDLE_TYPE_CONTACT, contactId)
156 assert self.__contactHandle == contact, "%r != %r" % (self.__contactHandle, contact)
157 contactNumber = contact.phoneNumber
159 self.CallStateChanged(self.__contactHandle, telepathy.constants.CHANNEL_CALL_STATE_RINGING)
160 self.__cancelId = gobject.idle_add(self._on_cancel)
161 self._conn.session.backend.call(contactNumber)
164 streamState = telepathy.constants.MEDIA_STREAM_STATE_CONNECTED
165 streamDirection = telepathy.constants.MEDIA_STREAM_DIRECTION_BIDIRECTIONAL
166 pendingSendFlags = telepathy.constants.MEDIA_STREAM_PENDING_REMOTE_SEND
167 return [(streamId, contact, streamTypes[0], streamState, streamDirection, pendingSendFlags)]
169 @gtk_toolbox.log_exception(_moduleLogger)
170 def GetCallStates(self):
172 For org.freedesktop.Telepathy.Channel.Interface.CallState
174 Get the current call states for all contacts involved in this call.
175 @returns {Contact: telepathy.constants.CHANNEL_CALL_STATE_*}
177 return {self.__contactHandle: telepathy.constants.CHANNEL_CALL_STATE_FORWARDED}
179 @gtk_toolbox.log_exception(_moduleLogger)
180 def _on_cancel(self, *args):
181 self.CallStateChanged(self.__contactHandle, telepathy.constants.CHANNEL_CALL_STATE_FORWARDED)
183 self.__cancelId = None