/// <summary>
        /// Populates a Jingle message object with the basic stuff needed to initiate an audio call with speex and mu-law support.
        /// RTP payloads are hard coded and the transport is hard-coded to ICE.
        /// </summary>
        /// <param name="strLocalIP">The local IP address that the client is listening on for audio</param>
        /// <param name="nLocalPort">The local port that the client is listening on for audio</param>
        /// <returns>A Jingle object that can be further modified and supplied to InitiateNewSession()</returns>
        public static GoogleSession CreateBasicOutgoingAudioRequest(string strLocalIP, int nLocalPort)
        {
            GoogleSession sessioncontent = new GoogleSession();

            sessioncontent.Action            = GoogleSession.Initiate;
            sessioncontent.Description       = new Description();
            sessioncontent.Description.media = "audio";


            sessioncontent.Description.Payloads.Add(new Payload()
            {
                PayloadId = 9, Channels = "1", ClockRate = "16000", Name = "G722"
            });
            sessioncontent.Description.Payloads.Add(new Payload()
            {
                PayloadId = 96, Channels = "1", ClockRate = "16000", Name = "speex"
            });
            sessioncontent.Description.Payloads.Add(new Payload()
            {
                PayloadId = 97, Channels = "1", ClockRate = "8000", Name = "speex"
            });
            sessioncontent.Description.Payloads.Add(new Payload()
            {
                PayloadId = 0, Channels = "1", ClockRate = "8000", Name = "PCMU"
            });

            /// If you don't want to use ICE UDP, new a different transport object
            sessioncontent.Transport = new Transport();
            sessioncontent.Transport.Candidates.Add(new Candidate()
            {
                ipaddress = strLocalIP, port = nLocalPort
            });

            return(sessioncontent);
        }
        internal void SendGoogleSession(GoogleSession jingleinfo)
        {
            GoogleTalkIQ iq = new GoogleTalkIQ();

            iq.From        = XMPPClient.JID;
            iq.To          = RemoteJID;
            iq.Type        = IQType.set.ToString();
            iq.Session     = jingleinfo;
            iq.Session.SID = this.SessionId;

            XMPPClient.SendObject(iq);
        }
        /// <summary>
        /// Create a simple audio session jingle accept
        /// </summary>
        /// <param name="strLocalIP">The local ip address that the client is listening on for media</param>
        /// <param name="nLocalPort">The local port the client is listening on for media</param>
        /// <param name="payloads">A list of payloads that are acceptable, or null to use the default paylodas (speex, PCMU)</param>
        /// <returns>A Jingle message object that can be supplied to </returns>
        public static GoogleSession CreateBasicAudioSessionAccept(string strLocalIP, int nLocalPort, Payload[] payloads)
        {
            GoogleSession sessioncontent = new GoogleSession();

            sessioncontent.Action            = GoogleSession.Accept;
            sessioncontent.Description       = new Description();
            sessioncontent.Description.media = "audio";


            if (payloads != null)
            {
                foreach (Payload payload in payloads)
                {
                    sessioncontent.Description.Payloads.Add(payload);
                }
            }
            else
            {
                sessioncontent.Description.Payloads.Add(new Payload()
                {
                    PayloadId = 9, Channels = "1", ClockRate = "16000", Name = "G722"
                });
                sessioncontent.Description.Payloads.Add(new Payload()
                {
                    PayloadId = 96, Channels = "1", ClockRate = "16000", Name = "speex"
                });
                sessioncontent.Description.Payloads.Add(new Payload()
                {
                    PayloadId = 97, Channels = "1", ClockRate = "8000", Name = "speex"
                });
                sessioncontent.Description.Payloads.Add(new Payload()
                {
                    PayloadId = 0, Channels = "1", ClockRate = "8000", Name = "PCMU"
                });
            }

            /// If you don't want to use ICE UDP, new a different transport object
            sessioncontent.Transport = new Transport();
            sessioncontent.Transport.Candidates.Add(new Candidate()
            {
                ipaddress = strLocalIP, port = nLocalPort
            });

            return(sessioncontent);
        }
        public void SendJingle(string strSessionId, GoogleSession sessioninfo)
        {
            /// Create a new session logic and send out the intial session create request
            ///
            GoogleTalkLogic session = null;

            lock (SessionLock)
            {
                if (Sessions.ContainsKey(strSessionId) == true)
                {
                    session = Sessions[strSessionId];
                }
            }
            if (session != null)
            {
                session.SendGoogleSession(sessioninfo);
            }
        }
        public string InitiateNewSession(JID jidto, GoogleSession sessioninfo)
        {
            /// Create a new session logic and send out the intial session create request
            ///

            string          strSessionId = Guid.NewGuid().ToString();
            GoogleTalkLogic session      = new GoogleTalkLogic(this.XMPPClient, strSessionId, this);

            sessioninfo.SID = strSessionId;
            lock (SessionLock)
            {
                Sessions.Add(strSessionId, session);
            }

            session.InitiateSession(sessioninfo, jidto);

            return(strSessionId);
        }
        internal void AcceptSession(GoogleSession jingleinfo)
        {
            if (AcceptSessionMessage != null) /// we've already started a session, the user needs to create a new one
            {
                throw new Exception(string.Format("Cannot accept a session that already exists, Session [{0}] has already been accepted, client must create a new session", this.SessionId));
            }

            AcceptSessionMessage                   = new GoogleTalkIQ();
            AcceptSessionMessage.From              = XMPPClient.JID;
            AcceptSessionMessage.To                = RemoteJID;
            AcceptSessionMessage.Type              = IQType.set.ToString();
            AcceptSessionMessage.Session           = jingleinfo;
            AcceptSessionMessage.Session.Action    = GoogleSession.Accept;
            AcceptSessionMessage.Session.Initiator = XMPPClient.JID;
            AcceptSessionMessage.Session.SID       = this.SessionId;

            XMPPClient.SendObject(AcceptSessionMessage);
        }
        internal void InitiateSession(GoogleSession jingleinfo, string strJIDTo)
        {
            if (OutgoingRequestMessage != null) /// we've already started a session, the user needs to create a new one
            {
                throw new Exception(string.Format("Cannot initiate a session that already exists, Session [{0}] has already sent out an initiate session message, client must create a new session", this.SessionId));
            }

            RemoteJID = strJIDTo;

            OutgoingRequestMessage                   = new GoogleTalkIQ();
            OutgoingRequestMessage.From              = XMPPClient.JID;
            OutgoingRequestMessage.To                = RemoteJID;
            OutgoingRequestMessage.Type              = IQType.set.ToString();
            OutgoingRequestMessage.Session           = jingleinfo;
            OutgoingRequestMessage.Session.Action    = GoogleSession.Initiate;
            OutgoingRequestMessage.Session.Initiator = XMPPClient.JID;
            if (OutgoingRequestMessage.Session.SID == null)
            {
                OutgoingRequestMessage.Session.SID = Guid.NewGuid().ToString();
            }

            XMPPClient.SendObject(OutgoingRequestMessage);
        }