8 import util.go_utils as gobject_utils
9 import util.misc as misc_utils
12 _moduleLogger = logging.getLogger("channel.call")
16 tp.ChannelTypeStreamedMedia,
17 tp.ChannelInterfaceCallState,
18 tp.ChannelInterfaceGroup,
21 def __init__(self, connection, manager, props, contactHandle):
22 self.__manager = manager
24 self._delayedCancel = gobject_utils.Async(self._on_cancel)
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.ChannelInterfaceCallState.__init__(self)
47 tp.ChannelInterfaceGroup.__init__(self)
48 self.__contactHandle = contactHandle
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 self._delayedCancel.cancel()
101 @misc_utils.log_exception(_moduleLogger)
102 def GetLocalPendingMembersWithInfo(self):
103 info = dbus.Array([], signature="(uuus)")
104 for member in self._local_pending:
105 info.append((member, self._handle, 0, ''))
108 @misc_utils.log_exception(_moduleLogger)
109 def AddMembers(self, handles, message):
110 _moduleLogger.info("Add members %r: %s" % (handles, message))
111 for handle in handles:
112 if handle == int(self.GetSelfHandle()) and self.GetSelfHandle() in self._local_pending:
113 _moduleLogger.info("Technically the user just accepted the call")
115 @misc_utils.log_exception(_moduleLogger)
116 def RemoveMembers(self, handles, message):
117 _moduleLogger.info("Remove members (no-op) %r: %s" % (handles, message))
119 @misc_utils.log_exception(_moduleLogger)
120 def RemoveMembersWithReason(self, handles, message, reason):
121 _moduleLogger.info("Remove members (no-op) %r: %s (%i)" % (handles, message, reason))
123 @misc_utils.log_exception(_moduleLogger)
124 def ListStreams(self):
126 For org.freedesktop.Telepathy.Channel.Type.StreamedMedia
130 @misc_utils.log_exception(_moduleLogger)
131 def RemoveStreams(self, streams):
133 For org.freedesktop.Telepathy.Channel.Type.StreamedMedia
135 raise telepathy.errors.NotImplemented("Cannot remove a stream")
137 @misc_utils.log_exception(_moduleLogger)
138 def RequestStreamDirection(self, stream, streamDirection):
140 For org.freedesktop.Telepathy.Channel.Type.StreamedMedia
142 @note Since streams are short lived, not bothering to implement this
144 _moduleLogger.info("A request was made to change the stream direction")
145 raise telepathy.errors.NotImplemented("Cannot change directions")
147 @misc_utils.log_exception(_moduleLogger)
148 def RequestStreams(self, contactId, streamTypes):
150 For org.freedesktop.Telepathy.Channel.Type.StreamedMedia
152 @returns [(Stream ID, contact, stream type, stream state, stream direction, pending send flags)]
154 contact = self._conn.get_handle_by_id(telepathy.constants.HANDLE_TYPE_CONTACT, contactId)
155 assert self.__contactHandle == contact, "%r != %r" % (self.__contactHandle, contact)
156 contactNumber = contact.phoneNumber
158 self.CallStateChanged(self.__contactHandle, telepathy.constants.CHANNEL_CALL_STATE_RINGING)
159 self._delayedCancel.start()
160 self._conn.session.backend.call(contactNumber)
163 streamState = telepathy.constants.MEDIA_STREAM_STATE_CONNECTED
164 streamDirection = telepathy.constants.MEDIA_STREAM_DIRECTION_BIDIRECTIONAL
165 pendingSendFlags = telepathy.constants.MEDIA_STREAM_PENDING_REMOTE_SEND
166 return [(streamId, contact, streamTypes[0], streamState, streamDirection, pendingSendFlags)]
168 @misc_utils.log_exception(_moduleLogger)
169 def GetCallStates(self):
171 For org.freedesktop.Telepathy.Channel.Interface.CallState
173 Get the current call states for all contacts involved in this call.
174 @returns {Contact: telepathy.constants.CHANNEL_CALL_STATE_*}
176 return {self.__contactHandle: telepathy.constants.CHANNEL_CALL_STATE_FORWARDED}
178 @misc_utils.log_exception(_moduleLogger)
179 def _on_cancel(self, *args):
180 self.CallStateChanged(self.__contactHandle, telepathy.constants.CHANNEL_CALL_STATE_FORWARDED)