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
48 self._implement_property_get(
49 telepathy.interfaces.CHANNEL_TYPE_STREAMED_MEDIA,
51 "InitialAudio": self.initial_audio,
52 "InitialVideo": self.initial_video,
55 self._add_immutables({
56 'InitialAudio': telepathy.interfaces.CHANNEL_TYPE_STREAMED_MEDIA,
57 'InitialVideo': telepathy.interfaces.CHANNEL_TYPE_STREAMED_MEDIA,
59 self._implement_property_get(
60 telepathy.interfaces.CHANNEL_INTERFACE,
62 'InitiatorHandle': lambda: dbus.UInt32(self._initiator.id),
63 'InitiatorID': lambda: self._initiator.name,
66 self._add_immutables({
67 'InitiatorHandle': telepathy.interfaces.CHANNEL_INTERFACE,
68 'InitiatorID': telepathy.interfaces.CHANNEL_INTERFACE,
71 self.GroupFlagsChanged(0, 0)
73 '', [self._conn.GetSelfHandle()], [], [], [contactHandle],
74 0, telepathy.CHANNEL_GROUP_CHANGE_REASON_NONE
77 def initial_audio(self):
80 def initial_video(self):
83 @gtk_toolbox.log_exception(_moduleLogger)
88 _moduleLogger.debug("Closing call")
89 tp.ChannelTypeStreamedMedia.Close(self)
90 self.remove_from_connection()
91 if self.__cancelId is not None:
92 gobject.source_remove(self.__cancelId)
93 self.__cancelId = None
95 @gtk_toolbox.log_exception(_moduleLogger)
96 def GetLocalPendingMembersWithInfo(self):
99 @gtk_toolbox.log_exception(_moduleLogger)
100 def ListStreams(self):
102 For org.freedesktop.Telepathy.Channel.Type.StreamedMedia
106 @gtk_toolbox.log_exception(_moduleLogger)
107 def RemoveStreams(self, streams):
109 For org.freedesktop.Telepathy.Channel.Type.StreamedMedia
111 raise telepathy.errors.NotImplemented("Cannot remove a stream")
113 @gtk_toolbox.log_exception(_moduleLogger)
114 def RequestStreamDirection(self, stream, streamDirection):
116 For org.freedesktop.Telepathy.Channel.Type.StreamedMedia
118 @note Since streams are short lived, not bothering to implement this
120 _moduleLogger.info("A request was made to change the stream direction")
121 raise telepathy.errors.NotImplemented("Cannot change directions")
123 @gtk_toolbox.log_exception(_moduleLogger)
124 def RequestStreams(self, contactId, streamTypes):
126 For org.freedesktop.Telepathy.Channel.Type.StreamedMedia
128 @returns [(Stream ID, contact, stream type, stream state, stream direction, pending send flags)]
130 contact = self._conn.get_handle_by_id(telepathy.constants.HANDLE_TYPE_CONTACT, contactId)
131 assert self.__contactHandle == contact, "%r != %r" % (self.__contactHandle, contact)
132 contactNumber = contact.phoneNumber
134 self.CallStateChanged(self.__contactHandle, telepathy.constants.CHANNEL_CALL_STATE_RINGING)
135 self.__cancelId = gobject.idle_add(self._on_cancel)
136 self._conn.session.backend.call(contactNumber)
139 streamState = telepathy.constants.MEDIA_STREAM_STATE_DISCONNECTED
140 streamDirection = telepathy.constants.MEDIA_STREAM_DIRECTION_BIDIRECTIONAL
141 pendingSendFlags = telepathy.constants.MEDIA_STREAM_PENDING_REMOTE_SEND
142 return [(streamId, contact, streamTypes[0], streamState, streamDirection, pendingSendFlags)]
144 @gtk_toolbox.log_exception(_moduleLogger)
145 def GetCallStates(self):
147 For org.freedesktop.Telepathy.Channel.Interface.CallState
149 Get the current call states for all contacts involved in this call.
150 @returns {Contact: telepathy.constants.CHANNEL_CALL_STATE_*}
152 return {self.__contactHandle: telepathy.constants.CHANNEL_CALL_STATE_FORWARDED}
154 @gtk_toolbox.log_exception(_moduleLogger)
155 def _on_cancel(self, *args):
156 self.CallStateChanged(self.__contactHandle, telepathy.constants.CHANNEL_CALL_STATE_FORWARDED)
158 self.__cancelId = None