9 _moduleLogger = logging.getLogger("channel.call")
13 telepathy.server.ChannelTypeStreamedMedia,
14 telepathy.server.ChannelInterfaceCallState,
15 telepathy.server.ChannelInterfaceGroup,
18 def __init__(self, connection, manager, props, contactHandle):
19 self.__manager = manager
23 # HACK Older python-telepathy way
24 telepathy.server.ChannelTypeStreamedMedia.__init__(self, connection, None)
25 self._requested = props[telepathy.interfaces.CHANNEL_INTERFACE + '.Requested']
26 self._implement_property_get(
27 telepathy.interfaces.CHANNEL_INTERFACE,
28 {"Requested": lambda: self._requested}
31 # HACK Newer python-telepathy way
32 telepathy.server.ChannelTypeStreamedMedia.__init__(self, connection, manager, props)
33 telepathy.server.ChannelInterfaceCallState.__init__(self)
34 telepathy.server.ChannelInterfaceGroup.__init__(self)
35 self.__contactHandle = contactHandle
36 self._implement_property_get(
37 telepathy.interfaces.CHANNEL_TYPE_STREAMED_MEDIA,
39 "InitialAudio": self.initial_audio,
40 "InitialVideo": self.initial_video,
44 self.GroupFlagsChanged(0, 0)
46 '', [self._conn.GetSetHandle()], [], [], [contactHandle],
47 0, telepathy.CHANNEL_GROUP_CHANGE_REASON_NONE
50 def initial_audio(self):
53 def initial_video(self):
57 # HACK Older python-telepathy doesn't provide this
58 _immutable_properties = {
59 'ChannelType': telepathy.server.interfaces.CHANNEL_INTERFACE,
60 'TargetHandle': telepathy.server.interfaces.CHANNEL_INTERFACE,
61 'Interfaces': telepathy.server.interfaces.CHANNEL_INTERFACE,
62 'TargetHandleType': telepathy.server.interfaces.CHANNEL_INTERFACE,
63 'TargetID': telepathy.server.interfaces.CHANNEL_INTERFACE,
64 'Requested': telepathy.server.interfaces.CHANNEL_INTERFACE
67 for prop, iface in _immutable_properties.items():
68 props[iface + '.' + prop] = \
69 self._prop_getters[iface][prop]()
72 @gtk_toolbox.log_exception(_moduleLogger)
77 telepathy.server.ChannelTypeStreamedMedia.Close(self)
78 if self.__manager.channel_exists(self.__props):
79 # HACK Older python-telepathy requires doing this manually
80 self.__manager.remove_channel(self)
81 self.remove_from_connection()
83 @gtk_toolbox.log_exception(_moduleLogger)
84 def ListStreams(self):
86 For org.freedesktop.Telepathy.Channel.Type.StreamedMedia
90 @gtk_toolbox.log_exception(_moduleLogger)
91 def RemoveStreams(self, streams):
93 For org.freedesktop.Telepathy.Channel.Type.StreamedMedia
95 raise telepathy.errors.NotImplemented("Cannot remove a stream")
97 @gtk_toolbox.log_exception(_moduleLogger)
98 def RequestStreamDirection(self, stream, streamDirection):
100 For org.freedesktop.Telepathy.Channel.Type.StreamedMedia
102 @note Since streams are short lived, not bothering to implement this
104 _moduleLogger.info("A request was made to change the stream direction")
105 raise telepathy.errors.NotImplemented("Cannot change directions")
107 @gtk_toolbox.log_exception(_moduleLogger)
108 def RequestStreams(self, contactId, streamTypes):
110 For org.freedesktop.Telepathy.Channel.Type.StreamedMedia
112 @returns [(Stream ID, contact, stream type, stream state, stream direction, pending send flags)]
114 contact = self._conn.handle(telepathy.constants.HANDLE_TYPE_CONTACT, contactId)
115 assert self.__contactHandle == contact, "%r != %r" % (self.__contactHandle, contact)
116 contactId, contactNumber = handle.ContactHandle.from_handle_name(contact.name)
118 self.CallStateChanged(self.__contactHandle, telepathy.constants.CHANNEL_CALL_STATE_RINGING)
119 self._conn.session.backend.call(contactNumber)
120 self.CallStateChanged(self.__contactHandle, telepathy.constants.CHANNEL_CALL_STATE_FORWARDED)
123 streamState = telepathy.constants.MEDIA_STREAM_STATE_DISCONNECTED
124 streamDirection = telepathy.constants.MEDIA_STREAM_DIRECTION_BIDIRECTIONAL
125 pendingSendFlags = telepathy.constants.MEDIA_STREAM_PENDING_REMOTE_SEND
126 return [(streamId, contact, streamTypes[0], streamState, streamDirection, pendingSendFlags)]
128 @gtk_toolbox.log_exception(_moduleLogger)
129 def GetCallStates(self):
131 For org.freedesktop.Telepathy.Channel.Interface.CallState
133 Get the current call states for all contacts involved in this call.
134 @returns {Contact: telepathy.constants.CHANNEL_CALL_STATE_*}
136 return {self.__contactHandle: telepathy.constants.CHANNEL_CALL_STATE_FORWARDED}