Exemple #1
0
    public Call GenerateCall()
    {
        string   callerName     = GenerateName();
        float    callLegitimacy = GenerateLegitimacy();
        Location callLocation   = GenerateLocation();

        Call.CallType callType = GenerateCalltype(callLocation);
        int           scale    = GenerateScale();

        // set up those values

        Call newCall = new Call();

        newCall.Setup(callerName, callLegitimacy, callLocation, callType, scale, new List <Dialog>());
        newCall.DebugPrint();
        return(newCall);
    }
Exemple #2
0
        void OnCallStateChanged(IntPtr lc, IntPtr call, LinphoneCallState cstate, string message)
        {
            if (linphoneCore == IntPtr.Zero || !running)
            {
                return;
            }
            #if (TRACE)
            Console.WriteLine("OnCallStateChanged: {0}", cstate);
            #endif

            Call.CallState newstate = Call.CallState.None;
            Call.CallType  newtype  = Call.CallType.None;
            string         from     = "";
            string         to       = "";
            IntPtr         addressStringPtr;

            // detecting direction, state and source-destination data by state
            switch (cstate)
            {
            case LinphoneCallState.LinphoneCallIncomingReceived:
            case LinphoneCallState.LinphoneCallIncomingEarlyMedia:
                newstate         = Call.CallState.Loading;
                newtype          = Call.CallType.Incoming;
                addressStringPtr = linphone_call_get_remote_address_as_string(call);
                if (addressStringPtr != IntPtr.Zero)
                {
                    from = Marshal.PtrToStringAnsi(addressStringPtr);
                }
                to = identity;
                break;

            case LinphoneCallState.LinphoneCallConnected:
            case LinphoneCallState.LinphoneCallStreamsRunning:
            case LinphoneCallState.LinphoneCallPausedByRemote:
            case LinphoneCallState.LinphoneCallUpdatedByRemote:
                newstate = Call.CallState.Active;
                break;

            case LinphoneCallState.LinphoneCallOutgoingInit:
            case LinphoneCallState.LinphoneCallOutgoingProgress:
            case LinphoneCallState.LinphoneCallOutgoingRinging:
            case LinphoneCallState.LinphoneCallOutgoingEarlyMedia:
                newstate         = Call.CallState.Loading;
                newtype          = Call.CallType.Outcoming;
                addressStringPtr = linphone_call_get_remote_address_as_string(call);
                if (addressStringPtr != IntPtr.Zero)
                {
                    to = Marshal.PtrToStringAnsi(addressStringPtr);
                }
                from = this.identity;
                break;

            case LinphoneCallState.LinphoneCallError:
                newstate = Call.CallState.Error;
                break;

            case LinphoneCallState.LinphoneCallReleased:
            case LinphoneCallState.LinphoneCallEnd:
                newstate = Call.CallState.Completed;
                if (linphone_call_params_get_record_file(callsDefaultParams) != IntPtr.Zero)
                {
                    linphone_call_stop_recording(call);
                }
                break;

            default:
                break;
            }

            LinphoneCall existCall = FindCall(call);

            if (existCall == null)
            {
                existCall = new LinphoneCall();
                existCall.SetCallState(newstate);
                existCall.SetCallType(newtype);
                existCall.SetFrom(from);
                existCall.SetTo(to);
                existCall.LinphoneCallPtr = call;

                calls.Add(existCall);

                if ((CallStateChangedEvent != null))
                {
                    CallStateChangedEvent(existCall);
                }
            }
            else
            {
                if (existCall.GetState() != newstate)
                {
                    existCall.SetCallState(newstate);
                    CallStateChangedEvent(existCall);
                }
            }
        }
        // TODO: Add OnCallStateChanged and OnChatMessageStateChanged.
        void OnCallStateChanged(IntPtr lc, IntPtr call, LinphoneCallState cstate, string message)
        {
            if (linphoneCore == IntPtr.Zero || !running)
            {
                return;
            }
            #if (TRACE)
            Console.WriteLine("OnCallStateChanged: {0}", cstate);
            #endif

            Call.State    newstate  = Call.State.Idle;
            Call.CallType newtype   = Call.CallType.None;
            string        from      = "";
            string        to        = "";
            string        peer_name = nameFromAddress(linphone_call_get_remote_address(call));
            IntPtr        addressStringPtr;

            // detecting direction, state and source-destination data by state
            switch (cstate)
            {
            case LinphoneCallState.LinphoneCallIncomingReceived:
                newstate         = Call.State.IncomingRinging;
                newtype          = Call.CallType.Incoming;
                addressStringPtr = linphone_call_get_remote_address_as_string(call);
                if (addressStringPtr != IntPtr.Zero)
                {
                    from = Marshal.PtrToStringAnsi(addressStringPtr);
                    to   = this.identity;
                }
                break;

            case LinphoneCallState.LinphoneCallIncomingEarlyMedia:
                newstate         = Call.State.IncomingEarlyMedia;
                newtype          = Call.CallType.Incoming;
                addressStringPtr = linphone_call_get_remote_address_as_string(call);
                if (addressStringPtr != IntPtr.Zero)
                {
                    from = Marshal.PtrToStringAnsi(addressStringPtr);
                    to   = this.identity;
                }
                break;

            case LinphoneCallState.LinphoneCallConnected:
                newstate = Call.State.Connected;
                break;

            case LinphoneCallState.LinphoneCallStreamsRunning:
                newstate = Call.State.StreamsRunning;
                break;

            case LinphoneCallState.LinphoneCallPausedByRemote:
                newstate = Call.State.PausedByRemote;
                break;

            case LinphoneCallState.LinphoneCallUpdatedByRemote:
                newstate = Call.State.UpdatedByRemote;
                break;

            case LinphoneCallState.LinphoneCallOutgoingInit:
                newstate         = Call.State.OutgoingStart;
                addressStringPtr = linphone_call_get_remote_address_as_string(call);
                if (addressStringPtr != IntPtr.Zero)
                {
                    from = this.identity;
                    to   = Marshal.PtrToStringAnsi(addressStringPtr);
                }
                break;

            case LinphoneCallState.LinphoneCallOutgoingProgress:
                newstate = Call.State.InProgress;
                break;

            case LinphoneCallState.LinphoneCallOutgoingRinging:
                newstate = Call.State.OutgoingRinging;
                break;

            case LinphoneCallState.LinphoneCallOutgoingEarlyMedia:
                newstate         = Call.State.OutgoingEarlyMedia;
                newtype          = Call.CallType.Outcoming;
                addressStringPtr = linphone_call_get_remote_address_as_string(call);
                if (addressStringPtr != IntPtr.Zero)
                {
                    from = this.identity;
                    to   = Marshal.PtrToStringAnsi(addressStringPtr);
                }
                break;

            case LinphoneCallState.LinphoneCallError:
                newstate = Call.State.Error;
                break;

            case LinphoneCallState.LinphoneCallReleased:
                newstate = Call.State.Released;

                break;

            case LinphoneCallState.LinphoneCallEnd:
                newstate = Call.State.Ended;
                //hangupCall(call);
                if (linphone_call_params_get_record_file(calls_default_params) != IntPtr.Zero)
                {
                    linphone_call_stop_recording(call);
                }
                break;

            default:
                break;
            }

            //Change the calls state or create a new call if it doesn't exist yet
            LinphoneCall existCall = FindCall(call);
            if (existCall == null)
            {
                existCall           = new LinphoneCall();
                existCall.state     = newstate;
                existCall.call_type = newtype;
                existCall.from      = from;
                existCall.to        = to;
                existCall.ptr       = call;
                existCall.peer_name = peer_name;

                calls.Add(existCall);

                if ((CallStateChangedEvent != null))
                {
                    CallStateChangedEvent(existCall);
                }
            }
            else
            {
                if (existCall.state != newstate)
                {
                    existCall.state = newstate;
                    CallStateChangedEvent(existCall);
                }
            }
        }
Exemple #4
0
 public void NewCall(Call.CallType callType)
 {
     CallList.Add(new Call(callType));
 }