/// <summary> /// For creating a dialog to handle an incoming IM conversation /// </summary> /// <param name="rtcClient"></param> /// <param name="activeSession"></param> public RtcDlg(Microsoft.Ccf.Csr.Rtc.RtcClient rtcClient, Microsoft.Ccf.Csr.Rtc.Session activeSession) { // // Required for Windows Form Designer support // InitializeComponent(); this.rtcClient = rtcClient; sipAddress = null; firstName = lastName = ""; header.Text = ""; // make a sound indicating a new IM conversation try { rtcClient.PlayRing(RingType.Message, true); } catch { // OK to ignore this exception as it is caused by absence of working audio device. } // save the active session this.activeSession = activeSession; statusBar.Text = localize.RTCDLG_MSG_ANSWERING; information.Text = localize.RTCDLG_INFO; }
/// <summary> /// Fired when a session enters the disconnected state. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void activeSession_Disconnected(object sender, SessionEventArgs e) { if (activeSession != null && e.Session.GetHashCode() == activeSession.GetHashCode()) { activeSession.Terminate(); activeSession = null; } statusBar.Text = localize.RTCDLG_TEXTMSG_CONVERSATION_CLOSED; }
/// <summary> /// Called when the IM conversation is ended. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void RtcDlg_Closing(object sender, System.ComponentModel.CancelEventArgs e) { try { if (null != activeSession) { lock ( activeSession ) { activeSession.Terminate(); activeSession = null; } } } finally { // indicate another outbound request may be made ExistingRequest = false; } }
private void btnSend_Click(object sender, System.EventArgs e) { try { string text = sendText.Text.Trim(); if (text != String.Empty) { lock (this) { // If not connected, establish connection first. if (activeSession == null) { if (sipAddress == null || sipAddress == String.Empty) { Logging.Error(Application.ProductName, localize.RTCDLG_MSGBOX_MSG_UNABLE_REACH); return; } activeSession = rtcClient.CreateIMSession(); if (null != activeSession) { lock ( activeSession ) { activeSession.Connected += new Microsoft.Ccf.Csr.Rtc.SessionEventHandler(this.activeSession_Connected); activeSession.Disconnected += new Microsoft.Ccf.Csr.Rtc.SessionEventHandler(this.activeSession_Disconnected); activeSession.AddParticipant(sipAddress, firstName + " " + lastName); // first send some introductory info string xmlHeader; xmlHeader = "<request><subject>" + subject + "</subject><context>" + context + "</context></request>"; // now send message activeSession.SendMessage(xmlHeader); activeSession.SendMessage(text); } } } else { lock ( activeSession ) { // Connection will not actually take place until first message is sent activeSession.SendMessage(text); } } // conversationText.Rtf += "\r\n\\bYou say:\\b0\n " + sendText.Text.Trim(); conversationText.Text += localize.RTCDLG_TEXTMSG_YOUSAY + " " + text; scrollToBottom(); sendText.Text = String.Empty; } sendText.Focus(); } } catch (Exception exp) { Logging.Error(Application.ProductName, localize.RTCDLG_ERRMSG_EXCEPTION, exp); } }