Beispiel #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                selectedAddress.Open(TAPIMEDIATYPES.AUDIO);
            }
            catch (TapiException ex)
            {
                MessageBox.Show(ex.Message);
            }

            currCall = selectedAddress.CreateCall(textBox1.Text, LINEADDRESSTYPES.PhoneNumber, TAPIMEDIATYPES.AUDIO);
            if (currCall != null)
            {
                try
                {
                    currCall.Connect(false);
                }
                catch (TapiException ex)
                {
                    MessageBox.Show(ex.Message);
                }

                // This must be done AFTER call is connected.  Otherwise it will not
                // associate the terminal.  This is a requirement of TAPI3 itself.
                try
                {
                    playbackTerminal = currCall.RequestTerminal(
                        TTerminal.FilePlaybackTerminal,
                        TAPIMEDIATYPES.AUDIO, JulMar.Tapi3.TERMINAL_DIRECTION.TD_CAPTURE);
                    if (playbackTerminal != null)
                    {
                        playbackTerminal.MediaPlayList = new string[] { MESSAGE_PROMPT };
                        currCall.SelectTerminalOnCall(playbackTerminal);
                    }
                    else
                    {
                        MessageBox.Show("Failed to retrieve playback terminal.");
                    }
                }
                catch (TapiException ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Beispiel #2
0
        private static void InitiateCall(string phoneNumber)
        {
            string lineToUse = Configuration.Container.lineToUse;

            log.Info(String.Format("Creating call via line '{0}'.", lineToUse));
            TAddress line = tapi.Addresses.SingleOrDefault(a => a.AddressName == lineToUse);

            // Always assumes 0 prefix is needed to dial out.
            TCall call = line.CreateCall("0" + phoneNumber, LINEADDRESSTYPES.PhoneNumber, TAPIMEDIATYPES.AUDIO);

            try {
                call.Connect(false);
            }
            catch (TapiException ex) {
                log.Error("TapiException: ", ex);
                return;
            }

            log.Info(String.Format("Calling '{0}'...", phoneNumber));
        }
Beispiel #3
0
        private void OnDial(object sender, EventArgs e)
        {
            TAddress         addr     = (TAddress)cbAddress.SelectedItem;
            LINEADDRESSTYPES addrType = (LINEADDRESSTYPES)cbDestinationType.SelectedItem;

            TAPIMEDIATYPES mediaType = TAPIMEDIATYPES.AUDIO;

            if (addr.QueryMediaType(TAPIMEDIATYPES.VIDEO))
            {
                mediaType |= TAPIMEDIATYPES.VIDEO;
            }

            try
            {
                addr.Open(mediaType);
            }
            catch (TapiException ex)
            {
                // Invalid media mode? Try just datamodem for unimodem.
                if (ex.ErrorCode == unchecked ((int)0x80040004))
                {
                    try
                    {
                        addr.Open(TAPIMEDIATYPES.DATAMODEM);
                    }
                    catch
                    {
                        toolStripStatusLabel1.Text = ex.Message;
                    }
                }
                else
                {
                    toolStripStatusLabel1.Text = ex.Message;
                }
            }

            // Create a call -- this should always succeed
            currCall = addr.CreateCall(textDestination.Text, addrType, mediaType);
            if (currCall != null)
            {
                // Get the playback terminal from the call
                try
                {
                    playbackTerminal = currCall.RequestTerminal(
                        TTerminal.FilePlaybackTerminal,
                        TAPIMEDIATYPES.AUDIO, TERMINAL_DIRECTION.TD_CAPTURE);
                    if (playbackTerminal != null)
                    {
                        playbackTerminal.MediaPlayList = new string[] { PLAY_FILENAME };
                        //string[] names = playbackTerminal.MediaPlayList;
                        //playbackTerminal.Name;
                        //currCall.SelectTerminalOnCall(playbackTerminal);
                    }
                    else
                    {
                        MessageBox.Show("Failed to retrieve playback terminal.");
                    }
                }
                catch (TapiException ex)
                {
                    MessageBox.Show(ex.Message);
                }


                //// If the address supports media streams, then select terminals on it.
                //if (addr.SupportsMediaStreams)
                //{
                //    // This walks through the streams of the call and selects the default terminal
                //    // for each one.
                //    currCall.SelectDefaultTerminals();
                //}

                try
                {
                    // Connect the call
                    currCall.Connect(false);
                    toolStripStatusLabel1.Text = "Placing call...";
                }
                catch (TapiException ex)
                {
                    toolStripStatusLabel1.Text = ex.Message;
                }
            }
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            TTapi tapi = new JulMar.Tapi3.TTapi();
            TCall call = null; TAddress modemAddr = null;

            Console.WriteLine("{0} found", tapi.Initialize());

            tapi.TE_CALLNOTIFICATION += delegate(object sender, TapiCallNotificationEventArgs e)
            {
                Console.WriteLine("New call {0} detected from {1}", e.Call.ToString(), e.Event);
            };
            tapi.TE_CALLSTATE += delegate(object sender, TapiCallStateEventArgs e)
            {
                Console.WriteLine("{0}:{4} has changed state to {1} due to {2} - current={3}:{5}", e.Call, e.State, e.Cause, e.Call == call, e.Call.GetHashCode(), (call != null) ? call.GetHashCode() : 0);

                if (e.State == CALL_STATE.CS_INPROGRESS && e.Call == call)
                {
                    Console.WriteLine("Dropping call");
                    e.Call.Disconnect(DISCONNECT_CODE.DC_NORMAL);
                }
            };

            foreach (TPhone phone in tapi.Phones)
            {
                using (phone)
                {
                    phone.Open(PHONE_PRIVILEGE.PP_MONITOR);
                    Console.WriteLine("{0}\nTotal buttons: {1}", phone.Display, phone.get_PhoneCapability(PHONECAPS_LONG.PCL_NUMBUTTONLAMPS));
                }
            }

            foreach (TAddress addr in tapi.Addresses)
            {
                if (String.Compare(addr.ServiceProviderName, "unimdm.tsp", true) == 0 && addr.QueryMediaType(TAPIMEDIATYPES.AUDIO))
                {
                    modemAddr = addr;
                }
            }

            if (modemAddr != null)
            {
                Console.WriteLine("{0} = {1} ({3}) [{2}]", modemAddr.AddressName, modemAddr.State, modemAddr.ServiceProviderName, modemAddr.DialableAddress);
                modemAddr.Monitor(TAPIMEDIATYPES.AUDIO);

                ConsoleKey ki = ConsoleKey.A;
                while (ki != ConsoleKey.Q)
                {
                    // Flip the auto-destroy flag
                    if (ki == ConsoleKey.D)
                    {
                        tapi.AutoDestroyCalls = !tapi.AutoDestroyCalls;
                        Console.WriteLine("Set AutoDestroy to {0}", tapi.AutoDestroyCalls);
                    }

                    // List existing calls
                    if (ki == ConsoleKey.L)
                    {
                        foreach (TCall _call in modemAddr.Calls)
                        {
                            Console.WriteLine("Existing call found: {0}:{1}", _call, _call.GetHashCode());
                            _call.Dispose(); // Go ahead and dump it
                        }
                    }

                    // Create a new call
                    else
                    {
                        call = modemAddr.CreateCall("5551213", LINEADDRESSTYPES.PhoneNumber, TAPIMEDIATYPES.DATAMODEM);
                        Console.WriteLine("Created new call {0}:{1}", call, call.GetHashCode());
                        try
                        {
                            // This will fail if existing call interface is still around (i.e. not disposed)
                            call.Connect(false);
                        }
                        catch (TapiException ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                    }
                    Console.WriteLine("Press a key to try another call.. Q to quit");
                    ki = Console.ReadKey().Key;
                }
            }

            tapi.Shutdown();

            // Call should be disposed here.. state will be CS_UNKNOWN
            if (call != null)
            {
                Console.WriteLine("{0} {1}", call, call.CallState);
            }
        }