Exemplo n.º 1
0
        private void DoConnectCOMAPI()
        {
            try
            {
                // Connect to the Plantronics COM API
                _sessionManager = new COMSessionManager();
                _sessionManager.Register(AppName, out _session);

                _sessionManagerEvents = (ICOMSessionManagerEvents_Event)_sessionManager;
                // obtain session manager events interface
                _sessionManagerEvents.onDeviceStateChanged += _sessionManagerEvents_onDeviceStateChanged;
                // register for device state changed events (device arrival / removal)
                _sessionManagerEvents.onCallStateChanged += _sessionManagerEvents_onCallStateChanged;

                _session.onCallStateChanged += _session_onCallStateChanged;
                // register for call state changed events (headset call control)

                _callCommand = _session.GetCallCommand();
                // obtain Plantronics object for controlling call state of Plantronics device
                AttachDevice(); // register for device events and obtain device listener
                _apiConnected = true;
                OnSDKInfo(new SDKInfoArgs(SDKInfoType.sdk_connected, "SDK now connected"));
            }
            catch (Exception e)
            {
                DoTidyUpSDK(_session != null);
                OnSDKError(new SDKErrorArgs(SDKErrorType.sdk_connection_failed, e.ToString()));
                DoAttemptReconnectAfterDelay();
            }
        }
Exemplo n.º 2
0
        private static int _callid; // variable to track call id between my app and Plantronics

        static void Main()
        {
            Console.WriteLine("C# Plantronics COM API Sample");
            bool quit = false;

            // Connect to the Plantronics COM API
            _sessionManager = new COMSessionManager();
            _sessionManager.Register("My App", out _session);

            _sessionManagerEvents = (ICOMSessionManagerEvents_Event)_sessionManager;                  // obtain session manager events interface
            _sessionManagerEvents.onDeviceStateChanged += _sessionManagerEvents_onDeviceStateChanged; // register for device state changed events (device arrival / removal)

            _session.onCallStateChanged += _session_onCallStateChanged;                               // register for call state changed events (headset call control)

            _callCommand = _session.GetCallCommand();                                                 // obtain Plantronics object for controlling call state of Plantronics device
            AttachDevice();                                                                           // register for device events and obtain device listener

            while (!quit)
            {
                ShowMenu();
                string cmd = Console.ReadLine();
                switch (cmd)
                {
                case "1":
                    _callid++;
                    DoIncomingCall(_callid, "Bob%20Smith");     // inform Plantronics my app has an incoming (ringing) call
                    break;

                case "2":
                    _callid++;
                    DoOutgoingCall(_callid, "Bob%20Smith");     // inform Plantronics my app has an outgoing call
                    break;

                case "3":
                    DoAnswerCall(_callid);     // inform Plantronics my app has now answered an incoming (ringing) call
                    break;

                case "4":
                    DoHoldCall(_callid);     // place call on hold
                    break;

                case "5":
                    DoResumeCall(_callid);     // resume the call
                    break;

                case "6":
                    DoMuteCall(true);     // mute the headset (note for wireless products, audio link must be active)
                    break;

                case "7":
                    DoMuteCall(false);     // unmute the headset (note for wireless products, audio link must be active)
                    break;

                case "8":
                    DoTerminateCall(_callid);     // inform Plantronics my app has now terminated the call
                    break;

                case "0":
                    quit = true;
                    break;

                default:
                    Console.WriteLine("Unrecognised menu choice.");
                    break;
                }
            }

            // Cleanup the Plantronics COM API
            DetachDevice();
            _session.onCallStateChanged -= _session_onCallStateChanged;
            _sessionManagerEvents.onDeviceStateChanged -= _sessionManagerEvents_onDeviceStateChanged;
            _sessionManager.Unregister(_session);
            Marshal.ReleaseComObject(_session);
            Marshal.ReleaseComObject(_sessionManager);
        }