Beispiel #1
0
        public Phone(Account account)
        {
            Debug.Assert(null != account, "Phone requires an Account to make calls.");
            this.account = account;
            linphone     = new Linphone();
            linphone.RegistrationStateChangedEvent += (Linphone.LinphoneRegistrationState state) => {
                switch (state)
                {
                case Linphone.LinphoneRegistrationState.LinphoneRegistrationProgress:
                    connectState = ConnectState.Progress;
                    break;

                case Linphone.LinphoneRegistrationState.LinphoneRegistrationFailed:
                    linphone.DestroyPhone();
                    if (ErrorEvent != null)
                    {
                        ErrorEvent(null, Error.RegisterFailed);
                    }
                    break;

                case Linphone.LinphoneRegistrationState.LinphoneRegistrationCleared:
                    connectState = ConnectState.Disconnected;
                    if (PhoneDisconnectedEvent != null)
                    {
                        PhoneDisconnectedEvent();
                    }
                    break;

                case Linphone.LinphoneRegistrationState.LinphoneRegistrationOk:
                    connectState = ConnectState.Connected;
                    if (PhoneConnectedEvent != null)
                    {
                        PhoneConnectedEvent();
                    }
                    break;

                case Linphone.LinphoneRegistrationState.LinphoneRegistrationNone:
                default:
                    break;
                }
            };

            linphone.ErrorEvent += (call, message) => {
                Console.WriteLine("Error: {0}", message);
                if (ErrorEvent != null)
                {
                    ErrorEvent(call, Error.UnknownError);
                }
            };

            linphone.CallStateChangedEvent += (Call call) => {
                Call.CallState state = call.GetState();

                switch (state)
                {
                case Call.CallState.Active:
                    lineState = LineState.Busy;
                    if (CallActiveEvent != null)
                    {
                        CallActiveEvent(call);
                    }
                    break;

                case Call.CallState.Loading:
                    lineState = LineState.Busy;
                    if (call.GetCallType() == Call.CallType.Incoming)
                    {
                        if (IncomingCallEvent != null)
                        {
                            IncomingCallEvent(call);
                        }
                    }
                    if (call.GetCallType() == Call.CallType.Outcoming)
                    {
                        if (LoadEvent != null)
                        {
                            LoadEvent(call);
                        }
                    }
                    break;

                case Call.CallState.Error:
                    this.lineState = LineState.Free;
                    if (ErrorEvent != null)
                    {
                        ErrorEvent(null, Error.CallError);
                    }
                    break;

                case Call.CallState.Completed:
                default:
                    this.lineState = LineState.Free;
                    if (CallCompletedEvent != null)
                    {
                        CallCompletedEvent(call);
                    }
                    break;
                }
            };
        }
Beispiel #2
0
        public Phone(Account account)
        {
            Debug.Assert (null != account, "Phone requires an Account to make calls.");
            this.account = account;
            linphone = new Linphone ();
            linphone.RegistrationStateChangedEvent += (Linphone.LinphoneRegistrationState state) => {
                switch (state) {
                    case Linphone.LinphoneRegistrationState.LinphoneRegistrationProgress:
                        connectState = ConnectState.Progress;
                        break;

                    case Linphone.LinphoneRegistrationState.LinphoneRegistrationFailed:
                        linphone.DestroyPhone();
                        if (ErrorEvent != null) ErrorEvent (null, Error.RegisterFailed);
                        break;

                    case Linphone.LinphoneRegistrationState.LinphoneRegistrationCleared:
                        connectState = ConnectState.Disconnected;
                        if (PhoneDisconnectedEvent != null) PhoneDisconnectedEvent();
                        break;

                    case Linphone.LinphoneRegistrationState.LinphoneRegistrationOk:
                        connectState = ConnectState.Connected;
                        if (PhoneConnectedEvent != null) PhoneConnectedEvent();
                        break;

                    case Linphone.LinphoneRegistrationState.LinphoneRegistrationNone:
                    default:
                        break;
                }
            };

            linphone.ErrorEvent += (call, message) => {
                Console.WriteLine ("Error: {0}", message);
                if (ErrorEvent != null) ErrorEvent (call, Error.UnknownError);
            };

            linphone.CallStateChangedEvent += (Call call) => {
                Call.CallState state = call.GetState();

                switch (state) {
                case Call.CallState.Active:
                    lineState = LineState.Busy;
                    if (CallActiveEvent != null)
                        CallActiveEvent (call);
                    break;

                case Call.CallState.Loading:
                    lineState = LineState.Busy;
                    if (call.GetCallType () == Call.CallType.Incoming)
                        if (IncomingCallEvent != null)
                            IncomingCallEvent (call);
                    break;

                case Call.CallState.Error:
                    this.lineState = LineState.Free;
                    if (ErrorEvent != null) ErrorEvent(null, Error.CallError);
                    if (CallCompletedEvent != null)
                        CallCompletedEvent(call);
                    break;

                case Call.CallState.Completed:
                default:
                    this.lineState = LineState.Free;
                    if (CallCompletedEvent != null)
                        CallCompletedEvent (call);
                    break;
                }

            };
        }