Beispiel #1
0
 private void OnTextChannelClosed()
 {
     if (TextChannelClosed != null)
     {
         TextChannelClosed(this);
     }
     this.txtChannel = null;
 }
Beispiel #2
0
 /// <summary>
 /// Method to close an existing text channel
 /// </summary>
 public void RemoveTextChannel()
 {
     if (txtChannel == null)
     {
         return;
     }
     txtChannel.Received -= OnReceiveMessageHandler;
     try { txtChannel.Close(); } catch {}
     txtChannel = null;
 }
Beispiel #3
0
 /// <summary>
 /// Method to open and setup a text channel
 /// </summary>
 public void AddTextChannel(IChannelText existingTxtChannel)
 {
     if (txtChannel != null)
     {
         return;
     }
     txtChannel           = existingTxtChannel;
     txtChannel.Received += OnReceiveMessageHandler;
     txtChannel.Closed   += OnTextChannelClosed;
 }
Beispiel #4
0
        public void Dispose()
        {
            if (txtChannel != null)
            {
                try { txtChannel.Close(); } catch {}
                txtChannel = null;
            }

            if (this.mediaChannel != null)
            {
                try { this.mediaChannel.Close(); } catch {}
                mediaChannel = null;
            }
        }
Beispiel #5
0
        /// <summary>
        /// Constructor for a conversation initiated
        /// from a text channel via a remote user
        /// </summary>
        internal Conversation(
            Account account,
            ProviderUser providerUser,
            ObjectPath objectpath,
            IChannelText channel)
        {
            this.Init(account, providerUser);

            this.txtChannelObjectPath = objectpath;
            this.initiated            = false;

            txtChannel           = channel;
            txtChannel.Received += OnReceiveMessageHandler;
            txtChannel.Closed   += OnTextChannelClosed;

            AddPendingMessages();
        }
Beispiel #6
0
        /// New methods 6/7

        /// <summary>
        /// Method to open and setup a text channel
        /// </summary>
        public void AddTextChannel()
        {
            if (txtChannel != null)
            {
                return;
            }

            txtChannelObjectPath =
                tlpConnection.RequestChannel(
                    org.freedesktop.Telepathy.ChannelType.Text,
                    HandleType.Contact,
                    this.peerUser.ID,
                    true);

            txtChannel =
                Bus.Session.GetObject <IChannelText> (account.BusName, txtChannelObjectPath);
            txtChannel.Received += OnReceiveMessageHandler;
            txtChannel.Closed   += OnTextChannelClosed;
        }
        /// <summary>
        ///	Method called from Account when a new channel is created
        /// </summary>
        internal static void ProcessNewChannel(
            Account account,
            ObjectPath channelPath,
            string channelType,
            HandleType handleType,
            uint handle,
            bool suppressHandler)
        {
            Logger.Debug ("ConversationManager::ProcessNewChannel - called");
            bool createdNewConversation = false;
            Conversation conversation = null;
            ChatType chattype = ChatType.Text;
            ProviderUser peerUser = null;

            switch (channelType)
            {
                case "org.freedesktop.Telepathy.Channel.Type.Text":
                {
                    IChannelText txtChannel = null;
                    if (handle == 0) return;

                    // Check if we have an existing conversation with the peer user
                    try {
                        peerUser = ProviderUserManager.GetProviderUser (handle);
                        if (peerUser == null) return;

                        txtChannel =
                            Bus.Session.GetObject<IChannelText> (
                                account.BusName,
                                channelPath);

                        conversation = ConversationManager.GetExistingConversation (peerUser);
                        if (conversation.ActiveTextChannel == false) {
                            conversation.AddTextChannel (txtChannel);
                            conversation.IndicateReceivedMessages ();
                        }
                    } catch (Exception ex) {
                        Logger.Debug (ex.Message);
                    }

                    if (conversation == null) {
                        try
                        {
                            Logger.Debug ("creating conversation object");
                            conversation =
                                new Conversation (account, peerUser, channelPath, txtChannel);
                            conversations.Add (conversation);
                            createdNewConversation = true;
                            Logger.Debug ("created new conversation object");
                        }
                        catch (Exception es)
                        {
                            Logger.Debug (es.Message);
                            Logger.Debug (es.StackTrace);
                        }
                    }
                    break;
                }

                case "org.freedesktop.Telepathy.ChannelType.StreamedMedia":
                {
                    // Check if we have an existing conversation with the peer user
                    IChannelStreamedMedia mediaChannel = null;
                    try {
                        mediaChannel =
                            Bus.Session.GetObject<IChannelStreamedMedia> (
                                account.BusName,
                                channelPath);

                        peerUser = ProviderUserManager.GetProviderUser (mediaChannel.Members[0]);
                        if (peerUser == null) return;

                        mediaChannel.AddMembers (mediaChannel.LocalPendingMembers, String.Empty);
                        conversation = ConversationManager.GetExistingConversation (peerUser);
                        conversation.AddMediaChannel (channelPath, mediaChannel);

                        chattype = ChatType.Audio;
                        StreamInfo[] streams = mediaChannel.ListStreams ();

                        Logger.Debug ("#streams: {0}", streams.Length);
                        foreach (StreamInfo si in streams)
                            if (si.Type == StreamType.Video) {
                                chattype = ChatType.Video;
                                break;
                            }

                        // FIXME::Pump conversation to create the channel
                        Logger.Debug (
                            "An existing conversation with {0} already exists",
                            peerUser.Uri);
                    } catch{}

                    if (peerUser == null) return;

                    if (conversation == null) {
                        try
                        {
                            Logger.Debug ("creating conversation object");
                            conversation =
                                new Conversation (account, peerUser, channelPath, mediaChannel);
                            conversations.Add (conversation);
                            chattype = ChatType.Audio;
                            StreamInfo[] streams = mediaChannel.ListStreams ();

                            Logger.Debug ("#streams: {0}", streams.Length);
                            foreach (StreamInfo si in streams)
                                if (si.Type == StreamType.Video) {
                                    chattype = ChatType.Video;
                                    break;
                                }

                            createdNewConversation = true;
                            Logger.Debug ("created new conversation object");
                        }
                        catch (Exception es)
                        {
                            Logger.Debug (es.Message);
                            Logger.Debug (es.StackTrace);
                        }
                    }
                    break;

                    /*
                    if(ichannel.Members.Length > 0) {
                        foreach(uint ch in ichannel.Members) {
                            Logger.Debug("Member in ichannel.Members {0}", ch);
                        }

                    }
                    if(ichannel.Members.Length > 0) {
                        peerHandle = ichannel.Members[0];
                    }
                    else
                        return;
                    */

                    /*
                    if (handle == 0) {

                        if (ichannel.LocalPendingMembers.Length > 0) {
                            Logger.Debug ("Incoming media conversation");
                            handle = ichannel.LocalPendingMembers[0];
                        } else if (ichannel.RemotePendingMembers.Length > 0) {
                            handle = ichannel.RemotePendingMembers[0];
                            Logger.Debug ("Pulled the handle from ichannel.RemotePendingMembers");
                            return;
                        } else if (ichannel.Members.Length > 0) {
                            handle = ichannel.Members[0];
                            Logger.Debug ("Pulled the handle from ichannel.Members");
                            return;
                        } else {
                            Logger.Debug ("Could not resolve the remote handle");
                            return;
                        }
                    } else {
                        Logger.Debug ("Handle was non-zero {0} - returning", handle);
                        return;
                    }

                    if (handle == this.tlpConnection.SelfHandle) {
                        Logger.Debug ("Handle was me - yay");
                        uint[] meHandles = {handle};

                        uint[] ids = {ichannel.Members[0]};

                        // Check if we have an existing conversation with the peer user
                        ProviderUser puMe = null;
                        ProviderUser puPeer = null;

                        try {
                            puMe = ProviderUserManager.GetProviderUser (handle);
                            puPeer = ProviderUserManager.GetProviderUser(peerHandle);
                        } catch{}

                        if (puMe == null) return;
                        if (puPeer == null) return;

                        if (ConversationManager.Exist (puPeer) == true) {
                            Logger.Debug ("An existing conversation with {0} already exists", puPeer.Uri);
                            return;
                        }

                        ichannel.AddMembers(meHandles, String.Empty);

                        Logger.Debug ("Peer: {0}", peer.Id);
                        Logger.Debug ("Peer Name: {0}", peer.DisplayName);

                        try
                        {
                            Logger.Debug ("creating conversation object");
                            conversation = ConversationManager.Create (this, peer, false);
                            IChannelText txtChannel =
                                Bus.Session.GetObject<IChannelText> (busName, channelPath);

                            conversation.SetTextChannel (txtChannel);
                            conversation.SetMediaChannel (ichannel, channelPath);
                            Logger.Debug ("created new conversation object");

                            conversation.SetPreviewWindow (cw.PreviewWindowId);
                            conversation.SetPeerWindow (cw.VideoWindowId);
                            conversation.StartVideo (false);
                        }
                        catch (Exception es)
                        {
                            Logger.Debug (es.Message);
                            Logger.Debug (es.StackTrace);
                        }
                    }

                    break;
                    */
                }

                default:
                    break;
            }

            // If successfully created a conversation and have registered consumers
            // of the callback event - fire the rocket
            if (conversation != null)
            {
                if (createdNewConversation == true && NewIncomingConversation != null)
                    NewIncomingConversation (conversation, chattype);
                else if (chattype == ChatType.Audio) {
                    conversation.IndicateAudioCall ();
                } else if (chattype == ChatType.Video) {
                    conversation.IndicateVideoCall ();
                }
            }
        }
Beispiel #8
0
 private void OnTextChannelClosed()
 {
     if (TextChannelClosed != null)
         TextChannelClosed (this);
     this.txtChannel = null;
 }
Beispiel #9
0
 /// <summary>
 /// Method to close an existing text channel
 /// </summary>
 public void RemoveTextChannel()
 {
     if (txtChannel == null) return;
     txtChannel.Received -= OnReceiveMessageHandler;
     try {txtChannel.Close();} catch{}
     txtChannel = null;
 }
Beispiel #10
0
        public void Dispose()
        {
            if (txtChannel != null)	{
                try {txtChannel.Close();} catch{}
                txtChannel = null;
            }

            if (this.mediaChannel != null) {
                try {this.mediaChannel.Close();} catch{}
                mediaChannel = null;
            }
        }
Beispiel #11
0
 /// <summary>
 /// Method to open and setup a text channel
 /// </summary>
 public void AddTextChannel(IChannelText existingTxtChannel)
 {
     if (txtChannel != null) return;
     txtChannel = existingTxtChannel;
     txtChannel.Received += OnReceiveMessageHandler;
     txtChannel.Closed += OnTextChannelClosed;
 }
Beispiel #12
0
        /// New methods 6/7
        /// <summary>
        /// Method to open and setup a text channel
        /// </summary>
        public void AddTextChannel()
        {
            if (txtChannel != null) return;

            txtChannelObjectPath =
                tlpConnection.RequestChannel (
                    org.freedesktop.Telepathy.ChannelType.Text,
                    HandleType.Contact,
                    this.peerUser.ID,
                    true);

            txtChannel =
                Bus.Session.GetObject<IChannelText> (account.BusName, txtChannelObjectPath);
            txtChannel.Received += OnReceiveMessageHandler;
            txtChannel.Closed += OnTextChannelClosed;
        }
Beispiel #13
0
        /// <summary>
        /// Constructor for a conversation initiated
        /// from a text channel via a remote user
        /// </summary>
        internal Conversation(
			Account account, 
			ProviderUser providerUser,
			ObjectPath objectpath,
			IChannelText channel)
        {
            this.Init (account, providerUser);

            this.txtChannelObjectPath = objectpath;
            this.initiated = false;

            txtChannel = channel;
            txtChannel.Received += OnReceiveMessageHandler;
            txtChannel.Closed += OnTextChannelClosed;

            AddPendingMessages ();
        }