Help please

Hi, I am currently trying to create an application that uses the RTC API to communicate Voice via IP address of the other client and not SIP server. I am experiencing problems with the code i wrote. Just on this one line:
_session.Answer();

With the prints out i get, alot of session state change happens and when it goes into the INCOMING, it doesn't run the _session.Answer(); at all. but the application does not hang.

However in the immediate Window of VS 2005 it "prompted" the following message at some point when i try to connect the clients together:
A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in VoIP2.exe

The following is the codes:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using RTCCORELib;
namespace VoIP2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

RTCClientClass _rtc = new RTCClientClass();

IRTCSession2 _session;

private void Form1_Load(object sender, EventArgs e)
{
_rtc.Initialize();

_rtc.SetPreferredMediaTypes(0x0000000F | 0x00000002 | 0x00000001, true);

_rtc.EventFilter = 0x00000400|0x00000004|0x00000020;

_rtc.IRTCEventNotification_Event_Event += new IRTCEventNotification_EventEventHandler(RTC_IRTCEventNotification_Event_Event);

// _rtc.set_AllowedPorts(0, RTC_LISTEN_MODE.RTCLM_BOTH);

// _rtc.set_AnswerMode(RTC_SESSION_TYPE.RTCST_PC_TO_PC, RTC_ANSWER_MODE.RTCAM_OFFER_SESSION_EVENT);

_rtc.ListenForIncomingSessions = RTC_LISTEN_MODE.RTCLM_BOTH;

MessageBox.Show("Before CreateSession.", "O.o ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
_session = _rtc.CreateSession(RTC_SESSION_TYPE.RTCST_PC_TO_PC, null, null, 0);
}

private void RTC_IRTCEventNotification_Event_Event(RTC_EVENT RTCEvent, object pEvent)
{
switch (RTCEvent)
{
case RTC_EVENT.RTCE_SESSION_STATE_CHANGE:
{
MessageBox.Show("state change.", "=____=||", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
IRTCSessionStateChangeEvent sessionEvent = null;
sessionEvent = (IRTCSessionStateChangeEvent)pEvent;
OnIRTCSessionStateChangeEvent(sessionEvent);
}
break;

case RTC_EVENT.RTCE_MEDIA:
{
MessageBox.Show("Media.", "=____=||", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
IRTCMediaEvent mediaEvent = null;
mediaEvent = (IRTCMediaEvent)pEvent;
OnIRTCMediaEvent(mediaEvent);
}
break;
}
}

private void OnIRTCMediaEvent(IRTCMediaEvent mediaEvent)
{
RTC_MEDIA_EVENT_TYPE mediaType;

IVideoWindow videoWindow = null;

mediaType = mediaEvent.EventType;

switch (mediaType)
{
case RTC_MEDIA_EVENT_TYPE.RTCMET_STARTED:
{
textBox2.Text += "start \n";

videoWindow = _rtc.get_IVideoWindow(RTC_VIDEO_DEVICE.RTCVD_RECEIVE);
videoWindow.SetWindowPosition(50, 50, 40, 380);
videoWindow.Visible = 1;
}
break;

case RTC_MEDIA_EVENT_TYPE.RTCMET_STOPPED:
{
textBox2.Text += "stopped \n";

videoWindow.Visible = 0;
videoWindow = null;
}
break;

case RTC_MEDIA_EVENT_TYPE.RTCMET_FAILED:
{
MessageBox.Show("Media Failed.", "=____=||", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
break;
}
}

private void OnIRTCSessionStateChangeEvent(IRTCSessionStateChangeEvent sessionEvent)
{
RTC_SESSION_STATE sessionState;
sessionState = sessionEvent.State;

switch (sessionState)
{
case RTC_SESSION_STATE.RTCSS_INCOMING:
{
_rtc.PlayRing(RTC_RING_TYPE.RTCRT_PHONE, true);
textBox2.Text += "Incoming \n";
_session.Answer(); //this line not working
textBox2.Text += "Incoming Answer \n";
}
break;

case RTC_SESSION_STATE.RTCSS_ANSWERING:
{
textBox2.Text += "Answering \n";
}
break;

case RTC_SESSION_STATE.RTCSS_INPROGRESS:
{
textBox2.Text += "InProgress \n";
}
break;

case RTC_SESSION_STATE.RTCSS_CONNECTED:
{
_session.AddStream(0x00000002 | 0x00000001 | 0x0000000F, 0);
MessageBox.Show("Add Stream.", "Good", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
break;

case RTC_SESSION_STATE.RTCSS_DISCONNECTED:
{
MessageBox.Show("DisConnected.", "boo!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
textBox1.Visible = true;
button1.Visible = true;
button2.Visible = false;
}
break;
}
}

private void button1_Click(object sender, EventArgs e)
{
// MessageBox.Show("Before CreateSession.", "O.o ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
// _session = _rtc.CreateSession(RTC_SESSION_TYPE.RTCST_PC_TO_PC, null, null, 0);

_session.AddParticipant(textBox1.Text, "Name");
textBox1.Visible = false;
button1.Visible = false;
button2.Visible = true;
}

private void button2_Click(object sender, EventArgs e)
{
_session.Terminate(RTC_TERMINATE_REASON.RTCTR_SHUTDOWN);
MessageBox.Show("ShutDown.", "boo!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}

}
}



Answer this question

Help please

  • Vicky_Dangwal

    you must see what is the error in VoIP2.exe. Ususaly they return Error code that could hlp you to identify error.

    Unfortunately I cannot help you further as I do not know VoIP2.exe



  • Tom Serface

    first try with eventfilter put it 0x01FFFFFF
    and try to do _session=ev.session; before _session.answer();
    it should work.

  • Ian Gitlin

    er... the VoIP2.exe is the above codes i posted.



  • Help please